Skip to content

Commit b138709

Browse files
committed
Fix for when there are densely packed values
1 parent 7a81139 commit b138709

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -886,11 +886,26 @@ export const QueryResultsChart = memo(function QueryResultsChart({
886886
const xAxisAngle = timeGranularity === "hours" || timeGranularity === "seconds" ? -45 : 0;
887887
const xAxisHeight = xAxisAngle !== 0 ? 60 : undefined;
888888

889+
// Check if the data would produce duplicate labels at the current granularity.
890+
// Only use the custom tick renderer (with interval:0) when duplicates exist,
891+
// otherwise let Recharts handle label spacing to avoid collisions.
892+
const hasDuplicateLabels = useMemo(() => {
893+
if (!isDateBased || !timeGranularity || data.length === 0) return false;
894+
const labels = new Set<string>();
895+
for (const point of data) {
896+
const ts = point.__timestamp ?? point[xDataKey];
897+
if (typeof ts === "number") {
898+
labels.add(formatDateByGranularity(new Date(ts), timeGranularity));
899+
}
900+
}
901+
return labels.size < data.length;
902+
}, [isDateBased, timeGranularity, data, xDataKey]);
903+
889904
// Custom tick renderer for date-based axes: shows either a text label or
890905
// a small tick mark, but never both. This avoids duplicate labels while
891906
// still giving visual markers for unlabelled data points.
892907
const dateAxisTick = useMemo(() => {
893-
if (!isDateBased || !xAxisTickFormatter) return undefined;
908+
if (!isDateBased || !xAxisTickFormatter || !hasDuplicateLabels) return undefined;
894909
return (props: Record<string, unknown>) => {
895910
const { x, y, payload } = props as { x: number; y: number; payload: { value: number } };
896911
const label = xAxisTickFormatter(payload.value);
@@ -927,7 +942,7 @@ export const QueryResultsChart = memo(function QueryResultsChart({
927942
/>
928943
);
929944
};
930-
}, [isDateBased, xAxisTickFormatter, xAxisAngle]);
945+
}, [isDateBased, xAxisTickFormatter, xAxisAngle, hasDuplicateLabels]);
931946

932947
// Validation — all hooks must be above this point
933948
if (!xAxisColumn) {

0 commit comments

Comments
 (0)