(elements: OnionElement[], fit: boolean, W: number, H: number)
| 200 | } |
| 201 | |
| 202 | function pathBody(elements: OnionElement[], fit: boolean, W: number, H: number): string { |
| 203 | const all = elements.flatMap((e) => e.samples.flatMap((s) => [...s.q, s.c])); |
| 204 | const { k, cx, cy } = fit ? fitTransform(all, W, H) : { k: 1, cx: W / 2, cy: H / 2 }; |
| 205 | const M = (p: Pt): Pt => ({ x: (p.x - cx) * k + W / 2, y: (p.y - cy) * k + H / 2 }); |
| 206 | let out = ""; |
| 207 | for (const el of elements) { |
| 208 | const last = el.samples.length - 1; |
| 209 | const fOf = (i: number) => (last <= 0 ? 0 : i / last); |
| 210 | el.samples.forEach((s, i) => (out += ghost(s.q.map(M), M(s.c), s.color, s.opacity, fOf(i)))); |
| 211 | for (let i = 0; i < last; i++) |
| 212 | out += line(M(el.samples[i]!.c), M(el.samples[i + 1]!.c), timeColor(fOf(i)), 3.5, 0.85); |
| 213 | el.samples.forEach((s, i) => { |
| 214 | const c = M(s.c); |
| 215 | out += circle(c, 4, timeColor(fOf(i))); |
| 216 | out += text({ x: c.x + 10, y: c.y + (i % 2 === 0 ? -10 : 18) }, `${s.t}s`, timeColor(fOf(i))); |
| 217 | }); |
| 218 | } |
| 219 | return out; |
| 220 | } |
| 221 | |
| 222 | function stripBody(samples: OnionSample[], W: number, H: number): string { |
| 223 | if (samples.length === 0) return ""; |
no test coverage detected