🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(experiments): thin x-axis ticks so long-name charts stop smearing (LFE-10583) (#14670)
Nikita Kabardin26002a9ec408
diff --git a/web/src/features/widgets/chart-library/AreaChartTimeSeries.tsx b/web/src/features/widgets/chart-library/AreaChartTimeSeries.tsxindex 5eeb779a3e..f1d248e843 100644--- a/web/src/features/widgets/chart-library/AreaChartTimeSeries.tsx+++ b/web/src/features/widgets/chart-library/AreaChartTimeSeries.tsx@@ -125,6 +125,7 @@ export const AreaChartTimeSeries: React.FC<ChartProps> = ({axisLine={false}interval={timeAxis.interval}tickFormatter={timeAxis.formatTick}+ {...timeAxis.tickProps}/><YAxistype="number"diff --git a/web/src/features/widgets/chart-library/LineChartTimeSeries.tsx b/web/src/features/widgets/chart-library/LineChartTimeSeries.tsxindex 796e37f506..5b40f3224d 100644--- a/web/src/features/widgets/chart-library/LineChartTimeSeries.tsx+++ b/web/src/features/widgets/chart-library/LineChartTimeSeries.tsx@@ -301,6 +301,7 @@ export const LineChartTimeSeries: React.FC<ChartProps> = ({axisLine={false}interval={timeAxis.interval}tickFormatter={timeAxis.formatTick}+ {...timeAxis.tickProps}/><YAxistype="number"diff --git a/web/src/features/widgets/chart-library/VerticalBarChartTimeSeries.tsx b/web/src/features/widgets/chart-library/VerticalBarChartTimeSeries.tsxindex 73d6671fa0..d8e709fe04 100644--- a/web/src/features/widgets/chart-library/VerticalBarChartTimeSeries.tsx+++ b/web/src/features/widgets/chart-library/VerticalBarChartTimeSeries.tsx@@ -132,6 +132,7 @@ export const VerticalBarChartTimeSeries: React.FC<ChartProps> = ({axisLine={false}interval={timeAxis.interval}tickFormatter={timeAxis.formatTick}+ {...timeAxis.tickProps}/><YAxistype="number"diff --git a/web/src/features/widgets/chart-library/prepareTimeAxis.clienttest.ts b/web/src/features/widgets/chart-library/prepareTimeAxis.clienttest.tsindex a0b855d5d5..b53f508a5b 100644--- a/web/src/features/widgets/chart-library/prepareTimeAxis.clienttest.ts+++ b/web/src/features/widgets/chart-library/prepareTimeAxis.clienttest.ts@@ -123,6 +123,67 @@ describe("prepareTimeAxis", () => {expect(axis.formatTooltip("1")).toBe("1");});+ it("categorical axis thins width-aware (equidistant), not by a numeric index step (LFE-10583)", () => {+ // The smear bug: a numeric recharts `interval` shows every Nth tick BY INDEX+ // and skips the label-collision test, so long entity names overlap however+ // few we target. The fix hands recharts "equidistantPreserveStart" so it+ // picks the even step whose *rendered* labels don't collide — even spacing,+ // width-aware, robust to hundreds of points.+ const manyLongRuns = Array.from(+ { length: 200 },+ (_, i) => `demo-dataset-run-${i}-demo-english-transcription-dataset`,+ );+ const axis = prepareTimeAxis(manyLongRuns, 6);+ expect(axis.mode).toBe("category");+ // The crux: NOT a numeric index step (which smears) — the width-aware one.+ expect(axis.interval).toBe("equidistantPreserveStart");+ // A deliberate gap between the (thinned) ticks, so they read as a handful.+ expect(axis.tickProps.minTickGap).toBeGreaterThan(0);+ });++ it("long categorical labels are angled and end-truncated, full name in tooltip (LFE-10583)", () => {+ // The experiments / dataset-compare x-axis: long entity (run) names that+ // recharts would otherwise render flat and overlap into a smear.+ const runs = [+ "demo-dataset-run-0-demo-english-transcription-dataset",+ "demo-dataset-run-1-demo-english-transcription-dataset",+ "demo-dataset-run-2-demo-english-transcription-dataset",+ ];+ const axis = prepareTimeAxis(runs, 6);+ expect(axis.mode).toBe("category");++ // Angled + end-anchored so neighbours don't collide horizontally.+ expect(axis.tickProps.angle).toBeLessThan(0);+ expect(axis.tickProps.textAnchor).toBe("end");++ // Shown tick is truncated (keeps the distinguishing head, drops the tail)…+ const shown = axis.formatTick(runs[1]);+ expect(shown.length).toBeLessThan(runs[1].length);+ expect(shown.endsWith("…")).toBe(true);+ expect(shown.startsWith("demo-dataset-run-1")).toBe(true);+ // …but the different runs still truncate to DIFFERENT strings.+ expect(axis.formatTick(runs[0])).not.toBe(axis.formatTick(runs[1]));++ // …while the tooltip carries the full, untruncated name (nothing lost).+ expect(axis.formatTooltip(runs[1])).toBe(runs[1]);+ });++ it("short categorical labels are not truncated and time ticks stay flat + numeric (dashboards unchanged)", () => {+ const shortCategories = prepareTimeAxis(["run-a", "run-b", "run-c"], 6);+ expect(shortCategories.formatTick("run-a")).toBe("run-a");+ expect(shortCategories.tickProps.angle).toBeLessThan(0);++ // Time-mode ticks are unchanged: flat tickProps AND a numeric index step, so+ // dashboards render pixel-identically (no width-aware equidistant thinning).+ const start = Date.UTC(2026, 5, 28, 0);+ const timeVals = Array.from({ length: 24 }, (_, h) =>+ iso(start + h * HOUR),+ );+ const timeAxis = prepareTimeAxis(timeVals, 6);+ expect(timeAxis.tickProps).toEqual({});+ expect(typeof timeAxis.interval).toBe("number");+ });+it("does not coerce bare numeric strings into epoch dates", () => {expect(parseChartTimestamp("1")).toBeNull();expect(parseChartTimestamp("20241230")).toBeNull();diff --git a/web/src/features/widgets/chart-library/prepareTimeAxis.ts b/web/src/features/widgets/chart-library/prepareTimeAxis.tsindex cbc7d40a63..7db8e98a38 100644--- a/web/src/features/widgets/chart-library/prepareTimeAxis.ts+++ b/web/src/features/widgets/chart-library/prepareTimeAxis.ts@@ -30,6 +30,34 @@ const MONTH_SCALE_MIN = 180 * DAY;type AxisMode = "time" | "date" | "month" | "category";+/**+ * Max characters shown for a categorical (non-time) x-axis tick. Entity names+ * (experiment / dataset-run names) are frequently long and recharts neither+ * wraps nor truncates a tick. The width-aware thinning (see `prepareTimeAxis`)+ * is what keeps ticks from colliding; this cap just bounds the *shown* width so+ * a single very long outlier can't force the step so wide that almost nothing+ * shows (nor run off-canvas). The full value always stays in the tooltip; short+ * labels are untouched.+ */+const MAX_CATEGORY_LABEL_CHARS = 24;++/**+ * Minimum whitespace (px) recharts must leave between two shown categorical+ * ticks. `equidistantPreserveStart` (see `prepareTimeAxis`) already drops ticks+ * until their *labels* don't overlap; this adds a deliberate gap on top so the+ * kept ticks read as a handful of clearly-separated labels, not a dense strip.+ */+const CATEGORY_MIN_TICK_GAP_PX = 16;++/** End-truncate a long categorical label ("foo-bar-…"). Entity names carry+ * their distinguishing token early (e.g. "…-run-2-…"), so keeping the head and+ * dropping the tail preserves what tells ticks apart; the tooltip has the full+ * name. Short labels pass through untouched. */+function truncateCategoryLabel(label: string): string {+ if (label.length <= MAX_CATEGORY_LABEL_CHARS) return label;+ return `${label.slice(0, MAX_CATEGORY_LABEL_CHARS - 1)}…`;+}+/*** Parse a raw bucket value into a Date, but ONLY when it actually looks like a* timestamp: an epoch-ms number, an ISO string, or a "YYYY-MM-DD[ T]HH:MM:SS"@@ -94,13 +122,38 @@ function inferBucketMs(timestamps: number[]): number {}export type TimeAxis = {- /** recharts numeric x-axis `interval` (ticks skipped between shown ticks). */- interval: number;+ /**+ * recharts x-axis `interval`. Two shapes, by axis kind:+ * - time / date / month → a NUMERIC index-step (evenly spaced, width-blind).+ * Labels are short single units ("2 PM" / "Jun 28"), so an index step gives+ * uniform gaps that don't depend on chart width — the dashboard behaviour.+ * - categorical entity names → `"equidistantPreserveStart"`. These labels are+ * long and variable-width; a numeric step skips recharts' collision test and+ * overlaps them into a smear. This string interval instead picks the largest+ * even step whose *rendered* labels don't collide. (LFE-10583)+ */+ interval: number | "equidistantPreserveStart";/** Scale-appropriate label for a shown tick. */formatTick: (raw: unknown) => string;/** Fuller label for the tooltip (always date + year, time when intraday). */formatTooltip: (raw: unknown) => string;mode: AxisMode;+ /**+ * Tick-label props the visualiser spreads onto the recharts `XAxis`.+ * Time / date / month ticks are short single-units rendered flat (`{}` → the+ * spread is a no-op, so dashboards are unchanged). Categorical entity names+ * are long, so we render them angled + end-anchored — the standard way to fit+ * long category labels — and set a `minTickGap` so the (width-aware thinned)+ * ticks keep a real gap between them. (LFE-10583)+ */+ tickProps: {+ angle?: number;+ textAnchor?: "start" | "middle" | "end";+ /** Extra x-axis height (px) an angled label needs so it isn't clipped. */+ height?: number;+ /** Minimum px gap recharts leaves between two shown ticks. */+ minTickGap?: number;+ };};/**@@ -116,19 +169,41 @@ export function prepareTimeAxis(rawValues: unknown[], maxTicks = 6): TimeAxis {const target = Math.max(2, maxTicks);- // Non-temporal x-axis (e.g. dataset-compare run names): the labels aren't- // timestamps, so we don't invent dates — render them verbatim and only thin- // by index. We treat the axis as time only when most values actually parse.+ // Non-temporal x-axis (e.g. the experiments / dataset-compare charts, whose+ // ticks are entity names like "demo-dataset-run-2-…-transcription-dataset"):+ // the labels aren't timestamps, so we don't invent dates. We treat the axis as+ // time only when most values actually parse.const temporal =timestamps.length > 0 && timestamps.length >= rawValues.length / 2;if (!temporal) {- const passthrough = (raw: unknown): string =>+ const full = (raw: unknown): string =>raw == null ? "" : typeof raw === "string" ? raw : String(raw);return {- interval: getEvenTickInterval(rawValues.length, target),- formatTick: passthrough,- formatTooltip: passthrough,+ // The fix for the categorical smear (LFE-10583). A numeric interval makes+ // recharts show every Nth tick BY INDEX and skip its label-collision test,+ // so a handful of long entity names (~50 chars each) still overlap into an+ // illegible black strip — no matter how few we target, index-thinning is+ // blind to how wide each label actually is. `equidistantPreserveStart`+ // instead picks the largest even step at which every Nth *rendered* label+ // fits without colliding (recharts measures the formatted, angled label ++ // minTickGap), so long names collapse to a few evenly-spaced ticks with a+ // real gap, robust to hundreds of points. This is the "measure labels,+ // don't guess" principle (ARCHITECTURE.md #4) — the numeric time/date+ // budget guesses ~64px/label, which is 5× too small for entity names.+ interval: "equidistantPreserveStart",+ // Angle + end-anchor the (now few) long labels — the standard long-category+ // treatment, and it lets recharts fit a couple more without overlap. Also+ // end-truncate the shown label so a single outlier name can't run+ // off-canvas; the full name always stays in the tooltip.+ formatTick: (raw: unknown) => truncateCategoryLabel(full(raw)),+ formatTooltip: full,mode: "category",+ tickProps: {+ angle: -30,+ textAnchor: "end",+ height: 60,+ minTickGap: CATEGORY_MIN_TICK_GAP_PX,+ },};}@@ -205,5 +280,7 @@ export function prepareTimeAxis(rawValues: unknown[], maxTicks = 6): TimeAxis {});};- return { interval, formatTick, formatTooltip, mode };+ // Time / date / month ticks are short single-units — rendered flat, exactly+ // as the dashboards do today (no orientation change → pixel-identical).+ return { interval, formatTick, formatTooltip, mode, tickProps: {} };}