From 94182ac76189ac2c8e8eab200cc1c4d146b03f57 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Wed, 29 May 2013 22:55:44 +0200 Subject: Support for trendlines in charts when exporting in OOXML format. Trendline support at exporting in OOXML was missing. Add support for exporting regression type and properties and additionally line properties. The only missing are working dashed / dotted lines which are currently kind of "broken" for all lines. Change-Id: Ib7574e58febeb70f2a488db3546b74807c14df14 --- oox/source/export/chartexport.cxx | 123 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) (limited to 'oox') diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx index a79512bb6772..3b3fc73ddc9e 100644 --- a/oox/source/export/chartexport.cxx +++ b/oox/source/export/chartexport.cxx @@ -69,6 +69,7 @@ #include #include #include +#include #include #include @@ -1520,6 +1521,7 @@ void ChartExport::exportSeries( Reference< chart2::XChartType > xChartType, sal_ case chart::TYPEID_SCATTER: { exportMarker( ); + exportTrendlines( aSeriesSeq[nSeriesIdx] ); exportSmooth( ); break; } @@ -1799,6 +1801,7 @@ void ChartExport::exportShapeProps( Reference< XPropertySet > xPropSet ) WriteFill( xPropSet ); WriteOutline( xPropSet ); + pFS->endElement( FSNS( XML_c, XML_spPr ) ); } @@ -2469,6 +2472,126 @@ void ChartExport::exportGrouping( sal_Bool isBar ) FSEND ); } +void ChartExport::exportTrendlines( Reference< chart2::XDataSeries > xSeries ) +{ + FSHelperPtr pFS = GetFS(); + Reference< chart2::XRegressionCurveContainer > xRegressionCurveContainer( xSeries, UNO_QUERY ); + if( xRegressionCurveContainer.is() ) + { + Sequence< Reference< chart2::XRegressionCurve > > aRegCurveSeq = xRegressionCurveContainer->getRegressionCurves(); + const Reference< chart2::XRegressionCurve >* pBeg = aRegCurveSeq.getConstArray(); + const Reference< chart2::XRegressionCurve >* pEnd = pBeg + aRegCurveSeq.getLength(); + for( const Reference< chart2::XRegressionCurve >* pIt = pBeg; pIt != pEnd; ++pIt ) + { + Reference< chart2::XRegressionCurve > xRegCurve = *pIt; + if (!xRegCurve.is()) + continue; + + pFS->startElement( FSNS( XML_c, XML_trendline ), FSEND ); + + Reference< XPropertySet > xProperties( xRegCurve , uno::UNO_QUERY ); + + OUString aService; + + Reference< lang::XServiceName > xServiceName( xProperties, UNO_QUERY ); + if( !xServiceName.is() ) + continue; + aService = xServiceName->getServiceName(); + + if( aService == "com.sun.star.chart2.LinearRegressionCurve" ) + { + pFS->singleElement( FSNS( XML_c, XML_trendlineType ), + XML_val, "linear", + FSEND ); + } + else if( aService == "com.sun.star.chart2.ExponentialRegressionCurve" ) + { + pFS->singleElement( FSNS( XML_c, XML_trendlineType ), + XML_val, "exp", + FSEND ); + } + else if( aService == "com.sun.star.chart2.LogarithmicRegressionCurve" ) + { + pFS->singleElement( FSNS( XML_c, XML_trendlineType ), + XML_val, "log", + FSEND ); + } + else if( aService == "com.sun.star.chart2.PotentialRegressionCurve" ) + { + pFS->singleElement( FSNS( XML_c, XML_trendlineType ), + XML_val, "power", + FSEND ); + } + else if( aService == "com.sun.star.chart2.PolynomialRegressionCurve" ) + { + pFS->singleElement( FSNS( XML_c, XML_trendlineType ), + XML_val, "poly", + FSEND ); + + sal_Int32 aDegree = 2; + xProperties->getPropertyValue( "PolynomialDegree") >>= aDegree; + pFS->singleElement( FSNS( XML_c, XML_order ), + XML_val, I32S(aDegree), + FSEND ); + } + else if( aService == "com.sun.star.chart2.MovingAverageRegressionCurve" ) + { + pFS->singleElement( FSNS( XML_c, XML_trendlineType ), + XML_val, "movingAvg", + FSEND ); + + sal_Int32 aPeriod = 2; + xProperties->getPropertyValue( "MovingAveragePeriod") >>= aPeriod; + + pFS->singleElement( FSNS( XML_c, XML_period ), + XML_val, I32S(aPeriod), + FSEND ); + } + else + { + continue; + } + + double aExtrapolateForward = 0.0; + double aExtrapolateBackward = 0.0; + + xProperties->getPropertyValue( "ExtrapolateForward") >>= aExtrapolateForward; + xProperties->getPropertyValue( "ExtrapolateBackward") >>= aExtrapolateBackward; + + pFS->singleElement( FSNS( XML_c, XML_forward ), + XML_val, OString::number(aExtrapolateForward).getStr(), + FSEND ); + + pFS->singleElement( FSNS( XML_c, XML_backward ), + XML_val, OString::number(aExtrapolateBackward).getStr(), + FSEND ); + + exportShapeProps( xProperties ); + + // Equation properties + Reference< XPropertySet > xEquationProperties( xRegCurve->getEquationProperties() ); + + // Show Equation + sal_Bool aShowEquation = false; + xEquationProperties->getPropertyValue( "ShowEquation" ) >>= aShowEquation; + + pFS->singleElement( FSNS( XML_c, XML_dispEq ), + XML_val, aShowEquation ? "1" : "0", + FSEND ); + + // Show R^2 + sal_Bool aShowCorrelationCoefficient = false; + xEquationProperties->getPropertyValue( "ShowCorrelationCoefficient" ) >>= aShowCorrelationCoefficient; + + pFS->singleElement( FSNS( XML_c, XML_dispRSqr ), + XML_val, aShowCorrelationCoefficient ? "1" : "0", + FSEND ); + + pFS->endElement( FSNS( XML_c, XML_trendline ) ); + } + } +} + void ChartExport::exportMarker() { FSHelperPtr pFS = GetFS(); -- cgit