1 /*global Gallery,Dygraph,data */
5 name
: 'Link Interaction',
6 setup
: function(parent
) {
8 "<div class='link-interaction'>",
9 "<style>.link-interaction a:visited { color: blue; }</style>",
10 "<div id='div_g'></div>",
12 "<a href='#' id='hour'>hour</a> ",
13 "<a href='#' id='day'>day</a> ",
14 "<a href='#' id='week'>week</a> ",
15 "<a href='#' id='month'>month</a> ",
16 "<a href='#' id='full'>full</a> ",
18 "<a href='#' id='left'>left</a> ",
19 "<a href='#' id='right'>right</a> ",
24 var base_time
= Date
.parse("2008/07/01");
25 var num
= 24 * 0.25 * 365;
26 for (var i
= 0; i
< num
; i
++) {
27 r
.push([ new Date(base_time
+ i
* 3600 * 1000),
28 i
+ 50 * (i
% 60), // line
29 i
* (num
- i
) * 4.0 / num // parabola
32 var orig_range
= [ r
[0][0].valueOf(), r
[r
.length
- 1][0].valueOf() ];
34 document
.getElementById("div_g"),
41 labels
: ["Date", "a", "b"]
45 var desired_range
= null, animate
;
46 function approach_range() {
47 if (!desired_range
) return;
49 var range
= g
.xAxisRange();
50 if (Math
.abs(desired_range
[0] - range
[0]) < 60 &&
51 Math
.abs(desired_range
[1] - range
[1]) < 60) {
52 g
.updateOptions({dateWindow
: desired_range
});
53 // (do not set another timeout.)
56 new_range
= [0.5 * (desired_range
[0] + range
[0]),
57 0.5 * (desired_range
[1] + range
[1])];
58 g
.updateOptions({dateWindow
: new_range
});
62 animate
= function() {
63 setTimeout(approach_range
, 50);
66 var zoom
= function(res
) {
67 var w
= g
.xAxisRange();
68 desired_range
= [ w
[0], w
[0] + res
* 1000 ];
72 var reset
= function() {
73 desired_range
= orig_range
;
77 var pan
= function(dir
) {
78 var w
= g
.xAxisRange();
79 var scale
= w
[1] - w
[0];
80 var amount
= scale
* 0.25 * dir
;
81 desired_range
= [ w
[0] + amount
, w
[1] + amount
];
85 document
.getElementById('hour').onclick
= function() { zoom(3600); };
86 document
.getElementById('day').onclick
= function() { zoom(86400); };
87 document
.getElementById('week').onclick
= function() { zoom(604800); };
88 document
.getElementById('month').onclick
= function() { zoom(30 * 86400); };
89 document
.getElementById('full').onclick
= function() { reset(); };
90 document
.getElementById('left').onclick
= function() { pan(-1); };
91 document
.getElementById('right').onclick
= function() { pan(+1); };