diff options
author | Balazs Varga <balazs.varga991@gmail.com> | 2019-04-16 11:19:55 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2019-04-17 14:30:17 +0200 |
commit | 9be1b6cf5b97727135c7f5e48c971edd8dc45e70 (patch) | |
tree | 09706b07954bc5a06bcae6fc90fcef0a8e261f67 | |
parent | 74cd1675d80bc1c1609655148546fc960fb99af8 (diff) |
tdf#123828 XLSX combined chart export: fix order of axis types
Also fix tdf#123833 and tdf#123837.
In combined charts, now axis types are exported in the right order
(catAx[1], valAx[1], catAx[2], valAx[2]). The Y axes are exported
correctly with the correct axIDs of the chart types: the first one with
the primary axId, the second one with the secondary axId. X category
axis crosses the Y axis at the right place, all data series are attached
to the right Y axis, and the Y major grid doesn't disappear.
Note: don't export the CrossoverPosition/CrossoverValue, if the axis
is deleted and invisible, because MSO will show the secondary X axis,
even if the axis doesn't exist. The problem was the unnecessary export
of the axis with the default css::chart::ChartAxisPosition_END
CrossoverPosition value.
Change-Id: Id429e654ff0ba45b5f9db877b7c4dd6e65433408
Reviewed-on: https://gerrit.libreoffice.org/70814
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 | 44 | ||||
-rw-r--r-- | chart2/qa/extras/data/ods/combined_chart_secondary_axis.ods | bin | 0 -> 16334 bytes | |||
-rw-r--r-- | chart2/qa/extras/data/xlsx/combined_chart_secondary_axis.xlsx | bin | 0 -> 15304 bytes | |||
-rw-r--r-- | oox/source/export/chartexport.cxx | 31 |
4 files changed, 68 insertions, 7 deletions
diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx index 6dd8d7d9e9c1..a5c42530a0b6 100644 --- a/chart2/qa/extras/chart2export.cxx +++ b/chart2/qa/extras/chart2export.cxx @@ -114,6 +114,8 @@ public: void testMultipleAxisXLSX(); void testSecondaryAxisXLSX(); void testSetSeriesToSecondaryAxisXLSX(); + void testCombinedChartSecondaryAxisXLSX(); + void testCombinedChartSecondaryAxisODS(); void testAxisTitleRotationXLSX(); void testAxisCrossBetweenXSLX(); void testPieChartDataPointExplosionXLSX(); @@ -208,6 +210,8 @@ public: CPPUNIT_TEST(testMultipleAxisXLSX); CPPUNIT_TEST(testSecondaryAxisXLSX); CPPUNIT_TEST(testSetSeriesToSecondaryAxisXLSX); + CPPUNIT_TEST(testCombinedChartSecondaryAxisXLSX); + CPPUNIT_TEST(testCombinedChartSecondaryAxisODS); CPPUNIT_TEST(testAxisTitleRotationXLSX); CPPUNIT_TEST(testAxisCrossBetweenXSLX); CPPUNIT_TEST(testPieChartDataPointExplosionXLSX); @@ -1782,6 +1786,46 @@ void Chart2ExportTest::testSetSeriesToSecondaryAxisXLSX() assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart", 2); } +void Chart2ExportTest::testCombinedChartSecondaryAxisXLSX() +{ + // Original file was created with MS Office + load("/chart2/qa/extras/data/xlsx/", "combined_chart_secondary_axis.xlsx"); + xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML"); + CPPUNIT_ASSERT(pXmlDoc); + // Collect barchart axID on secondary Axis + OUString XValueIdOfBarchart = getXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:axId[1]", "val"); + OUString YValueIdOfBarchart = getXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:axId[2]", "val"); + // Collect linechart axID on primary Axis + OUString XValueIdOfLinechart = getXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:axId[1]", "val"); + OUString YValueIdOfLinechart = getXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:axId[2]", "val"); + // Check which c:catAx and c:valAx contain the AxisId of charttypes + assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:catAx[1]/c:axId", "val", XValueIdOfLinechart); + assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx[1]/c:axId", "val", YValueIdOfLinechart); + assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:catAx[2]/c:axId", "val", XValueIdOfBarchart); + assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx[2]/c:axId", "val", YValueIdOfBarchart); +} + +void Chart2ExportTest::testCombinedChartSecondaryAxisODS() +{ + // Original file was created with LibreOffice + load("/chart2/qa/extras/data/ods/", "combined_chart_secondary_axis.ods"); + xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML"); + CPPUNIT_ASSERT(pXmlDoc); + // Collect barchart axID on secondary Axis + OUString XValueIdOfBarchart = getXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:axId[1]", "val"); + OUString YValueIdOfBarchart = getXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:axId[2]", "val"); + // Collect linechart axID on primary Axis + OUString XValueIdOfLinechart = getXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:axId[1]", "val"); + OUString YValueIdOfLinechart = getXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:axId[2]", "val"); + // Check which c:catAx and c:valAx contain the AxisId of charttypes + assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:catAx[1]/c:axId", "val", XValueIdOfLinechart); + assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx[1]/c:axId", "val", YValueIdOfLinechart); + assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:catAx[2]/c:axId", "val", XValueIdOfBarchart); + assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx[2]/c:axId", "val", YValueIdOfBarchart); + // do not need CT_crosses tag if the actual axis is deleted, so we need to make sure it is not saved + assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:catAx[2]/c:crosses", 0); +} + void Chart2ExportTest::testAxisTitleRotationXLSX() { load("/chart2/qa/extras/data/xlsx/", "axis_title_rotation.xlsx"); diff --git a/chart2/qa/extras/data/ods/combined_chart_secondary_axis.ods b/chart2/qa/extras/data/ods/combined_chart_secondary_axis.ods Binary files differnew file mode 100644 index 000000000000..d125bc23d3af --- /dev/null +++ b/chart2/qa/extras/data/ods/combined_chart_secondary_axis.ods diff --git a/chart2/qa/extras/data/xlsx/combined_chart_secondary_axis.xlsx b/chart2/qa/extras/data/xlsx/combined_chart_secondary_axis.xlsx Binary files differnew file mode 100644 index 000000000000..e922d4df4ad3 --- /dev/null +++ b/chart2/qa/extras/data/xlsx/combined_chart_secondary_axis.xlsx diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx index 672ae2579d99..54379188649e 100644 --- a/oox/source/export/chartexport.cxx +++ b/oox/source/export/chartexport.cxx @@ -2471,9 +2471,14 @@ void ChartExport::InitPlotArea( ) void ChartExport::exportAxes( ) { sal_Int32 nSize = maAxes.size(); - for( sal_Int32 nIdx = 0; nIdx < nSize; nIdx++ ) + // let's export the axis types in the right order + for ( sal_Int32 nSortIdx = AXIS_PRIMARY_X; nSortIdx <= AXIS_SECONDARY_Y; nSortIdx++ ) { - exportAxis( maAxes[nIdx] ); + for ( sal_Int32 nIdx = 0; nIdx < nSize; nIdx++ ) + { + if (nSortIdx == maAxes[nIdx].nAxisType) + exportAxis( maAxes[nIdx] ); + } } } @@ -2843,7 +2848,8 @@ void ChartExport::_exportAxis( // crosses & crossesAt bool bCrossesValue = false; const char* sCrosses = nullptr; - if(GetProperty( xAxisProp, "CrossoverPosition" ) ) + // do not export the CrossoverPosition/CrossoverValue, if the axis is deleted and not visible + if( GetProperty( xAxisProp, "CrossoverPosition" ) && !bDeleted && bVisible ) { css::chart::ChartAxisPosition ePosition( css::chart::ChartAxisPosition_ZERO ); mAny >>= ePosition; @@ -2874,9 +2880,12 @@ void ChartExport::_exportAxis( } else { - pFS->singleElement( FSNS( XML_c, XML_crosses ), - XML_val, sCrosses, - FSEND ); + if(sCrosses) + { + pFS->singleElement(FSNS(XML_c, XML_crosses), + XML_val, sCrosses, + FSEND); + } } if( ( nAxisType == XML_catAx ) @@ -3451,8 +3460,16 @@ void ChartExport::exportDataPoints( void ChartExport::exportAxesId(bool bPrimaryAxes, bool bCheckCombinedAxes) { sal_Int32 nAxisIdx, nAxisIdy; + bool bPrimaryAxisExists = false; + bool bSecondaryAxisExists = false; + // let's check which axis already exists and which axis is attached to the actual dataseries + if (maAxes.size() >= 2) + { + bPrimaryAxisExists = bPrimaryAxes && maAxes[1].nAxisType == AXIS_PRIMARY_Y; + bSecondaryAxisExists = !bPrimaryAxes && maAxes[1].nAxisType == AXIS_SECONDARY_Y; + } // tdf#114181 keep axes of combined charts - if ( bCheckCombinedAxes && bPrimaryAxes && maAxes.size() == 2 ) + if ( bCheckCombinedAxes && ( bPrimaryAxisExists || bSecondaryAxisExists ) ) { nAxisIdx = maAxes[0].nAxisId; nAxisIdy = maAxes[1].nAxisId; |