5 <script type=
"text/javascript" src=
"../excanvas.js"></script>
8 <script type=
"text/javascript" src=
"dygraph-combined.js"></script>
10 <script type=
"text/javascript" src=
"../strftime/strftime-min.js"></script>
11 <script type=
"text/javascript" src=
"../rgbcolor/rgbcolor.js"></script>
12 <script type=
"text/javascript" src=
"../dygraph-canvas.js"></script>
13 <script type=
"text/javascript" src=
"../dygraph.js"></script>
14 <style type=
"text/css">
20 <h3>Annotations Demo
</h3>
21 <p>Click any point to add an annotation to it or click
"Add Annotation".
</p>
22 <input type=
"button" value=
"Add Annotation" onclick=
"add()" />
23 <input type=
"button" value=
"Shove to bottom" onclick=
"bottom(this)" />
24 <div id=
"events"> </div>
25 <div style=
"position:absolute; left:200px; top: 200px;" id=
"g_div"></div>
26 <div style=
"position:absolute; left:700px; top: 200px;" id=
"list"></div>
28 <script type=
"text/javascript">
29 var eventDiv = document.getElementById(
"events");
30 function nameAnnotation(ann) {
31 return
"(" + ann.series +
", " + ann.x +
")";
35 document.getElementById(
"g_div"),
37 var zp = function(x) { if (x <
10) return
"0"+x; else return x; };
38 var r =
"date,parabola,line,another line,sine wave\n";
39 for (var i=
1; i<=
31; i++) {
40 r +=
"200610" + zp(i);
41 r +=
"," +
10*(i*(
31-i));
43 r +=
"," +
10*(
250 -
8*i);
44 r +=
"," +
10*(
125 +
125 * Math.sin(
0.3*i));
54 drawCallback: function(g) {
55 var ann = g.annotations();
57 for (var i =
0; i < ann.length; i++) {
58 var name = nameAnnotation(ann[i]);
59 html +=
"<span id='" + name +
"'>"
60 html += name +
": " + ann[i].shortText +
" -> ";
61 html += ann[i].text +
"</span><br/>";
63 document.getElementById(
"list").innerHTML = html;
70 for (var x =
10; x <
15; x +=
2) {
75 text: 'Stock Market Crash ' + x
80 series: 'another line',
87 cssClass: 'annotation',
88 clickHandler: function() {
89 document.getElementById(
"events").innerHTML +=
"special handler<br/>";
92 g.setAnnotations(annotations);
96 var annnotations = g.annotations();
105 g.setAnnotations(annotations);
108 function bottom(el) {
109 var to_bottom = true;
110 if (el.value != 'Shove to bottom') to_bottom = false;
112 var anns = g.annotations();
113 for (var i =
0; i < anns.length; i++) {
114 anns[i].attachAtBottom = to_bottom;
116 g.setAnnotations(anns);
119 el.value = 'Lift back up';
121 el.value = 'Shove to bottom';
128 annotationClickHandler: function(ann, point, dg, event) {
129 eventDiv.innerHTML +=
"click: " + nameAnnotation(ann) +
"<br/>";
131 annotationDblClickHandler: function(ann, point, dg, event) {
132 eventDiv.innerHTML +=
"dblclick: " + nameAnnotation(ann) +
"<br/>";
134 annotationMouseOverHandler: function(ann, point, dg, event) {
135 document.getElementById(nameAnnotation(ann)).style.fontWeight = 'bold';
136 saveBg = ann.div.style.backgroundColor;
137 ann.div.style.backgroundColor = '#ddd';
139 annotationMouseOutHandler: function(ann, point, dg, event) {
140 document.getElementById(nameAnnotation(ann)).style.fontWeight = 'normal';
141 ann.div.style.backgroundColor = saveBg;
144 pointClickCallback: function(event, p) {
145 // Check if the point is already annotated.
146 if (p.annotation) return;
153 text:
"Annotation #" + num
155 var anns = g.annotations();
157 g.setAnnotations(anns);