Skip to content

Commit

Permalink
fix(tooltip): Fix tooltip.format.value arg for bar range data
Browse files Browse the repository at this point in the history
- Make format function called once for range(array) data type
- Update on defaultValueFormat to handle array type value also.

Fix #3507
  • Loading branch information
netil authored Nov 8, 2023
1 parent 048c4e2 commit c0f445e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/ChartInternal/internals/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export default {
};
},

defaultValueFormat(v): number|string {
return isValue(v) ? +v : "";
defaultValueFormat(v: number|number[]): number|string {
return isArray(v) ? v.join("~") : (isValue(v) ? +v : "");
},

defaultArcValueFormat(v, ratio): string {
Expand Down
4 changes: 2 additions & 2 deletions src/ChartInternal/internals/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ export default {

value = `<b>Open:</b> ${open} <b>High:</b> ${high} <b>Low:</b> ${low} <b>Close:</b> ${close}${volume ? ` <b>Volume:</b> ${volume}` : ""}`;
} else if ($$.isBarRangeType(row)) {
const {value: [start, end], id, index} = row;
const {value: rangeValue, id, index} = row;

value = `${valueFormat(start, undefined, id, index)} ~ ${valueFormat(end, undefined, id, index)}`;
value = `${valueFormat(rangeValue, undefined, id, index)}`;
} else {
value = valueFormat(getRowValue(row), ...param);
}
Expand Down
7 changes: 3 additions & 4 deletions test/internals/tooltip-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1953,7 +1953,7 @@ describe("TOOLTIP", function() {
util.hoverChart(chart, "mousemove", {clientX: 180, clientY: 130});

expect(chart.$.tooltip.select(".value").html())
.to.be.equal("1300 ~ 1339");
.to.be.equal("1300~1339");
});
});

Expand Down Expand Up @@ -2080,13 +2080,12 @@ describe("TOOLTIP", function() {
// when
chart.tooltip.show({x: 1});

expect(spy.callCount).to.be.equal(2);

expect(spy.callCount).to.be.equal(1);
expect(spy.args.every(v => v.length === 4)).to.be.true;
expect(spy.args.every(v => {
const [value, ratio, id, index]= v;

return isNumber(value) && isUndefined(ratio) && isString(id) && isNumber(index);
return Array.isArray(value) && isUndefined(ratio) && isString(id) && isNumber(index);
})).to.be.true;

spy.resetHistory();
Expand Down

0 comments on commit c0f445e

Please sign in to comment.