summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2013-04-28 23:45:08 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2013-04-29 00:15:00 +0200
commit33671ee41300d762c8fc7a674a60efe152fffd45 (patch)
treece19d7f1b77b8b9d247a8d3473e0123d5d9b763b /oox
parent3ba4b5a907530a93114177f30206f1bf81917464 (diff)
export for error bars to OOXML, fdo#62312
This does not work yet as we have several validation errors in our exported OOXML chart doc. I have to clean them up before the documents are accepted by Excel. Change-Id: I0bba64a9c6cab489199c8e6f04158fea7b953d0a
Diffstat (limited to 'oox')
-rw-r--r--oox/source/export/chartexport.cxx154
1 files changed, 154 insertions, 0 deletions
diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx
index 07b5371fbf17..ea872b43e566 100644
--- a/oox/source/export/chartexport.cxx
+++ b/oox/source/export/chartexport.cxx
@@ -43,6 +43,7 @@
#include <com/sun/star/chart/ChartAxisPosition.hpp>
#include <com/sun/star/chart/ChartSolidType.hpp>
#include <com/sun/star/chart/DataLabelPlacement.hpp>
+#include <com/sun/star/chart/ErrorBarStyle.hpp>
#include <com/sun/star/chart2/XChartDocument.hpp>
#include <com/sun/star/chart2/XDiagram.hpp>
@@ -103,6 +104,8 @@ using ::com::sun::star::sheet::XFormulaTokens;
using ::oox::core::XmlFilterBase;
using ::sax_fastparser::FSHelperPtr;
+namespace cssc = com::sun::star::chart;
+
DBG(extern void dump_pset(Reference< XPropertySet > rXPropSet));
namespace oox { namespace drawingml {
@@ -1542,6 +1545,17 @@ void ChartExport::exportSeries( Reference< chart2::XChartType > xChartType, sal_
// export data points
exportDataPoints( uno::Reference< beans::XPropertySet >( aSeriesSeq[nSeriesIdx], uno::UNO_QUERY ), nSeriesLength );
+ //export error bars here
+ Reference< XPropertySet > xSeriesPropSet( xSource, uno::UNO_QUERY );
+ Reference< XPropertySet > xErrorBarYProps;
+ xSeriesPropSet->getPropertyValue("ErrorBarY") >>= xErrorBarYProps;
+ if(xErrorBarYProps.is())
+ exportErrorBar(xErrorBarYProps, true);
+ Reference< XPropertySet > xErrorBarXProps;
+ xSeriesPropSet->getPropertyValue("ErrorBarX") >>= xErrorBarXProps;
+ if(xErrorBarXProps.is())
+ exportErrorBar(xErrorBarXProps, false);
+
// export categories
if( mxCategoriesValues.is() )
exportSeriesCategory( mxCategoriesValues );
@@ -2536,6 +2550,146 @@ void ChartExport::exportFirstSliceAng( )
FSEND );
}
+namespace {
+
+const char* getErrorBarStyle(sal_Int32 nErrorBarStyle)
+{
+ switch(nErrorBarStyle)
+ {
+ case cssc::ErrorBarStyle::NONE:
+ // I have no idea how to map it to OOXML
+ // this approach is as good as any else
+ return "fixedVal";
+ case cssc::ErrorBarStyle::VARIANCE:
+ break;
+ case cssc::ErrorBarStyle::STANDARD_DEVIATION:
+ return "stdDev";
+ case cssc::ErrorBarStyle::ABSOLUTE:
+ return "fixedVal";
+ case cssc::ErrorBarStyle::RELATIVE:
+ return "percentage";
+ case cssc::ErrorBarStyle::ERROR_MARGIN:
+ break;
+ case cssc::ErrorBarStyle::STANDARD_ERROR:
+ return "stdErr";
+ case cssc::ErrorBarStyle::FROM_DATA:
+ return "cust";
+ default:
+ assert(false); // can't happen
+ }
+ return "";
+}
+
+Reference< chart2::data::XDataSequence> getLabeledSequence(
+ uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence > > aSequences,
+ bool bPositive )
+{
+ const OUString aRolePrefix( "error-bars" );
+ OUString aDirection;
+ if(bPositive)
+ aDirection = "positive";
+ else
+ aDirection = "negative";
+
+ for( sal_Int32 nI=0; nI< aSequences.getLength(); ++nI )
+ {
+ if( aSequences[nI].is())
+ {
+ uno::Reference< chart2::data::XDataSequence > xSequence( aSequences[nI]->getValues());
+ uno::Reference< beans::XPropertySet > xSeqProp( xSequence, uno::UNO_QUERY_THROW );
+ OUString aRole;
+ if( ( xSeqProp->getPropertyValue(
+ OUString( "Role" )) >>= aRole ) &&
+ aRole.match( aRolePrefix ) && aRole.indexOf(aDirection) >= 0 )
+ {
+ return xSequence;
+ }
+ }
+ }
+
+ return Reference< chart2::data::XDataSequence > ();
+}
+
+}
+
+void ChartExport::exportErrorBar(Reference< XPropertySet> xErrorBarProps, bool bYError)
+{
+ FSHelperPtr pFS = GetFS();
+ pFS->startElement( FSNS( XML_c, XML_errBars ),
+ FSEND );
+ pFS->singleElement( FSNS( XML_c, XML_errDir ),
+ XML_val, bYError ? "y" : "x",
+ FSEND );
+ bool bPositive, bNegative;
+ xErrorBarProps->getPropertyValue("ShowPositiveError") >>= bPositive;
+ xErrorBarProps->getPropertyValue("ShowNegativeError") >>= bNegative;
+ const char* pErrBarType;
+ if(bPositive && bNegative)
+ pErrBarType = "both";
+ else if(bPositive)
+ pErrBarType = "plus";
+ else if(bNegative)
+ pErrBarType = "minus";
+ else
+ {
+ // what the hell should we do now?
+ // at least this makes the file valid
+ pErrBarType = "both";
+ }
+ pFS->singleElement( FSNS( XML_c, XML_errBarType ),
+ XML_val, pErrBarType,
+ FSEND );
+
+ sal_Int32 nErrorBarStyle;
+ xErrorBarProps->getPropertyValue("ErrorBarStyle") >>= nErrorBarStyle;
+ const char* pErrorBarStyle = getErrorBarStyle(nErrorBarStyle);
+ pFS->singleElement( FSNS( XML_c, XML_errValType ),
+ XML_val, pErrorBarStyle,
+ FSEND );
+ pFS->singleElement( FSNS( XML_c, XML_noEndCap ),
+ XML_val, "0",
+ FSEND );
+ if(nErrorBarStyle == cssc::ErrorBarStyle::FROM_DATA)
+ {
+ uno::Reference< chart2::data::XDataSource > xDataSource(xErrorBarProps, uno::UNO_QUERY);
+ Sequence< Reference < chart2::data::XLabeledDataSequence > > aSequences =
+ xDataSource->getDataSequences();
+
+ if(bPositive)
+ {
+ exportSeriesValues(getLabeledSequence(aSequences, true), XML_plus);
+ }
+
+ if(bNegative)
+ {
+ exportSeriesValues(getLabeledSequence(aSequences, false), XML_minus);
+ }
+ }
+ else
+ {
+ double nVal;
+ if(nErrorBarStyle == cssc::ErrorBarStyle::STANDARD_DEVIATION)
+ {
+ xErrorBarProps->getPropertyValue("Weight") >>= nVal;
+ }
+ else
+ {
+ if(bPositive)
+ xErrorBarProps->getPropertyValue("PositiveError") >>= nVal;
+ else
+ xErrorBarProps->getPropertyValue("NegativeError") >>= nVal;
+ }
+
+ OString aVal = OString::number(nVal);
+
+ pFS->singleElement( FSNS( XML_c, XML_val ),
+ XML_val, aVal.getStr(),
+ FSEND );
+ }
+
+ pFS->endElement( FSNS( XML_c, XML_errBars) );
+}
+
void ChartExport::exportView3D()
{
Reference< XPropertySet > xPropSet( mxDiagram , uno::UNO_QUERY);