all required events working
[dygraphs.git] / tests / annotation.html
CommitLineData
ce49c2fa
DV
1<html>
2 <head>
3 <title>demo</title>
4 <!--[if IE]>
5 <script type="text/javascript" src="excanvas.js"></script>
6 <![endif]-->
7 <script type="text/javascript" src="../strftime/strftime-min.js"></script>
8 <script type="text/javascript" src="../rgbcolor/rgbcolor.js"></script>
9 <script type="text/javascript" src="../dygraph-canvas.js"></script>
10 <script type="text/javascript" src="../dygraph.js"></script>
5c528fa2
DV
11 <style type="text/css">
12 .annotation {
13 background-color: #dddddd
14 }
15 </style>
ce49c2fa
DV
16 </head>
17 <body>
70aa9072
DV
18 <input type="button" value="Add Annotation" onclick="add()" />
19 <div id="events"> </div>
5c528fa2
DV
20 <div style="position:absolute; left:100px; top: 200px;" id="g"></div>
21 <div style="position:absolute; left:600px; top: 200px;" id="list"></div>
ce49c2fa
DV
22
23 <script type="text/javascript">
24 g = new DateGraph(
25 document.getElementById("g"),
26 function() {
27 var zp = function(x) { if (x < 10) return "0"+x; else return x; };
28 var r = "date,parabola,line,another line,sine wave\n";
29 for (var i=1; i<=31; i++) {
30 r += "200610" + zp(i);
31 r += "," + 10*(i*(31-i));
32 r += "," + 10*(8*i);
33 r += "," + 10*(250 - 8*i);
34 r += "," + 10*(125 + 125 * Math.sin(0.3*i));
35 r += "\n";
36 }
37 return r;
38 },
39 {
40 rollPeriod: 1,
5c528fa2 41 showRoller: true,
ce49c2fa 42 width: 480,
5c528fa2
DV
43 height: 320,
44 drawCallback: function(g) {
45 var ann = g.annotations();
46 var html = "";
47 for (var i = 0; i < ann.length; i++) {
48 html += "(" + ann[i].series + ", " + ann[i].x + "): " + ann[i].shortText + " -> " + ann[i].text + "<br/>";
49 }
50 document.getElementById("list").innerHTML = html;
51 },
ce49c2fa
DV
52 }
53 );
5c528fa2
DV
54
55 var last_ann = 0;
56 annotations = [];
57 for (var x = 10; x < 15; x += 2) {
58 annotations.push( {
59 series: 'sine wave',
60 x: "200610" + x,
61 shortText: x,
62 text: 'Stock Market Crash ' + x
63 } );
64 last_ann = x;
65 }
66 annotations.push( {
67 series: 'another line',
68 x: "20061013",
69 shortText: 'X',
70 text: 'Another one',
ab5e5c75
DV
71 cssClass: 'annotation',
72 clickHandler: function() {
73 document.getElementById("events").innerHTML += "special handler<br/>";
74 }
5c528fa2
DV
75 } );
76 g.setAnnotations(annotations);
77
78 function add() {
79 var x = last_ann + 2;
80 var annnotations = g.annotations();
81 annotations.push( {
82 series: 'line',
83 x: "200610" + x,
84 shortText: x,
85 text: 'Line ' + x
86 } );
87 last_ann = x;
88 g.setAnnotations(annotations);
89 }
ab5e5c75 90
70aa9072
DV
91 var eventDiv = document.getElementById("events");
92 function nameAnnotation(ann) {
93 return "(" + ann.series + ", " + ann.x + ")";
94 }
ab5e5c75
DV
95 g.updateOptions( {
96 annotationClickHandler: function(ann, point, dg, event) {
70aa9072
DV
97 eventDiv.innerHTML += "click: " + nameAnnotation(ann) + "<br/>";
98 },
99 annotationDblClickHandler: function(ann, point, dg, event) {
100 eventDiv.innerHTML += "dblclick: " + nameAnnotation(ann) + "<br/>";
101 },
102 annotationMouseOverHandler: function(ann, point, dg, event) {
103 eventDiv.innerHTML += "mouseenter: " + nameAnnotation(ann) + "<br/>";
104 },
105 annotationMouseOutHandler: function(ann, point, dg, event) {
106 eventDiv.innerHTML += "mouseout: " + nameAnnotation(ann) + "<br/>";
ab5e5c75
DV
107 }
108 });
ce49c2fa
DV
109 </script>
110</body>
111</html>