TypeScript-Test/plot.ts

15 lines
562 B
TypeScript

import * as Plot from "npm:@observablehq/plot";
import { DOMParser, SVGElement } from "npm:linkedom";
export const document = new DOMParser().parseFromString(
`<!DOCTYPE html><html></html>`,
);
export const plot = (data) => {
return Plot.line(data, {x: "x", y: "y"}).plot({y: {grid: true}, document})
}
export const plotxy = (xmin, xmax, step, y) => {
const x = Array.from({length: (xmax - xmin)/step}, (_, i) => (i - xmin) * step)
const data = x.map(x => ({x, y: y(x)}))
return Plot.line(data, {x: "x", y: "y"}).plot({y: {grid: true}, document})
}