Commit | Line | Data |
---|---|---|
b258a3da DV |
1 | <html> |
2 | <head> | |
3 | <title>callbacks</title> | |
4 | <!--[if IE]> | |
5 | <script type="text/javascript" src="excanvas.js"></script> | |
6 | <![endif]--> | |
7 | <script type="text/javascript" src="../dygraph-combined.js"></script> | |
8 | <script type="text/javascript" src="../dygraph-canvas.js"></script> | |
9 | <script type="text/javascript" src="../dygraph.js"></script> | |
10 | <script type="text/javascript" src="data.js"></script> | |
3230c662 DV |
11 | <style type="text/css"> |
12 | #div_g { | |
13 | position: absolute; | |
14 | left: 200px; | |
15 | top: 100px; | |
16 | } | |
17 | #status { | |
18 | position: absolute; | |
19 | top: 400px; | |
20 | } | |
21 | </style> | |
b258a3da DV |
22 | </head> |
23 | <body> | |
24 | <p>Hover, click and zoom to test the callbacks:</p> | |
d16579a0 | 25 | <div id="div_g" style="width:600px; height:300px;"></div> |
b258a3da | 26 | |
599fb4ad DV |
27 | <input type="button" value="Clear list" onclick="javascript:document.getElementById('status').innerHTML=''" /> |
28 | <input type="checkbox" id="highlight" checked><label for="highlight"> Show 'highlight' events</label> | |
b258a3da DV |
29 | <div id="status" style="width:100%; height:200px;"></div> |
30 | ||
31 | <script type="text/javascript"> | |
32 | s = document.getElementById("status"); | |
3230c662 DV |
33 | g = null; |
34 | pts_info = function(e, x, pts) { | |
b258a3da DV |
35 | var str = "(" + x + ") "; |
36 | for (var i = 0; i < pts.length; i++) { | |
37 | var p = pts[i]; | |
38 | if (i) str += ", "; | |
3230c662 | 39 | str += p.name + ": " + p.yval; |
b258a3da | 40 | } |
3230c662 DV |
41 | |
42 | var x = e.offsetX; | |
43 | var y = e.offsetY; | |
44 | var dataXY = g.toDataCoords(x, y); | |
45 | str += ", (" + x + ", " + y + ")"; | |
46 | str += " -> (" + dataXY[0] + ", " + dataXY[1] + ")"; | |
47 | ||
b258a3da DV |
48 | return str; |
49 | }; | |
50 | ||
51 | g = new Dygraph( | |
d16579a0 | 52 | document.getElementById("div_g"), |
b258a3da DV |
53 | NoisyData, { |
54 | rollPeriod: 7, | |
55 | showRoller: true, | |
56 | errorBars: true, | |
57 | ||
58 | highlightCallback: function(e, x, pts) { | |
599fb4ad | 59 | if (document.getElementById('highlight').checked) { |
3230c662 | 60 | s.innerHTML += "<b>Highlight</b> " + pts_info(e,x,pts) + "<br/>"; |
599fb4ad | 61 | } |
b258a3da DV |
62 | }, |
63 | ||
64 | clickCallback: function(e, x, pts) { | |
3230c662 | 65 | s.innerHTML += "<b>Click</b> " + pts_info(e,x,pts) + "<br/>"; |
b258a3da DV |
66 | }, |
67 | ||
68 | zoomCallback: function(minX, maxX) { | |
69 | s.innerHTML += "<b>Zoom</b> [" + minX + ", " + maxX + "]<br/>"; | |
599fb4ad DV |
70 | }, |
71 | ||
72 | drawCallback: function(g) { | |
73 | s.innerHTML += "<b>Draw</b> [" + g.xAxisRange() + "]<br/>"; | |
b258a3da DV |
74 | } |
75 | } | |
76 | ); | |
77 | </script> | |
78 | </body> | |
79 | </html> |