X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=gallery%2Fplotter.js;h=be39eb3dd1695843dfe000be4f69ac3d0df85056;hb=5c227b7e2a0544347eb27b2722c14179507af835;hp=7a60aba87c56560f6ca6c8cd11375152e222ac18;hpb=d0d1f76beeadb9f41d0194cf689ea93c4987a565;p=dygraphs.git diff --git a/gallery/plotter.js b/gallery/plotter.js index 7a60aba..be39eb3 100644 --- a/gallery/plotter.js +++ b/gallery/plotter.js @@ -5,31 +5,32 @@ Gallery.register( name: 'Function Plotter', title: 'Define your data with functions', setup: function(parent) { - parent.innerHTML = - "

Equation:
\n" + - "
\n" + - "Preset functions: \n" + - "

\n" + - "\n" + - "

x range: \n" + - " to

\n" + - "

\n" + - "\n" + - "
"; + parent.innerHTML = [ + "

Equation:
", + "
", + "Preset functions: ", + "

", + "", + "

x range: ", + "to

", + "

", + "", + "
"].join("\n"); }, run: function() { - window.preset = function() { - var sel = document.getElementById("presets").selectedIndex; - var id = document.getElementById("presets").options[sel].id; + var select = document.getElementById("presets"); + select.onchange = function() { + var sel = select.selectedIndex; + var id = select.options[sel].id; var presets = { 'id': [ -10, 10, 'function(x) {\n return x;\n}' ], 'sine': [ -10, 10, 'function(x) {\n return Math.sin(x);\n}' ], @@ -44,7 +45,8 @@ Gallery.register( plot(); } - window.plot = function() { + var plotButton = document.getElementById("plot"); + var plot = function() { var eq = document.getElementById("eq").value; eval("fn = " + eq); @@ -71,6 +73,7 @@ Gallery.register( g = new Dygraph(graph, data); } - window.plot(); + plot.onclick = plot; + plot(); } });