Skip to content

Commit 4e6ebd7

Browse files
committed
Fix for bar widths being wrong in small datasets
1 parent 19e41fa commit 4e6ebd7

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -807,24 +807,31 @@ export const QueryResultsChart = memo(function QueryResultsChart({
807807
const xAxisAngle = timeGranularity === "hours" || timeGranularity === "seconds" ? -45 : 0;
808808
const xAxisHeight = xAxisAngle !== 0 ? 60 : undefined;
809809

810-
// Build xAxisProps - different config for date-based (continuous) vs categorical axes
811-
const xAxisProps = isDateBased
810+
// Base x-axis props shared by all chart types
811+
const baseXAxisProps = {
812+
tickFormatter: xAxisTickFormatter,
813+
angle: xAxisAngle,
814+
textAnchor: xAxisAngle !== 0 ? ("end" as const) : ("middle" as const),
815+
height: xAxisHeight,
816+
};
817+
818+
// Line charts use continuous time scale for date-based data
819+
// This properly represents time gaps between data points
820+
const xAxisPropsForLine = isDateBased
812821
? {
813822
type: "number" as const,
814823
domain: timeDomain ?? (["auto", "auto"] as [string, string]),
815824
scale: "time" as const,
816825
// Explicitly specify tick positions so labels appear across the entire range
817826
ticks: timeTicks ?? undefined,
818-
tickFormatter: xAxisTickFormatter,
819-
angle: xAxisAngle,
820-
textAnchor: xAxisAngle !== 0 ? ("end" as const) : ("middle" as const),
821-
height: xAxisHeight,
827+
...baseXAxisProps,
822828
}
823-
: {
824-
angle: xAxisAngle,
825-
textAnchor: xAxisAngle !== 0 ? ("end" as const) : ("middle" as const),
826-
height: xAxisHeight,
827-
};
829+
: baseXAxisProps;
830+
831+
// Bar charts always use categorical axis positioning
832+
// This ensures bars are evenly distributed regardless of data point count
833+
// (prevents massive bars when there are only a few data points)
834+
const xAxisPropsForBar = baseXAxisProps;
828835

829836
const yAxisProps = {
830837
tickFormatter: yAxisFormatter,
@@ -846,7 +853,7 @@ export const QueryResultsChart = memo(function QueryResultsChart({
846853
minHeight="300px"
847854
>
848855
<Chart.Bar
849-
xAxisProps={xAxisProps}
856+
xAxisProps={xAxisPropsForBar}
850857
yAxisProps={yAxisProps}
851858
stackId={stacked ? "stack" : undefined}
852859
tooltipLabelFormatter={tooltipLabelFormatter}
@@ -868,7 +875,7 @@ export const QueryResultsChart = memo(function QueryResultsChart({
868875
minHeight="300px"
869876
>
870877
<Chart.Line
871-
xAxisProps={xAxisProps}
878+
xAxisProps={xAxisPropsForLine}
872879
yAxisProps={yAxisProps}
873880
stacked={stacked && series.length > 1}
874881
tooltipLabelFormatter={tooltipLabelFormatter}

0 commit comments

Comments
 (0)