tdf#50934: Initial implementation of connector lines for bar-of-pie
Change-Id: I586dd5ae784f5e86ad1e0d863765b058873eac68
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160728
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
diff --git a/chart2/source/view/charttypes/PieChart.cxx b/chart2/source/view/charttypes/PieChart.cxx
index ed20a65..b74a536 100644
--- a/chart2/source/view/charttypes/PieChart.cxx
+++ b/chart2/source/view/charttypes/PieChart.cxx
@@ -952,24 +952,11 @@ void PieChart::createOneRing([[maybe_unused]]enum SubPieType eType,
{
bool bHasFillColorMapping = pSeries->hasPropertyMapping("FillColor");
/// The angle degree offset is set by the same property of the
/// data series.
/// Counter-clockwise offset from the 3 o'clock position.
m_aPosHelper.m_fAngleDegreeOffset = pSeries->getStartingAngle();
///the `explodeable` ring is the first one except when the radius axis
///orientation is reversed (always!?) and we are dealing with a donut: in
///such a case the `explodeable` ring is the last one.
std::vector< VDataSeriesGroup >::size_type nExplodeableSlot = 0;
if( m_aPosHelper.isMathematicalOrientationRadius() && m_bUseRings )
nExplodeableSlot = m_aZSlots.front().size()-1;
sal_Int32 nBegin = pDataSrc->getBeginIndex(pSeries, eType);
sal_Int32 nEnd = pDataSrc->getEndIndex(pSeries, eType);
sal_Int32 nRingPtCnt = pDataSrc->getNPoints(pSeries, eType);
// Find sum of entries for this ring or sub-pie
double ringSum = 0;
for (sal_Int32 nPointIndex = nBegin; nPointIndex < nEnd; nPointIndex++ ) {
for (sal_Int32 nPointIndex = 0; nPointIndex < nRingPtCnt; nPointIndex++ ) {
double fY = pDataSrc->getData(pSeries, nPointIndex, eType);
if (!std::isnan(fY) ) ringSum += fY;
}
@@ -981,7 +968,7 @@ void PieChart::createOneRing([[maybe_unused]]enum SubPieType eType,
// Left of-pie has the "composite" wedge (the one expanded in the right
// subgraph) facing to the right in the chart, to allow the expansion
// lines to meet it
double compositeVal = pDataSrc->getData(pSeries, nEnd - 1, eType);
double compositeVal = pDataSrc->getData(pSeries, nRingPtCnt - 1, eType);
return compositeVal * 360 / (ringSum * 2);
} else {
/// The angle degree offset is set by the same property of the
@@ -993,9 +980,16 @@ void PieChart::createOneRing([[maybe_unused]]enum SubPieType eType,
m_aPosHelper.m_fAngleDegreeOffset = sAngle();
///the `explodeable` ring is the first one except when the radius axis
///orientation is reversed (always!?) and we are dealing with a donut: in
///such a case the `explodeable` ring is the last one.
std::vector< VDataSeriesGroup >::size_type nExplodeableSlot = 0;
if( m_aPosHelper.isMathematicalOrientationRadius() && m_bUseRings )
nExplodeableSlot = m_aZSlots.front().size()-1;
double fLogicYForNextPoint = 0.0;
///iterate through all points to create shapes
for(sal_Int32 nPointIndex = nBegin; nPointIndex < nEnd; nPointIndex++ )
for(sal_Int32 nPointIndex = 0; nPointIndex < nRingPtCnt; nPointIndex++ )
{
double fLogicInnerRadius, fLogicOuterRadius;
@@ -1061,7 +1055,8 @@ void PieChart::createOneRing([[maybe_unused]]enum SubPieType eType,
const bool bConcentricExplosion = m_bUseRings && (m_aZSlots.front().size() > 1);
rtl::Reference<SvxShape> xPointShape =
createDataPoint(eType, xSeriesGroupShape_Shapes,
xPointProperties, aParam, nEnd, bConcentricExplosion);
xPointProperties, aParam, nRingPtCnt,
bConcentricExplosion);
///point color:
if (!pSeries->hasPointOwnColor(nPointIndex) && m_xColorScheme.is())
@@ -1134,12 +1129,11 @@ void PieChart::createOneBar(
{
bool bHasFillColorMapping = pSeries->hasPropertyMapping("FillColor");
sal_Int32 nBegin = pDataSrc->getBeginIndex(pSeries, eType);
sal_Int32 nEnd = pDataSrc->getEndIndex(pSeries, eType);
sal_Int32 nBarPtCnt = pDataSrc->getNPoints(pSeries, eType);
// Find sum of entries for this bar chart
double barSum = 0;
for (sal_Int32 nPointIndex = nBegin; nPointIndex < nEnd; nPointIndex++ ) {
for (sal_Int32 nPointIndex = 0; nPointIndex < nBarPtCnt; nPointIndex++ ) {
double fY = pDataSrc->getData(pSeries, nPointIndex, eType);
if (!std::isnan(fY) ) barSum += fY;
}
@@ -1147,7 +1141,7 @@ void PieChart::createOneBar(
double fBarBottom = 0.0;
double fBarTop = -0.5; // make the bar go from -0.5 to 0.5
///iterate through all points to create shapes
for(sal_Int32 nPointIndex = nBegin; nPointIndex < nEnd; nPointIndex++ )
for(sal_Int32 nPointIndex = 0; nPointIndex < nBarPtCnt; nPointIndex++ )
{
aParam.mfDepth = getTransformedDepth() * (n3DRelativeHeight / 100.0);
@@ -2006,14 +2000,7 @@ double PieDataSrc::getData(const VDataSeries* pSeries, sal_Int32 nPtIdx,
return fabs(pSeries->getYValue( nPtIdx ));
}
sal_Int32 PieDataSrc::getBeginIndex([[maybe_unused]]const VDataSeries* pSeries,
[[maybe_unused]] enum SubPieType eType) const
{
assert(eType == SubPieType::NONE);
return 0;
}
sal_Int32 PieDataSrc::getEndIndex(const VDataSeries* pSeries,
sal_Int32 PieDataSrc::getNPoints(const VDataSeries* pSeries,
[[maybe_unused]] enum SubPieType eType) const
{
assert(eType == SubPieType::NONE);
@@ -2038,25 +2025,14 @@ uno::Reference< beans::XPropertySet > PieDataSrc::getProps(
// behaviors should be supported later.
// TODO
sal_Int32 OfPieDataSrc::getBeginIndex(const VDataSeries* pSeries,
enum SubPieType eType) const
{
if (eType == SubPieType::LEFT) {
return 0;
} else {
assert(eType == SubPieType::RIGHT);
return pSeries->getTotalPointCount() - 3;
}
}
sal_Int32 OfPieDataSrc::getEndIndex(const VDataSeries* pSeries,
sal_Int32 OfPieDataSrc::getNPoints(const VDataSeries* pSeries,
enum SubPieType eType) const
{
if (eType == SubPieType::LEFT) {
return pSeries->getTotalPointCount() - 2;
} else {
assert(eType == SubPieType::RIGHT);
return pSeries->getTotalPointCount();
return 3;
}
}
@@ -2075,10 +2051,8 @@ double OfPieDataSrc::getData(const VDataSeries* pSeries, sal_Int32 nPtIdx,
fabs(pSeries->getYValue(n+2));
}
} else {
// nPtIdx should be in [n, n+2]
assert(eType == SubPieType::RIGHT);
assert(nPtIdx >= n && nPtIdx <= n+2);
return fabs(pSeries->getYValue(nPtIdx));
return fabs(pSeries->getYValue(nPtIdx + n));
}
}
@@ -2099,7 +2073,7 @@ uno::Reference< beans::XPropertySet > OfPieDataSrc::getProps(
}
} else {
assert(eType == SubPieType::RIGHT);
return pSeries->getPropertiesOfPoint(nPtIdx);
return pSeries->getPropertiesOfPoint(nPtIdx + n);
}
}
diff --git a/chart2/source/view/charttypes/PieChart.hxx b/chart2/source/view/charttypes/PieChart.hxx
index 1630874..a3e4519 100644
--- a/chart2/source/view/charttypes/PieChart.hxx
+++ b/chart2/source/view/charttypes/PieChart.hxx
@@ -60,10 +60,8 @@ public:
PieDataSrcBase() = default;
virtual ~PieDataSrcBase() = default;
// Beginning and ending indices for given pie subtype
virtual sal_Int32 getBeginIndex(const VDataSeries* pSeries,
enum SubPieType eType) const = 0;
virtual sal_Int32 getEndIndex(const VDataSeries* pSeries,
// Number of data points for given pie subtype
virtual sal_Int32 getNPoints(const VDataSeries* pSeries,
enum SubPieType eType) const = 0;
// Get the value for the given pie wedge, for the given subtype
@@ -82,9 +80,7 @@ public:
class PieDataSrc : public PieDataSrcBase
{
public:
sal_Int32 getBeginIndex(const VDataSeries* pSeries,
enum SubPieType eType) const;
sal_Int32 getEndIndex(const VDataSeries* pSeries,
sal_Int32 getNPoints(const VDataSeries* pSeries,
enum SubPieType eType) const;
double getData(const VDataSeries* pSeries, sal_Int32 nPtIdx,
@@ -104,9 +100,7 @@ public:
// Minimum sensible number of data points
static sal_Int32 minPoints() { return 4; }
sal_Int32 getBeginIndex(const VDataSeries* pSeries,
enum SubPieType eType) const;
sal_Int32 getEndIndex(const VDataSeries* pSeries,
sal_Int32 getNPoints(const VDataSeries* pSeries,
enum SubPieType eType) const;
double getData(const VDataSeries* pSeries, sal_Int32 nPtIdx,
@@ -228,7 +222,21 @@ struct PieLabelInfo;
sal_Int32 n3DRelativeHeight);
private: //member
// Radius scalings for left and right of-pie subcharts
static constexpr double m_fLeftScale = 2.0/3;
static constexpr double m_fRightScale = 1.0/3;
// Shifts left/right for of-pie subcharts
static constexpr double m_fLeftShift = -0.75;
static constexpr double m_fRightShift = 0.75;
// Height of bar-of-pie bar
static constexpr double m_fFullBarHeight = 1.0;
// Bar-of-pie bar left side position
static constexpr double m_fBarLeft = 0.75;
// Bar-of-pie bar right side position
static constexpr double m_fBarRight = 1.25;
PiePositionHelper m_aPosHelper;
bool m_bUseRings;
bool m_bSizeExcludesLabelsAndExplodedSegments;
std::vector< ExplicitScaleData > m_aCartesianScales; // for bar-of-pie