X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;ds=sidebyside;f=gallery%2Fplotter.js;h=0ecaefa2d89adcdc9f19758d7fb88db02b3e8bc9;hb=debdb88d1ccca3648f45d6cc5d49896f3014cfdd;hp=dfbe4b2e12d885ed3e6c57b230487b3f65ec4488;hpb=3c10a0f3519355ee651d04bf2972bd31298eff18;p=dygraphs.git diff --git a/gallery/plotter.js b/gallery/plotter.js index dfbe4b2..0ecaefa 100644 --- a/gallery/plotter.js +++ b/gallery/plotter.js @@ -1,42 +1,41 @@ -// Use this as a template for new Gallery entries. Gallery.register( 'plotter', { name: 'Function Plotter', title: 'Define your data with functions', setup: function(parent) { - parent.innerHTML = - "
Equation:
\n" +
- "
\n" +
- "Preset functions: \n" +
- "
x range: \n" + - " to
\n" + - " \n" + - "\n" + - " "; + parent.innerHTML = [ + "Equation:
",
+ "
",
+ "Preset functions: ",
+ "
x range: ", + "to
", + "", + "", + ""].join("\n"); }, run: function() { var select = document.getElementById("presets"); + var presets = { + 'id': [ -10, 10, 'function(x) {\n return x;\n}' ], + 'sine': [ -10, 10, 'function(x) {\n return Math.sin(x);\n}' ], + 'taylor': [ -3, 3, 'function(x) {\n return [Math.cos(x), 1 - x*x/2 + x*x*x*x/24];\n}' ], + 'sawtooth': [-10, 10, 'function(x) {\n var y = 0;\n for (var i = 1; i < 20; i+=2) {\n y += Math.sin(i * x)/i;\n }\n var final = 1 - 2*(Math.abs(Math.floor(x / Math.PI)) % 2);\n return [4/Math.PI * y, final];\n}' ] + }; 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}' ], - 'taylor': [ -3, 3, 'function(x) {\n return [Math.cos(x), 1 - x*x/2 + x*x*x*x/24];\n}' ], - 'sawtooth': [-10, 10, 'function(x) {\n var y = 0;\n for (var i = 1; i < 20; i+=2) {\n y += Math.sin(i * x)/i;\n }\n var final = 1 - 2*(Math.abs(Math.floor(x / Math.PI)) % 2);\n return [4/Math.PI * y, final];\n}' ] - }; if (id == "custom") { return; } document.getElementById("x1").value = presets[id][0]; @@ -73,7 +72,7 @@ Gallery.register( g = new Dygraph(graph, data); } - plot.onclick = plot; + plotButton.onclick = plot; plot(); } });