Skip to content

Commit 0d35cae

Browse files
authored
fix(TooltipContext): correct hit detection by accounting for chart padding (#806)
1 parent f6f7778 commit 0d35cae

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

.changeset/metal-flowers-sneeze.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'layerchart': patch
3+
---
4+
5+
fix(TooltipContext): correct `bisect-band` hit detection by accounting for chart padding

packages/layerchart/src/lib/components/tooltip/TooltipContext.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@
310310
311311
case 'bisect-band': {
312312
// `x` and `y` values at pointer coordinate
313-
const xValueAtPoint = scaleInvert(ctx.xScale, point.x);
314-
const yValueAtPoint = scaleInvert(ctx.yScale, point.y);
313+
const xValueAtPoint = scaleInvert(ctx.xScale, point.x - ctx.padding.left);
314+
const yValueAtPoint = scaleInvert(ctx.yScale, point.y - ctx.padding.top);
315315
316316
if (isScaleBand(ctx.xScale)) {
317317
// Find point closest to pointer within the x band

0 commit comments

Comments
 (0)