Kaydet (Commit) 9be1b6cf authored tarafından Balazs Varga's avatar Balazs Varga Kaydeden (comit) László Németh

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/70814Reviewed-by: 's avatarLászló Németh <nemeth@numbertext.org>
Tested-by: 's avatarLászló Németh <nemeth@numbertext.org>
üst 74cd1675
...@@ -114,6 +114,8 @@ public: ...@@ -114,6 +114,8 @@ public:
void testMultipleAxisXLSX(); void testMultipleAxisXLSX();
void testSecondaryAxisXLSX(); void testSecondaryAxisXLSX();
void testSetSeriesToSecondaryAxisXLSX(); void testSetSeriesToSecondaryAxisXLSX();
void testCombinedChartSecondaryAxisXLSX();
void testCombinedChartSecondaryAxisODS();
void testAxisTitleRotationXLSX(); void testAxisTitleRotationXLSX();
void testAxisCrossBetweenXSLX(); void testAxisCrossBetweenXSLX();
void testPieChartDataPointExplosionXLSX(); void testPieChartDataPointExplosionXLSX();
...@@ -208,6 +210,8 @@ public: ...@@ -208,6 +210,8 @@ public:
CPPUNIT_TEST(testMultipleAxisXLSX); CPPUNIT_TEST(testMultipleAxisXLSX);
CPPUNIT_TEST(testSecondaryAxisXLSX); CPPUNIT_TEST(testSecondaryAxisXLSX);
CPPUNIT_TEST(testSetSeriesToSecondaryAxisXLSX); CPPUNIT_TEST(testSetSeriesToSecondaryAxisXLSX);
CPPUNIT_TEST(testCombinedChartSecondaryAxisXLSX);
CPPUNIT_TEST(testCombinedChartSecondaryAxisODS);
CPPUNIT_TEST(testAxisTitleRotationXLSX); CPPUNIT_TEST(testAxisTitleRotationXLSX);
CPPUNIT_TEST(testAxisCrossBetweenXSLX); CPPUNIT_TEST(testAxisCrossBetweenXSLX);
CPPUNIT_TEST(testPieChartDataPointExplosionXLSX); CPPUNIT_TEST(testPieChartDataPointExplosionXLSX);
...@@ -1782,6 +1786,46 @@ void Chart2ExportTest::testSetSeriesToSecondaryAxisXLSX() ...@@ -1782,6 +1786,46 @@ void Chart2ExportTest::testSetSeriesToSecondaryAxisXLSX()
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart", 2); 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() void Chart2ExportTest::testAxisTitleRotationXLSX()
{ {
load("/chart2/qa/extras/data/xlsx/", "axis_title_rotation.xlsx"); load("/chart2/qa/extras/data/xlsx/", "axis_title_rotation.xlsx");
......
...@@ -2471,9 +2471,14 @@ void ChartExport::InitPlotArea( ) ...@@ -2471,9 +2471,14 @@ void ChartExport::InitPlotArea( )
void ChartExport::exportAxes( ) void ChartExport::exportAxes( )
{ {
sal_Int32 nSize = maAxes.size(); 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( ...@@ -2843,7 +2848,8 @@ void ChartExport::_exportAxis(
// crosses & crossesAt // crosses & crossesAt
bool bCrossesValue = false; bool bCrossesValue = false;
const char* sCrosses = nullptr; 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 ); css::chart::ChartAxisPosition ePosition( css::chart::ChartAxisPosition_ZERO );
mAny >>= ePosition; mAny >>= ePosition;
...@@ -2874,9 +2880,12 @@ void ChartExport::_exportAxis( ...@@ -2874,9 +2880,12 @@ void ChartExport::_exportAxis(
} }
else else
{ {
pFS->singleElement( FSNS( XML_c, XML_crosses ), if(sCrosses)
XML_val, sCrosses, {
FSEND ); pFS->singleElement(FSNS(XML_c, XML_crosses),
XML_val, sCrosses,
FSEND);
}
} }
if( ( nAxisType == XML_catAx ) if( ( nAxisType == XML_catAx )
...@@ -3451,8 +3460,16 @@ void ChartExport::exportDataPoints( ...@@ -3451,8 +3460,16 @@ void ChartExport::exportDataPoints(
void ChartExport::exportAxesId(bool bPrimaryAxes, bool bCheckCombinedAxes) void ChartExport::exportAxesId(bool bPrimaryAxes, bool bCheckCombinedAxes)
{ {
sal_Int32 nAxisIdx, nAxisIdy; 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 // tdf#114181 keep axes of combined charts
if ( bCheckCombinedAxes && bPrimaryAxes && maAxes.size() == 2 ) if ( bCheckCombinedAxes && ( bPrimaryAxisExists || bSecondaryAxisExists ) )
{ {
nAxisIdx = maAxes[0].nAxisId; nAxisIdx = maAxes[0].nAxisId;
nAxisIdy = maAxes[1].nAxisId; nAxisIdy = maAxes[1].nAxisId;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment