X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=gallery%2Flink-interaction.js;h=68177a358d5af794769620fb164965344b4a8119;hb=2d0fdf6eb18eafde50830b8109f42e20b82247b1;hp=aa7f738a65d491064d7f23f7c412147f6ad9e0f4;hpb=e2a5e39886ea3bec49f24f937bb2625899710328;p=dygraphs.git diff --git a/gallery/link-interaction.js b/gallery/link-interaction.js index aa7f738..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,27 +56,35 @@ Gallery.register( animate(); } } - function animate() { + animate = function() { setTimeout(approach_range, 50); - } + }; - window.zoom = function(res) { + var zoom = function(res) { var w = g.xAxisRange(); desired_range = [ w[0], w[0] + res * 1000 ]; animate(); - } + }; - window.reset= function() { + var reset = function() { desired_range = orig_range; animate(); - } + }; - window.pan = function(dir) { + var pan = function(dir) { var w = g.xAxisRange(); var scale = w[1] - w[0]; 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); }; + document.getElementById('week').onclick = function() { zoom(604800); }; + document.getElementById('month').onclick = function() { zoom(30 * 86400); }; + document.getElementById('full').onclick = function() { reset(); }; + document.getElementById('left').onclick = function() { pan(-1); }; + document.getElementById('right').onclick = function() { pan(+1); }; } - }); \ No newline at end of file + });