MCPcopy Index your code
hub / github.com/ChartGPU/ChartGPU / computeZoomAwareTarget

Function computeZoomAwareTarget

examples/sampling/main.ts:120–133  ·  view source on GitHub ↗
(baseThreshold: number, spanFrac: number)

Source from the content-addressed store, hash-verified

118const formatPercent = (n: number): string => `${n.toFixed(2)}%`;
119
120const computeZoomAwareTarget = (baseThreshold: number, spanFrac: number): number => {
121 // Mirrors createRenderCoordinator’s behavior:
122 // - baseline target is samplingThreshold at full span
123 // - zooming in increases target ~ 1/spanFrac
124 // - capped to avoid pathological allocations
125 const MIN_TARGET_POINTS = 2;
126 const MAX_TARGET_POINTS_ABS = 200_000;
127 const MAX_TARGET_MULTIPLIER = 32;
128 const spanFracSafe = Math.max(1e-3, Math.min(1, spanFrac));
129
130 const baseT = Number.isFinite(baseThreshold) ? Math.max(1, baseThreshold | 0) : 1;
131 const maxTarget = Math.min(MAX_TARGET_POINTS_ABS, Math.max(MIN_TARGET_POINTS, baseT * MAX_TARGET_MULTIPLIER));
132 return clampInt(Math.round(baseT / spanFracSafe), MIN_TARGET_POINTS, maxTarget);
133};
134
135const updateReadouts = (
136 rawPointCount: number,

Callers 1

updateReadoutsFunction · 0.70

Calls 1

clampIntFunction · 0.70

Tested by

no test coverage detected