[Libreoffice-commits] .: Branch 'libreoffice-3-4' - oox/source

Andras Timar timar at kemper.freedesktop.org
Thu Jul 7 00:46:01 PDT 2011


 oox/source/drawingml/chart/seriesconverter.cxx |   31 +++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

New commits:
commit ce13dc1ac0f8ce6b6189bed53e8c60ede521dcf6
Author: Thorsten Behrens <tbehrens at novell.com>
Date:   Tue Jul 5 14:06:22 2011 +0200

    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.
    
    Signed-off-by: Andras Timar <atimar at suse.com>

diff --git a/oox/source/drawingml/chart/seriesconverter.cxx b/oox/source/drawingml/chart/seriesconverter.cxx
index bb1479f..7b3d266 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& )
     {


More information about the Libreoffice-commits mailing list