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