diff --git a/.changeset/metal-flowers-sneeze.md b/.changeset/metal-flowers-sneeze.md new file mode 100644 index 000000000..05e7b99cd --- /dev/null +++ b/.changeset/metal-flowers-sneeze.md @@ -0,0 +1,5 @@ +--- +'layerchart': patch +--- + +fix(TooltipContext): correct `bisect-band` hit detection by accounting for chart padding diff --git a/packages/layerchart/src/lib/components/tooltip/TooltipContext.svelte b/packages/layerchart/src/lib/components/tooltip/TooltipContext.svelte index a844762ac..5ff781ecd 100644 --- a/packages/layerchart/src/lib/components/tooltip/TooltipContext.svelte +++ b/packages/layerchart/src/lib/components/tooltip/TooltipContext.svelte @@ -310,8 +310,8 @@ case 'bisect-band': { // `x` and `y` values at pointer coordinate - const xValueAtPoint = scaleInvert(ctx.xScale, point.x); - const yValueAtPoint = scaleInvert(ctx.yScale, point.y); + const xValueAtPoint = scaleInvert(ctx.xScale, point.x - ctx.padding.left); + const yValueAtPoint = scaleInvert(ctx.yScale, point.y - ctx.padding.top); if (isScaleBand(ctx.xScale)) { // Find point closest to pointer within the x band