:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(quill-charts): match hover dot color to the visible line on ties (#79144)
jake sciotto455ef6c05a4a
diff --git a/packages/quill/packages/charts/src/charts/LineChart/closest-hover-series.test.ts b/packages/quill/packages/charts/src/charts/LineChart/closest-hover-series.test.tsindex 971ffd02e7df..1225dd16768e 100644--- a/packages/quill/packages/charts/src/charts/LineChart/closest-hover-series.test.ts+++ b/packages/quill/packages/charts/src/charts/LineChart/closest-hover-series.test.ts@@ -59,8 +59,14 @@ describe('closestHoverSeriesKey', () => {expect(result).toBeNull()})- it('keeps the first series on a distance tie (strict less-than)', () => {- const result = closestHoverSeriesKey([series('a'), series('b')], yPixelFromMap({ a: 30, b: 70 }), 50)- expect(result).toBe('a')+ it('picks the last tied series when lines coincide (the one painted on top)', () => {+ // Equal values put two lines at the same y-pixel; series paint in array order, so the+ // later one is the visible line and the dot must ring its color, not the covered one's.+ const result = closestHoverSeriesKey(+ [series('under'), series('over')],+ yPixelFromMap({ under: 40, over: 40 }),+ 50+ )+ expect(result).toBe('over')})})diff --git a/packages/quill/packages/charts/src/charts/LineChart/closest-hover-series.ts b/packages/quill/packages/charts/src/charts/LineChart/closest-hover-series.tsindex 12a5a6b37168..0385c02a61c0 100644--- a/packages/quill/packages/charts/src/charts/LineChart/closest-hover-series.ts+++ b/packages/quill/packages/charts/src/charts/LineChart/closest-hover-series.ts@@ -9,6 +9,10 @@ import type { ResolvedSeries } from '../../core/types'* lines, goal lines) are never candidates: in percent-stack mode their raw values ring far off-plot,* and they aren't the line the user is pointing at. `yPixelFor` returns a series' y-pixel at the* hovered index; a non-finite y skips that series. Returns null when no series qualifies.+ *+ * Ties go to the last tied series: equal values put lines exactly on top of each other, and series+ * paint in array order, so the last tied series is the line actually visible and the dot must take+ * its color.*/export function closestHoverSeriesKey(series: readonly ResolvedSeries[],@@ -24,7 +28,7 @@ export function closestHoverSeriesKey(const y = yPixelFor(s)if (Number.isFinite(y)) {const dist = Math.abs(y - cursorY)- if (dist < minDist) {+ if (dist <= minDist) {minDist = distclosestKey = s.key}diff --git a/packages/quill/packages/charts/src/overlays/tooltipUtils.test.ts b/packages/quill/packages/charts/src/overlays/tooltipUtils.test.tsindex 637b1525488a..2e04ace72e31 100644--- a/packages/quill/packages/charts/src/overlays/tooltipUtils.test.ts+++ b/packages/quill/packages/charts/src/overlays/tooltipUtils.test.ts@@ -37,8 +37,10 @@ describe('findClosestSeriesKey', () => {expect(findClosestSeriesKey([], 100)).toBeNull()})- it('prefers the first entry when distances are equal', () => {- expect(findClosestSeriesKey([row('a', 80), row('b', 120)], 100)).toBe('a')+ it('prefers the last entry on a distance tie, matching the hover dot on coinciding lines', () => {+ // Coinciding lines (equal values) paint last-on-top, so the highlighted tooltip row must+ // pick the same series the hover dot rings: the last tied one.+ expect(findClosestSeriesKey([row('under', 80), row('over', 80)], 100)).toBe('over')})describe('range containment (stacked bar segments)', () => {diff --git a/packages/quill/packages/charts/src/overlays/tooltipUtils.ts b/packages/quill/packages/charts/src/overlays/tooltipUtils.tsindex 5c5ce73033a6..9f31a9f043a6 100644--- a/packages/quill/packages/charts/src/overlays/tooltipUtils.ts+++ b/packages/quill/packages/charts/src/overlays/tooltipUtils.ts@@ -5,6 +5,9 @@* exact regardless of segment size differences — no midpoint dead-zones at boundaries.** When only `yPixel` is present (line dots, non-stacked bars), falls back to closest by distance.+ * Distance ties go to the last tied row: equal-valued lines sit exactly on top of each other and+ * paint in array order, so the last one is the visible line. This matches the hover dot's own+ * tie-breaking, keeping the highlighted tooltip row and the dot on the same series.*/export function findClosestSeriesKey(rows: Array<{ series: { key: string }; yPixel?: number; yPixelBottom?: number }>,@@ -28,7 +31,7 @@ export function findClosestSeriesKey(continue}const dist = Math.abs(s.yPixel - cursorY)- if (dist < bestDist) {+ if (dist <= bestDist) {bestDist = distbestKey = s.series.key}