Skip to content

Commit 9158723

Browse files
committed
2 parents 3c438a3 + bc53914 commit 9158723

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

src/charts/Bar.js

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,34 @@ class Bar {
319319
const graphics = new Graphics(this.ctx)
320320

321321
if (!lineFill) {
322+
// if user provided a function in colors, we need to eval here
323+
// Note: the position of this function logic (ex. stroke: { colors: ["",function(){}] }) i.e array index 1 depicts the realIndex/seriesIndex.
324+
function fetchColor(i) {
325+
const exp = w.config.stroke.colors
326+
let c
327+
if (Array.isArray(exp) && exp.length > 0) {
328+
c = exp[i]
329+
if (!c) c = ''
330+
if (typeof c === 'function') {
331+
return c({
332+
value: w.globals.series[i][j],
333+
dataPointIndex: j,
334+
w,
335+
})
336+
}
337+
}
338+
return c
339+
}
340+
341+
const checkAvailableColor =
342+
typeof w.globals.stroke.colors[realIndex] === 'function'
343+
? fetchColor(realIndex)
344+
: w.globals.stroke.colors[realIndex]
345+
322346
/* fix apexcharts#341 */
323347
lineFill = this.barOptions.distributed
324348
? w.globals.stroke.colors[j]
325-
: w.globals.stroke.colors[realIndex]
349+
: checkAvailableColor
326350
}
327351

328352
if (w.config.series[i].data[j] && w.config.series[i].data[j].strokeColor) {
@@ -545,7 +569,11 @@ class Bar {
545569
}
546570
}
547571

548-
y = this.barHelpers.getYForValue(this.series[i][j], zeroH, translationsIndex)
572+
y = this.barHelpers.getYForValue(
573+
this.series[i][j],
574+
zeroH,
575+
translationsIndex
576+
)
549577

550578
const paths = this.barHelpers.getColumnPaths({
551579
barXPosition,
@@ -578,7 +606,14 @@ class Bar {
578606
pathFrom: paths.pathFrom,
579607
x,
580608
y,
581-
goalY: this.barHelpers.getGoalValues('y', null, zeroH, i, j, translationsIndex),
609+
goalY: this.barHelpers.getGoalValues(
610+
'y',
611+
null,
612+
zeroH,
613+
i,
614+
j,
615+
translationsIndex
616+
),
582617
barXPosition,
583618
barWidth,
584619
}

types/apexcharts.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ type ApexStroke = {
344344
show?: boolean
345345
curve?: 'smooth' | 'straight' | 'stepline' | 'linestep' | 'monotoneCubic' | ('smooth' | 'straight' | 'stepline' | 'linestep' | 'monotoneCubic')[]
346346
lineCap?: 'butt' | 'square' | 'round'
347-
colors?: string[]
347+
colors?: any[] | string[]
348348
width?: number | number[]
349349
dashArray?: number | number[]
350350
fill?: ApexFill

0 commit comments

Comments
 (0)