diff options
author | Dennis Francis <dennis.francis@collabora.co.uk> | 2017-07-06 13:36:57 +0530 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2017-07-10 15:38:48 +0200 |
commit | 18909d45977a897cbd921d76d1dde4bf3a466271 (patch) | |
tree | ecbe2bcae7b51a425084ea315a3f7b0b85631ba1 /chart2 | |
parent | c9f6bd6a714b634c1f366a525cc3571116c3f9f5 (diff) |
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@libreoffice.org>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'chart2')
-rw-r--r-- | chart2/source/view/main/VLegend.cxx | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/chart2/source/view/main/VLegend.cxx b/chart2/source/view/main/VLegend.cxx index 6ded0aae091a..98925974aec6 100644 --- a/chart2/source/view/main/VLegend.cxx +++ b/chart2/source/view/main/VLegend.cxx @@ -267,10 +267,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); @@ -569,13 +574,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 ) @@ -947,7 +952,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; @@ -966,7 +974,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()); |