X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;ds=inline;f=gallery%2Flink-interaction.js;h=68177a358d5af794769620fb164965344b4a8119;hb=80be397c6428c0015c21f4a4ac96e222eb51f67e;hp=5d9b050fcf7aaf61d67f8dfbf357ad620639dc54;hpb=60bda09c058d85b1fad278ac4ce6df353e0a9275;p=dygraphs.git diff --git a/gallery/link-interaction.js b/gallery/link-interaction.js index 5d9b050..68177a3 100644 --- a/gallery/link-interaction.js +++ b/gallery/link-interaction.js @@ -1,20 +1,20 @@ -// Use this as a template for new Gallery entries. +/*global Gallery,Dygraph,data */ Gallery.register( 'link-interaction', { name: 'Link Interaction', setup: function(parent) { - parent.innerHTML = - "
" + - "Zoom:" + - "hour " + - "day " + - "week " + - "month " + - "full " + - "Pan: " + - "left " + - "right "; + parent.innerHTML = [ + "", + "Zoom:", + "hour ", + "day ", + "week ", + "month ", + "full ", + "Pan: ", + "left ", + "right "].join("\n"); }, run: function() { var r = [ ]; @@ -27,7 +27,7 @@ Gallery.register( ]); } var orig_range = [ r[0][0].valueOf(), r[r.length - 1][0].valueOf() ]; - g = new Dygraph( + var g = new Dygraph( document.getElementById("div_g"), r, { rollPeriod: 7, @@ -39,7 +39,7 @@ Gallery.register( } ); - var desired_range = null; + var desired_range = null, animate; function approach_range() { if (!desired_range) return; // go halfway there @@ -56,20 +56,20 @@ Gallery.register( animate(); } } - function animate() { + animate = function() { setTimeout(approach_range, 50); - } + }; var zoom = function(res) { var w = g.xAxisRange(); desired_range = [ w[0], w[0] + res * 1000 ]; animate(); - } + }; var reset = function() { desired_range = orig_range; animate(); - } + }; var pan = function(dir) { var w = g.xAxisRange(); @@ -77,7 +77,7 @@ Gallery.register( var amount = scale * 0.25 * dir; desired_range = [ w[0] + amount, w[1] + amount ]; animate(); - } + }; document.getElementById('hour').onclick = function() { zoom(3600); }; document.getElementById('day').onclick = function() { zoom(86400); }; @@ -87,4 +87,4 @@ Gallery.register( document.getElementById('left').onclick = function() { pan(-1); }; document.getElementById('right').onclick = function() { pan(+1); }; } - }); \ No newline at end of file + });