summaryrefslogtreecommitdiff
path: root/chart2
diff options
context:
space:
mode:
authorDennis Francis <dennis.francis@collabora.co.uk>2017-07-06 13:36:57 +0530
committerMiklos Vajna <vmiklos@collabora.co.uk>2017-07-12 11:03:34 +0200
commitf7d3c18da48822b7105b93395aaa4406b87df23f (patch)
tree9e75f20d84baf0a44468a9a99b3fbde084d025c8 /chart2
parentd778119b867b67241b54fd7a9698c839e9bc00f5 (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> (cherry picked from commit 18909d45977a897cbd921d76d1dde4bf3a466271) Reviewed-on: https://gerrit.libreoffice.org/39799 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'chart2')
-rw-r--r--chart2/source/view/main/VLegend.cxx20
1 files changed, 14 insertions, 6 deletions
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());