Skip to content

Commit

Permalink
fix #4657; fix #4818; border radius on last element when previous dat…
Browse files Browse the repository at this point in the history
…apoint is zero
  • Loading branch information
junedchhipa committed Oct 3, 2024
1 parent e13f3c6 commit b06abe8
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions src/charts/common/bar/Helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export default class Helpers {
}
}

this.arrBorderRadius = this.createBorderRadiusArr(w.globals.seriesPercent)

if (this.barCtx.seriesLen === 0) {
// A small adjustment when combo charts are used
this.barCtx.seriesLen = 1
Expand Down Expand Up @@ -243,24 +245,37 @@ export default class Helpers {
return strokeWidth
}

shouldApplyRadius(realIndex) {
createBorderRadiusArr(seriesPercent) {
const w = this.w
let applyRadius = false

if (w.config.plotOptions.bar.borderRadius > 0) {
if (w.config.chart.stacked) {
if (w.config.plotOptions.bar.borderRadiusWhenStacked === 'last') {
if (this.barCtx.lastActiveBarSerieIndex === realIndex) {
applyRadius = true
}
const alwaysApplyRadius =
!this.w.config.chart.stacked ||
w.config.plotOptions.bar.borderRadiusWhenStacked !== 'last' ||
w.config.plotOptions.bar.borderRadius <= 0

const numRows = seriesPercent.length
const numCols = seriesPercent[0].length

const resultArr = Array.from({ length: numRows }, () =>
Array.from({ length: numCols }, () => alwaysApplyRadius)
)

if (alwaysApplyRadius) return resultArr

// For each column
for (let j = 0; j < numCols; j++) {
// Iterate from the last row upwards
for (let i = numRows - 1, found = false; i >= 0; i--) {
if (!found && seriesPercent[i][j] !== 0) {
resultArr[i][j] = true
found = true
} else {
applyRadius = true
resultArr[i][j] = false
}
} else {
applyRadius = true
}
}
return applyRadius

return resultArr
}

barBackground({ j, i, x1, x2, y1, y2, elSeries }) {
Expand Down Expand Up @@ -362,7 +377,7 @@ export default class Helpers {
? ' Z'
: ' z')

if (this.shouldApplyRadius(realIndex)) {
if (this.arrBorderRadius[realIndex][j]) {
pathTo = graphics.roundPathCorners(
pathTo,
w.config.plotOptions.bar.borderRadius
Expand Down Expand Up @@ -450,7 +465,7 @@ export default class Helpers {
? ' Z'
: ' z')

if (this.shouldApplyRadius(realIndex)) {
if (this.arrBorderRadius[realIndex][j]) {
pathTo = graphics.roundPathCorners(
pathTo,
w.config.plotOptions.bar.borderRadius
Expand Down

0 comments on commit b06abe8

Please sign in to comment.