[Libreoffice-commits] core.git: Branch 'feature/polynomialregression' - include/oox oox/source sc/source
Tomaž Vajngerl
quikee at gmail.com
Wed May 29 14:04:16 PDT 2013
include/oox/export/chartexport.hxx | 1
oox/source/export/chartexport.cxx | 123 +++++++++++++++++++++++++++++++++++++
sc/source/filter/excel/xechart.cxx | 3
3 files changed, 125 insertions(+), 2 deletions(-)
New commits:
commit 16c3e6e693cf92c04669e85b9f387232c86cc63e
Author: Tomaž Vajngerl <quikee at gmail.com>
Date: Wed May 29 22:55:44 2013 +0200
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
diff --git a/include/oox/export/chartexport.hxx b/include/oox/export/chartexport.hxx
index d3212d0..40ea87f 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 b654001..8fdcf58 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 4138ec8..b0e13ac 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;
More information about the Libreoffice-commits
mailing list