| 96 | }>; |
| 97 | |
| 98 | const findExtrema = (data: ReadonlyArray<DataPoint>): Extrema => { |
| 99 | let maxIndex = 0; |
| 100 | let minIndex = 0; |
| 101 | let maxY = Number.NEGATIVE_INFINITY; |
| 102 | let minY = Number.POSITIVE_INFINITY; |
| 103 | |
| 104 | for (let i = 0; i < data.length; i++) { |
| 105 | const p = data[i]!; |
| 106 | const y = isTuplePoint(p) ? p[1] : p.y; |
| 107 | if (y > maxY) { |
| 108 | maxY = y; |
| 109 | maxIndex = i; |
| 110 | } |
| 111 | if (y < minY) { |
| 112 | minY = y; |
| 113 | minIndex = i; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | return { maxIndex, maxY, minIndex, minY }; |
| 118 | }; |
| 119 | |
| 120 | const createTimeSeries = (count: number): ReadonlyArray<DataPoint> => { |
| 121 | const n = Math.max(2, Math.floor(count)); |