forked from irae/jquery-visualize
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtooltip.visualize.jQuery.js
114 lines (102 loc) · 3.64 KB
/
tooltip.visualize.jQuery.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**
* --------------------------------------------------------------------
* Tooltip plugin for the jQuery-Plugin "Visualize"
* Tolltip by Iraê Carvalho, [email protected], http://irae.pro.br/en/
* Copyright (c) 2010 Iraê Carvalho
* Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) and GPL (filamentgroup.com/examples/gpl-license.txt) licenses.
*
* Visualize plugin by Scott Jehl, [email protected]
* Copyright (c) 2009 Filament Group, http://www.filamentgroup.com
*
* --------------------------------------------------------------------
*/
(function($){
$.visualizePlugins.push(function visualizeTooltip(options,tableData) {
//configuration
var o = $.extend({
tooltip: false,
tooltipalign: 'auto', // also available 'left' and 'right'
tooltipvalign: 'top',
tooltipclass: 'visualize-tooltip',
tooltiphtml: function(data){
if(options.multiHover) {
var html='';
for(var i=0;i<data.point.length;i++){
html += '<p>'+data.point[i].value+' - '+data.point[i].yLabels[0]+'</p>';
}
return html;
} else {
return '<p>'+data.point.value+' - '+data.point.yLabels[0]+'</p>';
}
},
delay:false
},options);
// don't go any further if we are not to show anything
if(!o.tooltip) {return;}
var self = $(this),
canvasContain = self.next(),
scroller = canvasContain.find('.visualize-scroller'),
scrollerW = scroller.width(),
tracker = canvasContain.find('.visualize-interaction-tracker');
// IE needs background color and opacity white or the tracker stays behind the tooltip
tracker.css({
backgroundColor:'white',
opacity:0,
zIndex:100
});
var tooltip = $('<div class="'+o.tooltipclass+'"/>').css({
position:'absolute',
display:'none',
zIndex:90
})
.insertAfter(scroller.find('canvas'));
var usescroll = true;
if( typeof(G_vmlCanvasManager) != 'undefined' ){
scroller.css({'position':'absolute'});
tracker.css({marginTop:'-'+(o.height)+'px'});
}
self.bind('vizualizeOver',function visualizeTooltipOver(e,data){
if(data.canvasContain.get(0) != canvasContain.get(0)) {return;} // for multiple graphs originated from same table
if(o.multiHover) {
var p = data.point[0].canvasCords;
} else {
var p = data.point.canvasCords;
}
var left,right,top,clasRem,clasAd,bottom,x=Math.round(p[0]+data.tableData.zeroLocX),y=Math.round(p[1]+data.tableData.zeroLocY);
if(o.tooltipalign == 'left' || ( o.tooltipalign=='auto' && x-scroller.scrollLeft()<=scrollerW/2 ) ) {
if($.browser.msie && ($.browser.version == 7 || $.browser.version == 6) ) {usescroll=false;} else {usescroll=true;}
left = x-(usescroll?scroller.scrollLeft():0);
if(x-scroller.scrollLeft()<0) { // even with when not using scroll we need to calc with it for IE
return;
}
left = left+'px';
right = '';
clasAdd="tooltipleft";
clasRem="tooltipright";
} else {
if($.browser.msie && $.browser.version == 7) {usescroll=false;} else {usescroll=true;}
right = Math.abs(x-o.width)- (o.width-(usescroll?scroller.scrollLeft():0)-scrollerW);
if(Math.abs(x-o.width)- (o.width-scroller.scrollLeft()-scrollerW)<0) { // even with when not using scroll we need to calc with it for IE
return;
}
left = '';
right = right+'px';
clasAdd="tooltipright";
clasRem="tooltipleft";
}
tooltip
.addClass(clasAdd)
.removeClass(clasRem)
.html(o.tooltiphtml(data))
.css({
display:'block',
top: y+'px',
left: left,
right: right
});
});
self.bind('vizualizeOut',function visualizeTooltipOut(e,data){
tooltip.css({display:'none'});
});
});
})(jQuery);