diff options
author | Dennis Francis <dennisfrancis.in@gmail.com> | 2021-09-02 14:33:55 +0530 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2021-09-06 08:47:50 +0200 |
commit | f547cf17a179ebd7de5c2b4dd2d00d0027a25429 (patch) | |
tree | 764038da5e3280c93099d2ca3ef2731484ece324 /chart2 | |
parent | ba1e42f05e785c30d03553acd5647eebd7cdede6 (diff) |
[API CHANGE] oox: fix import of chart date categories
Before this fix, date categories imported in oox's DataSourceContext were
stored as formatted strings according to number format code in <c:formatCode>
under the <c:cat> tree. As a result chart2 could not recognize them
as dates. This causes problems like:
* The axis that is linked to date categories cannot use the
scaling/range-selection(min/max)/increments specs mentioned as axis
properties. This results in distorted/unreadable chart renders w.r.t
the date axis.
* No re-formatting is attempted as per the number format provided for axis.
This patch introduces a role qualifer argument to the XDataProvider
interface method createDataSequenceByValueArray to support categories of
date type via this method.
When exporting to oox, write date categories and format code under
<c:cat>
<c:numRef>
<c:numCache>
This patch also fixes some discrepancies in date axis interval
computation (auto mode) found by already existing unit tests.
Change-Id: Ibc53b0a56fdddba80ba452d5567ce98d80460ea7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121525
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'chart2')
-rw-r--r-- | chart2/qa/extras/chart2dump/chart2dump.cxx | 1 | ||||
-rw-r--r-- | chart2/qa/extras/chart2dump/data/date-categories.pptx | bin | 0 -> 41931 bytes | |||
-rw-r--r-- | chart2/qa/extras/chart2dump/reference/axislabeltest/date-categories.txt | 180 | ||||
-rw-r--r-- | chart2/qa/extras/chart2export2.cxx | 39 | ||||
-rw-r--r-- | chart2/qa/extras/chart2import.cxx | 46 | ||||
-rw-r--r-- | chart2/qa/extras/charttest.hxx | 37 | ||||
-rw-r--r-- | chart2/source/inc/InternalDataProvider.hxx | 6 | ||||
-rw-r--r-- | chart2/source/tools/InternalDataProvider.cxx | 20 | ||||
-rw-r--r-- | chart2/source/view/axes/ScaleAutomatism.cxx | 4 | ||||
-rw-r--r-- | chart2/source/view/axes/VCoordinateSystem.cxx | 6 | ||||
-rw-r--r-- | chart2/source/view/charttypes/AreaChart.cxx | 4 |
11 files changed, 307 insertions, 36 deletions
diff --git a/chart2/qa/extras/chart2dump/chart2dump.cxx b/chart2/qa/extras/chart2dump/chart2dump.cxx index 28768ca68957..fc3944f494e3 100644 --- a/chart2/qa/extras/chart2dump/chart2dump.cxx +++ b/chart2/qa/extras/chart2dump/chart2dump.cxx @@ -616,6 +616,7 @@ DECLARE_DUMP_TEST(AxisLabelTest, Chart2DumpTest, false) "formated_axis_labels.odp", "percent_stacked_column_chart.odp", "tdf118150.xlsx", + "date-categories.pptx", }; for (const OUString& sTestFile : aTestFiles) diff --git a/chart2/qa/extras/chart2dump/data/date-categories.pptx b/chart2/qa/extras/chart2dump/data/date-categories.pptx Binary files differnew file mode 100644 index 000000000000..b9e0c69f32b7 --- /dev/null +++ b/chart2/qa/extras/chart2dump/data/date-categories.pptx diff --git a/chart2/qa/extras/chart2dump/reference/axislabeltest/date-categories.txt b/chart2/qa/extras/chart2dump/reference/axislabeltest/date-categories.txt new file mode 100644 index 000000000000..a9274fd7838a --- /dev/null +++ b/chart2/qa/extras/chart2dump/reference/axislabeltest/date-categories.txt @@ -0,0 +1,180 @@ +/// CID/D=0:CS=0:Axis=0,0 +// nAxisLabelsCount +22 +// xLabel->getString() +15/Jun/21 +// static_cast<sal_Int32>(aLabelFontColor) +5855577 +// fLabelFontHeight +9 +// xLabel->getString() +17/Jun/21 +// static_cast<sal_Int32>(aLabelFontColor) +5855577 +// fLabelFontHeight +9 +// xLabel->getString() +19/Jun/21 +// static_cast<sal_Int32>(aLabelFontColor) +5855577 +// fLabelFontHeight +9 +// xLabel->getString() +21/Jun/21 +// static_cast<sal_Int32>(aLabelFontColor) +5855577 +// fLabelFontHeight +9 +// xLabel->getString() +23/Jun/21 +// static_cast<sal_Int32>(aLabelFontColor) +5855577 +// fLabelFontHeight +9 +// xLabel->getString() +25/Jun/21 +// static_cast<sal_Int32>(aLabelFontColor) +5855577 +// fLabelFontHeight +9 +// xLabel->getString() +27/Jun/21 +// static_cast<sal_Int32>(aLabelFontColor) +5855577 +// fLabelFontHeight +9 +// xLabel->getString() +29/Jun/21 +// static_cast<sal_Int32>(aLabelFontColor) +5855577 +// fLabelFontHeight +9 +// xLabel->getString() +1/Jul/21 +// static_cast<sal_Int32>(aLabelFontColor) +5855577 +// fLabelFontHeight +9 +// xLabel->getString() +3/Jul/21 +// static_cast<sal_Int32>(aLabelFontColor) +5855577 +// fLabelFontHeight +9 +// xLabel->getString() +5/Jul/21 +// static_cast<sal_Int32>(aLabelFontColor) +5855577 +// fLabelFontHeight +9 +// xLabel->getString() +7/Jul/21 +// static_cast<sal_Int32>(aLabelFontColor) +5855577 +// fLabelFontHeight +9 +// xLabel->getString() +9/Jul/21 +// static_cast<sal_Int32>(aLabelFontColor) +5855577 +// fLabelFontHeight +9 +// xLabel->getString() +11/Jul/21 +// static_cast<sal_Int32>(aLabelFontColor) +5855577 +// fLabelFontHeight +9 +// xLabel->getString() +13/Jul/21 +// static_cast<sal_Int32>(aLabelFontColor) +5855577 +// fLabelFontHeight +9 +// xLabel->getString() +15/Jul/21 +// static_cast<sal_Int32>(aLabelFontColor) +5855577 +// fLabelFontHeight +9 +// xLabel->getString() +17/Jul/21 +// static_cast<sal_Int32>(aLabelFontColor) +5855577 +// fLabelFontHeight +9 +// xLabel->getString() +19/Jul/21 +// static_cast<sal_Int32>(aLabelFontColor) +5855577 +// fLabelFontHeight +9 +// xLabel->getString() +21/Jul/21 +// static_cast<sal_Int32>(aLabelFontColor) +5855577 +// fLabelFontHeight +9 +// xLabel->getString() +23/Jul/21 +// static_cast<sal_Int32>(aLabelFontColor) +5855577 +// fLabelFontHeight +9 +// xLabel->getString() +25/Jul/21 +// static_cast<sal_Int32>(aLabelFontColor) +5855577 +// fLabelFontHeight +9 +// xLabel->getString() +27/Jul/21 +// static_cast<sal_Int32>(aLabelFontColor) +5855577 +// fLabelFontHeight +9 +/// CID/D=0:CS=0:Axis=1,0 +// nAxisLabelsCount +7 +// xLabel->getString() +0 +// static_cast<sal_Int32>(aLabelFontColor) +5855577 +// fLabelFontHeight +9 +// xLabel->getString() +20 +// static_cast<sal_Int32>(aLabelFontColor) +5855577 +// fLabelFontHeight +9 +// xLabel->getString() +40 +// static_cast<sal_Int32>(aLabelFontColor) +5855577 +// fLabelFontHeight +9 +// xLabel->getString() +60 +// static_cast<sal_Int32>(aLabelFontColor) +5855577 +// fLabelFontHeight +9 +// xLabel->getString() +80 +// static_cast<sal_Int32>(aLabelFontColor) +5855577 +// fLabelFontHeight +9 +// xLabel->getString() +100 +// static_cast<sal_Int32>(aLabelFontColor) +5855577 +// fLabelFontHeight +9 +// xLabel->getString() +120 +// static_cast<sal_Int32>(aLabelFontColor) +5855577 +// fLabelFontHeight +9 diff --git a/chart2/qa/extras/chart2export2.cxx b/chart2/qa/extras/chart2export2.cxx index d7862946fd4d..2652572f847f 100644 --- a/chart2/qa/extras/chart2export2.cxx +++ b/chart2/qa/extras/chart2export2.cxx @@ -102,6 +102,7 @@ public: void testGraphicBlipXLSX(); void testNameRangeXLSX(); void testTdf143942(); + void testDateCategoriesPPTX(); CPPUNIT_TEST_SUITE(Chart2ExportTest2); CPPUNIT_TEST(testSetSeriesToSecondaryAxisXLSX); @@ -166,6 +167,7 @@ public: CPPUNIT_TEST(testGraphicBlipXLSX); CPPUNIT_TEST(testNameRangeXLSX); CPPUNIT_TEST(testTdf143942); + CPPUNIT_TEST(testDateCategoriesPPTX); CPPUNIT_TEST_SUITE_END(); }; @@ -1601,6 +1603,43 @@ void Chart2ExportTest2::testTdf143942() } } +void Chart2ExportTest2::testDateCategoriesPPTX() +{ + load(u"/chart2/qa/extras/data/pptx/", "bnc889755.pptx"); + xmlDocUniquePtr pXmlDoc = parseExport("ppt/charts/chart", "Impress Office Open XML"); + CPPUNIT_ASSERT(pXmlDoc); + + constexpr size_t nCats = 16; + double aDates[nCats] = { + 41183, 41214, 41244, 41275, 41306, 41334, 41365, 41395, + 41426, 41456, 41487, 41518, 41548, 41579, 41609, 41640, + }; + + assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:cat"); + assertXPathContent(pXmlDoc, + "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:cat/c:numRef/" + "c:numCache/c:formatCode", + "mmm\\-yy"); + assertXPath( + pXmlDoc, + "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:cat/c:numRef/c:numCache/c:ptCount", + "val", OUString::number(nCats)); + + for (size_t i = 0; i < nCats; ++i) + { + assertXPath( + pXmlDoc, + "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:cat/c:numRef/c:numCache/c:pt[" + + OString::number(i + 1) + "]", + "idx", OUString::number(i)); + assertXPathContent( + pXmlDoc, + "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:cat/c:numRef/c:numCache/c:pt[" + + OString::number(i + 1) + "]/c:v", + OUString::number(aDates[i])); + } +} + CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ExportTest2); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/chart2/qa/extras/chart2import.cxx b/chart2/qa/extras/chart2import.cxx index 388e0e5f1900..0b0977a1ebd8 100644 --- a/chart2/qa/extras/chart2import.cxx +++ b/chart2/qa/extras/chart2import.cxx @@ -29,7 +29,9 @@ #include <com/sun/star/chart2/Symbol.hpp> #include <com/sun/star/chart2/data/XTextualDataSequence.hpp> #include <com/sun/star/chart/DataLabelPlacement.hpp> +#include <com/sun/star/chart/XDateCategories.hpp> #include <com/sun/star/text/XTextRange.hpp> +#include <com/sun/star/util/NumberFormatter.hpp> #include <iterator> #include <com/sun/star/util/Color.hpp> @@ -767,26 +769,20 @@ void Chart2ImportTest::testBnc889755() uno::Reference<chart2::XChartDocument> xChartDoc(getChartDocFromDrawImpress(0, 5), uno::UNO_QUERY_THROW); CPPUNIT_ASSERT(xChartDoc->hasInternalDataProvider()); - uno::Reference< chart2::XInternalDataProvider > xDataProvider( xChartDoc->getDataProvider(), uno::UNO_QUERY_THROW ); - uno::Reference< chart::XChartDataArray > xChartDataArray(xDataProvider, uno::UNO_QUERY_THROW); - uno::Sequence< OUString > aRowLabels = xChartDataArray->getRowDescriptions(); - CPPUNIT_ASSERT_EQUAL(sal_Int32(16), aRowLabels.getLength()); - CPPUNIT_ASSERT_EQUAL(OUString("Oct-12"), aRowLabels[0]); - CPPUNIT_ASSERT_EQUAL(OUString("Nov-12"), aRowLabels[1]); - CPPUNIT_ASSERT_EQUAL(OUString("Dec-12"), aRowLabels[2]); - CPPUNIT_ASSERT_EQUAL(OUString("Jan-13"), aRowLabels[3]); - CPPUNIT_ASSERT_EQUAL(OUString("Feb-13"), aRowLabels[4]); - CPPUNIT_ASSERT_EQUAL(OUString("Mar-13"), aRowLabels[5]); - CPPUNIT_ASSERT_EQUAL(OUString("Apr-13"), aRowLabels[6]); - CPPUNIT_ASSERT_EQUAL(OUString("May-13"), aRowLabels[7]); - CPPUNIT_ASSERT_EQUAL(OUString("Jun-13"), aRowLabels[8]); - CPPUNIT_ASSERT_EQUAL(OUString("Jul-13"), aRowLabels[9]); - CPPUNIT_ASSERT_EQUAL(OUString("Aug-13"), aRowLabels[10]); - CPPUNIT_ASSERT_EQUAL(OUString("Sep-13"), aRowLabels[11]); - CPPUNIT_ASSERT_EQUAL(OUString("Oct-13"), aRowLabels[12]); - CPPUNIT_ASSERT_EQUAL(OUString("Nov-13"), aRowLabels[13]); - CPPUNIT_ASSERT_EQUAL(OUString("Dec-13"), aRowLabels[14]); - CPPUNIT_ASSERT_EQUAL(OUString("Jan-14"), aRowLabels[15]); + constexpr sal_Int32 nNumCategories = 16; + Sequence<OUString> aDateSeq = getFormattedDateCategories(xChartDoc); + + CPPUNIT_ASSERT_EQUAL(nNumCategories, aDateSeq.getLength()); + + const OUString aExpectedDateCategories[nNumCategories] = { + "Oct-12", "Nov-12", "Dec-12", "Jan-13", + "Feb-13", "Mar-13", "Apr-13", "May-13", + "Jun-13", "Jul-13", "Aug-13", "Sep-13", + "Oct-13", "Nov-13", "Dec-13", "Jan-14", + }; + + for (size_t nIdx = 0; nIdx < nNumCategories; ++nIdx) + CPPUNIT_ASSERT_EQUAL(aExpectedDateCategories[nIdx], aDateSeq[nIdx]); //tdf#139940 - the title's gradient was lost and was filled with solid blue, instead of a "blue underline". uno::Reference<drawing::XDrawPagesSupplier> xDoc(mxComponent, uno::UNO_QUERY_THROW); @@ -1724,7 +1720,7 @@ void Chart2ImportTest::testInternalDataProvider() { const uno::Reference< chart2::data::XDataProvider >& rxDataProvider = xChartDoc->getDataProvider(); // Parse 42 array - Reference<chart2::data::XDataSequence> xDataSeq = rxDataProvider->createDataSequenceByValueArray("values-y", "{42;42;42;42}"); + Reference<chart2::data::XDataSequence> xDataSeq = rxDataProvider->createDataSequenceByValueArray("values-y", "{42;42;42;42}", ""); Sequence<Any> xSequence = xDataSeq->getData(); CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int32(42)), xSequence[0]); CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int32(42)), xSequence[1]); @@ -1732,7 +1728,7 @@ void Chart2ImportTest::testInternalDataProvider() { CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int32(42)), xSequence[3]); // Parse empty first and last - xDataSeq = rxDataProvider->createDataSequenceByValueArray("values-y", "{\"\";42;42;\"\"}"); + xDataSeq = rxDataProvider->createDataSequenceByValueArray("values-y", "{\"\";42;42;\"\"}", ""); xSequence = xDataSeq->getData(); CPPUNIT_ASSERT( std::isnan( *static_cast<const double*>(xSequence[0].getValue()))); CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int32(42)), xSequence[1]); @@ -1740,7 +1736,7 @@ void Chart2ImportTest::testInternalDataProvider() { CPPUNIT_ASSERT( std::isnan( *static_cast<const double*>(xSequence[3].getValue()))); // Parse empty middle - xDataSeq = rxDataProvider->createDataSequenceByValueArray("values-y", "{42;\"\";\"\";42}"); + xDataSeq = rxDataProvider->createDataSequenceByValueArray("values-y", "{42;\"\";\"\";42}", ""); xSequence = xDataSeq->getData(); CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int32(42)), xSequence[0]); CPPUNIT_ASSERT( std::isnan( *static_cast<const double*>(xSequence[1].getValue())) ); @@ -1748,7 +1744,7 @@ void Chart2ImportTest::testInternalDataProvider() { CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int32(42)), xSequence[3]); // Parse mixed types, numeric only role - xDataSeq = rxDataProvider->createDataSequenceByValueArray("values-y", "{42;\"hello\";0;\"world\"}"); + xDataSeq = rxDataProvider->createDataSequenceByValueArray("values-y", "{42;\"hello\";0;\"world\"}", ""); xSequence = xDataSeq->getData(); CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int32(42)), xSequence[0]); CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int32(0)), xSequence[1]); @@ -1756,7 +1752,7 @@ void Chart2ImportTest::testInternalDataProvider() { CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int32(0)), xSequence[3]); // Parse mixed types, mixed role - xDataSeq = rxDataProvider->createDataSequenceByValueArray("categories", "{42;\"hello\";0;\"world\"}"); + xDataSeq = rxDataProvider->createDataSequenceByValueArray("categories", "{42;\"hello\";0;\"world\"}", ""); xSequence = xDataSeq->getData(); CPPUNIT_ASSERT_EQUAL(uno::Any(OUString("Row 1 42")), xSequence[0]); CPPUNIT_ASSERT_EQUAL(uno::Any(OUString("Row 2 hello")), xSequence[1]); diff --git a/chart2/qa/extras/charttest.hxx b/chart2/qa/extras/charttest.hxx index 9b162acc06e8..c1772702afd0 100644 --- a/chart2/qa/extras/charttest.hxx +++ b/chart2/qa/extras/charttest.hxx @@ -34,6 +34,7 @@ #include <rtl/math.hxx> #include <svx/charthelper.hxx> +#include <com/sun/star/chart2/AxisType.hpp> #include <com/sun/star/chart2/XAnyDescriptionAccess.hpp> #include <com/sun/star/chart2/XChartDocument.hpp> #include <com/sun/star/chart2/XChartTypeContainer.hpp> @@ -45,12 +46,15 @@ #include <com/sun/star/chart2/data/XLabeledDataSequence.hpp> #include <com/sun/star/chart2/data/XDataSource.hpp> #include <com/sun/star/chart/XChartDataArray.hpp> +#include <com/sun/star/chart2/XInternalDataProvider.hpp> +#include <com/sun/star/chart/XDateCategories.hpp> #include <com/sun/star/drawing/XDrawPagesSupplier.hpp> #include <com/sun/star/drawing/XDrawPageSupplier.hpp> #include <com/sun/star/chart/XChartDocument.hpp> #include <com/sun/star/text/XTextEmbeddedObjectsSupplier.hpp> #include <com/sun/star/util/XNumberFormatsSupplier.hpp> #include <com/sun/star/util/NumberFormat.hpp> +#include <com/sun/star/util/NumberFormatter.hpp> #include <unonames.hxx> @@ -121,6 +125,7 @@ public: uno::Reference<chart::XChartDocument> getChartDocFromDrawImpress( sal_Int32 nPage, sal_Int32 nShape ); uno::Reference<chart::XChartDocument> getChartDocFromWriter( sal_Int32 nShape ); + Sequence< OUString > getFormattedDateCategories( const Reference<chart2::XChartDocument>& xChartDoc ); awt::Size getPageSize( const Reference< chart2::XChartDocument > & xChartDoc ); awt::Size getSize(css::uno::Reference<chart2::XDiagram> xDiagram, const awt::Size& rPageSize); @@ -635,6 +640,38 @@ sal_Int16 getNumberFormatType( const Reference<chart2::XChartDocument>& xChartDo return nType; } +Sequence< double > getDateCategories(const Reference<chart2::XChartDocument>& xChartDoc) +{ + CPPUNIT_ASSERT(xChartDoc->hasInternalDataProvider()); + uno::Reference< chart2::XInternalDataProvider > xDataProvider( xChartDoc->getDataProvider(), uno::UNO_QUERY_THROW ); + uno::Reference< chart::XDateCategories > xDateCategories( xDataProvider, uno::UNO_QUERY_THROW ); + CPPUNIT_ASSERT(xDateCategories.is()); + return xDateCategories->getDateCategories(); +} + +Sequence< OUString > ChartTest::getFormattedDateCategories( const Reference<chart2::XChartDocument>& xChartDoc ) +{ + Reference<util::XNumberFormatsSupplier> xNFS(xChartDoc, uno::UNO_QUERY_THROW); + Reference< util::XNumberFormatter > xNumFormatter( + util::NumberFormatter::create(comphelper::getComponentContext(m_xSFactory)), uno::UNO_QUERY_THROW ); + xNumFormatter->attachNumberFormatsSupplier(xNFS); + + Reference<chart2::XAxis> xAxisX = getAxisFromDoc(xChartDoc, 0, 0, 0); + chart2::ScaleData aScaleData = xAxisX->getScaleData(); + CPPUNIT_ASSERT_EQUAL(chart2::AxisType::DATE, aScaleData.AxisType); + + sal_Int32 nNumFmt = getNumberFormatFromAxis(xAxisX); + + Sequence<double> aDateSeq = getDateCategories(xChartDoc); + const sal_Int32 nNumCategories = aDateSeq.getLength(); + Sequence<OUString> aFormattedDates(nNumCategories); + + for (sal_Int32 nIdx = 0; nIdx < nNumCategories; ++nIdx) + aFormattedDates[nIdx] = xNumFormatter->convertNumberToString(nNumFmt, aDateSeq[nIdx]); + + return aFormattedDates; +} + awt::Size ChartTest::getPageSize( const Reference< chart2::XChartDocument > & xChartDoc ) { awt::Size aSize( 0, 0 ); diff --git a/chart2/source/inc/InternalDataProvider.hxx b/chart2/source/inc/InternalDataProvider.hxx index 1e5821f94e6c..34c5d4831c17 100644 --- a/chart2/source/inc/InternalDataProvider.hxx +++ b/chart2/source/inc/InternalDataProvider.hxx @@ -112,7 +112,8 @@ public: const OUString& aRangeRepresentation ) override; virtual css::uno::Reference<css::chart2::data::XDataSequence> SAL_CALL - createDataSequenceByValueArray( const OUString& aRole, const OUString& aRangeRepresentation ) override; + createDataSequenceByValueArray( const OUString& aRole, const OUString& aRangeRepresentation, + const OUString& aRoleQualifier ) override; virtual css::uno::Reference< css::sheet::XRangeSelection > SAL_CALL getRangeSelection() override; @@ -183,7 +184,8 @@ private: createDataSequenceAndAddToMap( const OUString & rRangeRepresentation ); css::uno::Reference<css::chart2::data::XDataSequence> - createDataSequenceFromArray( const OUString& rArrayStr, std::u16string_view rRole ); + createDataSequenceFromArray( const OUString& rArrayStr, std::u16string_view rRole, + std::u16string_view rRoleQualifier); void deleteMapReferences( const OUString & rRangeRepresentation ); diff --git a/chart2/source/tools/InternalDataProvider.cxx b/chart2/source/tools/InternalDataProvider.cxx index 505159fa87b6..abbcc077e1c0 100644 --- a/chart2/source/tools/InternalDataProvider.cxx +++ b/chart2/source/tools/InternalDataProvider.cxx @@ -483,7 +483,7 @@ void InternalDataProvider::decreaseMapReferences( Reference< chart2::data::XDataSequence > InternalDataProvider::createDataSequenceAndAddToMap( const OUString & rRangeRepresentation ) { - Reference<chart2::data::XDataSequence> xSeq = createDataSequenceFromArray(rRangeRepresentation, u""); + Reference<chart2::data::XDataSequence> xSeq = createDataSequenceFromArray(rRangeRepresentation, u"", u""); if (xSeq.is()) return xSeq; @@ -493,7 +493,7 @@ Reference< chart2::data::XDataSequence > InternalDataProvider::createDataSequenc } uno::Reference<chart2::data::XDataSequence> -InternalDataProvider::createDataSequenceFromArray( const OUString& rArrayStr, std::u16string_view rRole ) +InternalDataProvider::createDataSequenceFromArray( const OUString& rArrayStr, std::u16string_view rRole, std::u16string_view rRoleQualifier ) { if (rArrayStr.indexOf('{') != 0 || rArrayStr[rArrayStr.getLength()-1] != '}') { @@ -620,9 +620,19 @@ InternalDataProvider::createDataSequenceFromArray( const OUString& rArrayStr, st { // Category labels. + // Store date categories as numbers. + bool bStoreNumeric = rRoleQualifier == u"date"; + double fValue; for (size_t i = 0; i < aRawElems.size(); ++i) { - std::vector<uno::Any> aLabels(1, uno::Any(aRawElems[i])); + if (bStoreNumeric) + { + bool bGetDouble = bAllNumeric && !aRawElems[i].isEmpty(); + fValue = bGetDouble ? aRawElems[i].toDouble() : + std::numeric_limits<double>::quiet_NaN(); + } + std::vector<uno::Any> aLabels(1, + bStoreNumeric ? uno::Any(fValue) : uno::Any(aRawElems[i])); m_aInternalData.setComplexRowLabel(i, aLabels); } @@ -831,9 +841,9 @@ Reference< chart2::data::XDataSequence > SAL_CALL InternalDataProvider::createDa Reference<chart2::data::XDataSequence> SAL_CALL InternalDataProvider::createDataSequenceByValueArray( - const OUString& aRole, const OUString& aRangeRepresentation ) + const OUString& aRole, const OUString& aRangeRepresentation, const OUString& aRoleQualifier ) { - return createDataSequenceFromArray(aRangeRepresentation, aRole); + return createDataSequenceFromArray(aRangeRepresentation, aRole, aRoleQualifier); } Reference< sheet::XRangeSelection > SAL_CALL InternalDataProvider::getRangeSelection() diff --git a/chart2/source/view/axes/ScaleAutomatism.cxx b/chart2/source/view/axes/ScaleAutomatism.cxx index 09da37aba034..7748df078ec6 100644 --- a/chart2/source/view/axes/ScaleAutomatism.cxx +++ b/chart2/source/view/axes/ScaleAutomatism.cxx @@ -654,7 +654,7 @@ void ScaleAutomatism::calculateExplicitIncrementAndScaleForDateTimeAxis( nDaysPerInterval = 1.0; } - nNumer = static_cast<sal_Int32>( rtl::math::approxCeil( nIntervalDays/nDaysPerInterval ) ); + nNumer = static_cast<sal_Int32>( rtl::math::approxFloor( nIntervalDays/nDaysPerInterval ) ); if(nNumer<=0) nNumer=1; if( rExplicitIncrement.MajorTimeInterval.TimeUnit == DAY ) @@ -665,7 +665,7 @@ void ScaleAutomatism::calculateExplicitIncrementAndScaleForDateTimeAxis( { rExplicitIncrement.MajorTimeInterval.TimeUnit = MONTH; nDaysPerInterval = 31.0; - nNumer = static_cast<sal_Int32>( rtl::math::approxCeil( nIntervalDays/nDaysPerInterval ) ); + nNumer = static_cast<sal_Int32>( rtl::math::approxFloor( nIntervalDays/nDaysPerInterval ) ); if(nNumer<=0) nNumer=1; } diff --git a/chart2/source/view/axes/VCoordinateSystem.cxx b/chart2/source/view/axes/VCoordinateSystem.cxx index ded24e5b1353..7259f3e92043 100644 --- a/chart2/source/view/axes/VCoordinateSystem.cxx +++ b/chart2/source/view/axes/VCoordinateSystem.cxx @@ -341,7 +341,8 @@ void VCoordinateSystem::updateScalesAndIncrementsOnAxes() void VCoordinateSystem::prepareAutomaticAxisScaling( ScaleAutomatism& rScaleAutomatism, sal_Int32 nDimIndex, sal_Int32 nAxisIndex ) { - if( rScaleAutomatism.getScale().AxisType==AxisType::DATE && nDimIndex==0 ) + bool bDateAxisX = (rScaleAutomatism.getScale().AxisType == AxisType::DATE) && (nDimIndex == 0); + if( bDateAxisX ) { // This is a date X dimension. Determine proper time resolution. sal_Int32 nTimeResolution = css::chart::TimeUnit::MONTH; @@ -384,6 +385,9 @@ void VCoordinateSystem::prepareAutomaticAxisScaling( ScaleAutomatism& rScaleAuto m_aMergedMinMaxSupplier.isExpandWideValuesToZero( nDimIndex ), m_aMergedMinMaxSupplier.isExpandNarrowValuesTowardZero( nDimIndex ) ); + if (bDateAxisX) + return; + VAxisBase* pVAxis = getVAxis(nDimIndex, nAxisIndex); if( pVAxis ) rScaleAutomatism.setMaximumAutoMainIncrementCount( pVAxis->estimateMaximumAutoMainIncrementCount() ); diff --git a/chart2/source/view/charttypes/AreaChart.cxx b/chart2/source/view/charttypes/AreaChart.cxx index 37b90cdfdbc0..e0a70af5339f 100644 --- a/chart2/source/view/charttypes/AreaChart.cxx +++ b/chart2/source/view/charttypes/AreaChart.cxx @@ -693,6 +693,8 @@ void AreaChart::createShapes() uno::Reference< drawing::XShapes > xSeriesGroupShape_Shapes = getSeriesGroupShapeFrontChild(pSeries.get(), m_xSeriesTarget); sal_Int32 nAttachedAxisIndex = pSeries->getAttachedAxisIndex(); + double fXMin, fXMax; + pSeries->getMinMaxXValue(fXMin, fXMax); PlottingPositionHelper& rPosHelper = getPlottingPositionHelper(nAttachedAxisIndex); m_pPosHelper = &rPosHelper; @@ -713,7 +715,7 @@ void AreaChart::createShapes() double fLogicX = pSeries->getXValue(nIndex); if (bDateCategory) { - if (std::isnan(fLogicX)) + if (std::isnan(fLogicX) || (fLogicX < fXMin || fLogicX > fXMax)) continue; fLogicX = DateHelper::RasterizeDateValue( fLogicX, m_aNullDate, m_nTimeResolution ); |