4 name
: 'Link Interaction',
5 setup
: function(parent
) {
7 "<div id='div_g'></div>",
9 "<a href='#' id='hour'>hour</a> ",
10 "<a href='#' id='day'>day</a> ",
11 "<a href='#' id='week'>week</a> ",
12 "<a href='#' id='month'>month</a> ",
13 "<a href='#' id='full'>full</a> ",
15 "<a href='#' id='left'>left</a> ",
16 "<a href='#' id='right'>right</a> "].join("\n");
20 var base_time
= Date
.parse("2008/07/01");
21 var num
= 24 * 0.25 * 365;
22 for (var i
= 0; i
< num
; i
++) {
23 r
.push([ new Date(base_time
+ i
* 3600 * 1000),
24 i
+ 50 * (i
% 60), // line
25 i
* (num
- i
) * 4.0 / num // parabola
28 var orig_range
= [ r
[0][0].valueOf(), r
[r
.length
- 1][0].valueOf() ];
30 document
.getElementById("div_g"),
37 labels
: ["Date", "a", "b"]
41 var desired_range
= null;
42 function approach_range() {
43 if (!desired_range
) return;
45 var range
= g
.xAxisRange();
46 if (Math
.abs(desired_range
[0] - range
[0]) < 60 &&
47 Math
.abs(desired_range
[1] - range
[1]) < 60) {
48 g
.updateOptions({dateWindow
: desired_range
});
49 // (do not set another timeout.)
52 new_range
= [0.5 * (desired_range
[0] + range
[0]),
53 0.5 * (desired_range
[1] + range
[1])];
54 g
.updateOptions({dateWindow
: new_range
});
59 setTimeout(approach_range
, 50);
62 var zoom
= function(res
) {
63 var w
= g
.xAxisRange();
64 desired_range
= [ w
[0], w
[0] + res
* 1000 ];
68 var reset
= function() {
69 desired_range
= orig_range
;
73 var pan
= function(dir
) {
74 var w
= g
.xAxisRange();
75 var scale
= w
[1] - w
[0];
76 var amount
= scale
* 0.25 * dir
;
77 desired_range
= [ w
[0] + amount
, w
[1] + amount
];
81 document
.getElementById('hour').onclick
= function() { zoom(3600); };
82 document
.getElementById('day').onclick
= function() { zoom(86400); };
83 document
.getElementById('week').onclick
= function() { zoom(604800); };
84 document
.getElementById('month').onclick
= function() { zoom(30 * 86400); };
85 document
.getElementById('full').onclick
= function() { reset(); };
86 document
.getElementById('left').onclick
= function() { pan(-1); };
87 document
.getElementById('right').onclick
= function() { pan(+1); };