1 function showTooltip(x, y, contents) { |
|
2 $('<div id="tooltip">' + contents + '</div>').css({ |
|
3 position: 'absolute', |
|
4 display: 'none', |
|
5 top: y + 5, |
|
6 left: x + 5, |
|
7 border: '1px solid #fdd', |
|
8 padding: '2px', |
|
9 'background-color': '#fee', |
|
10 opacity: 0.80 |
|
11 }).appendTo("body").fadeIn(200); |
|
12 } |
|
13 |
|
14 var previousPoint = null; |
|
15 function onPlotHover(event, pos, item) { |
|
16 var $fig = $(event.target); |
|
17 if (item) { |
|
18 if (previousPoint != item.datapoint) { |
|
19 previousPoint = item.datapoint; |
|
20 $("#tooltip").remove(); |
|
21 var x = item.datapoint[0].toFixed(2), |
|
22 y = item.datapoint[1].toFixed(2); |
|
23 if ($fig.data('mode') == 'time') { |
|
24 x = new Date(item.datapoint[0]); |
|
25 var dateformat = $fig.data('dateformat'); |
|
26 if (dateformat) { |
|
27 x = x.strftime(dateformat); |
|
28 } else { |
|
29 x = x.toLocaleDateString() + ' ' + x.toLocaleTimeString(); |
|
30 } |
|
31 } else if (item.datapoint.length == 4) { |
|
32 // NOTE: this has no chance to work with jquery flot >= 0.6 because |
|
33 // jquery flot normalizes datapoints and only keeps 2 columns. Either |
|
34 // use processRawData hook or use the 'dateformat' option. |
|
35 x = new Date(item.datapoint[2]); |
|
36 x = x.strftime(item.datapoint[3]); |
|
37 } |
|
38 showTooltip(item.pageX, item.pageY, item.series.label + ': (' + x + ' ; ' + y + ')'); |
|
39 } |
|
40 } else { |
|
41 $("#tooltip").remove(); |
|
42 previousPoint = null; |
|
43 } |
|
44 } |
|
45 |
|