MCPcopy Index your code
hub / github.com/ChartGPU/ChartGPU / makeCartesianData

Function makeCartesianData

examples/data-update-animation/main.ts:50–77  ·  view source on GitHub ↗
(
  count: number,
  rng: () => number,
  params: Readonly<{ phase: number; amplitude: number; offset: number }>
)

Source from the content-addressed store, hash-verified

48];
49
50const makeCartesianData = (
51 count: number,
52 rng: () => number,
53 params: Readonly<{ phase: number; amplitude: number; offset: number }>
54): Readonly<{ bars: ReadonlyArray<DataPoint>; line: ReadonlyArray<DataPoint> }> => {
55 const n = Math.max(8, Math.floor(count));
56 const bars: DataPoint[] = new Array(n);
57 const line: DataPoint[] = new Array(n);
58
59 const twoPi = Math.PI * 2;
60 for (let i = 0; i < n; i++) {
61 const t = i / (n - 1);
62 const x = i;
63 const noise = (rng() - 0.5) * 0.18;
64
65 // Keep x stable (match-by-index); change y so update animation is obvious.
66 const yLine = params.offset + Math.sin(t * twoPi + params.phase) * params.amplitude + noise;
67 const yBar =
68 params.offset * 0.4 +
69 Math.cos(t * twoPi * 0.75 + params.phase * 0.6) * (params.amplitude * 0.9) +
70 (rng() - 0.5) * 0.35;
71
72 line[i] = [x, yLine] as const;
73 bars[i] = [x, yBar] as const;
74 }
75
76 return { bars, line };
77};
78
79const makePieData = (rng: () => number): ReadonlyArray<PieDataItem> => {
80 return pieSliceBase.map((s) => {

Callers 2

mainFunction · 0.85
updateChartsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected