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

Function computeGlobalBounds

src/ChartGPU.ts:275–345  ·  view source on GitHub ↗
(
  series: ResolvedChartGPUOptions['series'],
  runtimeRawBoundsByIndex?: ReadonlyArray<Bounds | null> | null
)

Source from the content-addressed store, hash-verified

273};
274
275const computeGlobalBounds = (
276 series: ResolvedChartGPUOptions['series'],
277 runtimeRawBoundsByIndex?: ReadonlyArray<Bounds | null> | null
278): Bounds => {
279 let xMin = Number.POSITIVE_INFINITY;
280 let xMax = Number.NEGATIVE_INFINITY;
281 let yMin = Number.POSITIVE_INFINITY;
282 let yMax = Number.NEGATIVE_INFINITY;
283
284 for (let s = 0; s < series.length; s++) {
285 const seriesConfig = series[s]!;
286 // Pie series are non-cartesian; they don't participate in x/y bounds.
287 if (seriesConfig.type === 'pie') continue;
288
289 // Prefer the chart-owned runtime bounds (kept up to date by appendData()).
290 const runtimeBoundsCandidate = runtimeRawBoundsByIndex?.[s] ?? null;
291 if (runtimeBoundsCandidate) {
292 const b = runtimeBoundsCandidate;
293 if (
294 Number.isFinite(b.xMin) &&
295 Number.isFinite(b.xMax) &&
296 Number.isFinite(b.yMin) &&
297 Number.isFinite(b.yMax)
298 ) {
299 if (b.xMin < xMin) xMin = b.xMin;
300 if (b.xMax > xMax) xMax = b.xMax;
301 if (b.yMin < yMin) yMin = b.yMin;
302 if (b.yMax > yMax) yMax = b.yMax;
303 continue;
304 }
305 }
306
307 // Prefer resolver-provided bounds when available (avoids O(n) scans on initial setOption()).
308 // (Resolved series types include `rawBounds` for cartesian series; keep this defensive.)
309 const rawBoundsCandidate = (seriesConfig as unknown as { rawBounds?: Bounds | null }).rawBounds ?? null;
310 if (rawBoundsCandidate) {
311 const b = rawBoundsCandidate;
312 if (
313 Number.isFinite(b.xMin) &&
314 Number.isFinite(b.xMax) &&
315 Number.isFinite(b.yMin) &&
316 Number.isFinite(b.yMax)
317 ) {
318 if (b.xMin < xMin) xMin = b.xMin;
319 if (b.xMax > xMax) xMax = b.xMax;
320 if (b.yMin < yMin) yMin = b.yMin;
321 if (b.yMax > yMax) yMax = b.yMax;
322 continue;
323 }
324 }
325
326 const data = seriesConfig.data as ReadonlyArray<DataPoint>;
327 for (let i = 0; i < data.length; i++) {
328 const { x, y } = getPointXY(data[i]!);
329 if (!Number.isFinite(x) || !Number.isFinite(y)) continue;
330 if (x < xMin) xMin = x;
331 if (x > xMax) xMax = x;
332 if (y < yMin) yMin = y;

Callers 3

createChartGPUFunction · 0.70
setOptionFunction · 0.70
appendDataFunction · 0.70

Calls 1

getPointXYFunction · 0.70

Tested by

no test coverage detected