summaryrefslogtreecommitdiff
path: root/chart2
diff options
context:
space:
mode:
authorBalazs Varga <balazs.varga991@gmail.com>2020-06-16 12:07:45 +0200
committerXisco Fauli <xiscofauli@libreoffice.org>2020-06-25 12:18:50 +0200
commit2bb5d9624911eb78ce5a3cd0aa122f9307c50a5c (patch)
treeabe44c72db02bebd19b5ea24697c3f36d54619f2 /chart2
parent5451833f3af5582a8cab7e4b3da402f083f56908 (diff)
tdf#134029 Chart view: enable to move data label
if the position is 'Best Fit' and the data label is outside from the pie chart. To check the functionality of the patch: open the attached file http://bugs.documentfoundation.org/attachment.cgi?id=162039 and move the data label. Change-Id: I88546c64dd62ab40b35400b0330f7899ba09123f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96452 Tested-by: Jenkins Reviewed-by: László Németh <nemeth@numbertext.org> (cherry picked from commit c66cb6d6e4a843dc7c7d06e1c2c0723a6ff85fc5) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97000 Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'chart2')
-rw-r--r--chart2/qa/extras/chart2import.cxx2
-rw-r--r--chart2/source/view/charttypes/PieChart.cxx45
2 files changed, 23 insertions, 24 deletions
diff --git a/chart2/qa/extras/chart2import.cxx b/chart2/qa/extras/chart2import.cxx
index 4a6f07d5f310..3e0704c876ae 100644
--- a/chart2/qa/extras/chart2import.cxx
+++ b/chart2/qa/extras/chart2import.cxx
@@ -2523,7 +2523,7 @@ void Chart2ImportTest::testTdf133376()
CPPUNIT_ASSERT(xDataPointLabel.is());
// Check the position of the 3rd data point label, which is out from the pie slice
awt::Point aLabelPosition = xDataPointLabel->getPosition();
- CPPUNIT_ASSERT_DOUBLES_EQUAL(1466, aLabelPosition.X, 30);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1071, aLabelPosition.X, 30);
CPPUNIT_ASSERT_DOUBLES_EQUAL(5269, aLabelPosition.Y, 30);
}
diff --git a/chart2/source/view/charttypes/PieChart.cxx b/chart2/source/view/charttypes/PieChart.cxx
index 03e928a85c23..9032b40977f1 100644
--- a/chart2/source/view/charttypes/PieChart.cxx
+++ b/chart2/source/view/charttypes/PieChart.cxx
@@ -1581,16 +1581,10 @@ void PieChart::performLabelBestFit(ShapeParam& rShapeParam, PieLabelInfo const &
return;
// If it does not fit inside, let's put it outside
- PolarLabelPositionHelper aPolarPosHelper(m_pPosHelper.get(),m_nDimension,m_xLogicTarget,m_pShapeFactory);
- auto eAlignment = LABEL_ALIGN_CENTER;
- awt::Point aScreenPosition2D(
- aPolarPosHelper.getLabelScreenPositionAndAlignmentForUnitCircleValues(eAlignment, css::chart::DataLabelPlacement::OUTSIDE
- , rShapeParam.mfUnitCircleStartAngleDegree, rShapeParam.mfUnitCircleWidthAngleDegree
- , rShapeParam.mfUnitCircleInnerRadius, rShapeParam.mfUnitCircleOuterRadius, rShapeParam.mfLogicZ+0.5, 0 ));
+ awt::Point aOldPos(rPieLabelInfo.xLabelGroupShape->getPosition());
basegfx::B2IVector aTranslationVector = rPieLabelInfo.aFirstPosition - rPieLabelInfo.aOrigin;
- aTranslationVector.setLength(150);
- aScreenPosition2D.X += aTranslationVector.getX();
- aScreenPosition2D.Y += aTranslationVector.getY();
+ awt::Point aScreenPosition2D(aOldPos.X + aTranslationVector.getX(),
+ aOldPos.Y + aTranslationVector.getY());
double fAngleDegree = rShapeParam.mfUnitCircleStartAngleDegree + rShapeParam.mfUnitCircleWidthAngleDegree / 2.0;
::basegfx::B2IRectangle aBb(lcl_getRect(rPieLabelInfo.xLabelGroupShape));
@@ -1602,29 +1596,34 @@ void PieChart::performLabelBestFit(ShapeParam& rShapeParam, PieLabelInfo const &
while (fAngleDegree < 0.0)
fAngleDegree += 360.0;
- if( fAngleDegree <= 22.5 || fAngleDegree >= 337.5 )
- aScreenPosition2D.Y -= fLabelHeight / 2;
- else if( fAngleDegree < 67.5 )
- aScreenPosition2D.Y -= fLabelHeight;
- else if( fAngleDegree < 112.5 )
+ if (fAngleDegree <= 22.5 || fAngleDegree >= 337.5)
+ aScreenPosition2D.X += fLabelWidth / 2;
+ else if (fAngleDegree < 67.5)
{
- aScreenPosition2D.X -= fLabelWidth / 2;
- aScreenPosition2D.Y -= fLabelHeight;
+ aScreenPosition2D.X += fLabelWidth / 2;
+ aScreenPosition2D.Y -= fLabelHeight / 2;
}
+ else if (fAngleDegree < 112.5)
+ aScreenPosition2D.Y -= fLabelHeight / 2;
else if (fAngleDegree <= 157.5)
{
- aScreenPosition2D.X -= fLabelWidth;
- aScreenPosition2D.Y -= fLabelHeight;
+ aScreenPosition2D.X -= fLabelWidth / 2;
+ aScreenPosition2D.Y -= fLabelHeight / 2;
}
else if (fAngleDegree <= 202.5)
+ aScreenPosition2D.X -= fLabelWidth / 2;
+ else if (fAngleDegree < 247.5)
{
- aScreenPosition2D.X -= fLabelWidth;
- aScreenPosition2D.Y -= fLabelHeight / 2;
+ aScreenPosition2D.X -= fLabelWidth / 2;
+ aScreenPosition2D.Y += fLabelHeight / 2;
}
- else if (fAngleDegree < 247.5)
- aScreenPosition2D.X -= fLabelWidth;
else if (fAngleDegree < 292.5)
- aScreenPosition2D.X -= fLabelWidth / 2;
+ aScreenPosition2D.Y += fLabelHeight / 2;
+ else
+ {
+ aScreenPosition2D.X += fLabelWidth / 2;
+ aScreenPosition2D.Y += fLabelHeight / 2;
+ }
rPieLabelInfo.xLabelGroupShape->setPosition(aScreenPosition2D);
}