Skip to content

Commit

Permalink
fix(tooltip): fix tooltip.position call context
Browse files Browse the repository at this point in the history
Fix call context for tooltip.position

Fix #2265
  • Loading branch information
netil committed Aug 17, 2021
1 parent ba6c2b5 commit b78a48d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/ChartInternal/internals/tooltip.ts
Expand Up @@ -362,10 +362,10 @@ export default {
}

if (!bindto) {
const fnPos = config.tooltip_position || $$.tooltipPosition;
const fnPos = config.tooltip_position?.bind($$.api) || $$.tooltipPosition.bind($$);

// Get tooltip dimensions
const pos = fnPos.call(this, dataToShow, width, height, element);
const pos = fnPos(dataToShow, width, height, element);

["top", "left"].forEach(v => {
const value = pos[v];
Expand Down
4 changes: 3 additions & 1 deletion test/internals/tooltip-spec.ts
Expand Up @@ -83,6 +83,8 @@ describe("TOOLTIP", function() {
};

const tooltipPosition = function(data, width, height, element) {
expect(this).to.be.equal(chart);

expect(data.length).to.be.equal(args.data.columns.length - 1);
expect(data[0].index).to.be.equal(2);
expect(data[0].value).to.be.equal(100);
Expand Down Expand Up @@ -375,7 +377,7 @@ describe("TOOLTIP", function() {
});
});

describe("tooltip positionFunction", () => {
describe("tooltip.position callback function", () => {
before(() => {
args.tooltip = {
position: tooltipPosition
Expand Down

0 comments on commit b78a48d

Please sign in to comment.