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