Skip to content

Commit 8a5f773

Browse files
committed
Chart x-axis fix for very limited data results
1 parent 97486b3 commit 8a5f773

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,16 @@ function transformDataForChart(
558558
// for the range size (target ~150 points) so we don't create overly dense charts
559559
const rangeMs = rawMaxTime - rawMinTime;
560560
const minRangeInterval = timeRange ? snapToNiceInterval(rangeMs / 150) : 0;
561-
const effectiveInterval = Math.max(dataInterval, minRangeInterval);
561+
// Also cap the interval so we get enough data points to visually represent
562+
// the full time range. Without this, limited data (e.g. 1 point) defaults
563+
// to a 1-day interval which can be far too coarse for shorter ranges,
564+
// producing too few bars/points and potentially buckets outside the domain.
565+
const maxRangeInterval =
566+
timeRange && rangeMs > 0 ? snapToNiceInterval(rangeMs / 8) : Infinity;
567+
const effectiveInterval = Math.min(
568+
Math.max(dataInterval, minRangeInterval),
569+
maxRangeInterval
570+
);
562571
data = fillTimeGaps(
563572
data,
564573
xDataKey,
@@ -632,7 +641,16 @@ function transformDataForChart(
632641
// for the range size (target ~150 points) so we don't create overly dense charts
633642
const rangeMs = rawMaxTime - rawMinTime;
634643
const minRangeInterval = timeRange ? snapToNiceInterval(rangeMs / 150) : 0;
635-
const effectiveInterval = Math.max(dataInterval, minRangeInterval);
644+
// Also cap the interval so we get enough data points to visually represent
645+
// the full time range. Without this, limited data (e.g. 1 point) defaults
646+
// to a 1-day interval which can be far too coarse for shorter ranges,
647+
// producing too few bars/points and potentially buckets outside the domain.
648+
const maxRangeInterval =
649+
timeRange && rangeMs > 0 ? snapToNiceInterval(rangeMs / 8) : Infinity;
650+
const effectiveInterval = Math.min(
651+
Math.max(dataInterval, minRangeInterval),
652+
maxRangeInterval
653+
);
636654
data = fillTimeGaps(
637655
data,
638656
xDataKey,

0 commit comments

Comments
 (0)