Set this for drawCallback
[dygraphs.git] / tests / is-zoomed.html
1 <html>
2 <head>
3 <title>isZoomedIgnoresProgrammaticZoom Flag</title>
4 <!--
5 For production (minified) code, use:
6 <script type="text/javascript" src="dygraph-combined.js"></script>
7 -->
8 <script type="text/javascript" src="../dygraph-dev.js"></script>
9
10 <script type="text/javascript" src="data.js"></script>
11 </head>
12 <body>
13 <h1 id="zoom">Determining Zoom</h1>
14 <p>
15 It is possible to detect whether a chart has been zoomed in either axis by the use of the <code>isZoomed</code> function.
16 If called with no argument, it will report whether <em>either</em> axis has been zoomed.
17 Alternatively it can be called with an argument of either <code>'x'</code> or <code>'y'</code> and it will report the status of just that axis.
18 </p>
19
20 <p>Here's a simple example using <code>drawCallback</code> to display the various zoom states whenever the chart is zoomed:</p>
21
22 <div style="width:600px; text-align:center; font-weight: bold; font-size: 125%;">OUTPUT</div>
23 <div style="width: 750px">
24 <div style="float: right">
25 <p>Zoomed: <span id="zoomed">False</span><p/>
26 <p>Zoomed X: <span id="zoomedX">False</span><p/>
27 <p>Zoomed Y: <span id="zoomedY">False</span><p/>
28 </div>
29 <div class="codeoutput" style="float:left;">
30 <div id="zoomdiv"></div>
31 <script type="text/javascript">
32 var g = new Dygraph(
33
34 // containing div
35 document.getElementById("zoomdiv"),
36
37 // CSV or path to a CSV file.
38 "Date,Value\n" +
39 "2011-01-07,75\n" +
40 "2011-01-08,70\n" +
41 "2011-01-09,90\n" +
42 "2011-01-10,30\n" +
43 "2011-01-11,40\n" +
44 "2011-01-12,60\n" +
45 "2011-01-13,70\n" +
46 "2011-01-14,40\n",
47 {
48 drawCallback: function(me, initial) {
49 document.getElementById("zoomed").innerHTML = "" + me.isZoomed();
50 document.getElementById("zoomedX").innerHTML = "" + me.isZoomed("x");
51 document.getElementById("zoomedY").innerHTML = "" + me.isZoomed("y");
52 }
53 }
54 );
55 </script>
56 </div>
57 </div>
58
59 <p>
60 <div style="clear:both; width:600px; text-align:center; font-weight: bold; font-size: 125%;">HTML</div>
61
62 <pre>
63 new Dygraph(
64
65 // containing div
66 document.getElementById(&quot;zoomdiv&quot;),
67
68 // CSV or path to a CSV file.
69 &quot;Date,Temperature\n&quot; +
70 &quot;2011-01-07,75\n&quot; +
71 &quot;2011-01-08,70\n&quot; +
72 &quot;2011-01-09,90\n&quot; +
73 &quot;2011-01-10,30\n&quot; +
74 &quot;2011-01-11,40\n&quot; +
75 &quot;2011-01-12,60\n&quot; +
76 &quot;2011-01-13,70\n&quot; +
77 &quot;2011-01-14,40\n&quot;,
78 {
79 drawCallback: function(me, initial) {
80 document.getElementById(&quot;zoomed&quot;).innerHTML = &quot;&quot; + me.isZoomed();
81 document.getElementById(&quot;zoomedX&quot;).innerHTML = &quot;&quot; + me.isZoomed(&quot;x&quot;);
82 document.getElementById(&quot;zoomedY&quot;).innerHTML = &quot;&quot; + me.isZoomed(&quot;y&quot;);
83 }
84 }
85 );
86 </pre>
87 </p>
88
89 <p>The <a href="zoom.html">Tests for zoom operations</a> show a full example of this in action.</p>
90
91 <h3>Programmatic Zoom</h3>
92 <p>
93 When a chart is programmatically zoomed by updating either the <code>dateWindow</code>
94 or <code>valueRange</code> option, by default the zoomed flags are also updated correspondingly.
95 It is possible to prevent this by specifying the <code>isZoomedIgnoreProgrammaticZoom</code> in the same
96 call to the <code>updateOptions</code> method.
97 </p>
98 <p>
99 The <a href="tests/is-zoomed-ignore-programmatic-zoom.html">is-zoomed-ignore-programmatic-zoom</a> test shows this in operation.
100 </p>
101 </body>
102 </html>