one more
[dygraphs.git] / tests / zoom.html
... / ...
CommitLineData
1<!DOCTYPE html>
2<html>
3 <head>
4 <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7; IE=EmulateIE9">
5 <title>zoom</title>
6 <!--[if IE]>
7 <script type="text/javascript" src="../excanvas.js"></script>
8 <![endif]-->
9 <!--
10 For production (minified) code, use:
11 <script type="text/javascript" src="dygraph-combined.js"></script>
12 -->
13 <script type="text/javascript" src="../dygraph-dev.js"></script>
14
15 <script type="text/javascript" src="data.js"></script>
16 </head>
17 <body>
18 <h3>Click the buttons to change the zoom level or just use the normal
19 click-and drag. While zoom typically works by click-and-drag, the
20 buttons are useful for testing.</h3>
21 <h4>Window coordinates (in dates and values):</h4>
22 <div id="xdimensions"></div> <div id="ydimensions"></div>
23 <div style="float: right">
24 <p>Zoomed: <span id="zoomed">False</span><p/>
25 <p>Zoomed X: <span id="zoomedX">False</span><p/>
26 <p>Zoomed Y: <span id="zoomedY">False</span><p/>
27 </div>
28 <div id="div_g" style="width:600px; height:300px;"></div>
29
30
31 <p><b>Zoom operations:</b></p>
32 <p>
33 <input type="button" value="Y (3,5)" onclick="zoomGraphY(3,5)">&nbsp;
34 <input type="button" value="Y (0,4)" onclick="zoomGraphY(0,4)">&nbsp;
35 <input type="button" value="Y (2,4)" onclick="zoomGraphY(2,4)">&nbsp;
36 <input type="button" value="Y (0,2)" onclick="zoomGraphY(0,2)">&nbsp;
37 <input type="button" value="Y (0,1)" onclick="zoomGraphY(0,1)">&nbsp;
38 <br> <br>
39 <input type="button" value="Oct 8-13" onclick="zoomGraphX(1160261979962, 1163905694248)">&nbsp;
40 <input type="button" value="Oct 22-28" onclick="zoomGraphX(1161489164461 , 1162008465957)">&nbsp;
41 <input type="button" value="Oct 23-24" onclick="zoomGraphX(1161575878860, 1161660991675)">&nbsp;
42 <input type="button" value="Oct 26 6AM-noon" onclick="zoomGraphX(1161770537840, 1161792063332)">&nbsp;
43 <br> <br>
44 <input type="button" value="Unzoom" onclick="unzoomGraph()">&nbsp;
45 <br> <br>
46 <input type="button" value="pan frame null" onclick="panEdgeFraction(null)">&nbsp;
47 <input type="button" value="pan frame 0.1" onclick="panEdgeFraction(0.1)">&nbsp;
48 <input type="button" value="pan frame 0.5" onclick="panEdgeFraction(0.5)">&nbsp;
49 </p>
50
51
52 <script type="text/javascript">
53 g = new Dygraph(
54 document.getElementById("div_g"),
55 NoisyData, {
56 errorBars: true,
57 zoomCallback : function(minDate, maxDate, yRange) {
58 showDimensions(minDate, maxDate, yRange);
59 },
60 drawCallback: function(me, initial) {
61 document.getElementById("zoomed").innerHTML = "" + me.isZoomed();
62 document.getElementById("zoomedX").innerHTML = "" + me.isZoomed("x");
63 document.getElementById("zoomedY").innerHTML = "" + me.isZoomed("y");
64 }
65 }
66 );
67
68 // TODO(konigsberg): Implement a visualization that verifies that initial
69 // displays also show correctly.
70
71 // Pull an initial value for logging.
72 var minDate = g.xAxisRange()[0];
73 var maxDate = g.xAxisRange()[1];
74 var minValue = g.yAxisRange()[0];
75 var maxValue = g.yAxisRange()[1];
76 showDimensions(minDate, maxDate, [minValue, maxValue]);
77
78 function showDimensions(minDate, maxDate, yRanges) {
79 showXDimensions(minDate, maxDate);
80 showYDimensions(yRanges);
81 }
82
83 function showXDimensions(first, second) {
84 var elem = document.getElementById("xdimensions");
85 elem.innerHTML = "dateWindow : [" + first + ", "+ second + "]";
86 }
87
88 function showYDimensions(ranges) {
89 var elem = document.getElementById("ydimensions");
90 elem.innerHTML = "valueRange : [" + ranges + "]";
91 }
92
93 function zoomGraphX(minDate, maxDate) {
94 g.updateOptions({
95 dateWindow: [minDate, maxDate]
96 });
97 showXDimensions(minDate, maxDate);
98 }
99
100 function zoomGraphY(minValue, maxValue) {
101 g.updateOptions({
102 valueRange: [minValue, maxValue]
103 });
104 showYDimensions(g.yAxisRanges());
105 }
106
107 function unzoomGraph() {
108 g.updateOptions({
109 dateWindow: null,
110 valueRange: null
111 });
112 }
113
114 function panEdgeFraction(value) {
115 g.updateOptions({ panEdgeFraction : value });
116 }
117 </script>
118
119 </body>
120</html>