Skip to content

Commit

Permalink
fix(tooltip): show error data if dataset if large
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini committed Jun 21, 2024
1 parent 11846bc commit 33b429e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ const chart = new Chart({

// Specify visualization.
chart
.interval() // Create an interval mark and add it to the chart.
.data(data) // Bind data for this mark.
.encode('x', 'genre') // Assign genre column to x position channel.
.encode('y', 'sold') // Assign sold column to y position channel.
.encode('color', 'genre'); // Assign genre column to color channel.
.interval() // Create an interval mark and add it to the chart.
.data(data) // Bind data for this mark.
.encode('x', 'genre') // Assign genre column to x position channel.
.encode('y', 'sold') // Assign sold column to y position channel.
.encode('color', 'genre'); // Assign genre column to color channel.

// Render visualization.
chart.render();
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 33b429e

Please sign in to comment.