Skip to content

Commit 575ea72

Browse files
alex-fedotyevclaude
andcommitted
fix(app): cap RED error-rate y-axis at 100% and tighten axis labels
- The error-rate data is already bounded to [0,1], but recharts' default auto-domain turns a flat/zero series into a nonsense 0-400% scale. Add an opt-in yAxisMaxDomain to DBTimeChart / HDXMultiSeriesTimeChart that caps the upper bound (1 = 100%) while still auto-scaling to smaller values, and use it on the rate chart. A no-error range now shows 0-100%; a ~5% range still zooms to ~5%. - Nudge the compact x-axis tick offset up so labels sit closer to the axis (extra gap crept in with the edge-anchor change). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 59033f8 commit 575ea72

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

packages/app/src/HDXMultiSeriesTimeChart.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,7 @@ export const MemoChart = memo(function MemoChart({
652652
dateRangeEndInclusive = true,
653653
fitYAxisToData = false,
654654
compactXAxisLabels = false,
655+
yAxisMaxDomain,
655656
}: {
656657
graphResults: any[];
657658
setIsClickActive: (v: ActiveClickPayload | undefined) => void;
@@ -691,6 +692,13 @@ export const MemoChart = memo(function MemoChart({
691692
* narrow charts, e.g. the side-by-side RED metrics tiles.
692693
*/
693694
compactXAxisLabels?: boolean;
695+
/**
696+
* Cap the y-axis upper bound at this value (e.g. 1 for a 0-100% rate). The
697+
* axis still auto-scales below the cap so small values keep a tight range,
698+
* and a flat/zero series falls back to the cap instead of a degenerate
699+
* auto-domain. Only applied on the default (non-fit, non-selection) path.
700+
*/
701+
yAxisMaxDomain?: number;
694702
}) {
695703
const _id = useId();
696704
const id = _id.replace(/:/g, '');
@@ -807,6 +815,18 @@ export const MemoChart = memo(function MemoChart({
807815
// fit the lower bound to the data. When neither applies, let Recharts
808816
// auto-calculate the upper bound while pinning the lower bound to zero.
809817
if (!hasSelection && !shouldFitYAxis) {
818+
if (yAxisMaxDomain != null) {
819+
// Auto-scale up to the data max (with headroom) but never above the
820+
// cap; a flat or zero series uses the cap instead of a degenerate
821+
// auto-domain (which recharts renders as e.g. 0-400% for a 0% rate).
822+
return [
823+
0,
824+
(dataMax: number) =>
825+
Number.isFinite(dataMax) && dataMax > 0
826+
? Math.min(dataMax * 1.1, yAxisMaxDomain)
827+
: yAxisMaxDomain,
828+
];
829+
}
810830
return [0, 'auto'];
811831
}
812832

@@ -851,6 +871,7 @@ export const MemoChart = memo(function MemoChart({
851871
selectedSeriesNames,
852872
fitYAxisToData,
853873
displayType,
874+
yAxisMaxDomain,
854875
]);
855876

856877
const [containerWidth, setContainerWidth] = useState(0);
@@ -942,7 +963,7 @@ export const MemoChart = memo(function MemoChart({
942963
<Text
943964
x={x}
944965
y={y}
945-
dy={12}
966+
dy={8}
946967
textAnchor={textAnchor}
947968
verticalAnchor="start"
948969
fontSize={11}

packages/app/src/components/DBTimeChart.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,11 @@ type DBTimeChartComponentProps = {
307307
* narrow charts (e.g. side-by-side RED metric tiles). Forwarded to the chart.
308308
*/
309309
compactXAxisLabels?: boolean;
310+
/**
311+
* Cap the y-axis upper bound (e.g. 1 for a 0-100% rate) while still
312+
* auto-scaling below it. Forwarded to the chart.
313+
*/
314+
yAxisMaxDomain?: number;
310315
};
311316

312317
function DBTimeChartComponent({
@@ -333,6 +338,7 @@ function DBTimeChartComponent({
333338
errorVariant,
334339
onFocusSeries,
335340
compactXAxisLabels,
341+
yAxisMaxDomain,
336342
}: DBTimeChartComponentProps) {
337343
const [selectedSeriesSet, setSelectedSeriesSet] = useState<Set<string>>(
338344
new Set(),
@@ -855,6 +861,7 @@ function DBTimeChartComponent({
855861
dateRangeEndInclusive={queriedConfig.dateRangeEndInclusive}
856862
fitYAxisToData={queriedConfig.fitYAxisToData}
857863
compactXAxisLabels={compactXAxisLabels}
864+
yAxisMaxDomain={yAxisMaxDomain}
858865
/>
859866
</>
860867
)}

packages/app/src/components/Search/TraceRedMetricsChart.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ export function TraceRedMetricsChart({
188188
hiddenSeries={
189189
errorsMode === 'rate' ? ERROR_RATE_HELPER_SERIES : undefined
190190
}
191+
// Rate is 0-100%: cap the axis so a flat/near-zero series
192+
// can't render a nonsense 0-400% scale, while still
193+
// auto-scaling to small values.
194+
yAxisMaxDomain={errorsMode === 'rate' ? 1 : undefined}
191195
{...commonProps}
192196
/>
193197
</Box>

0 commit comments

Comments
 (0)