Skip to content

Commit

Permalink
Merge pull request #4566 from rosco54/Issue_4558
Browse files Browse the repository at this point in the history
Fix bar chart labels X-position calculations
  • Loading branch information
junedchhipa authored Jul 12, 2024
2 parents 1af289f + f6f740b commit da087c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/charts/BarStacked.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class BarStacked extends Bar {
elDataLabelsWrap,
elGoalsMarkers,
type: 'bar',
visibleSeries: 0,
visibleSeries: columnGroupIndex,
})
}

Expand Down
26 changes: 9 additions & 17 deletions src/charts/common/bar/DataLabels.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -381,8 +384,6 @@ export default class BarDataLabels {

barWidth = Math.abs(barWidth)

bcy += columnGroupIndex * barHeight

let dataLabelsY =
bcy -
(this.barCtx.isRangeBar ? 0 : dataPointsDividedHeight) +
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit da087c5

Please sign in to comment.