Skip to content

Commit 491a789

Browse files
committed
fix(webapp): apply width-aware x-axis thinning to categorical bar charts
The useMeasure ref was attached only to the line/area return path, so bar charts measured a width of 0 and never produced evenly-spaced x-axis ticks (and, because the categorical axis sets an angle, Chart.Bar's own useXAxisTicks was disabled too) — falling back to Recharts' default label spacing. Wrap the bar return in the same measuring div so categorical bar charts get the intended even-spaced label thinning.
1 parent d1cdcd1 commit 491a789

1 file changed

Lines changed: 38 additions & 36 deletions

File tree

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

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,40 @@ export const QueryResultsChart = memo(function QueryResultsChart({
11871187

11881188
if (chartType === "bar") {
11891189
return (
1190+
<div ref={chartMeasureRef} className="h-full w-full">
1191+
<Chart.Root
1192+
config={chartConfig}
1193+
data={data}
1194+
dataKey={xDataKey}
1195+
series={sortedSeries}
1196+
visibleSeries={visibleSeries}
1197+
labelFormatter={legendLabelFormatter}
1198+
showLegend={showLegend}
1199+
maxLegendItems={fullLegend ? Infinity : 5}
1200+
legendAggregation={config.aggregation}
1201+
legendValueFormatter={tooltipValueFormatter}
1202+
minHeight="300px"
1203+
fillContainer
1204+
onViewAllLegendItems={onViewAllLegendItems}
1205+
legendScrollable={legendScrollable}
1206+
state={isLoading ? "loading" : "loaded"}
1207+
beforeLegend={seriesLimitCallout}
1208+
>
1209+
<Chart.Bar
1210+
xAxisProps={xAxisPropsForBar}
1211+
yAxisProps={yAxisProps}
1212+
stackId={stacked ? "stack" : undefined}
1213+
tooltipLabelFormatter={tooltipLabelFormatter}
1214+
tooltipValueFormatter={tooltipValueFormatter}
1215+
/>
1216+
</Chart.Root>
1217+
</div>
1218+
);
1219+
}
1220+
1221+
// Line or stacked area chart
1222+
return (
1223+
<div ref={chartMeasureRef} className="h-full w-full">
11901224
<Chart.Root
11911225
config={chartConfig}
11921226
data={data}
@@ -1205,47 +1239,15 @@ export const QueryResultsChart = memo(function QueryResultsChart({
12051239
state={isLoading ? "loading" : "loaded"}
12061240
beforeLegend={seriesLimitCallout}
12071241
>
1208-
<Chart.Bar
1209-
xAxisProps={xAxisPropsForBar}
1242+
<Chart.Line
1243+
xAxisProps={xAxisPropsForLine}
12101244
yAxisProps={yAxisProps}
1211-
stackId={stacked ? "stack" : undefined}
1245+
stacked={stacked && visibleSeries.length > 1}
12121246
tooltipLabelFormatter={tooltipLabelFormatter}
12131247
tooltipValueFormatter={tooltipValueFormatter}
1248+
lineType="linear"
12141249
/>
12151250
</Chart.Root>
1216-
);
1217-
}
1218-
1219-
// Line or stacked area chart
1220-
return (
1221-
<div ref={chartMeasureRef} className="h-full w-full">
1222-
<Chart.Root
1223-
config={chartConfig}
1224-
data={data}
1225-
dataKey={xDataKey}
1226-
series={sortedSeries}
1227-
visibleSeries={visibleSeries}
1228-
labelFormatter={legendLabelFormatter}
1229-
showLegend={showLegend}
1230-
maxLegendItems={fullLegend ? Infinity : 5}
1231-
legendAggregation={config.aggregation}
1232-
legendValueFormatter={tooltipValueFormatter}
1233-
minHeight="300px"
1234-
fillContainer
1235-
onViewAllLegendItems={onViewAllLegendItems}
1236-
legendScrollable={legendScrollable}
1237-
state={isLoading ? "loading" : "loaded"}
1238-
beforeLegend={seriesLimitCallout}
1239-
>
1240-
<Chart.Line
1241-
xAxisProps={xAxisPropsForLine}
1242-
yAxisProps={yAxisProps}
1243-
stacked={stacked && visibleSeries.length > 1}
1244-
tooltipLabelFormatter={tooltipLabelFormatter}
1245-
tooltipValueFormatter={tooltipValueFormatter}
1246-
lineType="linear"
1247-
/>
1248-
</Chart.Root>
12491251
</div>
12501252
);
12511253
});

0 commit comments

Comments
 (0)