[Libreoffice-commits] core.git: Branch 'libreoffice-6-0' - oox/source sd/qa

Szymon Kłos szymon.klos at collabora.com
Wed Feb 14 09:00:07 UTC 2018


 oox/source/drawingml/chart/seriesconverter.cxx |   34 ++++++++++++-----
 sd/qa/unit/data/pptx/tdf114821.pptx            |binary
 sd/qa/unit/import-tests.cxx                    |   49 +++++++++++++++++++++++++
 3 files changed, 73 insertions(+), 10 deletions(-)

New commits:
commit f48053c06cfed8edcbcde08b1c193fd2ad080700
Author: Szymon Kłos <szymon.klos at collabora.com>
Date:   Wed Jan 3 13:24:32 2018 +0100

    tdf#114821 calculate better label position
    
    Positioning hack was improved. It calculates position
    depending on direct chart size factor. Preffered
    label positions are: top - vertical, and center - horizontal
    
    Change-Id: Ic25f08cd0bc3105fe34841dbc3f8aacacb694d43
    Reviewed-on: https://gerrit.libreoffice.org/48909
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Szymon Kłos <szymon.klos at collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/48927
    Reviewed-by: Andras Timar <andras.timar at collabora.com>

diff --git a/oox/source/drawingml/chart/seriesconverter.cxx b/oox/source/drawingml/chart/seriesconverter.cxx
index 6eceb213ea04..19538048e52e 100644
--- a/oox/source/drawingml/chart/seriesconverter.cxx
+++ b/oox/source/drawingml/chart/seriesconverter.cxx
@@ -54,13 +54,30 @@ using namespace ::com::sun::star::uno;
 
 namespace {
 
-/** nested-up sgn function - employs some gratuity around 0 - values
-   smaller than 0.33 are clamped to 0
+/** Function to get vertical position of label from chart height factor.
+    Value can be negative, prefer top placement.
  */
-int lclSgn( double nVal )
+int lclGetPositionY( double nVal )
 {
-    const int intVal=nVal*3;
-    return intVal == 0 ? 0 : (intVal < 0 ? -1 : 1);
+    if( nVal <= 0.1 )
+        return -1;
+    else if( nVal <= 0.6 )
+        return 0;
+    else
+        return 1;
+}
+
+/** Function to get horizontal position of label from chart width factor.
+    Value can be negative, prefer center placement.
+*/
+int lclGetPositionX( double nVal )
+{
+    if( nVal <= -0.2 )
+        return -1;
+    else if( nVal <= 0.2 )
+        return 0;
+    else
+        return 1;
 }
 
 Reference< XLabeledDataSequence > lclCreateLabeledDataSequence(
@@ -236,11 +253,8 @@ void DataLabelConverter::convertFromModel( const Reference< XDataSeries >& rxDat
                     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);
+            const int simplifiedX = lclGetPositionX(mrModel.mxLayout->mfX);
+            const int simplifiedY = lclGetPositionY(mrModel.mxLayout->mfY);
             aPropSet.setProperty( PROP_LabelPlacement,
                                   aPositionsLookupTable[ simplifiedX+1 + 3*(simplifiedY+1) ] );
         }
diff --git a/sd/qa/unit/data/pptx/tdf114821.pptx b/sd/qa/unit/data/pptx/tdf114821.pptx
new file mode 100644
index 000000000000..3813b0607903
Binary files /dev/null and b/sd/qa/unit/data/pptx/tdf114821.pptx differ
diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx
index 00e72e3b533c..255bac40ed28 100644
--- a/sd/qa/unit/import-tests.cxx
+++ b/sd/qa/unit/import-tests.cxx
@@ -56,6 +56,7 @@
 #include <com/sun/star/animations/XAnimationNode.hpp>
 #include <com/sun/star/animations/XAnimate.hpp>
 #include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/chart/DataLabelPlacement.hpp>
 #include <com/sun/star/chart/XChartDocument.hpp>
 #include <com/sun/star/chart2/XChartDocument.hpp>
 #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
@@ -165,6 +166,7 @@ public:
     void testTdf109187();
     void testTdf108926();
     void testTdf100065();
+    void testTdf114821();
 
     bool checkPattern(sd::DrawDocShellRef const & rDocRef, int nShapeNumber, std::vector<sal_uInt8>& rExpected);
     void testPatternImport();
@@ -238,6 +240,7 @@ public:
     CPPUNIT_TEST(testTdf109187);
     CPPUNIT_TEST(testTdf108926);
     CPPUNIT_TEST(testTdf100065);
+    CPPUNIT_TEST(testTdf114821);
 
     CPPUNIT_TEST_SUITE_END();
 };
@@ -2285,6 +2288,52 @@ void SdImportTest::testTdf100065()
     xDocShRef->DoClose();
 }
 
+void SdImportTest::testTdf114821()
+{
+    css::uno::Any aAny;
+    sd::DrawDocShellRef xDocShRef = loadURL( m_directories.getURLFromSrc( "/sd/qa/unit/data/pptx/tdf114821.pptx" ), PPTX );
+
+    uno::Reference< beans::XPropertySet > xPropSet( getShapeFromPage( 0, 0, xDocShRef ) );
+    aAny = xPropSet->getPropertyValue( "Model" );
+    CPPUNIT_ASSERT_MESSAGE( "The shape doesn't have the property", aAny.hasValue() );
+
+    uno::Reference< chart::XChartDocument > xChartDoc;
+    aAny >>= xChartDoc;
+    CPPUNIT_ASSERT_MESSAGE( "failed to load chart", xChartDoc.is() );
+    uno::Reference< chart2::XChartDocument > xChart2Doc( xChartDoc, uno::UNO_QUERY );
+    CPPUNIT_ASSERT_MESSAGE( "failed to load chart", xChart2Doc.is() );
+
+    uno::Reference< chart2::XCoordinateSystemContainer > xBCooSysCnt( xChart2Doc->getFirstDiagram(), uno::UNO_QUERY );
+    uno::Sequence< uno::Reference< chart2::XCoordinateSystem > > aCooSysSeq( xBCooSysCnt->getCoordinateSystems() );
+    uno::Reference< chart2::XChartTypeContainer > xCTCnt( aCooSysSeq[0], uno::UNO_QUERY );
+
+    uno::Reference< chart2::XDataSeriesContainer > xDSCnt( xCTCnt->getChartTypes()[0], uno::UNO_QUERY );
+    CPPUNIT_ASSERT_MESSAGE( "failed to load data series", xDSCnt.is() );
+    uno::Sequence< uno::Reference< chart2::XDataSeries > > aSeriesSeq( xDSCnt->getDataSeries() );
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Invalid Series count", static_cast<sal_Int32>( 1 ), aSeriesSeq.getLength() );
+
+    // Check the first label
+    const css::uno::Reference< css::beans::XPropertySet >& rPropSet0( aSeriesSeq[0]->getDataPointByIndex( 0 ) );
+    CPPUNIT_ASSERT( rPropSet0.is() );
+    sal_Int32 aPlacement;
+    rPropSet0->getPropertyValue( "LabelPlacement" ) >>= aPlacement;
+    CPPUNIT_ASSERT_EQUAL( css::chart::DataLabelPlacement::TOP, aPlacement );
+
+    // Check the second label
+    const css::uno::Reference< css::beans::XPropertySet >& rPropSet1( aSeriesSeq[0]->getDataPointByIndex( 1 ) );
+    CPPUNIT_ASSERT( rPropSet1.is() );
+    rPropSet1->getPropertyValue( "LabelPlacement" ) >>= aPlacement;
+    CPPUNIT_ASSERT_EQUAL( css::chart::DataLabelPlacement::CENTER, aPlacement );
+
+    // Check the third label
+    const css::uno::Reference< css::beans::XPropertySet >& rPropSet2( aSeriesSeq[0]->getDataPointByIndex( 2 ) );
+    CPPUNIT_ASSERT( rPropSet2.is() );
+    rPropSet2->getPropertyValue( "LabelPlacement") >>= aPlacement;
+    CPPUNIT_ASSERT_EQUAL( css::chart::DataLabelPlacement::TOP, aPlacement );
+
+    xDocShRef->DoClose();
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SdImportTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();


More information about the Libreoffice-commits mailing list