diff options
author | Thorsten Behrens <tbehrens@novell.com> | 2011-07-05 14:06:22 +0200 |
---|---|---|
committer | Thorsten Behrens <tbehrens@novell.com> | 2011-07-05 14:06:22 +0200 |
commit | bde6f4be556322808eeef9d0de2ce26fd5fe6caa (patch) | |
tree | f6549d3d2ca44cb096aa0a5446ca4200cc670357 /oox | |
parent | bfed95561999e53e3bf760d370782dd320b39c52 (diff) |
Fix label position for ooxml charts
Fixes bnc#694340 somewhat hackish - chart2 cannot individually place
chart data labels, so if the original ooxml document does, attempt
one of the canned position as an approximation.
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/drawingml/chart/seriesconverter.cxx | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/oox/source/drawingml/chart/seriesconverter.cxx b/oox/source/drawingml/chart/seriesconverter.cxx index f6f1ad8523ec..4005ac46c46e 100644 --- a/oox/source/drawingml/chart/seriesconverter.cxx +++ b/oox/source/drawingml/chart/seriesconverter.cxx @@ -35,6 +35,7 @@ #include <com/sun/star/chart2/XRegressionCurve.hpp> #include <com/sun/star/chart2/XRegressionCurveContainer.hpp> #include <com/sun/star/chart2/data/XDataSink.hpp> +#include <basegfx/numeric/ftools.hxx> #include "oox/drawingml/chart/datasourceconverter.hxx" #include "oox/drawingml/chart/seriesmodel.hxx" #include "oox/drawingml/chart/titleconverter.hxx" @@ -59,6 +60,15 @@ using ::rtl::OUString; namespace { +/** nastied-up sgn function - employs some gratuity around 0 - values + smaller than 0.33 are clamped to 0 + */ +int lclSgn( double nVal ) +{ + const int intVal=nVal*3; + return intVal == 0 ? 0 : (intVal < 0 ? -1 : 1); +} + Reference< XLabeledDataSequence > lclCreateLabeledDataSequence( const ConverterRoot& rParent, DataSourceModel* pValues, const OUString& rRole, @@ -178,6 +188,27 @@ void DataLabelConverter::convertFromModel( const Reference< XDataSeries >& rxDat { PropertySet aPropSet( rxDataSeries->getDataPointByIndex( mrModel.mnIndex ) ); lclConvertLabelFormatting( aPropSet, getFormatter(), mrModel, rTypeGroup, false ); + + if( !mrModel.mxLayout->mbAutoLayout ) + { + // bnc#694340 - nasty hack - chart2 cannot individually + // place data labels, let's try to find a useful + // compromise instead + namespace csscd = ::com::sun::star::chart::DataLabelPlacement; + const sal_Int32 aPositionsLookupTable[] = + { + csscd::TOP_LEFT, csscd::TOP, csscd::TOP_RIGHT, + csscd::LEFT, csscd::CENTER, csscd::RIGHT, + csscd::BOTTOM_LEFT, csscd::BOTTOM, csscd::BOTTOM_RIGHT + }; + const double nMax=std::max( + fabs(mrModel.mxLayout->mfX), + fabs(mrModel.mxLayout->mfY)); + const int simplifiedX=lclSgn(mrModel.mxLayout->mfX/nMax); + const int simplifiedY=lclSgn(mrModel.mxLayout->mfY/nMax); + aPropSet.setProperty( PROP_LabelPlacement, + aPositionsLookupTable[ simplifiedX+1 + 3*(simplifiedY+1) ] ); + } } catch( Exception& ) { |