2 * Holds the definition and the creation of the imageMap object
3 * @author Martynas Mickevicius <mmartynas@gmail.com>
8 * responsible for showing tooltips above the image chart
11 'mouseMoved': function(event
, cont
) {
12 // return if no imageMap set
13 // this can happen if server has no json
18 // get mouse coordinated relative to image
19 var mouseX
= event
.pageX
- cont
.offsetLeft
;
20 var mouseY
= event
.pageY
- cont
.offsetTop
;
22 //console.log("X: " + mouseX + ", Y: " + mouseY);
24 /* Check if we are flying over a map zone
25 * Lets use the following method to check if a given
26 * point is in any convex polygon.
27 * http://www.programmingforums.org/post168124-3.html
30 for (var key
= 0; key
< this.imageMap
.length
; key
++)
32 var seriesName
= this.imageMap
[key
]['n'];
33 var seriesValue
= this.imageMap
[key
]['v'];
36 for (var i
= 0; i
< this.imageMap
[key
]['p'].length
; i
++)
41 if (i
== this.imageMap
[key
]['p'].length
- 1)
51 var result
= this.getDeterminant(
52 this.imageMap
[key
]['p'][index1
][0],
53 this.imageMap
[key
]['p'][index1
][1],
54 this.imageMap
[key
]['p'][index2
][0],
55 this.imageMap
[key
]['p'][index2
][1],
59 if (result
> 0) { signSum
+= 1; } else { signSum
+= -1; }
62 if (Math
.abs(signSum
) == this.imageMap
[key
]['p'].length
)
65 if (this.currentKey
!= key
)
68 this.tooltip
.title(seriesName
);
69 this.tooltip
.text(seriesValue
);
70 this.currentKey
= key
;
72 this.tooltip
.move(mouseX
+ 20, mouseY
+ 20);
75 if (!found
&& this.currentKey
!= -1 )
82 'getDeterminant': function (X1
, Y1
, X2
, Y2
, X3
, Y3
) {
83 return (X2
*Y3
- X3
*Y2
) - (X1
*Y3
- X3
*Y1
) + (X1
*Y2
- X2
*Y1
);
86 'loadImageMap': function(map
) {
87 this.imageMap
= JSON
.parse(map
);
88 for (key
in this.imageMap
)
91 // without this loop image map does not work
92 // on IE8 in the status page
99 $("div#chart").bind('mousemove',function(e
) {
100 imageMap
.mouseMoved(e
, this);
103 this.tooltip
.attach("div#chart");
105 this.currentKey
= -1;
109 'init': function () {
110 this.el
= $('<div></div>');
111 this.el
.css('position', 'absolute');
112 this.el
.css('font-family', 'tahoma');
113 this.el
.css('background-color', '#373737');
114 this.el
.css('color', '#BEBEBE');
115 this.el
.css('padding', '3px');
117 var title
= $('<p></p>');
118 title
.attr('id', 'title');
119 title
.css('margin', '0px');
120 title
.css('padding', '3px');
121 title
.css('background-color', '#606060');
122 title
.css('text-align', 'center');
124 this.el
.append(title
);
126 var text
= $('<p></p>');
127 text
.attr('id', 'text');
128 text
.css('margin', '0');
130 this.el
.append(text
);
135 'attach': function (element
) {
136 $(element
).prepend(this.el
);
139 'move': function (x
, y
) {
140 this.el
.css('margin-left', x
);
141 this.el
.css('margin-top', y
);
144 'hide': function () {
145 this.el
.css('display', 'none');
148 'show': function () {
149 this.el
.css('display', 'block');
152 'title': function (title
) {
153 this.el
.find("p#title").html(title
);
156 'text': function (text
) {
157 this.el
.find("p#text").html(text
.replace(/;/g, "<br />"));
162 $(document).ready(function() {