MCPcopy Create free account
hub / github.com/ChartGPU/ChartGPU / computeCategoryStep

Function computeCategoryStep

src/renderers/createCandlestickRenderer.ts:125–141  ·  view source on GitHub ↗
(data: ReadonlyArray<OHLCDataPoint>)

Source from the content-addressed store, hash-verified

123};
124
125const computeCategoryStep = (data: ReadonlyArray<OHLCDataPoint>): number => {
126 const timestamps: number[] = [];
127 for (let i = 0; i < data.length; i++) {
128 const { timestamp } = getOHLC(data[i]);
129 if (Number.isFinite(timestamp)) timestamps.push(timestamp);
130 }
131
132 if (timestamps.length < 2) return 1;
133 timestamps.sort((a, b) => a - b);
134
135 let minStep = Number.POSITIVE_INFINITY;
136 for (let i = 1; i < timestamps.length; i++) {
137 const d = timestamps[i] - timestamps[i - 1];
138 if (d > 0 && d < minStep) minStep = d;
139 }
140 return Number.isFinite(minStep) && minStep > 0 ? minStep : 1;
141};
142
143const computeCategoryWidthClip = (
144 xScale: LinearScale,

Callers 1

prepareFunction · 0.70

Calls 1

getOHLCFunction · 0.85

Tested by

no test coverage detected