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