update IE documentation on home page
[dygraphs.git] / tests / annotation.html
CommitLineData
54425b14 1<!DOCTYPE html>
ce49c2fa
DV
2<html>
3 <head>
10494b48 4 <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7; IE=EmulateIE9">
ce49c2fa
DV
5 <title>demo</title>
6 <!--[if IE]>
a2b2c3a1 7 <script type="text/javascript" src="../excanvas.js"></script>
ce49c2fa 8 <![endif]-->
ec7ce8a2
DV
9 <!--
10 <script type="text/javascript" src="dygraph-combined.js"></script>
11 -->
ce49c2fa
DV
12 <script type="text/javascript" src="../strftime/strftime-min.js"></script>
13 <script type="text/javascript" src="../rgbcolor/rgbcolor.js"></script>
14 <script type="text/javascript" src="../dygraph-canvas.js"></script>
15 <script type="text/javascript" src="../dygraph.js"></script>
5c528fa2
DV
16 <style type="text/css">
17 .annotation {
5c528fa2
DV
18 }
19 </style>
ce49c2fa
DV
20 </head>
21 <body>
d14b9eed
DV
22 <h3>Annotations Demo</h3>
23 <p>Click any point to add an annotation to it or click "Add Annotation".</p>
70aa9072 24 <input type="button" value="Add Annotation" onclick="add()" />
d14b9eed 25 <input type="button" value="Shove to bottom" onclick="bottom(this)" />
70aa9072 26 <div id="events"> </div>
3bf2fa91 27 <div style="position:absolute; left:200px; top: 200px;" id="g_div"></div>
e6d53148 28 <div style="position:absolute; left:700px; top: 200px;" id="list"></div>
ce49c2fa
DV
29
30 <script type="text/javascript">
e6d53148
DV
31 var eventDiv = document.getElementById("events");
32 function nameAnnotation(ann) {
33 return "(" + ann.series + ", " + ann.x + ")";
34 }
35
33030f33 36 g = new Dygraph(
3bf2fa91 37 document.getElementById("g_div"),
ce49c2fa
DV
38 function() {
39 var zp = function(x) { if (x < 10) return "0"+x; else return x; };
40 var r = "date,parabola,line,another line,sine wave\n";
41 for (var i=1; i<=31; i++) {
e6d53148
DV
42 r += "200610" + zp(i);
43 r += "," + 10*(i*(31-i));
44 r += "," + 10*(8*i);
45 r += "," + 10*(250 - 8*i);
46 r += "," + 10*(125 + 125 * Math.sin(0.3*i));
47 r += "\n";
ce49c2fa
DV
48 }
49 return r;
50 },
51 {
52 rollPeriod: 1,
5c528fa2 53 showRoller: true,
ce49c2fa 54 width: 480,
5c528fa2
DV
55 height: 320,
56 drawCallback: function(g) {
57 var ann = g.annotations();
58 var html = "";
59 for (var i = 0; i < ann.length; i++) {
e6d53148
DV
60 var name = nameAnnotation(ann[i]);
61 html += "<span id='" + name + "'>"
62 html += name + ": " + ann[i].shortText + " -> ";
63 html += ann[i].text + "</span><br/>";
5c528fa2
DV
64 }
65 document.getElementById("list").innerHTML = html;
3bf2fa91 66 }
ce49c2fa
DV
67 }
68 );
5c528fa2
DV
69
70 var last_ann = 0;
71 annotations = [];
72 for (var x = 10; x < 15; x += 2) {
73 annotations.push( {
74 series: 'sine wave',
75 x: "200610" + x,
76 shortText: x,
77 text: 'Stock Market Crash ' + x
78 } );
79 last_ann = x;
80 }
81 annotations.push( {
82 series: 'another line',
83 x: "20061013",
ce5e8d36 84 icon: 'dollar.png',
33030f33
DV
85 width: 18,
86 height: 23,
ce5e8d36 87 tickHeight: 4,
5c528fa2 88 text: 'Another one',
ab5e5c75
DV
89 cssClass: 'annotation',
90 clickHandler: function() {
91 document.getElementById("events").innerHTML += "special handler<br/>";
92 }
5c528fa2
DV
93 } );
94 g.setAnnotations(annotations);
95
96 function add() {
97 var x = last_ann + 2;
98 var annnotations = g.annotations();
99 annotations.push( {
100 series: 'line',
101 x: "200610" + x,
102 shortText: x,
9a40897e
DV
103 text: 'Line ' + x,
104 tickHeight: 10
5c528fa2
DV
105 } );
106 last_ann = x;
107 g.setAnnotations(annotations);
108 }
ab5e5c75 109
d14b9eed
DV
110 function bottom(el) {
111 var to_bottom = true;
112 if (el.value != 'Shove to bottom') to_bottom = false;
113
114 var anns = g.annotations();
115 for (var i = 0; i < anns.length; i++) {
116 anns[i].attachAtBottom = to_bottom;
117 }
118 g.setAnnotations(anns);
119
120 if (to_bottom) {
121 el.value = 'Lift back up';
122 } else {
123 el.value = 'Shove to bottom';
124 }
125 }
126
e6d53148 127 var saveBg = '';
2ad87eaa 128 var num = 0;
ab5e5c75
DV
129 g.updateOptions( {
130 annotationClickHandler: function(ann, point, dg, event) {
70aa9072
DV
131 eventDiv.innerHTML += "click: " + nameAnnotation(ann) + "<br/>";
132 },
133 annotationDblClickHandler: function(ann, point, dg, event) {
134 eventDiv.innerHTML += "dblclick: " + nameAnnotation(ann) + "<br/>";
135 },
136 annotationMouseOverHandler: function(ann, point, dg, event) {
e6d53148
DV
137 document.getElementById(nameAnnotation(ann)).style.fontWeight = 'bold';
138 saveBg = ann.div.style.backgroundColor;
139 ann.div.style.backgroundColor = '#ddd';
70aa9072
DV
140 },
141 annotationMouseOutHandler: function(ann, point, dg, event) {
e6d53148
DV
142 document.getElementById(nameAnnotation(ann)).style.fontWeight = 'normal';
143 ann.div.style.backgroundColor = saveBg;
2ad87eaa
DV
144 },
145
146 pointClickCallback: function(event, p) {
147 // Check if the point is already annotated.
148 if (p.annotation) return;
149
150 // If not, add one.
151 var ann = {
152 series: p.name,
153 xval: p.xval,
154 shortText: num,
155 text: "Annotation #" + num
156 };
157 var anns = g.annotations();
158 anns.push(ann);
159 g.setAnnotations(anns);
160
161 num++;
ab5e5c75
DV
162 }
163 });
ce49c2fa
DV
164 </script>
165</body>
166</html>