Skip to content

Commit

Permalink
improve getyAxisLabelsCoords based on formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
junedchhipa committed Sep 18, 2023
1 parent 0563557 commit e006e9c
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/modules/dimensions/YAxis.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ export default class DimYAxis {
const axesUtils = new AxesUtils(this.dCtx.ctx)

w.config.yaxis.map((yaxe, index) => {
const formatterArgs = {
seriesIndex: index,
dataPointIndex: -1,
w,
}
const yS = w.globals.yAxisScale[index]
let yAxisMinWidth = 0
if (
Expand All @@ -39,20 +44,21 @@ export default class DimYAxis {
) {
let lbFormatter = w.globals.yLabelFormatters[index]
let minV = yS.niceMin === Number.MIN_VALUE ? 0 : yS.niceMin
const longestStr =
String(minV).length > String(yS.niceMax).length ? minV : yS.niceMax
let val = yS.result.reduce((acc, curr) => {
return String(lbFormatter(acc, formatterArgs))?.length >
String(lbFormatter(curr, formatterArgs))?.length
? acc
: curr
}, minV)

val = lbFormatter(val, formatterArgs)

// the second parameter -1 is the index of tick which user can use in the formatter
let val = lbFormatter(longestStr, {
seriesIndex: index,
dataPointIndex: -1,
w,
})
let valArr = val

// if user has specified a custom formatter, and the result is null or empty, we need to discard the formatter and take the value as it is.
if (typeof val === 'undefined' || val.length === 0) {
val = longestStr
val = yS.niceMax
}

if (w.globals.isBarHorizontal) {
Expand Down

0 comments on commit e006e9c

Please sign in to comment.