🪢 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(v4): show evenly spaced usage chart y-axis ticks (#14699)
Max Deichmannb501e7a866b3
diff --git a/web/src/features/v4/components/V4MigrationProjectCards.clienttest.tsx b/web/src/features/v4/components/V4MigrationProjectCards.clienttest.tsxindex d4e04b2527..5e1605981b 100644--- a/web/src/features/v4/components/V4MigrationProjectCards.clienttest.tsx+++ b/web/src/features/v4/components/V4MigrationProjectCards.clienttest.tsx@@ -7,6 +7,9 @@ const rechartsProps = vi.hoisted(() => ({barCharts: [] as Array<{ margin?: { left?: number } }>,yAxes: [] as Array<{width?: number;+ domain?: [number, number];+ interval?: number;+ ticks?: number[];tickFormatter?: (value: number) => string;}>,}));@@ -29,6 +32,11 @@ vi.mock("recharts", () => ({YAxis: (props: Record<string, unknown>) => {rechartsProps.yAxes.push({width: typeof props.width === "number" ? props.width : undefined,+ domain: Array.isArray(props.domain)+ ? (props.domain as [number, number])+ : undefined,+ interval: typeof props.interval === "number" ? props.interval : undefined,+ ticks: Array.isArray(props.ticks) ? (props.ticks as number[]) : undefined,tickFormatter:typeof props.tickFormatter === "function"? (props.tickFormatter as (value: number) => string)@@ -65,4 +73,42 @@ describe("UsageStackedBarOverview", () => {expect(rechartsProps.yAxes[0]?.width).toBeGreaterThanOrEqual(42);expect(rechartsProps.yAxes[0]?.tickFormatter?.(1800)).toBe("1.8K");});++ it("passes evenly spaced Y-axis ticks so intermediate values are not skipped", () => {+ render(+ <UsageStackedBarOverview+ bucketTimes={["2026-06-30T04:00:00.000Z"]}+ valueLabel="calls"+ series={[+ {+ name: "GET /api/public/traces",+ total: 1200,+ points: [1200],+ },+ ]}+ />,+ );++ expect(rechartsProps.yAxes[0]?.ticks).toEqual([0, 300, 600, 900, 1200]);+ expect(rechartsProps.yAxes[0]?.domain).toEqual([0, 1200]);+ expect(rechartsProps.yAxes[0]?.interval).toBe(0);+ });++ it("keeps Y-axis ticks as whole numbers for small count ranges", () => {+ render(+ <UsageStackedBarOverview+ bucketTimes={["2026-06-30T04:00:00.000Z"]}+ valueLabel="calls"+ series={[+ {+ name: "GET /api/public/traces",+ total: 5,+ points: [5],+ },+ ]}+ />,+ );++ expect(rechartsProps.yAxes[0]?.ticks).toEqual([0, 2, 4, 6, 8]);+ });});diff --git a/web/src/features/v4/components/V4MigrationProjectCards.tsx b/web/src/features/v4/components/V4MigrationProjectCards.tsxindex eb640b9ee9..513e898a34 100644--- a/web/src/features/v4/components/V4MigrationProjectCards.tsx+++ b/web/src/features/v4/components/V4MigrationProjectCards.tsx@@ -64,6 +64,7 @@ const V4_DOCS_LINK = {} as const;const MAX_STACKED_CHART_SERIES = 6;+const STACKED_CHART_Y_AXIS_TICK_COUNT = 5;const STACKED_CHART_COLORS = ["hsl(var(--chart-1))","hsl(var(--chart-2))",@@ -289,6 +290,38 @@ const getStackedChartSeries = (}));};+const getNiceCountStep = (rawStep: number): number => {+ if (!Number.isFinite(rawStep) || rawStep <= 0) return 1;++ const magnitude = 10 ** Math.floor(Math.log10(rawStep));+ const normalizedStep = rawStep / magnitude;+ const niceStep =+ [1, 1.25, 1.5, 2, 2.5, 3, 4, 5, 7.5, 10].find(+ (step) => normalizedStep <= step,+ ) ?? 10;++ return Math.max(1, Math.ceil(niceStep * magnitude));+};++const getStackedYAxisTicks = (+ series: UsageSeries[],+ tickCount = STACKED_CHART_Y_AXIS_TICK_COUNT,+): number[] => {+ const bucketCount = Math.max(0, ...series.map((item) => item.points.length));+ let maxStackedValue = 0;++ for (let bucketIndex = 0; bucketIndex < bucketCount; bucketIndex += 1) {+ const bucketTotal = series.reduce((sum, item) => {+ const value = item.points[bucketIndex] ?? 0;+ return Number.isFinite(value) && value > 0 ? sum + value : sum;+ }, 0);+ maxStackedValue = Math.max(maxStackedValue, bucketTotal);+ }++ const step = getNiceCountStep(maxStackedValue / (tickCount - 1));+ return Array.from({ length: tickCount }, (_, index) => index * step);+};+export const UsageStackedBarOverview = ({bucketTimes,series,@@ -299,6 +332,11 @@ export const UsageStackedBarOverview = ({valueLabel: string;}) => {const chartSeries = useMemo(() => getStackedChartSeries(series), [series]);+ const yAxisTicks = useMemo(+ () => getStackedYAxisTicks(chartSeries),+ [chartSeries],+ );+ const yAxisMax = yAxisTicks[yAxisTicks.length - 1] ?? 0;const chartData = useMemo(() =>bucketTimes.map((time, bucketIndex) => {@@ -359,6 +397,9 @@ export const UsageStackedBarOverview = ({axisLine={false}width={42}fontSize={11}+ domain={[0, yAxisMax]}+ ticks={yAxisTicks}+ interval={0}tickFormatter={(value) => compactNumberFormatter(Number(value), 1)}/><ChartTooltip