From 1f4a3f858c5e2ddef6ba3e04205de3db22ab7f0a Mon Sep 17 00:00:00 2001 From: Viktor Barzin Date: Sun, 8 Feb 2026 17:46:33 +0000 Subject: [PATCH] Fix heatmap crash on small datasets by clamping percentile indices Math.round(values.length * 0.95) produces an out-of-bounds index when the dataset has fewer than ~20 features (e.g. after tight travel time filtering). values[outOfBounds] returns undefined, cascading to NaN color stops which crash Mapbox's expression evaluator. Clamp both min and max indices to values.length - 1. --- frontend/src/components/Map.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/Map.tsx b/frontend/src/components/Map.tsx index 739dcf5..c4f9e66 100644 --- a/frontend/src/components/Map.tsx +++ b/frontend/src/components/Map.tsx @@ -103,8 +103,8 @@ export function Map(props: MapProps) { .sort(function (a: number, b: number) { return a - b; }); if (values.length > 0) { - const minIndex = Math.round(values.length * PERCENTILE_CONFIG.MIN_BOUND); - const maxIndex = Math.round(values.length * PERCENTILE_CONFIG.MAX_BOUND); + const minIndex = Math.min(Math.round(values.length * PERCENTILE_CONFIG.MIN_BOUND), values.length - 1); + const maxIndex = Math.min(Math.round(values.length * PERCENTILE_CONFIG.MAX_BOUND), values.length - 1); const min = values[minIndex]; // Ensure max > min so color stops are strictly monotonic const max = Math.max(values[maxIndex], min + 1);