X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;ds=sidebyside;f=gallery%2Flink-interaction.js;h=f95a34225319e81a0ec04a4589357775cbfcd47d;hb=0a31d41e94fae75808da6caa36e96fcdd40fd23f;hp=e1d6faaa0b60a3c1915db876e3a989be8808f6c5;hpb=d0c6a883771cf625d9d57f516dbc5f3121c2fc86;p=dygraphs.git diff --git a/gallery/link-interaction.js b/gallery/link-interaction.js index e1d6faa..f95a342 100644 --- a/gallery/link-interaction.js +++ b/gallery/link-interaction.js @@ -1,9 +1,12 @@ +/*global Gallery,Dygraph,data */ Gallery.register( 'link-interaction', { name: 'Link Interaction', setup: function(parent) { parent.innerHTML = [ + "
"].join("\n"); }, run: function() { var r = [ ]; @@ -26,7 +30,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, @@ -38,7 +42,7 @@ Gallery.register( } ); - var desired_range = null; + var desired_range = null, animate; function approach_range() { if (!desired_range) return; // go halfway there @@ -55,20 +59,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(); @@ -76,7 +80,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); };