Skip to content

Commit

Permalink
bar datalabels improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
junedchhipa committed Dec 1, 2023
1 parent 03d799f commit 2c0fb38
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/charts/BarStacked.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class BarStacked extends Bar {
})

let elGoalsMarkers = this.graphics.group({
class: 'apexcharts-bar-goals-markers'
class: 'apexcharts-bar-goals-markers',
})

let barHeight = 0
Expand Down
9 changes: 8 additions & 1 deletion src/charts/common/bar/DataLabels.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export default class BarDataLabels {
totalDataLabels = this.drawTotalDataLabels({
x: dataLabelsPos.totalDataLabelsX,
y: dataLabelsPos.totalDataLabelsY,
barWidth,
realIndex,
textAnchor: dataLabelsPos.totalDataLabelsAnchor,
val: this.getStackedTotalDataLabel({ realIndex, j }),
Expand Down Expand Up @@ -606,10 +607,12 @@ export default class BarDataLabels {
x,
y,
val,
barWidth,
realIndex,
textAnchor,
barTotalDataLabelsConfig,
}) {
const w = this.w
const graphics = new Graphics(this.barCtx.ctx)

let totalDataLabelText
Expand All @@ -621,7 +624,11 @@ export default class BarDataLabels {
this.barCtx.lastActiveBarSerieIndex === realIndex
) {
totalDataLabelText = graphics.drawText({
x: x,
x:
x -
(w.globals.seriesGroups.length
? barWidth / w.globals.seriesGroups.length
: 0),
y: y,
foreColor: barTotalDataLabelsConfig.style.color,
text: val,
Expand Down
4 changes: 2 additions & 2 deletions src/modules/DataLabels.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ class DataLabels {
if (correctedLabels.textRects) {
// fixes #2264
if (
x < -10 - correctedLabels.textRects.width ||
x > w.globals.gridWidth + correctedLabels.textRects.width + 10
x < -20 - correctedLabels.textRects.width ||
x > w.globals.gridWidth + correctedLabels.textRects.width + 30
) {
// datalabels fall outside drawing area, so draw a blank label
text = ''
Expand Down

0 comments on commit 2c0fb38

Please sign in to comment.