works with century-scale data
[dygraphs.git] / tests / zoom.html
1 <html>
2 <head>
3 <title>zoom</title>
4 <!--[if IE]>
5 <script type="text/javascript" src="../excanvas.js"></script>
6 <![endif]-->
7 <script type="text/javascript" src="../strftime/strftime-min.js"></script>
8 <script type="text/javascript" src="../rgbcolor/rgbcolor.js"></script>
9 <script type="text/javascript" src="../dygraph-canvas.js"></script>
10 <script type="text/javascript" src="../dygraph.js"></script>
11 <script type="text/javascript" src="data.js"></script>
12 </head>
13 <body>
14 <h3>Click the buttons to change the zoom level or just use the normal
15 click-and drag. While zoom typically works by click-and-drag, the
16 buttons are useful for testing.</h3>
17 <h4>Window coordinates (in dates and values):</h4>
18 <div id="xdimensions"></div> <div id="ydimensions"></div>
19 <div id="div_g" style="width:600px; height:300px;"></div>
20
21 <p><b>Zoom operations:</b></p>
22 <p>
23 <input type="button" value="Y (3,5)" onclick="zoomGraphY(3,5)">&nbsp;
24 <input type="button" value="Y (0,4)" onclick="zoomGraphY(0,4)">&nbsp;
25 <input type="button" value="Y (2,4)" onclick="zoomGraphY(2,4)">&nbsp;
26 <input type="button" value="Y (0,2)" onclick="zoomGraphY(0,2)">&nbsp;
27 <input type="button" value="Y (0,1)" onclick="zoomGraphY(0,1)">&nbsp;
28 <br>
29 <input type="button" value="Oct 8-13" onclick="zoomGraphX(1160261979962, 1163905694248)">&nbsp;
30 <input type="button" value="Oct 22-28" onclick="zoomGraphX(1161489164461 , 1162008465957)">&nbsp;
31 <input type="button" value="Oct 23-24" onclick="zoomGraphX(1161575878860, 1161660991675)">&nbsp;
32 <input type="button" value="Oct 26 6AM-noon" onclick="zoomGraphX(1161770537840, 1161792063332)">&nbsp;
33 <br>
34 <input type="button" value="Unzoom" onclick="unzoomGraph()">&nbsp;
35 </p>
36
37
38 <script type="text/javascript">
39 g = new Dygraph(
40 document.getElementById("div_g"),
41 NoisyData, {
42 errorBars: true,
43 zoomCallback : function(minDate, maxDate, yRanges) {
44 showDimensions(minDate, maxDate, yRanges);
45 }
46 }
47 );
48
49 // TODO(konigsberg): Implement a visualization that verifies that initial
50 // displays also show correctly.
51
52 // Pull an initial value for logging.
53 var minDate = g.xAxisRange()[0];
54 var maxDate = g.xAxisRange()[1];
55 var minValue = g.yAxisRange()[0];
56 var maxValue = g.yAxisRange()[1];
57 showDimensions(minDate, maxDate, [minValue, maxValue]);
58
59 function showDimensions(minDate, maxDate, yRanges) {
60 showXDimensions(minDate, maxDate);
61 showYDimensions(yRanges);
62 }
63
64 function showXDimensions(first, second) {
65 var elem = document.getElementById("xdimensions");
66 elem.innerHTML = "dateWindow : [" + first + ", "+ second + "]";
67 }
68
69 function showYDimensions(ranges) {
70 var elem = document.getElementById("ydimensions");
71 elem.innerHTML = "valueRange : [" + ranges + "]";
72 }
73
74 function zoomGraphX(minDate, maxDate) {
75 g.updateOptions({
76 dateWindow: [minDate, maxDate]
77 });
78 showXDimensions(minDate, maxDate);
79 }
80
81 function zoomGraphY(minValue, maxValue) {
82 g.updateOptions({
83 valueRange: [minValue, maxValue]
84 });
85 showYDimensions(g.yAxisRanges());
86 }
87
88 function unzoomGraph() {
89 g.updateOptions({
90 dateWindow: null,
91 valueRange: null
92 });
93 }
94 </script>
95
96 </body>
97 </html>