Skip to content

Commit 001269c

Browse files
committed
Chart axis for negative vals fix
1 parent 6e6c6c6 commit 001269c

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

apps/webapp/app/components/code/QueryResultsChart.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,9 +838,22 @@ export const QueryResultsChart = memo(function QueryResultsChart({
838838
// (prevents massive bars when there are only a few data points)
839839
const xAxisPropsForBar = baseXAxisProps;
840840

841+
const yAxisDomain = useMemo(() => {
842+
let min = 0;
843+
for (const point of data) {
844+
for (const s of series) {
845+
const val = point[s];
846+
if (typeof val === "number" && isFinite(val)) {
847+
min = Math.min(min, val);
848+
}
849+
}
850+
}
851+
return [min, "auto"] as [number, string];
852+
}, [data, series]);
853+
841854
const yAxisProps = {
842855
tickFormatter: yAxisFormatter,
843-
domain: [0, "auto"] as [number, string],
856+
domain: yAxisDomain,
844857
};
845858

846859
const showLegend = series.length > 0;

apps/webapp/app/components/primitives/charts/ChartBar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export function ChartBarRenderer({
184184
)}
185185

186186
{/* Zoom selection area - rendered before bars to appear behind them */}
187-
{enableZoom && zoom?.refAreaLeft && zoom?.refAreaRight && (
187+
{enableZoom && zoom?.refAreaLeft !== null && zoom?.refAreaRight !== null && (
188188
<ReferenceArea
189189
x1={zoom.refAreaLeft}
190190
x2={zoom.refAreaRight}

0 commit comments

Comments
 (0)