summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <quikee@gmail.com>2013-05-29 22:55:44 +0200
committerTomaž Vajngerl <quikee@gmail.com>2013-07-03 21:46:40 +0200
commit94182ac76189ac2c8e8eab200cc1c4d146b03f57 (patch)
tree0fc89717f4c6e35a065f90b82806a8789dc6a229
parentc818e23df3f608f247da0d4722d102a03725c1cf (diff)
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
-rw-r--r--include/oox/export/chartexport.hxx1
-rw-r--r--oox/source/export/chartexport.cxx123
-rw-r--r--sc/source/filter/excel/xechart.cxx3
3 files changed, 125 insertions, 2 deletions
diff --git a/include/oox/export/chartexport.hxx b/include/oox/export/chartexport.hxx
index d3212d0a5678..40ea87f62b0b 100644
--- a/include/oox/export/chartexport.hxx
+++ b/include/oox/export/chartexport.hxx
@@ -151,6 +151,7 @@ private:
const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xSeriesProperties,
sal_Int32 nSeriesLength );
void exportGrouping( sal_Bool isBar = sal_False );
+ void exportTrendlines( ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > xSeries );
void exportMarker();
void exportSmooth();
void exportFirstSliceAng();
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 <com/sun/star/drawing/XShape.hpp>
#include <com/sun/star/drawing/FillStyle.hpp>
#include <com/sun/star/drawing/BitmapMode.hpp>
+#include <com/sun/star/lang/XServiceName.hpp>
#include <com/sun/star/table/CellAddress.hpp>
#include <com/sun/star/sheet/XFormulaParser.hpp>
@@ -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();
diff --git a/sc/source/filter/excel/xechart.cxx b/sc/source/filter/excel/xechart.cxx
index 68f6b9c60e56..7879748f1334 100644
--- a/sc/source/filter/excel/xechart.cxx
+++ b/sc/source/filter/excel/xechart.cxx
@@ -1691,6 +1691,7 @@ bool XclExpChSerTrendLine::Convert( Reference< XRegressionCurve > xRegCurve, sal
// trend line type
ScfPropertySet aCurveProp( xRegCurve );
+
OUString aService = aCurveProp.GetServiceName();
if( aService == "com.sun.star.chart2.LinearRegressionCurve" )
{
@@ -1749,8 +1750,6 @@ bool XclExpChSerTrendLine::Convert( Reference< XRegressionCurve > xRegCurve, sal
}
// missing features
- // #i20819# polynomial trend lines
- // #i66819# moving average trend lines
// #i5085# manual trend line size
// #i34093# manual crossing point
return true;