[Libreoffice-commits] core.git: Branch 'libreoffice-5-4' - chart2/source

Dennis Francis dennis.francis at collabora.co.uk
Wed Jul 12 09:04:03 UTC 2017


 chart2/source/view/main/VLegend.cxx |   20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

New commits:
commit f7d3c18da48822b7105b93395aaa4406b87df23f
Author: Dennis Francis <dennis.francis at collabora.co.uk>
Date:   Thu Jul 6 13:36:57 2017 +0530

    tdf#108921 : Enforce a minimum legend size for pivot charts...
    
    ...proportional to the chart size. This lets a default pivot
    chart maintain its current size even when there are no data points
    which may result from a pivot field filter operation.
    
    Tried to add a test, but could not with a reasonable amount of
    effort.
    
    Some observations I made when tried to create a unit test:
    
    1. If a new chart is created using uno api fresh from a pivot table,
       no legend is created irrespective of whether there is data or not.
    2. Pivot charts with zero data points work fine with this patch, but
       on round trip the chart needs to be explicitly refreshed by
       clicking one of the pivot table's field selectors to make the chart
       show axis/labels etc.
    
    Change-Id: I010ca9093ce94dc216ba06e9d7aedaa412e59401
    Reviewed-on: https://gerrit.libreoffice.org/39620
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
    Tested-by: Tomaž Vajngerl <quikee at gmail.com>
    (cherry picked from commit 18909d45977a897cbd921d76d1dde4bf3a466271)
    Reviewed-on: https://gerrit.libreoffice.org/39799
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/chart2/source/view/main/VLegend.cxx b/chart2/source/view/main/VLegend.cxx
index 4790dec34763..ac6347e0f26d 100644
--- a/chart2/source/view/main/VLegend.cxx
+++ b/chart2/source/view/main/VLegend.cxx
@@ -268,10 +268,15 @@ awt::Size lcl_placeLegendEntries(
     const Reference< drawing::XShapes > & xTarget,
     const Reference< lang::XMultiServiceFactory > & xShapeFactory,
     const awt::Size& rRemainingSpace,
-    sal_Int32 nYStartPosition)
+    sal_Int32 nYStartPosition,
+    const awt::Size& rPageSize,
+    bool bIsPivotChart)
 {
     bool bIsCustomSize = (eExpansion == css::chart::ChartLegendExpansion_CUSTOM);
     awt::Size aResultingLegendSize(0,0);
+    // For Pivot charts set the *minimum* legend size as a function of page size.
+    if ( bIsPivotChart )
+        aResultingLegendSize = awt::Size((rPageSize.Width * 13) / 80, (rPageSize.Height * 31) / 90);
     if( bIsCustomSize )
         aResultingLegendSize = awt::Size(rRemainingSpace.Width, rRemainingSpace.Height + nYStartPosition);
 
@@ -570,13 +575,13 @@ awt::Size lcl_placeLegendEntries(
     if( !bIsCustomSize )
     {
         if( bSymbolsLeftSide )
-            aResultingLegendSize.Width  = nCurrentXPos + nXPadding;
+            aResultingLegendSize.Width  = std::max( aResultingLegendSize.Width, nCurrentXPos + nXPadding );
         else
         {
             sal_Int32 nLegendWidth = -(nCurrentXPos-nXPadding);
-            aResultingLegendSize.Width  = nLegendWidth;
+            aResultingLegendSize.Width  = std::max( aResultingLegendSize.Width, nLegendWidth );
         }
-        aResultingLegendSize.Height = nMaxYPos + nYPadding;
+        aResultingLegendSize.Height = std::max( aResultingLegendSize.Height, nMaxYPos + nYPadding );
     }
 
     if( !bSymbolsLeftSide )
@@ -948,7 +953,10 @@ void VLegend::createShapes(
 
             bool bSymbolsLeftSide = lcl_shouldSymbolsBePlacedOnTheLeftSide( xLegendProp, m_nDefaultWritingMode );
 
-            if (!aViewEntries.empty())
+            uno::Reference<chart2::data::XPivotTableDataProvider> xPivotTableDataProvider( mrModel.getDataProvider(), uno::UNO_QUERY );
+            bool bIsPivotChart = xPivotTableDataProvider.is();
+
+            if ( !aViewEntries.empty() || bIsPivotChart )
             {
                 // create buttons
                 long nUsedButtonHeight = 0;
@@ -967,7 +975,7 @@ void VLegend::createShapes(
                 // place the legend entries
                 aLegendSize = lcl_placeLegendEntries(aViewEntries, eExpansion, bSymbolsLeftSide, fViewFontSize,
                                                      aMaxSymbolExtent, aTextProperties, xLegendContainer,
-                                                     m_xShapeFactory, aLegendSize, nUsedButtonHeight);
+                                                     m_xShapeFactory, aLegendSize, nUsedButtonHeight, rPageSize, bIsPivotChart);
 
                 uno::Reference<beans::XPropertySet> xModelPage(mrModel.getPageBackground());
 


More information about the Libreoffice-commits mailing list