From f6f740b851be5bb3e1dbfbb7348b9f5a1e6974f4 Mon Sep 17 00:00:00 2001 From: Ross Johnson <159597299+rosco54@users.noreply.github.com> Date: Thu, 11 Jul 2024 21:28:15 +1000 Subject: [PATCH] Fix bar chart totals labels X-position calculation --- src/charts/BarStacked.js | 2 +- src/charts/common/bar/DataLabels.js | 26 +++++++++----------------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/charts/BarStacked.js b/src/charts/BarStacked.js index c84621cbd..e5fdf65ea 100644 --- a/src/charts/BarStacked.js +++ b/src/charts/BarStacked.js @@ -187,7 +187,7 @@ class BarStacked extends Bar { elDataLabelsWrap, elGoalsMarkers, type: 'bar', - visibleSeries: 0, + visibleSeries: columnGroupIndex, }) } diff --git a/src/charts/common/bar/DataLabels.js b/src/charts/common/bar/DataLabels.js index adefdc96a..20bd190d6 100644 --- a/src/charts/common/bar/DataLabels.js +++ b/src/charts/common/bar/DataLabels.js @@ -216,7 +216,7 @@ export default class BarDataLabels { j, }) - bcx = bcx - strokeWidth / 2 + columnGroupIndex * barWidth + bcx = bcx - strokeWidth / 2 let dataPointsDividedWidth = w.globals.gridWidth / w.globals.dataPoints @@ -328,12 +328,15 @@ export default class BarDataLabels { } // width divided into equal parts - let xDivision = w.globals.gridWidth / w.globals.dataPoints + let xDivision = dataPointsDividedWidth totalDataLabelsX = totalDataLabelsBcx + - barWidth * (w.globals.barGroups.length - 0.5) - - (w.globals.isXNumeric ? barWidth : xDivision) + + (w.globals.isXNumeric + ? -barWidth * w.globals.barGroups.length / 2 + : w.globals.barGroups.length * barWidth / 2 + - (w.globals.barGroups.length - 1) * barWidth + - xDivision) + barTotalDataLabelsConfig.offsetX } @@ -381,8 +384,6 @@ export default class BarDataLabels { barWidth = Math.abs(barWidth) - bcy += columnGroupIndex * barHeight - let dataLabelsY = bcy - (this.barCtx.isRangeBar ? 0 : dataPointsDividedHeight) + @@ -631,17 +632,8 @@ export default class BarDataLabels { this.barCtx.lastActiveBarSerieIndex === realIndex ) { totalDataLabelText = graphics.drawText({ - // TODO: Add gap, visibleI - x: - x - - (!w.globals.isBarHorizontal && w.globals.barGroups.length - ? (barWidth * (w.globals.barGroups.length - 1)) / 2 - : 0), - y: - y - - (w.globals.isBarHorizontal && w.globals.barGroups.length - ? (barHeight * (w.globals.barGroups.length - 1)) / 2 - : 0), + x: x, + y: y, foreColor: barTotalDataLabelsConfig.style.color, text: val, textAnchor,