( data: ReadonlyArray<DataPoint>, xMin: number, xMax: number )
| 791 | }; |
| 792 | |
| 793 | const findVisibleRangeIndicesByX = ( |
| 794 | data: ReadonlyArray<DataPoint>, |
| 795 | xMin: number, |
| 796 | xMax: number |
| 797 | ): { readonly start: number; readonly end: number } => { |
| 798 | const n = data.length; |
| 799 | if (n === 0) return { start: 0, end: 0 }; |
| 800 | if (!Number.isFinite(xMin) || !Number.isFinite(xMax)) return { start: 0, end: n }; |
| 801 | |
| 802 | const isTuple = isTupleDataArray(data); |
| 803 | const canBinarySearch = isMonotonicNonDecreasingFiniteX(data, isTuple); |
| 804 | if (!canBinarySearch) { |
| 805 | // Data is not monotonic by x; we can't represent the visible set as a contiguous index range. |
| 806 | // Fall back to processing the full series for correctness. |
| 807 | return { start: 0, end: n }; |
| 808 | } |
| 809 | |
| 810 | const start = isTuple |
| 811 | ? lowerBoundXTuple(data as ReadonlyArray<TuplePoint>, xMin) |
| 812 | : lowerBoundXObject(data as ReadonlyArray<ObjectPoint>, xMin); |
| 813 | const end = isTuple |
| 814 | ? upperBoundXTuple(data as ReadonlyArray<TuplePoint>, xMax) |
| 815 | : upperBoundXObject(data as ReadonlyArray<ObjectPoint>, xMax); |
| 816 | |
| 817 | const s = clampInt(start, 0, n); |
| 818 | const e = clampInt(end, 0, n); |
| 819 | return e <= s ? { start: s, end: s } : { start: s, end: e }; |
| 820 | }; |
| 821 | |
| 822 | function isTupleOHLCDataPoint(p: OHLCDataPoint): p is OHLCDataPointTuple { |
| 823 | return Array.isArray(p); |
no test coverage detected