diff --git a/assets/math.js b/assets/math.js index ff44f1e..c1c0c9e 100644 --- a/assets/math.js +++ b/assets/math.js @@ -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 => {