Skip to content

Commit

Permalink
fix(tooltip): show error data if dataset if large (#6307)
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini authored Jun 21, 2024
1 parent 11846bc commit 1571ad4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('chart.emit', () => {
const [tooltipShowed, resolveShow] = createPromise();
chart.on('tooltip:show', (event) => {
const { x } = event.data.data;
expect(x.toUTCString()).toBe('Mon, 18 Jun 2007 17:47:35 GMT');
expect(x.toUTCString()).toBe('Tue, 19 Jun 2007 00:00:00 GMT');
resolveShow();
});
dispatchPlotEvent(canvas, 'pointermove', {
Expand Down
9 changes: 8 additions & 1 deletion src/interaction/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -854,10 +854,17 @@ export function seriesTooltip(
});
}

// X in focus may related multiple points when dataset is large,
// so we need to find the first x to show tooltip.
const firstX = filteredSeriesData[0]?.[0].x;
const transformedX = firstX ?? abstractX(focus);

emitter.emit('tooltip:show', {
...event,
nativeEvent: true,
data: { data: { x: invert(scale.x, abstractX(focus), true) } },
data: {
data: { x: invert(scale.x, transformedX, true) },
},
});
},
wait,
Expand Down

0 comments on commit 1571ad4

Please sign in to comment.