()
| 35 | }; |
| 36 | |
| 37 | async function main() { |
| 38 | const container = document.getElementById('chart'); |
| 39 | if (!container) { |
| 40 | throw new Error('Chart container not found'); |
| 41 | } |
| 42 | |
| 43 | const dataA = createSineWave(300, { phase: 0, amplitude: 1 }); |
| 44 | const dataB = createSineWave(300, { phase: Math.PI / 3, amplitude: 1 }); |
| 45 | const dataC = createSineWave(300, { phase: (2 * Math.PI) / 3, amplitude: 1 }); |
| 46 | const xMax = Math.PI * 2; |
| 47 | |
| 48 | const options: ChartGPUOptions = { |
| 49 | // Grid margins (CSS px): reserve space for axis labels and titles. |
| 50 | // left=70 for Y-axis labels, bottom=56 for X-axis labels+title, top/right for padding. |
| 51 | grid: { left: 70, right: 24, top: 24, bottom: 56 }, |
| 52 | |
| 53 | // Explicit axis min/max ensures stable, consistent rendering across demos. |
| 54 | // Axis titles (name) label what each dimension represents. |
| 55 | xAxis: { type: 'value', min: 0, max: xMax, name: 'Angle (rad)' }, |
| 56 | yAxis: { type: 'value', min: -1.1, max: 1.1, name: 'Amplitude' }, |
| 57 | |
| 58 | palette: ['#4a9eff', '#ff4ab0', '#40d17c'], |
| 59 | |
| 60 | // Animation smoothly transitions data updates. Set duration: 0 to disable. |
| 61 | // Useful when appending live data where animation would be distracting. |
| 62 | animation: { duration: 900, easing: 'cubicOut', delay: 0 }, |
| 63 | series: [ |
| 64 | { |
| 65 | type: 'line', |
| 66 | name: 'sin(x) (filled)', |
| 67 | data: dataA, |
| 68 | color: '#4a9eff', |
| 69 | // Story 2.4 acceptance: `type: "line"` with `areaStyle` should render |
| 70 | // the area fill behind the line stroke. |
| 71 | // areaStyle creates a "filled line" by drawing the area under the curve. |
| 72 | // Low opacity (0.2) keeps the fill subtle and prevents overlapping fills from obscuring each other. |
| 73 | areaStyle: { opacity: 0.2 }, |
| 74 | lineStyle: { width: 2, opacity: 1 }, |
| 75 | }, |
| 76 | { |
| 77 | type: 'line', |
| 78 | name: 'sin(x + π/3)', |
| 79 | data: dataB, |
| 80 | lineStyle: { width: 2, opacity: 1 }, |
| 81 | }, |
| 82 | { |
| 83 | type: 'line', |
| 84 | name: 'sin(x + 2π/3)', |
| 85 | data: dataC, |
| 86 | lineStyle: { width: 2, opacity: 1 }, |
| 87 | }, |
| 88 | ], |
| 89 | }; |
| 90 | |
| 91 | const chart = await ChartGPU.create(container, options); |
| 92 | |
| 93 | // Story 3.11 acceptance: verify ChartGPUInstance.on/off event API |
| 94 | // Simple event usage: chart.on('event', callback) for high-level interactions. |
no test coverage detected