(data: ReadonlyArray<OHLCDataPoint>)
| 26 | const categoryStepCache = new WeakMap<ReadonlyArray<OHLCDataPoint>, number>(); |
| 27 | |
| 28 | const 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. |
no test coverage detected