scripts/build-dashboard-data.mjs 1// Maintain synthetic plot data only. Layout and animation are authored in Lay.2import {readFile, writeFile} from 'node:fs/promises';3 4const output = new URL('../examples/animation/dashboard-data.json', import.meta.url);5const rounded = value => Number(value.toFixed(5));6const xs = Array.from({length:192}, (_,j) => j * 10 / 191);7const scatterX = xs.filter((_,j) => j % 16 === 0);8const panels = Array.from({length:12}, (_,i) => {9 if (i % 3 === 2) return {z:Array.from({length:16}, (_,y) =>10 Array.from({length:16}, (_,x) => rounded(Math.sin(x*.3+i)*Math.cos(y*.25)+.3*Math.sin(x+y))))};11 return {12 series:Array.from({length:3}, (_,k) => xs.map(x =>13 rounded(Math.sin(x*(1+k*.31)+i*.28)*Math.exp(-x*.035)+.13*Math.cos(x*7+i+k)))),14 scatter_y:scatterX.map(x => rounded(Math.sin(x+i*.28)*Math.exp(-x*.035)))15 };16});17// Keep vectors on individual lines so the data tab has a readable structure.18const lines = ['{', ' "x":'+JSON.stringify(xs.map(rounded))+',',19 ' "scatter_x":'+JSON.stringify(scatterX.map(rounded))+',', ' "panels":['];20panels.forEach((panel,i) => {21 lines.push(' {');22 if (panel.z) lines.push(' "z":[',23 ...panel.z.map((row,j) => ' '+JSON.stringify(row)+(j<15?',':'')), ' ]');24 else lines.push(' "series":[',25 ...panel.series.map((row,j) => ' '+JSON.stringify(row)+(j<2?',':'')),26 ' ],', ' "scatter_y":'+JSON.stringify(panel.scatter_y));27 lines.push(' }'+(i<11?',':''));28});29lines.push(' ]', '}');30const content = lines.join('\n')+'\n';31if (process.argv.includes('--check')) {32 if (await readFile(output,'utf8') !== content) throw Error('Stale dashboard data; run scripts/build-dashboard-data.mjs');33} else await writeFile(output,content);34console.log(`${process.argv.includes('--check')?'Checked':'Wrote'} synthetic data for 8 signal plots and 4 heatmaps`);