tests pass
[dygraphs.git] / tests / callback.html
CommitLineData
54425b14 1<!DOCTYPE html>
b258a3da
DV
2<html>
3 <head>
10494b48 4 <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7; IE=EmulateIE9">
b258a3da
DV
5 <title>callbacks</title>
6 <!--[if IE]>
a2b2c3a1 7 <script type="text/javascript" src="../excanvas.js"></script>
b258a3da 8 <![endif]-->
d37dca40
DV
9 <script type="text/javascript" src="../strftime/strftime-min.js"></script>
10 <script type="text/javascript" src="../rgbcolor/rgbcolor.js"></script>
b258a3da
DV
11 <script type="text/javascript" src="../dygraph-canvas.js"></script>
12 <script type="text/javascript" src="../dygraph.js"></script>
13 <script type="text/javascript" src="data.js"></script>
3230c662
DV
14 <style type="text/css">
15 #div_g {
16 position: absolute;
17 left: 200px;
18 top: 100px;
19 }
20 #status {
21 position: absolute;
22 top: 400px;
23 }
24 </style>
b258a3da
DV
25 </head>
26 <body>
27 <p>Hover, click and zoom to test the callbacks:</p>
d16579a0 28 <div id="div_g" style="width:600px; height:300px;"></div>
b258a3da 29
599fb4ad
DV
30 <input type="button" value="Clear list" onclick="javascript:document.getElementById('status').innerHTML=''" />
31 <input type="checkbox" id="highlight" checked><label for="highlight"> Show 'highlight' events</label>
a4c6a67c 32 <input type="checkbox" id="unhighlight" checked><label for="unhighlight">Show 'unhighlight' events</label>
50360fd0
NK
33 <input type="checkbox" id="showLabels" checked
34 onclick='g.updateOptions({showLabelsOnHighlight: this.checked});'>
8bc236f9 35 <label for="showLabels"> Show Labels on highlight</label>
b258a3da
DV
36 <div id="status" style="width:100%; height:200px;"></div>
37
38 <script type="text/javascript">
39 s = document.getElementById("status");
3230c662 40 g = null;
2ddb1197 41 pts_info = function(e, x, pts, row) {
b258a3da
DV
42 var str = "(" + x + ") ";
43 for (var i = 0; i < pts.length; i++) {
44 var p = pts[i];
45 if (i) str += ", ";
3230c662 46 str += p.name + ": " + p.yval;
b258a3da 47 }
3230c662
DV
48
49 var x = e.offsetX;
50 var y = e.offsetY;
51 var dataXY = g.toDataCoords(x, y);
52 str += ", (" + x + ", " + y + ")";
53 str += " -> (" + dataXY[0] + ", " + dataXY[1] + ")";
2ddb1197 54 str += ", row #"+row;
3230c662 55
b258a3da
DV
56 return str;
57 };
58
59 g = new Dygraph(
d16579a0 60 document.getElementById("div_g"),
b258a3da
DV
61 NoisyData, {
62 rollPeriod: 7,
63 showRoller: true,
64 errorBars: true,
65
2ddb1197 66 highlightCallback: function(e, x, pts, row) {
599fb4ad 67 if (document.getElementById('highlight').checked) {
2ddb1197 68 s.innerHTML += "<b>Highlight</b> " + pts_info(e,x,pts,row) + "<br/>";
599fb4ad 69 }
b258a3da
DV
70 },
71
a4c6a67c
AV
72 unhighlightCallback: function(e) {
73 if (document.getElementById('unhighlight').checked) {
74 s.innerHTML += "<b>Unhighlight</b><br/>";
75 }
76 },
77
b258a3da 78 clickCallback: function(e, x, pts) {
3230c662 79 s.innerHTML += "<b>Click</b> " + pts_info(e,x,pts) + "<br/>";
b258a3da
DV
80 },
81
1e1bf7df
DV
82 pointClickCallback: function(e, p) {
83 s.innerHTML += "<b>Point Click</b> " + p.name + ": " + p.x + "<br/>";
84 },
85
8d4465c4
RK
86 zoomCallback: function(minX, maxX, yRanges) {
87 s.innerHTML += "<b>Zoom</b> [" + minX + ", " + maxX + ", [" + yRanges + "]]<br/>";
599fb4ad
DV
88 },
89
90 drawCallback: function(g) {
91 s.innerHTML += "<b>Draw</b> [" + g.xAxisRange() + "]<br/>";
b258a3da
DV
92 }
93 }
94 );
95 </script>
96 </body>
97</html>