X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;ds=inline;f=gallery%2Fplotter.js;h=0ecaefa2d89adcdc9f19758d7fb88db02b3e8bc9;hb=c9093b7b3b9cfd2471dff93b8df9cbe1e84a8448;hp=268ea884fe2d1ed27936ff54da48fee99e3ab0a2;hpb=605b6119bcc80db4ea100d66df3483425dcd32af;p=dygraphs.git
diff --git a/gallery/plotter.js b/gallery/plotter.js
index 268ea88..0ecaefa 100644
--- a/gallery/plotter.js
+++ b/gallery/plotter.js
@@ -1,4 +1,3 @@
-// Use this as a template for new Gallery entries.
Gallery.register(
'plotter',
{
@@ -11,32 +10,32 @@ Gallery.register(
" return [0.1 * x, 0.1 * x + Math.sin(x), 0.1*x + Math.cos(x)];",
"}
",
"Preset functions: ",
"
x range: ", - " to
", - " ", + "x range: ", + "to
", + "", "", - " "].join("\n"); + ""].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(); } });