diff options
author | Balazs Varga <balazs.varga991@gmail.com> | 2019-04-02 16:10:00 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2019-04-08 15:30:03 +0200 |
commit | a3881a66b8ffda4a8a89ecfc4347555e34193665 (patch) | |
tree | 403934182fbcb8b39d39ceb9af69e598e885cd1e | |
parent | 69b5da392951fbd655912185434edab94f8ac0af (diff) |
tdf#124466 XLSX: fix broken export by removing chart type data redundancy
XLSX import created a redundant series container for data series with the
same chart type, when they were attached to a different axis. Modifying
the loaded chart by the user, ie. attaching one of its data series to a
different axis resulted broken OOXML export later, because based on the
new axis, splitDataSeriesByAxis splitted the first or the redundant series
container further. Now the import creates only a single series container
for the series with the same chart type, preventing potential export problems.
Change-Id: If951feaca3cb3b5df7718e9d7bfd59620ef3c4d3
Reviewed-on: https://gerrit.libreoffice.org/70141
Reviewed-by: László Németh <nemeth@numbertext.org>
Tested-by: László Németh <nemeth@numbertext.org>
-rw-r--r-- | chart2/qa/extras/chart2export.cxx | 21 | ||||
-rwxr-xr-x | chart2/qa/extras/data/xlsx/add_series_secondary_axis.xlsx | bin | 0 -> 20217 bytes | |||
-rw-r--r-- | oox/source/drawingml/chart/typegroupconverter.cxx | 19 |
3 files changed, 38 insertions, 2 deletions
diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx index 3d537cf2ab90..6c769f0bbe63 100644 --- a/chart2/qa/extras/chart2export.cxx +++ b/chart2/qa/extras/chart2export.cxx @@ -113,6 +113,7 @@ public: void testBarChartVaryColorsXLSX(); void testMultipleAxisXLSX(); void testSecondaryAxisXLSX(); + void testSetSeriesToSecondaryAxisXLSX(); void testAxisTitleRotationXLSX(); void testAxisCrossBetweenXSLX(); void testPieChartDataPointExplosionXLSX(); @@ -206,6 +207,7 @@ public: CPPUNIT_TEST(testBarChartVaryColorsXLSX); CPPUNIT_TEST(testMultipleAxisXLSX); CPPUNIT_TEST(testSecondaryAxisXLSX); + CPPUNIT_TEST(testSetSeriesToSecondaryAxisXLSX); CPPUNIT_TEST(testAxisTitleRotationXLSX); CPPUNIT_TEST(testAxisCrossBetweenXSLX); CPPUNIT_TEST(testPieChartDataPointExplosionXLSX); @@ -1760,6 +1762,25 @@ void Chart2ExportTest::testSecondaryAxisXLSX() assertXPathContent(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart[2]/c:ser[1]/c:tx/c:strRef/c:strCache/c:pt/c:v", "a"); } +void Chart2ExportTest::testSetSeriesToSecondaryAxisXLSX() +{ + load("/chart2/qa/extras/data/xlsx/", "add_series_secondary_axis.xlsx"); + Reference< chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent); + // Second series + Reference<chart2::XDataSeries> xSeries = getDataSeriesFromDoc(xChartDoc, 1); + CPPUNIT_ASSERT(xSeries.is()); + + Reference<beans::XPropertySet> xPropSet(xSeries, uno::UNO_QUERY_THROW); + sal_Int32 AxisIndex = 1; + // Attach the second series to the secondary axis. (The third series is already attached.) + xPropSet->setPropertyValue("AttachedAxisIndex", uno::Any(AxisIndex)); + + xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML"); + CPPUNIT_ASSERT(pXmlDoc); + // Check there are only two <lineChart> tag in the XML, one for the primary and one for the secondary axis. + assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart", 2); +} + void Chart2ExportTest::testAxisTitleRotationXLSX() { load("/chart2/qa/extras/data/xlsx/", "axis_title_rotation.xlsx"); diff --git a/chart2/qa/extras/data/xlsx/add_series_secondary_axis.xlsx b/chart2/qa/extras/data/xlsx/add_series_secondary_axis.xlsx Binary files differnew file mode 100755 index 000000000000..03d7a47f6c3d --- /dev/null +++ b/chart2/qa/extras/data/xlsx/add_series_secondary_axis.xlsx diff --git a/oox/source/drawingml/chart/typegroupconverter.cxx b/oox/source/drawingml/chart/typegroupconverter.cxx index 1f6c73e11d0b..bd592e6adbc5 100644 --- a/oox/source/drawingml/chart/typegroupconverter.cxx +++ b/oox/source/drawingml/chart/typegroupconverter.cxx @@ -312,6 +312,10 @@ void TypeGroupConverter::convertFromModel( const Reference< XDiagram >& rxDiagra OUString aService = OUString::createFromAscii( maTypeInfo.mpcServiceName ); Reference< XChartType > xChartType( createInstance( aService ), UNO_QUERY_THROW ); + Reference< XChartTypeContainer > xChartTypeContOld( rxCoordSystem, UNO_QUERY_THROW ); + Sequence< Reference< XChartType > > xOldChartTypes( xChartTypeContOld->getChartTypes() ); + sal_Int32 nOldChartTypeIdx = -1; + // additional properties PropertySet aDiaProp( rxDiagram ); PropertySet aTypeProp( xChartType ); @@ -419,11 +423,19 @@ void TypeGroupConverter::convertFromModel( const Reference< XDiagram >& rxDiagra } else { + for( sal_Int32 nCTIdx=0; nCTIdx<xOldChartTypes.getLength(); ++nCTIdx ) + { + if ( xChartType->getChartType() == xOldChartTypes[nCTIdx]->getChartType() ) + { + nOldChartTypeIdx = nCTIdx; + } + } + for (auto const& elem : aSeries) { SeriesConverter& rSeriesConv = *elem; Reference< XDataSeries > xDataSeries = rSeriesConv.createDataSeries( *this, bVaryColorsByPoint ); - insertDataSeries( xChartType, xDataSeries, nAxesSetIdx ); + insertDataSeries( nOldChartTypeIdx == -1 ? xChartType : xOldChartTypes[nOldChartTypeIdx], xDataSeries, nAxesSetIdx ); /* Excel does not use the value of the c:smooth element of the chart type to set a default line smoothing for the data @@ -440,7 +452,10 @@ void TypeGroupConverter::convertFromModel( const Reference< XDiagram >& rxDiagra // add chart type object to coordinate system Reference< XChartTypeContainer > xChartTypeCont( rxCoordSystem, UNO_QUERY_THROW ); - xChartTypeCont->addChartType( xChartType ); + if (nOldChartTypeIdx == -1) + { + xChartTypeCont->addChartType(xChartType); + } // set existence of bar connector lines at diagram (only in stacked 2D bar charts) if( mrModel.mxSerLines.is() && !mb3dChart && (maTypeInfo.meTypeCategory == TYPECATEGORY_BAR) && (isStacked() || isPercent()) ) |