From 979fcb4dbfd2f115e4353f5fe182dfa8cffbb4b9 Mon Sep 17 00:00:00 2001 From: Matthew Meszaros Date: Thu, 5 Nov 2026 19:34:13 +0100 Subject: [PATCH] feat: widen the daily chart window to any day the server returns outside it, ignore a crosshair index past a shorter window, keep the hover card inside the chart by measuring it, and assert chart content before each proof shot in the analytics-charts flow --- qa/flows/analytics-charts.flow.ts | 11 +++++------ web/src/components/ui/charts.tsx | 25 ++++++++++++++++--------- web/src/components/ui/dither.tsx | 2 +- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/qa/flows/analytics-charts.flow.ts b/qa/flows/analytics-charts.flow.ts index babbc0987..69c85eea4 100644 --- a/qa/flows/analytics-charts.flow.ts +++ b/qa/flows/analytics-charts.flow.ts @@ -11,25 +11,24 @@ test("daily charts keep every day of the window, with sends in their own strip", const main = page.getByRole("main"); const daily = main.getByText("Daily performance"); await daily.evaluate((el) => el.scrollIntoView({ block: "start" })); + await expect(main.getByText("Sent per day")).toBeVisible(); await proof.chapter("Campaign chart", "Engagement lines on their own scale, sends as bars underneath"); await proof.dwell(); await proof.shot("campaign-daily-chart", { caption: "Every day of the window, sends in their own strip" }); const chart = daily.locator("xpath=ancestor::div[contains(@class,'rounded-md')][1]"); const box = await chart.boundingBox(); - if (box) await page.mouse.move(box.x + box.width * 0.6, box.y + box.height * 0.45); + expect(box).not.toBeNull(); + await page.mouse.move(box!.x + box!.width * 0.6, box!.y + box!.height * 0.45); + await expect(main.getByText(/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), /)).toBeVisible(); await proof.dwell(); await proof.shot("campaign-daily-hover", { caption: "One crosshair lists the day's sends and each line as a share of them" }); await page.goto("/app/analytics"); await expect(page.getByText("Email performance")).toBeVisible(); await page.getByRole("button", { name: "30d", exact: true }).click(); + await expect(page.getByText("Sent per day").first()).toBeVisible(); await proof.chapter("Workspace analytics", "The same chart over the last 30 days"); await proof.dwell(); await proof.shot("analytics-daily-chart", { caption: "Last 30 days, quiet days kept on the axis" }); - - await page.goto("/app/deliverability"); - await expect(page.getByText("Over time", { exact: true }).first()).toBeVisible(); - await proof.dwell(); - await proof.shot("deliverability-daily-chart", { caption: "Failure signals above, sends below" }); }); diff --git a/web/src/components/ui/charts.tsx b/web/src/components/ui/charts.tsx index 8bbf5b132..1e316aea0 100644 --- a/web/src/components/ui/charts.tsx +++ b/web/src/components/ui/charts.tsx @@ -99,8 +99,10 @@ function fillDays( ): { days: string[]; series: TrendSeries[] } { const keys = labels.map((l) => l.slice(0, 10)); const sorted = [...keys].sort(); - const from = range?.from ?? sorted[0]; - const to = range?.to ?? sorted[sorted.length - 1]; + // A day the server returned outside the window widens it rather than being dropped. + const ends = [range?.from, range?.to, sorted[0], sorted[sorted.length - 1]].filter((d): d is string => !!d).sort(); + const from = ends[0]; + const to = ends[ends.length - 1]; if (!from || !to) return { days: [], series }; const days: string[] = []; const end = dayDate(to).getTime(); @@ -159,7 +161,8 @@ export function MultiTrend({ volumeKey?: string; }) { const [wrapRef, { w }] = useMeasure(); - const [hover, setHover] = React.useState(null); + const [pointer, setHover] = React.useState(null); + const [tipW, setTipW] = React.useState(160); // Keyed on content: callers rebuild these arrays every render, and a new // identity would replay the bars' entrance on each one. @@ -181,6 +184,8 @@ export function MultiTrend({ const isEmpty = days.length === 0 || filled.series.length === 0 || total === 0; const n = days.length; + // The index from the last pointer move can outlive a shorter window. + const hover = pointer !== null && pointer < n ? pointer : null; const plotW = Math.max(0, w - GUTTER); const slot = n > 0 ? plotW / n : 0; const plotH = height - TICK_H; @@ -208,7 +213,9 @@ export function MultiTrend({ setHover(i >= 0 && i < n ? i : null); }; - const flip = hover !== null && cx(hover) > GUTTER + plotW / 2; + // Right of the crosshair when the card fits, else left of it, else pinned inside the chart. + const tipLeft = (x: number) => + x + 10 + tipW <= w ? x + 10 : x - 10 - tipW >= 0 ? x - 10 - tipW : Math.max(0, w - tipW); const volAt = hover !== null && volume ? volume.values[hover] : 0; return ( @@ -302,11 +309,11 @@ export function MultiTrend({ style={{ left: cx(hover), height: plotH }} />
{ + if (el && el.offsetWidth !== tipW) setTipW(el.offsetWidth); + }} + className="pointer-events-none absolute top-1 z-10 min-w-[140px] rounded-md border border-slate-200 bg-white px-2.5 py-1.5 text-[11px] text-slate-600 shadow-sm" + style={{ left: tipLeft(cx(hover)) }} >
{longDate(days[hover])}
{volume && } diff --git a/web/src/components/ui/dither.tsx b/web/src/components/ui/dither.tsx index 28d0e93dc..175b77c16 100644 --- a/web/src/components/ui/dither.tsx +++ b/web/src/components/ui/dither.tsx @@ -742,7 +742,7 @@ export function DitherMultiAreaChart({ height?: number; className?: string; renderTooltip?: (i: number) => React.ReactNode; - /** Top of the y scale; defaults to the largest value. */ + /** Lowest top of the y scale; values above it still raise the scale. */ max?: number; /** Controlled crosshair: the parent owns pointer, guide line and tooltip; only the dots draw here. */ hover?: number | null;