Don't move graph when replotting

This commit is contained in:
Aleks Rutins 2025-02-26 21:44:15 -05:00 committed by GitHub
parent f2421426fc
commit fce4a30e99
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -29,18 +29,23 @@ function defineVars(vars) {
function plot(target, fns, deps, [xDomain, yDomain] = [[-1, 9], [-1, 9]]) {
const depsEl = deps.map(document.querySelector.bind(document));
const data = () => fns(...(depsEl.map(el => parseFloat(el.value)))).map(fn => ({
fn, graphType: 'polyline'
}));
const opts = {
target,
width: 600,
height: 400,
xAxis: { domain: xDomain },
yAxis: { domain: yDomain },
grid: true
};
const plot = () => {
functionPlot({
target,
width: 600,
height: 400,
xAxis: { domain: xDomain },
yAxis: { domain: yDomain },
grid: true,
data: fns(...(depsEl.map(el => parseFloat(el.value)))).map(fn => ({
fn, graphType: 'polyline'
}))
});
opts.data = data();
functionPlot(opts);
}
depsEl.forEach(el => {