{
cg.canvas.width = cg.canvas.height = 384;
const xs = [];
const ys = [];
for (let x = 0; x <= 1; x += 0.001) {
xs.push(x);
ys.push(0.5 + 0.25 * Math.sin(x * 2 * Math.PI));
}
const viewport = {
x: 0,
y: 0,
width: cg.canvas.width,
height: cg.canvas.height,
};
const coords = CandyGraph.createCartesianCoordinateSystem(
CandyGraph.createLinearScale([0, 1], [32, viewport.width - 16]),
CandyGraph.createLinearScale([0, 1], [32, viewport.height - 16])
);
const font = await CandyGraph.createDefaultFont(cg);
cg.clear([1, 1, 1, 1]);
cg.render(coords, viewport, [
CandyGraph.createLineStrip(cg, xs, ys, {
colors: [1, 0.5, 0.0, 1.0],
widths: 3,
}),
CandyGraph.createOrthoAxis(cg, coords, "x", font, {
labelSide: 1,
tickOffset: -2.5,
tickLength: 6,
tickStep: 0.2,
labelFormatter: (n) => n.toFixed(1),
}),
CandyGraph.createOrthoAxis(cg, coords, "y", font, {
tickOffset: 2.5,
tickLength: 6,
tickStep: 0.2,
labelFormatter: (n) => n.toFixed(1),
}),
]);
targetHTML.appendChild(cg.copyTo(viewport));
}