diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2016-11-18 11:44:03 +0100 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2016-11-30 22:33:51 +0000 |
commit | ff22a22286bb4c17c3affc89d31a6c10447481c5 (patch) | |
tree | 9e63e100717d64eb58d824f678b5ef9d7cd96f67 /oox | |
parent | f45af7c8093dae17bada71e33a2c32023a2c1986 (diff) |
better varyColors export for charts, related tdf#103943
Change-Id: I4280e708c854c687b6281c56d5bccdb514afd81e
Reviewed-on: https://gerrit.libreoffice.org/31252
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/export/chartexport.cxx | 74 |
1 files changed, 55 insertions, 19 deletions
diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx index ccfc244126a3..8bfc59690ad5 100644 --- a/oox/source/export/chartexport.cxx +++ b/oox/source/export/chartexport.cxx @@ -1541,10 +1541,7 @@ void ChartExport::exportBarChart( const Reference< chart2::XChartType >& xChartT exportGrouping( true ); - const char* varyColors = "0"; - pFS->singleElement( FSNS( XML_c, XML_varyColors ), - XML_val, varyColors, - FSEND ); + exportVaryColors(xChartType); bool bPrimaryAxes = true; exportAllSeries(xChartType, bPrimaryAxes); @@ -1617,10 +1614,7 @@ void ChartExport::exportBubbleChart( const Reference< chart2::XChartType >& xCha pFS->startElement( FSNS( XML_c, XML_bubbleChart ), FSEND ); - const char* varyColors = "0"; - pFS->singleElement( FSNS( XML_c, XML_varyColors ), - XML_val, varyColors, - FSEND ); + exportVaryColors(xChartType); bool bPrimaryAxes = true; exportAllSeries(xChartType, bPrimaryAxes); @@ -1640,6 +1634,8 @@ void ChartExport::exportDoughnutChart( const Reference< chart2::XChartType >& xC pFS->startElement( FSNS( XML_c, XML_doughnutChart ), FSEND ); + exportVaryColors(xChartType); + bool bPrimaryAxes = true; exportAllSeries(xChartType, bPrimaryAxes); // firstSliceAng @@ -1712,9 +1708,9 @@ void ChartExport::exportLineChart( const Reference< chart2::XChartType >& xChart pFS->startElement( FSNS( XML_c, nTypeId ), FSEND ); + exportVaryColors(xChartType); + exportGrouping( ); - pFS->singleElement(FSNS(XML_c, XML_varyColors), - XML_val, "0", FSEND); // TODO: show marker symbol in series? bool bPrimaryAxes = true; exportSeries(xChartType, *itr, bPrimaryAxes); @@ -1755,11 +1751,8 @@ void ChartExport::exportPieChart( const Reference< chart2::XChartType >& xChartT nTypeId = XML_pie3DChart; pFS->startElement( FSNS( XML_c, nTypeId ), FSEND ); - // TODO: varyColors - const char* varyColors = "1"; - pFS->singleElement( FSNS( XML_c, XML_varyColors ), - XML_val, varyColors, - FSEND ); + + exportVaryColors(xChartType); bool bPrimaryAxes = true; exportAllSeries(xChartType, bPrimaryAxes); @@ -1789,6 +1782,8 @@ void ChartExport::exportRadarChart( const Reference< chart2::XChartType >& xChar pFS->singleElement( FSNS( XML_c, XML_radarStyle ), XML_val, radarStyle, FSEND ); + + exportVaryColors(xChartType); bool bPrimaryAxes = true; exportAllSeries(xChartType, bPrimaryAxes); exportAxesId(bPrimaryAxes); @@ -1825,10 +1820,7 @@ void ChartExport::exportScatterChart( const Reference< chart2::XChartType >& xCh XML_val, scatterStyle, FSEND ); - pFS->singleElement( FSNS( XML_c, XML_varyColors ), - XML_val, "0", - FSEND ); - + exportVaryColors(xChartType); // FIXME: should export xVal and yVal bool bPrimaryAxes = true; exportSeries(xChartType, *itr, bPrimaryAxes); @@ -1942,6 +1934,7 @@ void ChartExport::exportSurfaceChart( const Reference< chart2::XChartType >& xCh nTypeId = XML_surface3DChart; pFS->startElement( FSNS( XML_c, nTypeId ), FSEND ); + exportVaryColors(xChartType); bool bPrimaryAxes = true; exportAllSeries(xChartType, bPrimaryAxes); exportAxesId(bPrimaryAxes); @@ -1960,6 +1953,48 @@ void ChartExport::exportAllSeries(const Reference<chart2::XChartType>& xChartTyp exportSeries(xChartType, aSeriesSeq, rPrimaryAxes); } +namespace { + +Reference<chart2::XDataSeries> getPrimaryDataSeries(const Reference<chart2::XChartType>& xChartType) +{ + Reference< chart2::XDataSeriesContainer > xDSCnt(xChartType, uno::UNO_QUERY_THROW); + + // export dataseries for current chart-type + Sequence< Reference< chart2::XDataSeries > > aSeriesSeq(xDSCnt->getDataSeries()); + for (sal_Int32 nSeriesIdx=0; nSeriesIdx < aSeriesSeq.getLength(); ++nSeriesIdx) + { + Reference<chart2::XDataSeries> xSource(aSeriesSeq[nSeriesIdx], uno::UNO_QUERY); + if (xSource.is()) + return xSource; + } + + return Reference<chart2::XDataSeries>(); +} + +} + +void ChartExport::exportVaryColors(const Reference<chart2::XChartType>& xChartType) +{ + FSHelperPtr pFS = GetFS(); + try + { + Reference<chart2::XDataSeries> xDataSeries = getPrimaryDataSeries(xChartType); + Reference<beans::XPropertySet> xDataSeriesProps(xDataSeries, uno::UNO_QUERY_THROW); + Any aAnyVaryColors = xDataSeriesProps->getPropertyValue("VaryColorsByPoint"); + bool bVaryColors = false; + aAnyVaryColors >>= bVaryColors; + pFS->singleElement(FSNS(XML_c, XML_varyColors), + XML_val, bVaryColors ? "1": "0", + FSEND); + } + catch (...) + { + pFS->singleElement(FSNS(XML_c, XML_varyColors), + XML_val, "0", + FSEND); + } +} + void ChartExport::exportSeries( const Reference<chart2::XChartType>& xChartType, Sequence<Reference<chart2::XDataSeries> >& rSeriesSeq, bool& rPrimaryAxes ) { @@ -2009,6 +2044,7 @@ void ChartExport::exportSeries( const Reference<chart2::XChartType>& xChartType, // xLabelSeq contain those. Otherwise both are empty { FSHelperPtr pFS = GetFS(); + pFS->startElement( FSNS( XML_c, XML_ser ), FSEND ); |