summaryrefslogtreecommitdiffstats
path: root/chart2/source/view/charttypes
diff options
context:
space:
mode:
authorJustin Luth <justin.luth@collabora.com>2024-01-29 10:20:16 -0500
committerMiklos Vajna <vmiklos@collabora.com>2024-01-30 10:42:48 +0100
commit85f4395b6f40c0295a190cca09ecd51858fc3b31 (patch)
tree33469ce5c59789be98b49c5a9442c69bb64ef23d /chart2/source/view/charttypes
parenttdf#146756 pie chart2 import: use manualLayout Width for pie chart labels (diff)
downloadcore-85f4395b6f40c0295a190cca09ecd51858fc3b31.tar.gz
core-85f4395b6f40c0295a190cca09ecd51858fc3b31.zip
tdf#146756 pie chart2 import: improve response to bestFit failure
Fixes a 7.2 regression from commit b0068342398786ca50304260434a18880dddf74d author Tünde Tóth on Wed Dec 16 18:26:26 2020 +0100 tdf#138777 pie chart: improve long data label width When a label fails to bestFit inside the pie slice, it will be placed outside of the pie of course. However, we can't assume that there is any chart space available to place a label outside. Tünde got that part right. He limited the space available based on the chart edge. But there are some optimizations that can improve that. 1.) Every little bit can help. As we go away from the X-axis, we gain a little bit of space, so use that... 2.) Don't assume that the pie chart is in the middle of the page. 3.) Use a consistent algorithm for all degrees - much simpler. make CppunitTest_chart2_import CPPUNIT_TEST_NAME=testTdf146756 Change-Id: I0d8528bc227768f91237cda6b74bf9365820bfa7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162704 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'chart2/source/view/charttypes')
-rw-r--r--chart2/source/view/charttypes/PieChart.cxx38
1 files changed, 30 insertions, 8 deletions
diff --git a/chart2/source/view/charttypes/PieChart.cxx b/chart2/source/view/charttypes/PieChart.cxx
index 93221b468473..3635ea3fd3bc 100644
--- a/chart2/source/view/charttypes/PieChart.cxx
+++ b/chart2/source/view/charttypes/PieChart.cxx
@@ -402,6 +402,7 @@ void PieChart::createTextLabelShape(
// set the maximum text width to be used when text wrapping is enabled
double fTextMaximumFrameWidth = 0.8 * fPieRadius;
+ const double fCompatMaxTextLen = m_aAvailableOuterRect.getWidth() / 5.0;
if (m_aAvailableOuterRect.getWidth())
{
if (bHasCustomLabelPlacement)
@@ -412,7 +413,7 @@ void PieChart::createTextLabelShape(
if (aCustomSize.Width > 0)
fTextMaximumFrameWidth = aCustomSize.Width;
else
- fTextMaximumFrameWidth = m_aAvailableOuterRect.getWidth() / 5.0;
+ fTextMaximumFrameWidth = fCompatMaxTextLen;
}
else if (nLabelPlacement == css::chart::DataLabelPlacement::OUTSIDE)
{
@@ -450,13 +451,34 @@ void PieChart::createTextLabelShape(
{
if (m_aAvailableOuterRect.getWidth())
{
- if ((fAngleDegree >= 67.5 && fAngleDegree <= 112.5)
- || (fAngleDegree >= 247.5 && fAngleDegree <= 292.5))
- fTextMaximumFrameWidth = m_aAvailableOuterRect.getWidth() / 3.0;
- else
- fTextMaximumFrameWidth
- = 0.85 * (m_aAvailableOuterRect.getWidth() / 2.0 - fPieRadius);
- nTextMaximumFrameWidth = ceil(fTextMaximumFrameWidth);
+ /* This was bestFit, but it didn't fit. So how best to handle this?
+ *
+ * Two possible cases relating to compatibility
+ * 1.) It did fit for Microsoft, but our bestFit wasn't able to do the same
+ * * In that case, the best response is to be as small as possible
+ * (the distance from the chart edge to where the label attaches to the slice)
+ * to avoid scaling the diagram with too long outside labels,
+ * and to encourage fixing the bestFit algorithm.
+ * 2.) It didn't fit for Microsoft either (possible, but less likely situation)
+ * * In that case, the compatible max length would be best
+ * * can expect the chart space has been properly sized to handle the max length
+ *
+ * In the native LO case, it is also best to use as small as possible,
+ * so that the user creating the diagram is annoyed and makes the chart area larger.
+ *
+ * Therefore, handle this by making the label as small as possible.
+ *
+ * Complication (tdf122765.pptx): it is possiible for the aOuterPosition
+ * to be outside of the available outer rectangle (somehow),
+ * so in that bizarre case just try the positive value of the result...
+ */
+ const sal_Int32 nOuterX = aPieLabelInfo.aOuterPosition.getX();
+ if (fAngleDegree < 90 || fAngleDegree > 270) // label is placed on the right half
+ fTextMaximumFrameWidth = 0.8 * abs(m_aAvailableOuterRect.getWidth() - nOuterX);
+ else // label is placed on the left half
+ fTextMaximumFrameWidth = 0.8 * nOuterX;
+
+ nTextMaximumFrameWidth = ceil(std::min(fTextMaximumFrameWidth, fCompatMaxTextLen));
}
nScreenValueOffsetInRadiusDirection = (m_nDimension != 3) ? 150 : 0;