Skip to content

πŸͺ’ Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(widgets): don't smooth charts across no-data buckets (LFE-10694) (#14822)

Nikita Kabardin2d18e8181a55
diff --git a/web/.storybook/preview.tsx b/web/.storybook/preview.tsx
index bb85519615..0c3cf3bf7f 100644
--- a/web/.storybook/preview.tsx
+++ b/web/.storybook/preview.tsx
@@ -41,6 +41,30 @@ function StorybookThemeProvider({
};
}, [theme]);
+ // Overlay layer containers, declared exactly like _document.tsx: a
+ // <div data-overlay-root> holding one <div data-layer={name}/> per
+ // LAYER_ORDER. This is what the layer system (components/ui/layer.tsx)
+ // portals toasts / tooltips / peek into; without it those overlays are
+ // absent in Storybook. Positioning/isolation comes from globals.css.
+ //
+ // Mounted imperatively ON <body>, ONCE β€” not rendered per decorator:
+ // the docs view runs this decorator for every story block on the page, and
+ // Storybook's preview block carries a CSS transform, which would make it the
+ // containing block for the layers' `position: fixed` β€” a portaled chart
+ // tooltip would paint relative to the first story block instead of the
+ // viewport (i.e. offscreen). On <body> it behaves exactly like the app.
+ useEffect(() => {
+ if (document.querySelector("[data-overlay-root]")) return;
+ const root = document.createElement("div");
+ root.setAttribute("data-overlay-root", "");
+ for (const name of LAYER_ORDER) {
+ const layer = document.createElement("div");
+ layer.setAttribute("data-layer", name);
+ root.appendChild(layer);
+ }
+ document.body.appendChild(root);
+ }, []);
+
// Reproduce the app's DOM scaffold so the layout rules in globals.css that are
// scoped to `div#__next` / `div#__next > div` (height: 100%) and
// `div#__next { isolation: isolate }` actually apply β€” the app's tables live
@@ -49,26 +73,13 @@ function StorybookThemeProvider({
// _app.tsx). `#__next` is given a real viewport height so the `height: 100%`
// chain has something to resolve against.
return (
- <>
- <div
- id="__next"
- className="bg-background text-foreground"
- style={{ height: fullHeight ? "100vh" : "auto" }}
- >
- <div>{children}</div>
- </div>
- {/* Overlay layer containers, declared exactly like _document.tsx: a
- <div data-overlay-root> sibling AFTER #__next (so it paints on top by
- DOM order), holding one <div data-layer={name}/> per LAYER_ORDER. This
- is what the layer system (components/ui/layer.tsx) portals toasts /
- tooltips / peek into; without it those overlays are absent in
- Storybook. Positioning/isolation comes from globals.css. */}
- <div data-overlay-root>
- {LAYER_ORDER.map((name) => (
- <div key={name} data-layer={name} />
- ))}
- </div>
- </>
+ <div
+ id="__next"
+ className="bg-background text-foreground"
+ style={{ height: fullHeight ? "100vh" : "auto" }}
+ >
+ <div>{children}</div>
+ </div>
);
}
diff --git a/web/src/features/dashboard/components/DashboardLineTimeSeriesChart.tsx b/web/src/features/dashboard/components/DashboardLineTimeSeriesChart.tsx
index 62cc115ed3..90d0c9ff3f 100644
--- a/web/src/features/dashboard/components/DashboardLineTimeSeriesChart.tsx
+++ b/web/src/features/dashboard/components/DashboardLineTimeSeriesChart.tsx
@@ -2,7 +2,10 @@ import React, { useMemo } from "react";
import { Chart } from "@/src/features/widgets/chart-library/Chart";
import { timeSeriesToDataPoints } from "@/src/features/dashboard/lib/chart-data-adapters";
import { type TimeSeriesChartDataPoint } from "@/src/features/dashboard/components/hooks";
-import { type LegendSummaryMode } from "@/src/features/widgets/chart-library/chart-props";
+import {
+ type LegendSummaryMode,
+ type MissingBucketValue,
+} from "@/src/features/widgets/chart-library/chart-props";
/**
* Memoized LINE_TIME_SERIES card shared by the dashboard time-series panels.
@@ -23,6 +26,7 @@ export const DashboardLineTimeSeriesChart = React.memo(
legendSummary,
syncId,
subtleFill,
+ missingValue,
}: {
data: TimeSeriesChartDataPoint[];
label?: string;
@@ -30,6 +34,8 @@ export const DashboardLineTimeSeriesChart = React.memo(
legendSummary?: LegendSummaryMode;
syncId?: string;
subtleFill?: boolean;
+ /** See {@link MissingBucketValue}. Defaults to `"gap"`. */
+ missingValue?: MissingBucketValue;
}) {
const points = useMemo(() => timeSeriesToDataPoints(data), [data]);
const config = useMemo(
@@ -56,6 +62,7 @@ export const DashboardLineTimeSeriesChart = React.memo(
legendPosition="above"
legendSummary={legendSummary}
syncId={syncId}
+ missingValue={missingValue}
/>
);
},
diff --git a/web/src/features/dashboard/components/LatencyChart.tsx b/web/src/features/dashboard/components/LatencyChart.tsx
index 38f6a7ddcb..fc914b5339 100644
--- a/web/src/features/dashboard/components/LatencyChart.tsx
+++ b/web/src/features/dashboard/components/LatencyChart.tsx
@@ -135,6 +135,9 @@ export const GenerationLatencyChart = ({
],
),
selectedModels,
+ // A latency percentile has no honest value on a bucket without
+ // generations β€” gap the line, don't fabricate a 0. (LFE-10694)
+ "gap",
)
: [];
return [
@@ -180,6 +183,7 @@ export const GenerationLatencyChart = ({
label="Latency"
unit="millisecond"
syncId={syncId}
+ missingValue="gap"
/>
</div>
) : (
diff --git a/web/src/features/dashboard/components/ModelUsageChart.tsx b/web/src/features/dashboard/components/ModelUsageChart.tsx
index 99fa49227f..23c273374e 100644
--- a/web/src/features/dashboard/components/ModelUsageChart.tsx
+++ b/web/src/features/dashboard/components/ModelUsageChart.tsx
@@ -397,6 +397,8 @@ export const ModelUsageChart = ({
// Token/cost totals are additive sums. (LFE-10498)
legendSummary="sum"
syncId={syncId}
+ // Additive sums: a bucket without data honestly sums to 0. (LFE-10694)
+ missingValue="zero"
/>
</div>
)}
diff --git a/web/src/features/dashboard/components/TracesTimeSeriesChart.tsx b/web/src/features/dashboard/components/TracesTimeSeriesChart.tsx
index 20f9f2ae0e..497f7e167e 100644
--- a/web/src/features/dashboard/components/TracesTimeSeriesChart.tsx
+++ b/web/src/features/dashboard/components/TracesTimeSeriesChart.tsx
@@ -215,6 +215,8 @@ export const TracesAndObservationsTimeSeriesChart = ({
// the card headline. (LFE-10498)
legendSummary="sum"
syncId={syncId}
+ // Additive counts: a bucket without data honestly counts 0. (LFE-10694)
+ missingValue="zero"
/>
</div>
) : (
diff --git a/web/src/features/dashboard/components/hooks.clienttest.ts b/web/src/features/dashboard/components/hooks.clienttest.ts
new file mode 100644
index 0000000000..0867d80a50
--- /dev/null
+++ b/web/src/features/dashboard/components/hooks.clienttest.ts
@@ -0,0 +1,94 @@
+import { describe, expect, it } from "vitest";
+
+import {
+ fillMissingValuesAndTransform,
+ isEmptyTimeSeries,
+} from "@/src/features/dashboard/components/hooks";
+
+const ts1 = Date.UTC(2026, 6, 1);
+const ts2 = Date.UTC(2026, 6, 2);
+
+describe("fillMissingValuesAndTransform", () => {
+ it("fills missing labels with 0 by default (additive metrics)", () => {
+ const result = fillMissingValuesAndTransform(
+ new Map([
+ [ts1, [{ label: "gpt-4", value: 5 }]],
+ [ts2, []],
+ ]),
+ ["gpt-4", "gpt-3.5"],
+ );
+
+ expect(result).toEqual([
+ {
+ ts: ts1,
+ values: [
+ { label: "gpt-4", value: 5 },
+ { label: "gpt-3.5", value: 0 },
+ ],
+ },
+ {
+ ts: ts2,
+ values: [
+ { label: "gpt-4", value: 0 },
+ { label: "gpt-3.5", value: 0 },
+ ],
+ },
+ ]);
+ });
+
+ it("fills missing labels with no value for gap semantics (non-additive metrics)", () => {
+ // p50 latency over an empty bucket is unknown, not 0 β€” fabricating a 0
+ // deflates the chart. (LFE-10694)
+ const result = fillMissingValuesAndTransform(
+ new Map([
+ [ts1, [{ label: "gpt-4", value: 120 }]],
+ [ts2, []],
+ ]),
+ ["gpt-4"],
+ "gap",
+ );
+
+ expect(result).toEqual([
+ { ts: ts1, values: [{ label: "gpt-4", value: 120 }] },
+ { ts: ts2, values: [{ label: "gpt-4", value: undefined }] },
+ ]);
+ });
+});
+
+describe("isEmptyTimeSeries", () => {
+ it("treats all-zero series as empty by default", () => {
+ expect(
+ isEmptyTimeSeries({
+ data: [{ ts: ts1, values: [{ label: "a", value: 0 }] }],
+ }),
+ ).toBe(true);
+ });
+
+ it("treats value-less (gap-filled) series as empty by default", () => {
+ expect(
+ isEmptyTimeSeries({
+ data: [{ ts: ts1, values: [{ label: "a", value: undefined }] }],
+ }),
+ ).toBe(true);
+ });
+
+ it("keeps zero/gap values as real when isNullValueAllowed is set", () => {
+ expect(
+ isEmptyTimeSeries({
+ data: [{ ts: ts1, values: [{ label: "a", value: 0 }] }],
+ isNullValueAllowed: true,
+ }),
+ ).toBe(false);
+ });
+
+ it("is not empty when any bucket has a real value", () => {
+ expect(
+ isEmptyTimeSeries({
+ data: [
+ { ts: ts1, values: [{ label: "a", value: undefined }] },
+ { ts: ts2, values: [{ label: "a", value: 3 }] },
+ ],
+ }),
+ ).toBe(false);
+ });
+});
diff --git a/web/src/features/dashboard/components/hooks.ts b/web/src/features/dashboard/components/hooks.ts
index 96456f5450..c61fe47535 100644
--- a/web/src/features/dashboard/components/hooks.ts
+++ b/web/src/features/dashboard/components/hooks.ts
@@ -1,4 +1,5 @@
import { type FilterState, getGenerationLikeTypes } from "@langfuse/shared";
+import { type MissingBucketValue } from "@/src/features/widgets/chart-library/chart-props";
export type TimeSeriesChartDataPoint = {
ts: number;
@@ -146,16 +147,22 @@ export function extractTimeSeriesData(
export function fillMissingValuesAndTransform(
inputMap: Map<number, ChartData[]>,
labelsToAdd: string[] = [],
+ missingValue: MissingBucketValue = "zero",
): TimeSeriesChartDataPoint[] {
const result: TimeSeriesChartDataPoint[] = [];
inputMap.forEach((chartDataArray, timestamp) => {
const existingLabels = chartDataArray.map((value) => value.label);
- // For each label in labelsToAdd, add a default value of 0
+ // For each missing label, add the metric's honest no-data value: a real 0
+ // for additive metrics ("zero"), no value at all for non-additive ones
+ // ("gap") β€” an average over zero events has no honest value, and a
+ // fabricated 0 draws a fake drop to zero. (LFE-10694)
labelsToAdd.forEach((label) => {
if (!existingLabels.includes(label)) {
- chartDataArray.push({ label: label, value: 0 });
+ chartDataArray.push(
+ missingValue === "zero" ? { label, value: 0 } : { label },
+ );
}
});
@@ -181,7 +188,10 @@ export const isEmptyTimeSeries = ({
item.values.length === 0 ||
(isNullValueAllowed
? false
- : item.values.every((value) => value.value === 0)),
+ : // A gap-filled entry (no value) is as empty as a zero-filled one.
+ item.values.every(
+ (value) => value.value === 0 || value.value == null,
+ )),
)
);
};
diff --git a/web/src/features/dashboard/lib/chart-data-adapters.clienttest.ts b/web/src/features/dashboard/lib/chart-data-adapters.clienttest.ts
new file mode 100644
index 0000000000..4ab435955f
--- /dev/null
+++ b/web/src/features/dashboard/lib/chart-data-adapters.clienttest.ts
@@ -0,0 +1,44 @@
+import { describe, expect, it } from "vitest";
+
+import { timeSeriesToDataPoints } from "@/src/features/dashboard/lib/chart-data-adapters";
+
+describe("timeSeriesToDataPoints", () => {
+ it("passes real values through", () => {
+ const ts = Date.UTC(2026, 6, 1);
+ expect(
+ timeSeriesToDataPoints([{ ts, values: [{ label: "Traces", value: 5 }] }]),
+ ).toEqual([
+ {
+ time_dimension: new Date(ts).toISOString(),
+ dimension: "Traces",
+ metric: 5,
+ },
+ ]);
+ });
+
+ it("keeps a value-less entry as null instead of inventing a 0", () => {
+ // A latency percentile with no data in the bucket has no honest value;
+ // fabricating 0 draws a fake drop to zero. (LFE-10694)
+ const ts = Date.UTC(2026, 6, 2);
+ expect(
+ timeSeriesToDataPoints([{ ts, values: [{ label: "gpt-4" }] }]),
+ ).toEqual([
+ {
+ time_dimension: new Date(ts).toISOString(),
+ dimension: "gpt-4",
+ metric: null,
+ },
+ ]);
+ });
+
+ it("emits a dimension-less bucket marker for an empty bucket so the axis keeps it", () => {
+ const ts = Date.UTC(2026, 6, 3);
+ expect(timeSeriesToDataPoints([{ ts, values: [] }])).toEqual([
+ {
+ time_dimension: new Date(ts).toISOString(),
+ dimension: undefined,
+ metric: null,
+ },
+ ]);
+ });
+});
diff --git a/web/src/features/dashboard/lib/chart-data-adapters.ts b/web/src/features/dashboard/lib/chart-data-adapters.ts
index a939b07335..89e7681a07 100644
--- a/web/src/features/dashboard/lib/chart-data-adapters.ts
+++ b/web/src/features/dashboard/lib/chart-data-adapters.ts
@@ -13,6 +13,10 @@ type HistogramBinLike = { binLabel: string; [key: string]: string | number };
* DataPoint[]. One row per (timestamp, label). The timestamp is passed through
* as a raw ISO string β€” all date/time *formatting* is decided later by the
* `prepareTimeAxis` preparer, so every chart formats time identically. (LFE-10549)
+ *
+ * A value-less entry stays `null` (a gap, never a fabricated 0), and a bucket
+ * with no values at all emits a dimension-less marker so the time axis keeps
+ * the bucket. (LFE-10694)
*/
export function timeSeriesToDataPoints(
data: TimeSeriesChartDataPoint[],
@@ -20,11 +24,19 @@ export function timeSeriesToDataPoints(
const result: DataPoint[] = [];
for (const point of data) {
const timeDimension = new Date(point.ts).toISOString();
+ if (point.values.length === 0) {
+ result.push({
+ time_dimension: timeDimension,
+ dimension: undefined,
+ metric: null,
+ });
+ continue;
+ }
for (const v of point.values) {
result.push({
time_dimension: timeDimension,
dimension: v.label,
- metric: v.value ?? 0,
+ metric: v.value ?? null,
});
}
}
diff --git a/web/src/features/widgets/chart-library/ARCHITECTURE.md b/web/src/features/widgets/chart-library/ARCHITECTURE.md
index a2fec424f0..d9a6c09d0d 100644
--- a/web/src/features/widgets/chart-library/ARCHITECTURE.md
+++ b/web/src/features/widgets/chart-library/ARCHITECTURE.md
@@ -129,21 +129,26 @@ different β€” and sometimes wrong β€” dates. One source of truth per decision.)
## Where we are / where we're going
- **Now:** the visualiser is a set of recharts components behind one `Chart`
- dispatcher. Two preparer seams are in place: the **time axis**
+ dispatcher. Three preparer seams are in place: the **time axis**
(`prepareTimeAxis` β€” raw timestamps in, granularity-adaptive labels out, one
- formatter for every chart) and the **series cap** (`prepareVisibleSeries` β€”
+ formatter for every chart), the **series cap** (`prepareVisibleSeries` β€”
ranks a breakdown by magnitude and keeps the top‑N so a high-cardinality
group-by of hundreds of series stays both legible and fast, with an honest
- "top N of M" note rather than a silent truncation; see principle 5).
+ "top N of M" note rather than a silent truncation; see principle 5), and
+ **missing-cell semantics** (`prepareDenseSeries` β€” makes every
+ (bucket, series) cell explicit: a real `0` for additive metrics, `null` β€” a
+ visible gap β€” for non-additive ones, with `connectNulls` off by default so a
+ line never draws across a no-data bucket; V2 made real, LFE-10694).
The interaction direction (V4/V5) is largely in place: a synced vertical
crosshair, a tooltip that opens only on the hovered chart, and a vertical
proximity highlight.
-- **Known visual debts** (drawn but not yet matching the direction above): lines
- currently smooth (`type="monotone"`) rather than draw straight (V1), and series
- color is assigned by index and cycles every 8 rather than being a stable
- identity (V6). Both are visualiser defaults to migrate into the preparer.
+- **Known visual debts** (drawn but not yet matching the direction above):
+ series color is assigned by index and cycles every 8 rather than being a
+ stable identity (V6) β€” a visualiser default to migrate into the preparer.
+ (V1's smooth-by-default debt is paid: lines and areas draw straight
+ (`type="linear"`) since LFE-10694.)
- **Next:** move the remaining decisions β€” series colors (V6), curve/interpolation
- (V1), legend summaries, units, axis type & scale β€” out of the components and
+ opt-ins (V1), legend summaries, units, axis type & scale β€” out of the components and
into the preparer, until the visualiser is purely presentational and the
preparer is the single, tested place where "what should this look like" is
answered.
diff --git a/web/src/features/widgets/chart-library/AreaChartTimeSeries.tsx b/web/src/features/widgets/chart-library/AreaChartTimeSeries.tsx
index f1d248e843..e707518c47 100644
--- a/web/src/features/widgets/chart-library/AreaChartTimeSeries.tsx
+++ b/web/src/features/widgets/chart-library/AreaChartTimeSeries.tsx
@@ -14,7 +14,12 @@ import {
groupDataByTimeDimension,
toFullMetricString,
} from "@/src/features/widgets/chart-library/utils";
+import { isolatedPointDot } from "@/src/features/widgets/chart-library/IsolatedPointDot";
import { useChartTickBudget } from "@/src/features/widgets/chart-library/useChartTickBudget";
+import {
+ prepareDenseSeries,
+ prepareIsolatedPoints,
+} from "@/src/features/widgets/chart-library/prepareDenseSeries";
import { prepareTimeAxis } from "@/src/features/widgets/chart-library/prepareTimeAxis";
import { prepareVisibleSeries } from "@/src/features/widgets/chart-library/prepareVisibleSeries";
import {
@@ -42,10 +47,28 @@ export const AreaChartTimeSeries: React.FC<ChartProps> = ({
maxVisibleSeries,
syncId,
subtleFill = false,
+ missingValue = "gap",
+ connectNulls = false,
}) => {
const [selfHovered, setSelfHovered] = useState(false);
- const groupedData = useMemo(() => groupDataByTimeDimension(data), [data]);
const allDimensions = useMemo(() => getUniqueDimensions(data), [data]);
+ // Make every (bucket, series) cell explicit β€” 0 for additive metrics, null
+ // (a real gap) otherwise β€” so areas never draw across no-data buckets. (LFE-10694)
+ const groupedData = useMemo(
+ () =>
+ prepareDenseSeries(
+ groupDataByTimeDimension(data),
+ allDimensions,
+ missingValue,
+ ),
+ [data, allDimensions, missingValue],
+ );
+ // A real value with gaps on both sides spans no area segment β€” mark it with
+ // a dot so honest gaps never hide real data. (LFE-10694)
+ const isolatedPoints = useMemo(
+ () => prepareIsolatedPoints(groupedData, allDimensions),
+ [groupedData, allDimensions],
+ );
// Cap how many series we draw (data -> preparer seam): a high-cardinality
// breakdown of hundreds of series is both unreadable and slow to hover. (LFE-10549)
const series = useMemo(
@@ -139,17 +162,25 @@ export const AreaChartTimeSeries: React.FC<ChartProps> = ({
{dimensions.map((dimension, index) => {
if (!isRendered(dimension)) return null;
const muted = isDimmed(dimension);
+ const isolated = isolatedPoints.get(dimension);
return (
<Area
key={dimension}
- type="monotone"
+ type="linear"
dataKey={dimension}
+ // Neighborless points span no area segment; a dot is the only
+ // thing that keeps them visible. (LFE-10694)
+ dot={
+ isolated
+ ? isolatedPointDot(isolated, seriesColor(index), muted)
+ : false
+ }
stroke={seriesColor(index)}
fill={seriesColor(index)}
fillOpacity={muted ? 0.15 : subtleFill ? 0.3 : 0.75}
strokeWidth={2.5}
strokeOpacity={muted ? 0.2 : 1}
- connectNulls
+ connectNulls={connectNulls}
isAnimationActive={false}
/>
);
diff --git a/web/src/features/widgets/chart-library/Chart.tsx b/web/src/features/widgets/chart-library/Chart.tsx
index da446ebb4c..7cabea87fa 100644
--- a/web/src/features/widgets/chart-library/Chart.tsx
+++ b/web/src/features/widgets/chart-library/Chart.tsx
@@ -6,6 +6,7 @@ import {
type ChartThreshold,
type LegendSummaryMode,
type LegendInteraction,
+ type MissingBucketValue,
} from "@/src/features/widgets/chart-library/chart-props";
import { formatMetric } from "@/src/features/widgets/chart-library/utils";
import { CardContent } from "@/src/components/ui/card";
@@ -46,6 +47,7 @@ const ChartComponent = ({
overrideWarning = false,
metricFormatter: metricFormatterOverride,
thresholds,
+ missingValue,
}: {
chartType: DashboardWidgetChartType;
data: DataPoint[];
@@ -75,6 +77,8 @@ const ChartComponent = ({
overrideWarning?: boolean;
metricFormatter?: MetricFormatterFunction;
thresholds?: ChartThreshold[];
+ /** See {@link MissingBucketValue}; consumed by line/area time series. */
+ missingValue?: MissingBucketValue;
}) => {
const [forceRender, setForceRender] = useState(overrideWarning);
const shouldWarn = data.length > 2000 && !forceRender;
@@ -128,6 +132,7 @@ const ChartComponent = ({
syncId={syncId}
showDataPointDots={chartConfig?.show_data_point_dots ?? false}
thresholds={thresholds}
+ missingValue={missingValue}
/>
);
case "AREA_TIME_SERIES":
@@ -142,6 +147,7 @@ const ChartComponent = ({
maxVisibleSeries={maxVisibleSeries}
syncId={syncId}
subtleFill={chartConfig?.subtle_fill}
+ missingValue={missingValue}
/>
);
case "BAR_TIME_SERIES":
diff --git a/web/src/features/widgets/chart-library/ChartingPrinciples.mdx b/web/src/features/widgets/chart-library/ChartingPrinciples.mdx
index 161b2afe97..1a79057339 100644
--- a/web/src/features/widgets/chart-library/ChartingPrinciples.mdx
+++ b/web/src/features/widgets/chart-library/ChartingPrinciples.mdx
@@ -31,6 +31,35 @@ a value, not a synonym for absence.
<Canvas of={Principles.NullHandling} sourceState="none" />
+In production the choice is not made per chart β€” **the metric's aggregation
+decides it**. Counts and sums have an honest zero (nothing happened), so a
+missing bucket fills with a real `0` and the line stays continuous. Averages
+and percentiles have no honest value there, so the cell becomes `null` and the
+line breaks. The same missing buckets, two truthful renderings:
+
+<Canvas of={Principles.GapVersusZero} sourceState="none" />
+
+Bridging (`connectNulls`) exists, but as an explicit opt-in β€” never the
+default:
+
+<Canvas of={Principles.HonestVersusBridged} sourceState="none" />
+
+Each series breaks over its own missing buckets while the others keep drawing,
+and a bucket in which nothing measured anything **stays on the axis** β€” the
+empty era is visible instead of time silently compressing away:
+
+<Canvas of={Principles.StaggeredSeriesGaps} sourceState="none" />
+
+<Canvas of={Principles.EmptyBucketsStayOnAxis} sourceState="none" />
+
+Honest gaps must never hide real data. A value with no drawable neighbor spans
+no line segment, so it gets a dot β€” the only mark that keeps it visible. Areas
+follow the same grammar:
+
+<Canvas of={Principles.IsolatedPoints} sourceState="none" />
+
+<Canvas of={Principles.AreaGaps} sourceState="none" />
+
## 3. Show certainty in the ink
A still-aggregating final bucket and a previous-period comparison are real, but
diff --git a/web/src/features/widgets/chart-library/ChartingPrinciples.stories.tsx b/web/src/features/widgets/chart-library/ChartingPrinciples.stories.tsx
index 091d45f599..ba6b34ec64 100644
--- a/web/src/features/widgets/chart-library/ChartingPrinciples.stories.tsx
+++ b/web/src/features/widgets/chart-library/ChartingPrinciples.stories.tsx
@@ -7,6 +7,7 @@ import {
XAxis,
YAxis,
} from "recharts";
+import { AreaChartTimeSeries } from "./AreaChartTimeSeries";
import { LineChartTimeSeries } from "./LineChartTimeSeries";
import { formatMetric } from "./utils";
import { type DataPoint, type MetricFormatterFunction } from "./chart-props";
@@ -33,15 +34,30 @@ const sparse = [
const ExampleCard = ({
label,
caption,
+ tall = false,
children,
}: {
label: string;
caption: string;
+ /** Production-component demos need room for legends + axis labels. */
+ tall?: boolean;
children: React.ReactNode;
}) => (
- <div className="flex min-w-[210px] flex-1 flex-col gap-1">
+ <div
+ className={
+ tall
+ ? "flex min-w-[340px] flex-1 flex-col gap-1"
+ : "flex min-w-[210px] flex-1 flex-col gap-1"
+ }
+ >
<div className="text-xs font-bold tracking-wide uppercase">{label}</div>
- <div className="bg-background h-[150px] w-full rounded-md border p-2">
+ <div
+ className={
+ tall
+ ? "bg-background h-[240px] w-full rounded-md border p-2"
+ : "bg-background h-[150px] w-full rounded-md border p-2"
+ }
+ >
{children}
</div>
<div className="text-muted-foreground w-full text-xs">{caption}</div>
@@ -163,7 +179,7 @@ export const NullHandling = meta.story({
</ExampleCard>
<ExampleCard
label="Zero-fill βœ—"
- caption="Invents a measurement of 0. A lie, unless stacking demands it."
+ caption="Invents a measurement of 0. A lie for anything non-additive; only counts/sums may fill zeros."
>
<ResponsiveContainer>
<LineChart data={zeroFilled} margin={{ top: 8, right: 8, bottom: 0 }}>
@@ -338,3 +354,259 @@ export const BoundTheFrame = meta.story({
</ChartFrame>
),
});
+
+// ── V2 in production Β· missing data through the real components ─────────────
+// These mirror the exact data shape the widget transforms hand the charts
+// (LFE-10694): a series' missing bucket is an ABSENT DataPoint, and a bucket
+// where nothing measured anything arrives as a dimension-less bucket MARKER
+// (`dimension: undefined, metric: null`) β€” what the query's gap-fill
+// placeholder rows become.
+
+type SeriesSpec = {
+ name: string;
+ /** One entry per bucket; `null` = this series measured nothing there. */
+ values: (number | null)[];
+};
+
+/** Buckets are day labels 7/1..7/N; markers keep all-empty buckets on the axis. */
+const buildGappedData = (series: SeriesSpec[]): DataPoint[] => {
+ const bucketCount = Math.max(...series.map((s) => s.values.length));
+ const points: DataPoint[] = [];
+ for (let bucket = 0; bucket < bucketCount; bucket++) {
+ const label = `7/${bucket + 1}`;
+ let bucketHasData = false;
+ for (const { name, values } of series) {
+ const value = values[bucket];
+ if (value != null) {
+ bucketHasData = true;
+ points.push({ time_dimension: label, dimension: name, metric: value });
+ }
+ }
+ if (!bucketHasData) {
+ points.push({
+ time_dimension: label,
+ dimension: undefined,
+ metric: null,
+ });
+ }
+ }
+ return points;
+};
+
+// One series, healthy on both sides of a 3-bucket hole (the classic lie shape).
+const midRangeGap: SeriesSpec[] = [
+ {
+ name: "gpt-4o",
+ values: [820, 940, 760, null, null, null, 880, 810, 990, 870],
+ },
+];
+
+// Multi-series where the gaps don't line up β€” every bucket has SOME data, so
+// only per-series cells are missing (no markers involved).
+const staggeredGapSeries: SeriesSpec[] = [
+ {
+ name: "gpt-4o",
+ values: [820, 940, 760, null, null, 830, 880, 810, 990, 870],
+ },
+ {
+ name: "claude-3-5-sonnet",
+ values: [1450, null, null, 1380, 1520, 1490, null, null, null, 1400],
+ },
+ {
+ name: "gpt-4o-mini",
+ values: [310, 290, 340, 300, null, null, null, 280, 320, 330],
+ },
+ {
+ name: "mistral-7b",
+ values: [null, null, 540, 560, 520, null, 580, 610, null, null],
+ },
+];
+
+// Isolated points: a lone first bucket, a mid-gap single, a lone last bucket,
+// and a series that is a segment plus one stranded value.
+const isolatedPointSeries: SeriesSpec[] = [
+ {
+ name: "first-bucket-only",
+ values: [720, null, null, null, null, null, null, null, null, null],
+ },
+ {
+ name: "single-mid-gap",
+ values: [null, null, null, null, 1350, null, null, null, null, null],
+ },
+ {
+ name: "last-bucket-only",
+ values: [null, null, null, null, null, null, null, null, null, 980],
+ },
+ {
+ name: "segment-plus-stranded",
+ values: [420, 460, 440, null, null, null, null, 510, null, null],
+ },
+];
+
+// Long empty stretch (buckets exist only as markers) between two active eras.
+const twoEras: SeriesSpec[] = [
+ {
+ name: "gpt-4o",
+ values: [88, 96, 74, null, null, null, null, null, 91, 83],
+ },
+ {
+ name: "claude-3-5-sonnet",
+ values: [54, 61, null, null, null, null, null, null, 58, 66],
+ },
+];
+
+export const GapVersusZero = meta.story({
+ render: () => (
+ <div className="flex flex-wrap gap-5 p-1">
+ <ExampleCard
+ tall
+ label='missingValue="gap" (avg / percentiles)'
+ caption="No latency exists on a bucket without generations β€” the line breaks. Fabricating a 0 would deflate the chart."
+ >
+ <LineChartTimeSeries
+ data={buildGappedData(midRangeGap)}
+ missingValue="gap"
+ metricFormatter={msFormatter}
+ />
+ </ExampleCard>
+ <ExampleCard
+ tall
+ label='missingValue="zero" (count / sum)'
+ caption="Zero events on a bucket without data is the truth β€” the same shape stays continuous, touching 0."
+ >
+ <LineChartTimeSeries
+ data={buildGappedData(midRangeGap)}
+ missingValue="zero"
+ />
+ </ExampleCard>
+ </div>
+ ),
+});
+
+export const HonestVersusBridged = meta.story({
+ render: () => (
+ <div className="flex flex-wrap gap-5 p-1">
+ <ExampleCard
+ tall
+ label="default (honest)"
+ caption="Gap semantics: three empty buckets stay on the axis and the line breaks over them."
+ >
+ <LineChartTimeSeries
+ data={buildGappedData(midRangeGap)}
+ missingValue="gap"
+ metricFormatter={msFormatter}
+ />
+ </ExampleCard>
+ <ExampleCard
+ tall
+ label="connectNulls (the old default, now opt-in)"
+ caption="The bridge draws values that were never measured. Reserved for series that semantically continue across a gap."
+ >
+ <LineChartTimeSeries
+ data={buildGappedData(midRangeGap)}
+ missingValue="gap"
+ connectNulls
+ metricFormatter={msFormatter}
+ />
+ </ExampleCard>
+ </div>
+ ),
+});
+
+export const IsolatedPoints = meta.story({
+ render: () => (
+ <div className="flex flex-wrap gap-5 p-1">
+ <ExampleCard
+ tall
+ label="neighborless values"
+ caption="A value with gaps on both sides spans no line segment β€” the dot is what keeps it visible (first bucket, mid-gap, last bucket, and a stranded point after a segment)."
+ >
+ <LineChartTimeSeries
+ data={buildGappedData(isolatedPointSeries)}
+ missingValue="gap"
+ legendPosition="above"
+ metricFormatter={msFormatter}
+ />
+ </ExampleCard>
+ </div>
+ ),
+});
+
+export const StaggeredSeriesGaps = meta.story({
+ render: () => (
+ <div className="flex flex-wrap gap-5 p-1">
+ <ExampleCard
+ tall
+ label="per-series gaps, every bucket has some data"
+ caption="Each series breaks over its own missing buckets while the others keep drawing β€” no series borrows another's shape."
+ >
+ <LineChartTimeSeries
+ data={buildGappedData(staggeredGapSeries)}
+ missingValue="gap"
+ legendPosition="above"
+ metricFormatter={msFormatter}
+ />
+ </ExampleCard>
+ </div>
+ ),
+});
+
+export const EmptyBucketsStayOnAxis = meta.story({
+ render: () => (
+ <div className="flex flex-wrap gap-5 p-1">
+ <ExampleCard
+ tall
+ label="gap semantics"
+ caption="Buckets 7/4–7/8 exist only as markers. The axis keeps them, so the empty era is visible instead of time compressing away."
+ >
+ <LineChartTimeSeries
+ data={buildGappedData(twoEras)}
+ missingValue="gap"
+ legendPosition="above"
+ />
+ </ExampleCard>
+ <ExampleCard
+ tall
+ label="zero semantics"
+ caption="Same data as counts: the empty era reads as an honest flat 0, not as absence."
+ >
+ <LineChartTimeSeries
+ data={buildGappedData(twoEras)}
+ missingValue="zero"
+ legendPosition="above"
+ legendSummary="sum"
+ />
+ </ExampleCard>
+ </div>
+ ),
+});
+
+export const AreaGaps = meta.story({
+ render: () => (
+ <div className="flex flex-wrap gap-5 p-1">
+ <ExampleCard
+ tall
+ label='area Β· missingValue="gap"'
+ caption="The fill stops where the data stops; isolated values still get their dot."
+ >
+ <AreaChartTimeSeries
+ data={buildGappedData(staggeredGapSeries)}
+ missingValue="gap"
+ subtleFill
+ metricFormatter={msFormatter}
+ />
+ </ExampleCard>
+ <ExampleCard
+ tall
+ label='area Β· missingValue="zero"'
+ caption="Additive semantics: the fill dips to 0 across empty buckets."
+ >
+ <AreaChartTimeSeries
+ data={buildGappedData(twoEras)}
+ missingValue="zero"
+ subtleFill
+ />
+ </ExampleCard>
+ </div>
+ ),
+});
diff --git a/web/src/features/widgets/chart-library/IsolatedPointDot.tsx b/web/src/features/widgets/chart-library/IsolatedPointDot.tsx
new file mode 100644
index 0000000000..c72c234af9
--- /dev/null
+++ b/web/src/features/widgets/chart-library/IsolatedPointDot.tsx
@@ -0,0 +1,36 @@
+import React from "react";
+
+/**
+ * Builds a recharts `dot` renderer that marks ONLY a series' isolated points
+ * (see `prepareIsolatedPoints`). With honest gaps (`connectNulls` off), a
+ * value with no drawable neighbor spans no line segment β€” this dot is the only
+ * thing that makes it visible. All other points render nothing, keeping lines
+ * clean. (LFE-10694)
+ */
+export const isolatedPointDot = (
+ isolated: Set<number>,
+ color: string,
+ muted: boolean,
+) =>
+ function IsolatedPointDot(props: {
+ key?: React.Key | null;
+ cx?: number;
+ cy?: number;
+ index?: number;
+ }): React.ReactElement<SVGElement> {
+ const { key, cx, cy, index } = props;
+ if (cx == null || cy == null || index == null || !isolated.has(index)) {
+ return <g key={key} />;
+ }
+ return (
+ <circle
+ key={key}
+ cx={cx}
+ cy={cy}
+ r={3}
+ fill={color}
+ fillOpacity={muted ? 0.2 : 1}
+ stroke="none"
+ />
+ );
+ };
diff --git a/web/src/features/widgets/chart-library/LineChartTimeSeries.tsx b/web/src/features/widgets/chart-library/LineChartTimeSeries.tsx
index 5b40f3224d..b24a296a89 100644
--- a/web/src/features/widgets/chart-library/LineChartTimeSeries.tsx
+++ b/web/src/features/widgets/chart-library/LineChartTimeSeries.tsx
@@ -6,6 +6,7 @@ import {
ChartTooltipContent,
ChartTooltipPortal,
} from "@/src/components/ui/chart";
+import { isolatedPointDot } from "@/src/features/widgets/chart-library/IsolatedPointDot";
import { NearestSeriesProbe } from "@/src/features/widgets/chart-library/NearestSeriesProbe";
import {
CartesianGrid,
@@ -28,6 +29,10 @@ import {
toFullMetricString,
} from "@/src/features/widgets/chart-library/utils";
import { useChartTickBudget } from "@/src/features/widgets/chart-library/useChartTickBudget";
+import {
+ prepareDenseSeries,
+ prepareIsolatedPoints,
+} from "@/src/features/widgets/chart-library/prepareDenseSeries";
import { prepareTimeAxis } from "@/src/features/widgets/chart-library/prepareTimeAxis";
import { prepareVisibleSeries } from "@/src/features/widgets/chart-library/prepareVisibleSeries";
import {
@@ -197,11 +202,29 @@ export const LineChartTimeSeries: React.FC<ChartProps> = ({
// so the value is readable on hover without littering the line. (LFE-10549, V7)
showDataPointDots = false,
thresholds,
+ missingValue = "gap",
+ connectNulls = false,
}) => {
const metricExtent = useMemo(() => computeMetricExtent(data), [data]);
- const groupedData = useMemo(() => groupDataByTimeDimension(data), [data]);
const allDimensions = useMemo(() => getUniqueDimensions(data), [data]);
+ // Make every (bucket, series) cell explicit β€” 0 for additive metrics, null
+ // (a real gap) otherwise β€” so lines never draw across no-data buckets. (LFE-10694)
+ const groupedData = useMemo(
+ () =>
+ prepareDenseSeries(
+ groupDataByTimeDimension(data),
+ allDimensions,
+ missingValue,
+ ),
+ [data, allDimensions, missingValue],
+ );
+ // A real value with gaps on both sides spans no line segment β€” mark it with
+ // a dot so honest gaps never hide real data. (LFE-10694)
+ const isolatedPoints = useMemo(
+ () => prepareIsolatedPoints(groupedData, allDimensions),
+ [groupedData, allDimensions],
+ );
// Cap how many series we draw (data -> preparer seam): a high-cardinality
// breakdown of hundreds of series is both unreadable and slow to hover. (LFE-10549)
const series = useMemo(
@@ -317,19 +340,28 @@ export const LineChartTimeSeries: React.FC<ChartProps> = ({
if (!isRendered(dimension)) return null;
const nearest = proximityActive && nearestSet.has(dimension);
const muted = isDimmed(dimension) || (proximityActive && !nearest);
+ const isolated = isolatedPoints.get(dimension);
return (
<Line
key={dimension}
- type="monotone"
+ type="linear"
dataKey={dimension}
strokeWidth={nearest ? 3.5 : 2.5}
- dot={showDataPointDots && !muted ? { r: 4 } : false}
+ dot={
+ showDataPointDots && !muted
+ ? { r: 4 }
+ : // Neighborless points span no line segment; a dot is the
+ // only thing that keeps them visible. (LFE-10694)
+ isolated
+ ? isolatedPointDot(isolated, seriesColor(index), muted)
+ : false
+ }
// The hover marker is independent of the static-dot setting: even
// a dotless line reveals the point under the cursor.
activeDot={muted ? false : { r: 5, strokeWidth: 0 }}
stroke={seriesColor(index)}
strokeOpacity={muted ? 0.2 : 1}
- connectNulls
+ connectNulls={connectNulls}
isAnimationActive={false}
/>
);
diff --git a/web/src/features/widgets/chart-library/chart-props.ts b/web/src/features/widgets/chart-library/chart-props.ts
index 394e722c38..b01521fb2e 100644
--- a/web/src/features/widgets/chart-library/chart-props.ts
+++ b/web/src/features/widgets/chart-library/chart-props.ts
@@ -4,9 +4,31 @@ import type tailwindColors from "tailwindcss/colors";
export interface DataPoint {
time_dimension: string | undefined;
dimension: string | undefined;
- metric: number | Array<Array<number>>;
+ /**
+ * `null` means "measured nothing here": the bucket exists but the metric has
+ * no honest value (e.g. an average over zero events). Time-series charts
+ * render it as a gap; it is never coerced to `0`. A point with `null` metric
+ * AND no dimension is a pure bucket marker β€” it keeps the bucket on the time
+ * axis without contributing a series. (LFE-10694)
+ */
+ metric: number | null | Array<Array<number>>;
}
+/**
+ * What a time-series chart shows for a (bucket, series) cell that has no data
+ * point:
+ * - `"zero"`: additive metrics (counts, sums) β€” zero events happened, so the
+ * honest value is a real `0` and the line stays continuous.
+ * - `"gap"`: non-additive metrics (avg/min/max/percentiles) β€” no honest value
+ * exists, so the cell becomes `null` and the line breaks instead of
+ * fabricating a trend across the gap.
+ *
+ * The choice is a property of the metric's aggregation and is decided by the
+ * caller (who knows it), not the chart. Defaults to `"gap"` β€” never invent a
+ * number. (LFE-10694, manifesto V2)
+ */
+export type MissingBucketValue = "zero" | "gap";
+
export type LegendPosition = "above" | "none";
/**
@@ -101,4 +123,13 @@ export interface ChartProps {
showDataPointDots?: boolean;
subtleFill?: boolean;
thresholds?: ChartThreshold[];
+ /** See {@link MissingBucketValue}. Defaults to `"gap"`. */
+ missingValue?: MissingBucketValue;
+ /**
+ * Whether a line/area bridges `null` cells instead of breaking. Defaults to
+ * `false`: drawing across a no-data bucket fabricates values that were never
+ * measured. Opt in only when the series semantically continues across the
+ * gap. (LFE-10694, manifesto V2)
+ */
+ connectNulls?: boolean;
}
diff --git a/web/src/features/widgets/chart-library/prepareDenseSeries.clienttest.ts b/web/src/features/widgets/chart-library/prepareDenseSeries.clienttest.ts
new file mode 100644
index 0000000000..b1501147ef
--- /dev/null
+++ b/web/src/features/widgets/chart-library/prepareDenseSeries.clienttest.ts
@@ -0,0 +1,164 @@
+import { describe, expect, it } from "vitest";
+
+import {
+ groupDataByTimeDimension,
+ type TimeSeriesGroupedRow,
+} from "@/src/features/widgets/chart-library/utils";
+import {
+ prepareDenseSeries,
+ prepareIsolatedPoints,
+} from "@/src/features/widgets/chart-library/prepareDenseSeries";
+import { type DataPoint } from "@/src/features/widgets/chart-library/chart-props";
+
+const point = (
+ time: string,
+ dimension: string | undefined,
+ metric: number | null,
+): DataPoint => ({ time_dimension: time, dimension, metric });
+
+const rows = (data: DataPoint[]): TimeSeriesGroupedRow[] =>
+ groupDataByTimeDimension(data);
+
+describe("prepareDenseSeries", () => {
+ it("fills missing series cells with 0 for additive (zero) semantics", () => {
+ // gpt-4 has no row on day 2 β€” a count of zero events, not unknown data.
+ const grouped = rows([
+ point("2026-07-01", "gpt-4", 5),
+ point("2026-07-01", "gpt-3.5", 2),
+ point("2026-07-02", "gpt-3.5", 3),
+ point("2026-07-03", "gpt-4", 7),
+ point("2026-07-03", "gpt-3.5", 1),
+ ]);
+
+ const dense = prepareDenseSeries(grouped, ["gpt-4", "gpt-3.5"], "zero");
+
+ expect(dense).toEqual([
+ { time_dimension: "2026-07-01", "gpt-4": 5, "gpt-3.5": 2 },
+ { time_dimension: "2026-07-02", "gpt-4": 0, "gpt-3.5": 3 },
+ { time_dimension: "2026-07-03", "gpt-4": 7, "gpt-3.5": 1 },
+ ]);
+ });
+
+ it("fills missing series cells with null for non-additive (gap) semantics", () => {
+ // No honest average exists for a bucket without data β€” the line must gap.
+ const grouped = rows([
+ point("2026-07-01", "gpt-4", 120),
+ point("2026-07-03", "gpt-4", 180),
+ ]);
+
+ const dense = prepareDenseSeries(grouped, ["gpt-4"], "gap");
+
+ expect(dense).toEqual([
+ { time_dimension: "2026-07-01", "gpt-4": 120 },
+ { time_dimension: "2026-07-03", "gpt-4": 180 },
+ ]);
+ });
+
+ it("keeps buckets that exist only as empty markers, so the axis shows the gap", () => {
+ // A WITH FILL marker row (no dimension, no metric) proves the bucket exists;
+ // it must stay on the axis with every series filled by its semantics.
+ const grouped = rows([
+ point("2026-07-01", "gpt-4", 5),
+ point("2026-07-02", undefined, null),
+ point("2026-07-03", "gpt-4", 7),
+ ]);
+
+ expect(prepareDenseSeries(grouped, ["gpt-4"], "zero")).toEqual([
+ { time_dimension: "2026-07-01", "gpt-4": 5 },
+ { time_dimension: "2026-07-02", "gpt-4": 0 },
+ { time_dimension: "2026-07-03", "gpt-4": 7 },
+ ]);
+
+ expect(prepareDenseSeries(grouped, ["gpt-4"], "gap")).toEqual([
+ { time_dimension: "2026-07-01", "gpt-4": 5 },
+ { time_dimension: "2026-07-02", "gpt-4": null },
+ { time_dimension: "2026-07-03", "gpt-4": 7 },
+ ]);
+ });
+
+ it("preserves real 0 and null values instead of re-deciding them", () => {
+ const grouped = rows([
+ point("2026-07-01", "gpt-4", 0),
+ point("2026-07-02", "gpt-4", null),
+ ]);
+
+ expect(prepareDenseSeries(grouped, ["gpt-4"], "zero")).toEqual([
+ { time_dimension: "2026-07-01", "gpt-4": 0 },
+ { time_dimension: "2026-07-02", "gpt-4": null },
+ ]);
+ });
+
+ it("does not mutate the input rows", () => {
+ const grouped = rows([
+ point("2026-07-01", "gpt-4", 5),
+ point("2026-07-02", "gpt-3.5", 3),
+ ]);
+ const snapshot = JSON.parse(JSON.stringify(grouped));
+
+ prepareDenseSeries(grouped, ["gpt-4", "gpt-3.5"], "zero");
+
+ expect(grouped).toEqual(snapshot);
+ });
+});
+
+describe("prepareIsolatedPoints", () => {
+ it("finds points with no drawable neighbor on either side", () => {
+ const grouped = prepareDenseSeries(
+ rows([
+ point("d1", "a", 1),
+ point("d2", "a", 2),
+ point("d3", undefined, null),
+ point("d4", "a", 4),
+ point("d5", undefined, null),
+ ]),
+ ["a"],
+ "gap",
+ );
+
+ // d4 is isolated (null on both sides); d1/d2 form a segment.
+ expect(prepareIsolatedPoints(grouped, ["a"])).toEqual(
+ new Map([["a", new Set([3])]]),
+ );
+ });
+
+ it("marks a single-bucket series as isolated", () => {
+ const grouped = rows([point("d1", "a", 1)]);
+ expect(prepareIsolatedPoints(grouped, ["a"])).toEqual(
+ new Map([["a", new Set([0])]]),
+ );
+ });
+
+ it("returns no entry for series without isolated points", () => {
+ const grouped = rows([
+ point("d1", "a", 1),
+ point("d2", "a", 2),
+ point("d3", "a", 3),
+ ]);
+ expect(prepareIsolatedPoints(grouped, ["a"]).size).toBe(0);
+ });
+
+ it("treats a real 0 as drawable and null as a gap", () => {
+ const grouped = rows([
+ point("d1", "a", null),
+ point("d2", "a", 0),
+ point("d3", "a", null),
+ ]);
+ expect(prepareIsolatedPoints(grouped, ["a"])).toEqual(
+ new Map([["a", new Set([1])]]),
+ );
+ });
+});
+
+describe("groupDataByTimeDimension with bucket markers", () => {
+ it("keeps a marker point's time bucket without inventing an 'Unknown' series", () => {
+ const grouped = rows([
+ point("2026-07-01", "gpt-4", 5),
+ point("2026-07-02", undefined, null),
+ ]);
+
+ expect(grouped).toEqual([
+ { time_dimension: "2026-07-01", "gpt-4": 5 },
+ { time_dimension: "2026-07-02" },
+ ]);
+ });
+});
diff --git a/web/src/features/widgets/chart-library/prepareDenseSeries.ts b/web/src/features/widgets/chart-library/prepareDenseSeries.ts
new file mode 100644
index 0000000000..a5263049bc
--- /dev/null
+++ b/web/src/features/widgets/chart-library/prepareDenseSeries.ts
@@ -0,0 +1,74 @@
+import { type MissingBucketValue } from "@/src/features/widgets/chart-library/chart-props";
+import { type TimeSeriesGroupedRow } from "@/src/features/widgets/chart-library/utils";
+
+/**
+ * Preparer (data -> visualiser seam): makes every (bucket, series) cell
+ * explicit so the renderer never guesses what "no data point" means.
+ *
+ * The upstream query densifies the time axis (every bucket in the queried
+ * range arrives as at least one row), but a series only has rows for buckets
+ * where it measured something. Left implicit, the missing cells let the chart
+ * lie: a smoothed line draws straight across buckets that have no data,
+ * fabricating a trend. This pass fills each missing cell with the metric's
+ * honest no-data value β€” a real `0` for additive metrics, `null` (a visible
+ * gap) for non-additive ones. Real `0`s and `null`s in the data pass through
+ * untouched; buckets are never invented, only completed. (LFE-10694,
+ * manifesto V2: missing is a gap, not a zero.)
+ *
+ * Pure and side-effect free: presentation components consume the result, they
+ * don't re-decide it. See ARCHITECTURE.md.
+ */
+export function prepareDenseSeries(
+ rows: TimeSeriesGroupedRow[],
+ dimensions: string[],
+ missingValue: MissingBucketValue,
+): TimeSeriesGroupedRow[] {
+ const fill = missingValue === "zero" ? 0 : null;
+ return rows.map((row) => {
+ const filled: TimeSeriesGroupedRow = { ...row };
+ for (const dimension of dimensions) {
+ if (!(dimension in filled)) {
+ filled[dimension] = fill;
+ }
+ }
+ return filled;
+ });
+}
+
+/**
+ * Preparer: finds each series' isolated points β€” real values with no drawable
+ * neighbor on either side. With gaps rendered honestly (no `connectNulls`),
+ * such a point spans no line segment, so without a marker it would be
+ * invisible, silently dropping real data (V8). The visualiser draws a dot for
+ * exactly these points.
+ *
+ * @returns per-dimension sets of isolated row indices; dimensions without any
+ * isolated point are absent, so the common dense case costs the renderer
+ * nothing.
+ */
+export function prepareIsolatedPoints(
+ rows: TimeSeriesGroupedRow[],
+ dimensions: string[],
+): Map<string, Set<number>> {
+ const isolated = new Map<string, Set<number>>();
+ for (const dimension of dimensions) {
+ const drawable = (row: TimeSeriesGroupedRow | undefined): boolean =>
+ typeof row?.[dimension] === "number" &&
+ Number.isFinite(row[dimension] as number);
+ for (let index = 0; index < rows.length; index++) {
+ if (
+ drawable(rows[index]) &&
+ !drawable(rows[index - 1]) &&
+ !drawable(rows[index + 1])
+ ) {
+ let set = isolated.get(dimension);
+ if (!set) {
+ set = new Set();
+ isolated.set(dimension, set);
+ }
+ set.add(index);
+ }
+ }
+ }
+ return isolated;
+}
diff --git a/web/src/features/widgets/chart-library/utils.ts b/web/src/features/widgets/chart-library/utils.ts
index a2a676dfc1..5f4089a3c7 100644
--- a/web/src/features/widgets/chart-library/utils.ts
+++ b/web/src/features/widgets/chart-library/utils.ts
@@ -9,21 +9,33 @@ import { compactNumberFormatter, numberFormatter } from "@/src/utils/numbers";
export const toFullMetricString = (metric: FormattedMetric): string =>
`${metric.negative ? "-" : ""}${metric.prefix ?? ""}${metric.main}${metric.suffix ?? ""}`;
+/** One recharts row: the time bucket plus a value per series present in it. */
+export type TimeSeriesGroupedRow = {
+ time_dimension: string;
+} & {
+ [dimension: string]: number | null | string;
+};
+
/**
* Groups data by dimension to prepare it for time series breakdowns
* @param data
*/
-export const groupDataByTimeDimension = (data: DataPoint[]) => {
+export const groupDataByTimeDimension = (
+ data: DataPoint[],
+): TimeSeriesGroupedRow[] => {
// First, group by time_dimension
const timeGroups = data.reduce(
- (acc: Record<string, Record<string, number>>, item: DataPoint) => {
+ (acc: Record<string, Record<string, number | null>>, item: DataPoint) => {
const time = item.time_dimension || "Unknown";
if (!acc[time]) {
acc[time] = {};
}
- const dimension = item.dimension || "Unknown";
- acc[time][dimension] = item.metric as number;
+ // A dimension-less point is a bucket marker (e.g. a gap-filled empty
+ // bucket): it keeps the bucket on the axis without adding a series.
+ if (item.dimension) {
+ acc[time][item.dimension] = item.metric as number | null;
+ }
return acc;
},
diff --git a/web/src/features/widgets/components/DashboardWidget.tsx b/web/src/features/widgets/components/DashboardWidget.tsx
index 596d836ea1..f58014b2ca 100644
--- a/web/src/features/widgets/components/DashboardWidget.tsx
+++ b/web/src/features/widgets/components/DashboardWidget.tsx
@@ -32,6 +32,7 @@ import {
shouldUseWidgetSSE,
sanitizePivotTableDefaultSort,
getWidgetMetricPresentation,
+ getWidgetMissingBucketValue,
} from "@/src/features/widgets/utils";
import { ChartLoadingState } from "@/src/features/widgets/chart-library/ChartLoadingState";
import {
@@ -274,17 +275,45 @@ export function DashboardWidget({
};
const metricField = `${metric.agg}_${metric.measure}`;
const metricValue = item[metricField];
+ const isTimeSeries = isTimeSeriesChart(widget.data.chartType);
const dimensionField =
widget.data.dimensions.slice().shift()?.field ?? "none";
+ const dimensionValue = item[dimensionField];
+
+ // A gap-filled empty bucket arrives as a row with no dimension and the
+ // metric column's type default: NULL for nullable aggregations
+ // (avg/percentiles), 0 for non-nullable ones (count/uniq/sum). Keep it
+ // as a pure bucket marker (holds the spot on the time axis) instead of
+ // inventing an "n/a" series. The 0 form is only treated as filler for
+ // additive metrics, where the marker is lossless (prepareDenseSeries
+ // re-derives the honest 0 for any series that exists); a real
+ // dimension-less avg/percentile 0 stays a visible data point. (LFE-10694)
+ const isFillerMetricValue =
+ metricValue == null ||
+ (getWidgetMissingBucketValue(metric.agg) === "zero" &&
+ Number(metricValue) === 0);
+ if (
+ isTimeSeries &&
+ (dimensionValue === null || dimensionValue === "") &&
+ isFillerMetricValue
+ ) {
+ return {
+ dimension: undefined,
+ metric: null,
+ time_dimension: item["time_dimension"],
+ };
+ }
+
return {
dimension:
- item[dimensionField] !== undefined
+ dimensionValue !== undefined
? (() => {
- const val = item[dimensionField];
- if (typeof val === "string") return val;
+ const val = dimensionValue;
+ // Empty first: "" is a string, so the order matters. (LFE-10694)
if (val === null || val === undefined || val === "")
return "n/a";
+ if (typeof val === "string") return val;
if (Array.isArray(val)) return val.join(", ");
// Objects / numbers / booleans are stringified to avoid React key issues
return String(val);
@@ -292,7 +321,11 @@ export function DashboardWidget({
: formatMetricName(metricField),
metric: Array.isArray(metricValue)
? metricValue
- : Number(metricValue || 0),
+ : // On a time series a missing value stays null β€” the chart renders
+ // it by the metric's missing-bucket semantics instead of a fake 0.
+ isTimeSeries && metricValue == null
+ ? null
+ : Number(metricValue || 0),
time_dimension: item["time_dimension"],
};
});
@@ -501,6 +534,9 @@ export function DashboardWidget({
}
isLoading={queryResult.isPending}
metricFormatter={chartPresentation?.metricFormatter}
+ missingValue={getWidgetMissingBucketValue(
+ widget.data.metrics[0]?.agg ?? "count",
+ )}
/>
<ChartLoadingState
isLoading={chartLoadingState.isLoading}
diff --git a/web/src/features/widgets/components/InlineWidget.tsx b/web/src/features/widgets/components/InlineWidget.tsx
index fa15220ad7..3e56b8987f 100644
--- a/web/src/features/widgets/components/InlineWidget.tsx
+++ b/web/src/features/widgets/components/InlineWidget.tsx
@@ -17,8 +17,10 @@ import {
formatMetricName,
shouldUseWidgetSSE,
getWidgetMetricPresentation,
+ getWidgetMissingBucketValue,
type WidgetChartConfig,
} from "@/src/features/widgets/utils";
+import { isTimeSeriesChart } from "@/src/features/widgets/chart-library/utils";
import { useV4Beta } from "@/src/features/events/hooks/useV4Beta";
import { cn } from "@/src/utils/tailwind";
@@ -254,14 +256,42 @@ export function WidgetContent({
xAxisValue = String(item["time_dimension"]);
}
+ const isTimeSeries = isTimeSeriesChart(chartType);
+ const dimensionValue = item[dimensionField];
+
+ // A gap-filled empty bucket arrives as a row with no dimension and the
+ // metric column's type default: NULL for nullable aggregations
+ // (avg/percentiles), 0 for non-nullable ones (count/uniq/sum). Keep it
+ // as a pure bucket marker (holds the spot on the x axis) instead of
+ // inventing an "n/a" series. The 0 form is only treated as filler for
+ // additive metrics, where the marker is lossless (prepareDenseSeries
+ // re-derives the honest 0 for any series that exists); a real
+ // dimension-less avg/percentile 0 stays a visible data point. (LFE-10694)
+ const isFillerMetricValue =
+ metricValue == null ||
+ (getWidgetMissingBucketValue(metric.agg) === "zero" &&
+ Number(metricValue) === 0);
+ if (
+ isTimeSeries &&
+ (dimensionValue === null || dimensionValue === "") &&
+ isFillerMetricValue
+ ) {
+ return {
+ time_dimension: xAxisValue,
+ dimension: undefined,
+ metric: null,
+ };
+ }
+
// Handle series dimension (for legend)
let seriesDimension: string;
- if (item[dimensionField] !== undefined) {
- const val = item[dimensionField];
- if (typeof val === "string") {
- seriesDimension = val;
- } else if (val === null || val === undefined || val === "") {
+ if (dimensionValue !== undefined) {
+ const val = dimensionValue;
+ // Empty first: "" is a string, so the order matters. (LFE-10694)
+ if (val === null || val === undefined || val === "") {
seriesDimension = "n/a";
+ } else if (typeof val === "string") {
+ seriesDimension = val;
} else if (Array.isArray(val)) {
seriesDimension = val.join(", ");
} else {
@@ -277,7 +307,11 @@ export function WidgetContent({
dimension: seriesDimension,
metric: Array.isArray(metricValue)
? metricValue
- : Number(metricValue || 0),
+ : // On a time series a missing value stays null β€” the chart renders
+ // it by the metric's missing-bucket semantics instead of a fake 0.
+ isTimeSeries && metricValue == null
+ ? null
+ : Number(metricValue || 0),
};
});
@@ -406,6 +440,7 @@ export function WidgetContent({
onSortChange={chartType === "PIVOT_TABLE" ? onSortChange : undefined}
isLoading={queryResult.isPending || isExternalLoading}
metricFormatter={chartPresentation?.metricFormatter}
+ missingValue={getWidgetMissingBucketValue(metrics[0]?.agg ?? "count")}
/>
<ChartLoadingState
isLoading={chartLoadingState.isLoading}
diff --git a/web/src/features/widgets/components/WidgetForm.tsx b/web/src/features/widgets/components/WidgetForm.tsx
index d94b70ae55..b805e1bde3 100644
--- a/web/src/features/widgets/components/WidgetForm.tsx
+++ b/web/src/features/widgets/components/WidgetForm.tsx
@@ -92,6 +92,7 @@ import {
buildWidgetDescription,
formatMetricName,
getWidgetMetricPresentation,
+ getWidgetMissingBucketValue,
sanitizePivotTableDefaultSort,
type WidgetChartConfig,
} from "@/src/features/widgets/utils";
@@ -1172,19 +1173,56 @@ export function WidgetForm({
const metricField = `${selectedAggregation}_${selectedMeasure}`;
const metric = item[metricField];
const dimensionField = selectedDimension;
+ const dimensionValue = item[dimensionField];
+ const isTimeSeries = isTimeSeriesChart(
+ selectedChartType as DashboardWidgetChartType,
+ );
+
+ // A gap-filled empty bucket arrives as a row with no dimension and the
+ // metric column's type default: NULL for nullable aggregations
+ // (avg/percentiles), 0 for non-nullable ones (count/uniq/sum). Keep it
+ // as a pure bucket marker (holds the spot on the time axis) instead of
+ // inventing an "n/a" series. The 0 form is only treated as filler for
+ // additive metrics, where the marker is lossless (prepareDenseSeries
+ // re-derives the honest 0 for any series that exists); a real
+ // dimension-less avg/percentile 0 stays a visible data point. (LFE-10694)
+ const isFillerMetricValue =
+ metric == null ||
+ (getWidgetMissingBucketValue(selectedAggregation) === "zero" &&
+ Number(metric) === 0);
+ if (
+ isTimeSeries &&
+ dimensionField !== "none" &&
+ (dimensionValue === null || dimensionValue === "") &&
+ isFillerMetricValue
+ ) {
+ return {
+ dimension: undefined,
+ metric: null,
+ time_dimension: item["time_dimension"],
+ };
+ }
+
return {
dimension:
- item[dimensionField] !== undefined && dimensionField !== "none"
+ dimensionValue !== undefined && dimensionField !== "none"
? (() => {
- const val = item[dimensionField];
- if (typeof val === "string") return val;
+ const val = dimensionValue;
+ // Empty first: "" is a string, so the order matters. (LFE-10694)
if (val === null || val === undefined || val === "")
return "n/a";
+ if (typeof val === "string") return val;
if (Array.isArray(val)) return val.join(", ");
return String(val);
})()
: formatMetricName(metricField),
- metric: Array.isArray(metric) ? metric : Number(metric || 0),
+ metric: Array.isArray(metric)
+ ? metric
+ : // On a time series a missing value stays null β€” the chart renders
+ // it by the metric's missing-bucket semantics instead of a fake 0.
+ isTimeSeries && metric == null
+ ? null
+ : Number(metric || 0),
time_dimension: item["time_dimension"],
};
}) ?? [],
@@ -2295,6 +2333,9 @@ export function WidgetForm({
onSortChange={undefined}
isLoading={queryResult.isPending}
metricFormatter={chartPresentation?.metricFormatter}
+ missingValue={getWidgetMissingBucketValue(
+ selectedAggregation,
+ )}
/>
<ChartLoadingState
isLoading={chartLoadingState.isLoading}
diff --git a/web/src/features/widgets/utils.ts b/web/src/features/widgets/utils.ts
index cc4831c80a..41f4a685fc 100644
--- a/web/src/features/widgets/utils.ts
+++ b/web/src/features/widgets/utils.ts
@@ -7,7 +7,10 @@ import {
type ViewVersion,
} from "@langfuse/shared/query";
import { formatMetric } from "@/src/features/widgets/chart-library/utils";
-import { type MetricFormatterFunction } from "@/src/features/widgets/chart-library/chart-props";
+import {
+ type MetricFormatterFunction,
+ type MissingBucketValue,
+} from "@/src/features/widgets/chart-library/chart-props";
// Shared widget chart configuration types
export type WidgetChartConfig = {
@@ -216,6 +219,17 @@ const widgetUnitLabels: Record<string, string> = {
calls: "Calls",
};
+/**
+ * Decides what a widget's time-series chart shows for a bucket its metric has
+ * no data point in, from the metric's aggregation: counting and additive
+ * aggregations (count, uniq, sum) have an honest `0` β€” nothing happened β€”
+ * while avg/min/max/percentiles have no honest value and must render a gap
+ * instead of a fabricated number. (LFE-10694)
+ */
+export function getWidgetMissingBucketValue(agg: string): MissingBucketValue {
+ return agg === "count" || agg === "uniq" || agg === "sum" ? "zero" : "gap";
+}
+
export function getWidgetMetricPresentation(params: {
metric: { measure: string; agg: string };
view: string;