Merge pull request #522 from danvk/callback-tweaks
[dygraphs.git] / tests / zoom.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>zoom</title>
5 <!--
6 For production (minified) code, use:
7 <script type="text/javascript" src="dygraph-combined.js"></script>
8 -->
9 <script type="text/javascript" src="../dygraph-dev.js"></script>
10
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 style="float: right">
20 <p>Zoomed: <span id="zoomed">False</span><p/>
21 <p>Zoomed X: <span id="zoomedX">False</span><p/>
22 <p>Zoomed Y: <span id="zoomedY">False</span><p/>
23 </div>
24 <div id="div_g" style="width:600px; height:300px;"></div>
25
26
27 <p><b>Zoom operations:</b></p>
28 <p>
29 <input type="button" value="Y (3,5)" onclick="zoomGraphY(3,5)">&nbsp;
30 <input type="button" value="Y (0,4)" onclick="zoomGraphY(0,4)">&nbsp;
31 <input type="button" value="Y (2,4)" onclick="zoomGraphY(2,4)">&nbsp;
32 <input type="button" value="Y (0,2)" onclick="zoomGraphY(0,2)">&nbsp;
33 <input type="button" value="Y (0,1)" onclick="zoomGraphY(0,1)">&nbsp;
34 <br> <br>
35 <input type="button" value="Oct 8-13" onclick="zoomGraphX(1160261979962, 1163905694248)">&nbsp;
36 <input type="button" value="Oct 22-28" onclick="zoomGraphX(1161489164461 , 1162008465957)">&nbsp;
37 <input type="button" value="Oct 23-24" onclick="zoomGraphX(1161575878860, 1161660991675)">&nbsp;
38 <input type="button" value="Oct 26 6AM-noon" onclick="zoomGraphX(1161770537840, 1161792063332)">&nbsp;
39 <br> <br>
40 <input type="button" value="Unzoom" onclick="unzoomGraph()">&nbsp;
41 <br> <br>
42 <input type="button" value="pan frame null" onclick="panEdgeFraction(null)">&nbsp;
43 <input type="button" value="pan frame 0.1" onclick="panEdgeFraction(0.1)">&nbsp;
44 <input type="button" value="pan frame 0.5" onclick="panEdgeFraction(0.5)">&nbsp;
45 </p>
46
47
48 <script type="text/javascript">
49 g = new Dygraph(
50 document.getElementById("div_g"),
51 NoisyData, {
52 errorBars: true,
53 zoomCallback : function(minDate, maxDate, yRange) {
54 showDimensions(minDate, maxDate, yRange);
55 },
56 drawCallback: function(me, initial) {
57 document.getElementById("zoomed").innerHTML = "" + me.isZoomed();
58 document.getElementById("zoomedX").innerHTML = "" + me.isZoomed("x");
59 document.getElementById("zoomedY").innerHTML = "" + me.isZoomed("y");
60 }
61 }
62 );
63
64 // TODO(konigsberg): Implement a visualization that verifies that initial
65 // displays also show correctly.
66
67 // Pull an initial value for logging.
68 var minDate = g.xAxisRange()[0];
69 var maxDate = g.xAxisRange()[1];
70 var minValue = g.yAxisRange()[0];
71 var maxValue = g.yAxisRange()[1];
72 showDimensions(minDate, maxDate, [minValue, maxValue]);
73
74 function showDimensions(minDate, maxDate, yRanges) {
75 showXDimensions(minDate, maxDate);
76 showYDimensions(yRanges);
77 }
78
79 function showXDimensions(first, second) {
80 var elem = document.getElementById("xdimensions");
81 elem.innerHTML = "dateWindow : [" + first + ", "+ second + "]";
82 }
83
84 function showYDimensions(ranges) {
85 var elem = document.getElementById("ydimensions");
86 elem.innerHTML = "valueRange : [" + ranges + "]";
87 }
88
89 function zoomGraphX(minDate, maxDate) {
90 g.updateOptions({
91 dateWindow: [minDate, maxDate]
92 });
93 showXDimensions(minDate, maxDate);
94 }
95
96 function zoomGraphY(minValue, maxValue) {
97 g.updateOptions({
98 valueRange: [minValue, maxValue]
99 });
100 showYDimensions(g.yAxisRanges());
101 }
102
103 function unzoomGraph() {
104 g.updateOptions({
105 dateWindow: null,
106 valueRange: null
107 });
108 }
109
110 function panEdgeFraction(value) {
111 g.updateOptions({ panEdgeFraction : value });
112 }
113 </script>
114
115 </body>
116 </html>