5 title
: 'Dynamic Annotations Demo',
6 setup
: function(parent
) {
8 "<p>Click any point to add an annotation to it or click 'Add Annotation'.</p>" +
9 "<input type='button' value='Add Annotation' onclick='add()' />" +
10 "<input type='button' value='Shove to bottom' onclick='bottom(this)' />" +
11 "<div id='list'></div>" +
12 "<div id='g_div'></div>" +
13 "<div id='events'></div>";
17 var eventDiv
= document
.getElementById("events");
18 function nameAnnotation(ann
) {
19 return "(" + ann
.series
+ ", " + ann
.x
+ ")";
23 document
.getElementById("g_div"),
25 var zp
= function(x
) { if (x
< 10) return "0"+x
; else return x
; };
26 var r
= "date,parabola,line,another line,sine wave\n";
27 for (var i
=1; i
<=31; i
++) {
28 r
+= "200610" + zp(i
);
29 r
+= "," + 10*(i
*(31-i
));
31 r
+= "," + 10*(250 - 8*i
);
32 r
+= "," + 10*(125 + 125 * Math
.sin(0.3*i
));
42 drawCallback
: function(g
) {
43 var ann
= g
.annotations();
45 for (var i
= 0; i
< ann
.length
; i
++) {
46 var name
= nameAnnotation(ann
[i
]);
47 html
+= "<span id='" + name
+ "'>"
48 html
+= name
+ ": " + (ann
[i
].shortText
|| '(icon)')
49 html
+= " -> " + ann
[i
].text
+ "</span><br/>";
51 document
.getElementById("list").innerHTML
= html
;
58 for (var x
= 10; x
< 15; x
+= 2) {
63 text
: 'Stock Market Crash ' + x
68 series
: 'another line',
70 icon
: 'images/dollar.png',
75 cssClass
: 'annotation',
76 clickHandler
: function() {
77 eventDiv
.innerHTML
+= "special handler<br/>";
80 g
.setAnnotations(annotations
);
82 window
.add
= function() {
84 var annnotations
= g
.annotations();
93 g
.setAnnotations(annotations
);
96 window
.bottom
= function(el
) {
98 if (el
.value
!= 'Shove to bottom') to_bottom
= false;
100 var anns
= g
.annotations();
101 for (var i
= 0; i
< anns
.length
; i
++) {
102 anns
[i
].attachAtBottom
= to_bottom
;
104 g
.setAnnotations(anns
);
107 el
.value
= 'Lift back up';
109 el
.value
= 'Shove to bottom';
116 annotationClickHandler
: function(ann
, point
, dg
, event
) {
117 eventDiv
.innerHTML
+= "click: " + nameAnnotation(ann
) + "<br/>";
119 annotationDblClickHandler
: function(ann
, point
, dg
, event
) {
120 eventDiv
.innerHTML
+= "dblclick: " + nameAnnotation(ann
) + "<br/>";
122 annotationMouseOverHandler
: function(ann
, point
, dg
, event
) {
123 document
.getElementById(nameAnnotation(ann
)).style
.fontWeight
= 'bold';
124 saveBg
= ann
.div
.style
.backgroundColor
;
125 ann
.div
.style
.backgroundColor
= '#ddd';
127 annotationMouseOutHandler
: function(ann
, point
, dg
, event
) {
128 document
.getElementById(nameAnnotation(ann
)).style
.fontWeight
= 'normal';
129 ann
.div
.style
.backgroundColor
= saveBg
;
132 pointClickCallback
: function(event
, p
) {
133 // Check if the point is already annotated.
134 if (p
.annotation
) return;
141 text
: "Annotation #" + num
143 var anns
= g
.annotations();
145 g
.setAnnotations(anns
);