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

Function computeCategoryStep

src/interaction/findCandlestick.ts:28–49  ·  view source on GitHub ↗
(data: ReadonlyArray<OHLCDataPoint>)

Source from the content-addressed store, hash-verified

26const categoryStepCache = new WeakMap<ReadonlyArray<OHLCDataPoint>, number>();
27
28const computeCategoryStep = (data: ReadonlyArray<OHLCDataPoint>): number => {
29 const cached = categoryStepCache.get(data);
30 if (cached !== undefined) return cached;
31
32 const timestamps: number[] = [];
33 for (let i = 0; i < data.length; i++) {
34 const t = getTimestamp(data[i]);
35 if (Number.isFinite(t)) timestamps.push(t);
36 }
37
38 if (timestamps.length < 2) return 1;
39 timestamps.sort((a, b) => a - b);
40
41 let minStep = Number.POSITIVE_INFINITY;
42 for (let i = 1; i < timestamps.length; i++) {
43 const d = timestamps[i] - timestamps[i - 1];
44 if (d > 0 && d < minStep) minStep = d;
45 }
46 const step = Number.isFinite(minStep) && minStep > 0 ? minStep : 1;
47 categoryStepCache.set(data, step);
48 return step;
49};
50
51/**
52 * Computes the candlestick body width in xScale **range-space** units.

Callers 1

Calls 1

getTimestampFunction · 0.70

Tested by

no test coverage detected