Merge pull request #674 from danvk/module
[dygraphs.git] / tests / zoom.html
CommitLineData
54425b14 1<!DOCTYPE html>
8b83c6cc
RK
2<html>
3 <head>
937029df 4 <title>zoom</title>
7e5ddc94
DV
5 <!--
6 For production (minified) code, use:
7 <script type="text/javascript" src="dygraph-combined.js"></script>
8 -->
fbd6834a 9 <script type="text/javascript" src="../dist/dygraph.js"></script>
7e5ddc94 10
8b83c6cc
RK
11 <script type="text/javascript" src="data.js"></script>
12 </head>
13 <body>
437c0979 14 <h3>Click the buttons to change the zoom level or just use the normal
447254de 15 click-and drag. While zoom typically works by click-and-drag, the
c65f2303 16 buttons are useful for testing.</h3>
8b83c6cc 17 <h4>Window coordinates (in dates and values):</h4>
c65f2303 18 <div id="xdimensions"></div> <div id="ydimensions"></div>
45f2c689
NN
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>
8b83c6cc
RK
24 <div id="div_g" style="width:600px; height:300px;"></div>
25
45f2c689 26
8b83c6cc
RK
27 <p><b>Zoom operations:</b></p>
28 <p>
437c0979
RK
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;
937029df 33 <input type="button" value="Y (0,1)" onclick="zoomGraphY(0,1)">&nbsp;
4cac8c7a 34 <br> <br>
437c0979
RK
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;
4cac8c7a 39 <br> <br>
437c0979 40 <input type="button" value="Unzoom" onclick="unzoomGraph()">&nbsp;
4cac8c7a 41 <br> <br>
9ec21d0a 42 <input type="button" value="pan frame null" onclick="panEdgeFraction(null)">&nbsp;
965a030e
RK
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;
8b83c6cc
RK
45 </p>
46
47
48 <script type="text/javascript">
49 g = new Dygraph(
50 document.getElementById("div_g"),
51 NoisyData, {
a6cc9f3e 52 errorBars: true,
f0f2aef6
RK
53 zoomCallback : function(minDate, maxDate, yRange) {
54 showDimensions(minDate, maxDate, yRange);
45f2c689
NN
55 },
56 drawCallback: function(me, initial) {
57baab03
NN
57 document.getElementById("zoomed").innerHTML = "" + me.isZoomed();
58 document.getElementById("zoomedX").innerHTML = "" + me.isZoomed("x");
59 document.getElementById("zoomedY").innerHTML = "" + me.isZoomed("y");
45f2c689 60 }
8b83c6cc
RK
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];
dea5c743 72 showDimensions(minDate, maxDate, [minValue, maxValue]);
8b83c6cc 73
dea5c743 74 function showDimensions(minDate, maxDate, yRanges) {
90b15133 75 showXDimensions(minDate, maxDate);
885c13e4 76 showYDimensions(yRanges);
c65f2303
RK
77 }
78
79 function showXDimensions(first, second) {
80 var elem = document.getElementById("xdimensions");
81 elem.innerHTML = "dateWindow : [" + first + ", "+ second + "]";
82 }
83
5f3b823b 84 function showYDimensions(ranges) {
c65f2303 85 var elem = document.getElementById("ydimensions");
5f3b823b 86 elem.innerHTML = "valueRange : [" + ranges + "]";
8b83c6cc
RK
87 }
88
437c0979 89 function zoomGraphX(minDate, maxDate) {
c65f2303
RK
90 g.updateOptions({
91 dateWindow: [minDate, maxDate]
92 });
90b15133 93 showXDimensions(minDate, maxDate);
437c0979
RK
94 }
95
96 function zoomGraphY(minValue, maxValue) {
c65f2303
RK
97 g.updateOptions({
98 valueRange: [minValue, maxValue]
99 });
f99d913c 100 showYDimensions(g.yAxisRanges());
437c0979
RK
101 }
102
103 function unzoomGraph() {
c65f2303 104 g.updateOptions({
eeab5025
RK
105 dateWindow: null,
106 valueRange: null
c65f2303 107 });
8b83c6cc 108 }
4cac8c7a 109
965a030e
RK
110 function panEdgeFraction(value) {
111 g.updateOptions({ panEdgeFraction : value });
4cac8c7a 112 }
8b83c6cc
RK
113 </script>
114
115 </body>
116</html>