| 20 | }; |
| 21 | |
| 22 | const createPoints = ( |
| 23 | count: number, |
| 24 | seed: number, |
| 25 | opts: Readonly<{ |
| 26 | xMin: number; |
| 27 | xMax: number; |
| 28 | yMin: number; |
| 29 | yMax: number; |
| 30 | includeSize?: boolean; |
| 31 | sizeMin?: number; |
| 32 | sizeMax?: number; |
| 33 | }> |
| 34 | ): ReadonlyArray<ScatterPointTuple> => { |
| 35 | const n = Math.max(0, Math.floor(count)); |
| 36 | const rng = mulberry32(seed); |
| 37 | const out: ScatterPointTuple[] = new Array(n); |
| 38 | |
| 39 | const xSpan = opts.xMax - opts.xMin; |
| 40 | const ySpan = opts.yMax - opts.yMin; |
| 41 | const sizeMin = opts.sizeMin ?? 1; |
| 42 | const sizeMax = opts.sizeMax ?? 8; |
| 43 | const sizeSpan = sizeMax - sizeMin; |
| 44 | |
| 45 | for (let i = 0; i < n; i++) { |
| 46 | const x = opts.xMin + rng() * xSpan; |
| 47 | const y = opts.yMin + rng() * ySpan; |
| 48 | |
| 49 | if (opts.includeSize) { |
| 50 | const size = sizeMin + rng() * sizeSpan; |
| 51 | out[i] = [x, y, size] as const; |
| 52 | } else { |
| 53 | out[i] = [x, y] as const; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | // Interaction utilities assume increasing-x order for efficient lookups. |
| 58 | out.sort((a, b) => a[0] - b[0]); |
| 59 | return out; |
| 60 | }; |
| 61 | |
| 62 | async function main() { |
| 63 | const container = document.getElementById('chart'); |