Skip to content

Commit

Permalink
fix(axis): fix axis.y/y2.tick.format context error
Browse files Browse the repository at this point in the history
Make format function to be called within current instance context

Fix #2976
  • Loading branch information
netil committed Nov 24, 2022
1 parent 692e598 commit 54ee419
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ChartInternal/internals/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function getFormat($$, typeValue: AxisType, v: number): number | string {
const format = config[type] ?
config[type] : $$.defaultValueFormat;

return format(v);
return format.call($$.api, v);
}

export default {
Expand Down
28 changes: 28 additions & 0 deletions test/internals/axis-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1570,6 +1570,34 @@ describe("AXIS", function() {
});
});

describe("axis.y.tick.format", () => {
before(() => {
args = {
data: {
columns: [
["data1", 30, 200, 100]
],
},
axis: {
y: {
tick: {
format: function(x) {
return this.data.values("data1")[0];
}
}
}
}
};
});

it("tick.format context should be chart instance itself.", () => {
// when
chart.tooltip.show({x:1});

expect(+chart.$.tooltip.select(".value").text()).to.be.equal(30);
});
});

describe("axis.y.tick.rotate", () => {
describe("y Axis", () => {
before(() => {
Expand Down

0 comments on commit 54ee419

Please sign in to comment.