Skip to content

Commit 1a0801c

Browse files
committed
fix: range-aware downsampling for zoom support
When zoomed in, filter data to visible range first, then apply LTTB downsampling. This ensures full detail is visible when zoomed in to a specific range (e.g., 100-200 out of 100000 points).
1 parent adb5e28 commit 1a0801c

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

src/components/ChartContainer.jsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ export default function ChartContainer({
277277
const MAX_DISPLAY_POINTS = 3000;
278278

279279
const colors = useMemo(() => ['#ef4444', '#3b82f6', '#10b981', '#f59e0b', '#8b5cf6', '#f97316'], []);
280+
281+
// Create chart data with range-aware downsampling
282+
// When zoomed in, we show more detail within the visible range
280283
const createChartData = useCallback((dataArray) => {
281284
// Ensure no duplicate datasets
282285
const uniqueItems = dataArray.reduce((acc, item) => {
@@ -290,13 +293,27 @@ export default function ChartContainer({
290293
return {
291294
datasets: uniqueItems.map((item, index) => {
292295
const color = colors[index % colors.length];
293-
// Apply LTTB downsampling for display - preserves trends while reducing memory
294-
const displayData = adaptiveDownsample(item.data, MAX_DISPLAY_POINTS);
296+
297+
// Filter data to visible range first, then downsample
298+
let visibleData = item.data;
299+
if (xRange.min !== undefined || xRange.max !== undefined) {
300+
visibleData = item.data.filter(p => {
301+
const inMin = xRange.min === undefined || p.x >= xRange.min;
302+
const inMax = xRange.max === undefined || p.x <= xRange.max;
303+
return inMin && inMax;
304+
});
305+
}
306+
307+
// Apply LTTB downsampling only to visible data
308+
// This means when zoomed in, you see more detail
309+
const displayData = adaptiveDownsample(visibleData, MAX_DISPLAY_POINTS);
310+
295311
return {
296312
label: item.name?.replace(/\.(log|txt)$/i, '') || `File ${index + 1}`,
297313
data: displayData,
298314
// Store original data length for reference
299315
_originalLength: item.data.length,
316+
_visibleLength: visibleData.length,
300317
borderColor: color,
301318
backgroundColor: `${color}33`,
302319
borderWidth: 2,
@@ -315,7 +332,7 @@ export default function ChartContainer({
315332
};
316333
})
317334
};
318-
}, [colors]);
335+
}, [colors, xRange]);
319336

320337
const getComparisonData = (data1, data2, mode) => {
321338
const map2 = new Map(data2.map(p => [p.x, p.y]));

0 commit comments

Comments
 (0)