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

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/70141Reviewed-by: 's avatarLászló Németh <nemeth@numbertext.org>
Tested-by: 's avatarLászló Németh <nemeth@numbertext.org>
üst 69b5da39
......@@ -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");
......
......@@ -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()) )
......
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