summaryrefslogtreecommitdiff
path: root/chart2
diff options
context:
space:
mode:
authorDennis Francis <dennis.francis@collabora.co.uk>2017-08-21 13:59:41 +0530
committerAndras Timar <andras.timar@collabora.com>2017-09-01 16:17:22 +0200
commit256e2cb6702a22c55d1e5db304e58dbe5f7b26bf (patch)
treebfafd4dfadcbf433c548ed26159e3dae27e7e9f0 /chart2
parent895c23b97eecd9cd32a145a6267f4b43db479248 (diff)
tdf#62363: When pie chart sector is too small do "Outside" placement
...of its label when "Best fit" label placement setting is used. Change-Id: Id201d922505de0e134286f4772abe282bb0722bc Reviewed-on: https://gerrit.libreoffice.org/41572 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com> (cherry picked from commit 8c8edfabdee656ac5a9a0b1106f90baf315f1dd4) Reviewed-on: https://gerrit.libreoffice.org/41622 (cherry picked from commit d44e12f1f77514059375e6da3f981a992ff7de7e)
Diffstat (limited to 'chart2')
-rw-r--r--chart2/source/view/charttypes/PieChart.cxx12
1 files changed, 10 insertions, 2 deletions
diff --git a/chart2/source/view/charttypes/PieChart.cxx b/chart2/source/view/charttypes/PieChart.cxx
index f3b854ee8707..98fffc60e430 100644
--- a/chart2/source/view/charttypes/PieChart.cxx
+++ b/chart2/source/view/charttypes/PieChart.cxx
@@ -288,14 +288,23 @@ void PieChart::createTextLabelShape(
///the label position is allowed; the `createTextLabelShape` treats the
///`AVOID_OVERLAP` as if it was of `CENTER` type;
+ double nVal = rSeries.getYValue(nPointIndex);
//AVOID_OVERLAP is in fact "Best fit" in the UI.
bool bMovementAllowed = ( nLabelPlacement == css::chart::DataLabelPlacement::AVOID_OVERLAP );
if( bMovementAllowed )
+ {
// Use center for "Best fit" for now. In the future we
// may want to implement a real best fit algorithm.
// But center is good enough, and close to what Excel
// does.
- nLabelPlacement = css::chart::DataLabelPlacement::CENTER;
+
+ // Place the label outside if the sector is too small
+ // The threshold is set to 2%, but can be improved by making it a function of
+ // label width and radius too ?
+ double fFrac = fabs( nVal / rParam.mfLogicYSum );
+ nLabelPlacement = ( fFrac <= 0.02 ) ? css::chart::DataLabelPlacement::OUTSIDE :
+ css::chart::DataLabelPlacement::CENTER;
+ }
///for `OUTSIDE` (`INSIDE`) label placements an offset of 150 (-150), in the
///radius direction, is added to the final screen position of the label
@@ -354,7 +363,6 @@ void PieChart::createTextLabelShape(
sal_Int32 nTextMaximumFrameWidth = ceil(fTextMaximumFrameWidth);
///the text shape for the label is created
- double nVal = rSeries.getYValue(nPointIndex);
aPieLabelInfo.xTextShape = createDataLabel(
xTextTarget, rSeries, nPointIndex, nVal, rParam.mfLogicYSum,
aScreenPosition2D, eAlignment, 0, nTextMaximumFrameWidth);