plot = function (functions, xDomain = [0,1], yDomain = [0,1]) {
if (!Array.isArray(functions)) {
functions = [functions];
}
const resolution = 1000;
let u = 300;
const xDiff = xDomain[1] - xDomain[0];
const yDiff = yDomain[1] - yDomain[0];
const r = yDiff / xDiff;
let d = [];
functions.forEach((f, idx) => {
for (let i = 0; i < resolution; i++) {
const t = i / resolution;
const x = xDomain[0] + xDiff * t;
d.push({x, y: f(x), z: idx})
}
});
return LineChart(d, {
x: d => d.x,
y: d => d.y,
z: d => d.z,
xType: d3.scaleLinear,
yLabel: "y",
zFormat: d => d.y,
xDomain,
yDomain,
width,
height: u,
title: d => Math.round(d.y*100)/100,
color: "steelblue"
});
}