X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=gallery%2Fplotter.js;h=be39eb3dd1695843dfe000be4f69ac3d0df85056;hb=5c227b7e2a0544347eb27b2722c14179507af835;hp=14283c7351ac3ff21181c096ac6d1696b725f8fc;hpb=795b16307db2a673ba7aa3452f6f6b0e93baeb3a;p=dygraphs.git diff --git a/gallery/plotter.js b/gallery/plotter.js index 14283c7..be39eb3 100644 --- a/gallery/plotter.js +++ b/gallery/plotter.js @@ -2,34 +2,35 @@ Gallery.register( 'plotter', { - name: 'Plotter', - title: 'title', + 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,5 +73,7 @@ Gallery.register( g = new Dygraph(graph, data); } + plot.onclick = plot; + plot(); } });