Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(web): pulse strip spacing and axis labels (#18355)

Trang Nguyenc418fe83fedd
diff --git a/web/src/components/metric-strip/MetricStripBand.tsx b/web/src/components/metric-strip/MetricStripBand.tsx
index c65479fcd2..39081af727 100644
--- a/web/src/components/metric-strip/MetricStripBand.tsx
+++ b/web/src/components/metric-strip/MetricStripBand.tsx
@@ -29,7 +29,7 @@ export type MetricStripStatus = "loading" | "empty" | "ready";
*/
export function MetricStripMessage({ message }: { message: string }) {
return (
- <div className="text-muted-foreground flex h-full items-center justify-center text-[11px]">
+ <div className="text-muted-foreground flex h-full items-center justify-center text-sm">
{message}
</div>
);
@@ -86,12 +86,7 @@ export const MetricStripBand = forwardRef<
// sits closer to its chart than to the band's edge.
<div className="relative px-2 pt-2.5 pb-1">
{status === "loading" ? (
- <div
- className={cn(
- "bg-muted animate-pulse rounded",
- contentHeightClass,
- )}
- />
+ <div className={contentHeightClass} />
) : status === "empty" ? (
<div className={contentHeightClass}>
<MetricStripMessage message={emptyMessage} />
diff --git a/web/src/components/metric-strip/MetricStripTrigger.tsx b/web/src/components/metric-strip/MetricStripTrigger.tsx
index 5e456a4035..49372852fd 100644
--- a/web/src/components/metric-strip/MetricStripTrigger.tsx
+++ b/web/src/components/metric-strip/MetricStripTrigger.tsx
@@ -13,7 +13,7 @@ export type MetricStripTriggerVariant = "metric" | "aggregation";
/** Shared so a strip whose menu is a different primitive still matches. */
export const METRIC_STRIP_TRIGGER_CLASS =
- "flex items-center gap-0.5 text-[13px] leading-none";
+ "flex items-center gap-0.5 text-sm leading-none";
export const metricStripTriggerClasses: Record<
MetricStripTriggerVariant,
diff --git a/web/src/features/events/components/outlier-strip/EventsOutlierStrip.tsx b/web/src/features/events/components/outlier-strip/EventsOutlierStrip.tsx
index abd4608301..931581309c 100644
--- a/web/src/features/events/components/outlier-strip/EventsOutlierStrip.tsx
+++ b/web/src/features/events/components/outlier-strip/EventsOutlierStrip.tsx
@@ -3,6 +3,7 @@ import { useMemo, useState } from "react";
import type * as React from "react";
import { type FilterState, type QueryType } from "@langfuse/shared";
import { api } from "@/src/utils/api";
+import { cn } from "@/src/utils/tailwind";
import { useElementSize } from "@/src/hooks/useElementSize";
import {
MetricStripBand,
@@ -20,6 +21,7 @@ import {
import { toChartFilters } from "@/src/features/chart-view/lib/chartFilterCompatibility";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics";
import {
+ estimateYLabelWidthPx,
OutlierBarStrip,
type OutlierStripDrillTrigger,
} from "./OutlierBarStrip";
@@ -58,6 +60,25 @@ import { canApplyOutlierStripFilters } from "./lib/filterCompatibility";
/** Target horizontal pixels per bar for granularity picking. */
const BAR_SLOT_TARGET_PX = 5;
+/** Band `px-2` on both sides plus the base `ml-6` y-label gutter and `mr-2`. */
+const PLOT_HORIZONTAL_INSET_PX = 16 + 24 + 8;
+
+/** Gutter steps for the right-aligned y labels; the base step is `ml-6`. */
+const Y_LABEL_GUTTERS = [
+ { px: 24, className: "ml-6" },
+ { px: 32, className: "ml-8" },
+ { px: 40, className: "ml-10" },
+ { px: 48, className: "ml-12" },
+] as const;
+
+function yLabelGutter(labelWidthPx: number) {
+ const needed = labelWidthPx + 4;
+ return (
+ Y_LABEL_GUTTERS.find((gutter) => gutter.px >= needed) ??
+ Y_LABEL_GUTTERS[Y_LABEL_GUTTERS.length - 1]
+ );
+}
+
type StripMode = OutlierStripSettings["mode"];
const MODE_OPTIONS: StripMode[] = ["count", "cost", "latency"];
@@ -168,8 +189,8 @@ export function EventsOutlierStrip({
const fromMs = fromTimestamp.getTime();
const toMs = toTimestamp.getTime();
const validRange = fromMs < toMs;
- // getBoundingClientRect includes the wrapper's px-2 padding (border-box).
- const width = Math.max((size?.width ?? 0) - 16, 0);
+ // getBoundingClientRect includes the band's padding (border-box).
+ const width = Math.max((size?.width ?? 0) - PLOT_HORIZONTAL_INSET_PX, 0);
const mode: StripMode = settings.mode;
const chartWidth = width;
@@ -358,44 +379,52 @@ export function EventsOutlierStrip({
: "ready";
const header = (
- <MetricStripHeaderRow>
- <ModeDropdownController
- options={MODE_OPTIONS}
- onChange={handleModeChange}
- >
- {({ Trigger }) => (
- <Trigger asChild>
- <MetricStripTrigger
- ariaLabel={`Chart mode: ${modeLabel(mode)}`}
- label={modeLabel(mode)}
- variant="metric"
- />
- </Trigger>
- )}
- </ModeDropdownController>
- {/* The bar's aggregate must be legible where there is a choice (p95 vs
- avg); single-option metrics are unambiguous and render no
- aggregation label. A chart that cannot represent the filters is not
- drawn with any aggregate, so it shows none. */}
- {canApplyFilters && aggOptions.length > 1 && (
- <AggDropdownController
- options={aggOptions}
- onChange={(agg) => setAggregation(mode, agg)}
+ <div className="pt-0.5 pr-2 pl-1">
+ <MetricStripHeaderRow>
+ <ModeDropdownController
+ options={MODE_OPTIONS}
+ onChange={handleModeChange}
>
{({ Trigger }) => (
- <span className="flex items-baseline gap-1">
- <Trigger asChild>
- <MetricStripTrigger
- ariaLabel={`${def.shortLabel} aggregation: ${aggregation}`}
- label={aggregation}
- variant="aggregation"
- />
- </Trigger>
- </span>
+ <Trigger asChild>
+ <MetricStripTrigger
+ ariaLabel={`Chart mode: ${modeLabel(mode)}`}
+ label={modeLabel(mode)}
+ variant="metric"
+ />
+ </Trigger>
)}
- </AggDropdownController>
- )}
- </MetricStripHeaderRow>
+ </ModeDropdownController>
+ {/* The bar's aggregate must be legible where there is a choice (p95 vs
+ avg); single-option metrics are unambiguous and render no
+ aggregation label. A chart that cannot represent the filters is not
+ drawn with any aggregate, so it shows none. */}
+ {canApplyFilters && aggOptions.length > 1 && (
+ <AggDropdownController
+ options={aggOptions}
+ onChange={(agg) => setAggregation(mode, agg)}
+ >
+ {({ Trigger }) => (
+ <span className="flex items-baseline gap-1">
+ <Trigger asChild>
+ <MetricStripTrigger
+ ariaLabel={`${def.shortLabel} aggregation: ${aggregation}`}
+ label={aggregation}
+ variant="aggregation"
+ />
+ </Trigger>
+ </span>
+ )}
+ </AggDropdownController>
+ )}
+ </MetricStripHeaderRow>
+ </div>
+ );
+
+ const yGutter = yLabelGutter(estimateYLabelWidthPx(series.maxValue, mode));
+ const plotWidthPx = Math.max(
+ chartWidth - (yGutter.px - Y_LABEL_GUTTERS[0].px),
+ 1,
);
return (
@@ -409,10 +438,12 @@ export function EventsOutlierStrip({
// switch, drill-in) — stale data must not read as current.
stale={queryResult.isPlaceholderData && queryResult.isFetching}
header={header}
+ // Ready height (header + plot + time labels), so loading doesn't jump.
+ contentHeightClass="h-22.25"
>
{!canApplyFilters ? (
<OutlierBarStrip
- className="mt-1.5"
+ className="mt-2 mr-2 ml-6"
dense={[]}
maxValue={0}
ticks={[]}
@@ -423,13 +454,13 @@ export function EventsOutlierStrip({
/>
) : (
<OutlierBarStrip
- className="mt-1.5"
+ className={cn("mt-2 mr-2", yGutter.className)}
dense={series.dense}
maxValue={series.maxValue}
ticks={series.ticks}
stepMs={stepMs}
metric={mode}
- widthPx={chartWidth}
+ widthPx={plotWidthPx}
onSelectBucket={handleSelectBucket}
onPreviewPinned={(trigger) =>
capture("pulse:preview_pinned", {
diff --git a/web/src/features/events/components/outlier-strip/OutlierBarStrip.tsx b/web/src/features/events/components/outlier-strip/OutlierBarStrip.tsx
index 1c2a91c4ce..5a8b610502 100644
--- a/web/src/features/events/components/outlier-strip/OutlierBarStrip.tsx
+++ b/web/src/features/events/components/outlier-strip/OutlierBarStrip.tsx
@@ -33,6 +33,21 @@ const METRIC_COLOR: Record<OutlierStripMetricKey, string> = {
latency: "hsl(var(--chart-2))",
};
+/** Widest y-axis label in px at the strip's default height and scale. */
+export function estimateYLabelWidthPx(
+ maxValue: number,
+ metric: OutlierStripMetricKey,
+): number {
+ const ticks = prepareOutlierYTicks({
+ maxValue,
+ metric,
+ plotHeightPx: 49,
+ scale: "sqrt",
+ });
+ const chars = Math.max(0, ...ticks.map((tick) => tick.label.length));
+ return chars * 6;
+}
+
/** Pointer travel before a press becomes a range-drag instead of a click. */
const DRAG_THRESHOLD_PX = 5;
@@ -162,7 +177,7 @@ export function OutlierBarStrip({
const barWidth = Math.max(slotPx - 1, 0.5);
// Bars sit ON the 1px baseline, never across it.
const plotHeight = heightPx - 1;
- const labelHeight = showTimeLabels ? 13 : 0;
+ const labelHeight = showTimeLabels ? 16 : 0;
const hasData = maxValue > 0;
const hasActivity = dense.some((bin) => bin.count > 0);
@@ -266,33 +281,28 @@ export function OutlierBarStrip({
<text
key={`label-${tick.index}`}
x={tick.x}
- y={heightPx + 9}
+ y={heightPx + 12}
textAnchor={tick.textAnchor}
className="fill-muted-foreground/80 font-sans"
- fontSize={9}
+ fontSize={10}
>
{tick.label}
</text>
))}
- {/* Y-axis labels — after the bars so they stay legible on top; the
- background-colored stroke (paint-order) keeps them readable where
- they overlap a bar. Every label hangs BELOW its gridline: the top
- gridline can hug the plot's top edge (no room above), and one
- consistent side means the preparer's line spacing is also the
- label spacing. */}
+ {/* Y-axis labels sit in the left gutter, centred on their gridlines. */}
{yTicks.map((tick) => {
const lineY = plotHeight - tick.offsetPx;
return (
<text
key={`y-label-${tick.value}`}
- x={3}
- y={lineY + 9}
- textAnchor="start"
- className="fill-muted-foreground stroke-background font-sans"
- fontSize={9}
- strokeWidth={2.5}
- style={{ paintOrder: "stroke" }}
+ x={-4}
+ // Half a line below the top edge so a top tick never paints above the plot.
+ y={Math.max(lineY, 5)}
+ textAnchor="end"
+ dominantBaseline="middle"
+ className="fill-muted-foreground font-sans"
+ fontSize={10}
>
{tick.label}
</text>
@@ -380,7 +390,7 @@ export function OutlierBarStrip({
// Crosshair over the whole plot: the standard "this surface supports
// range selection" affordance (Grafana/Datadog) — it makes the
// drag-to-zoom brush discoverable where a pointer only said "click".
- className="block cursor-crosshair touch-pan-y select-none"
+ className="block cursor-crosshair touch-pan-y overflow-visible select-none"
onPointerLeave={(event) => {
if (event.pointerType !== "mouse") return;
setHoverIndex(null);
@@ -541,15 +551,15 @@ export function OutlierBarStrip({
</svg>
{!hasData && (
- // Centered on the bar canvas, not the svg: inset-0 would include the
- // time-label band and push the notice below the plot's middle.
+ // Centered on the bar canvas, nudged up so it reads optically centred
+ // with the time labels underneath.
<span
- className="text-muted-foreground/70 pointer-events-none absolute inset-x-0 top-0 flex items-center justify-center text-[10px]"
+ className="text-muted-foreground pointer-events-none absolute inset-x-0 top-0 flex items-center justify-center pb-2 text-sm"
style={{ height: heightPx }}
>
{hasActivity
- ? `No ${metricSpec.shortLabel.toLowerCase()} data in range`
- : "No observations in range"}
+ ? `No ${metricSpec.shortLabel.toLowerCase()} data`
+ : "No data"}
</span>
)}
diff --git a/web/src/features/events/components/outlier-strip/lib/binning.ts b/web/src/features/events/components/outlier-strip/lib/binning.ts
index 55786cb6c2..09548fbe05 100644
--- a/web/src/features/events/components/outlier-strip/lib/binning.ts
+++ b/web/src/features/events/components/outlier-strip/lib/binning.ts
@@ -1,6 +1,7 @@
/* eslint-disable no-nested-ternary */
import { format } from "date-fns";
import {
+ compactNumberFormatter,
latencyFormatter,
numberFormatter,
usdFormatter,
@@ -139,6 +140,8 @@ export type OutlierStripMetricDef = {
/** Raw result value → plotted unit (e.g. latency ms → s). */
fromRaw: (raw: number) => number;
format: (value: number) => string;
+ /** Y-axis tick label; defaults to `format`. */
+ formatTick?: (value: number) => string;
/** Ascending "nice" y-tick values in the plotted unit. Metrics without a
* ladder (plain numbers like cost) tick on 1-2-5 decades; durations need
* time-native steps so ticks read "1m", not "1m 40s" (100). */
@@ -198,6 +201,7 @@ export const OUTLIER_STRIP_METRICS: Record<
aggregations: [{ key: "count", queryAggregation: "count" }],
fromRaw: (raw) => raw,
format: (value) => numberFormatter(value, 0),
+ formatTick: (value) => compactNumberFormatter(value, 1),
},
cost: {
shortLabel: "Cost",
@@ -567,7 +571,11 @@ export function prepareOutlierYTicks(params: {
const offsetPx = toOffsetPx(value);
if (offsetPx < Y_TICK_MIN_OFFSET_PX) break;
if (lastOffsetPx - offsetPx < Y_TICK_MIN_SPACING_PX) continue;
- ticks.push({ value, label: def.format(value), offsetPx });
+ ticks.push({
+ value,
+ label: (def.formatTick ?? def.format)(value),
+ offsetPx,
+ });
if (ticks.length >= Y_TICK_MAX_COUNT) break;
lastOffsetPx = offsetPx;
}