Skip to content

Commit 14519e9

Browse files
committed
FlotTooltip: Create a tooltip callback and fix the hover callback (https://rbcommons.com/s/pepperdata/r/2176)
Needed for custom actions on tooltip click
1 parent f0ff167 commit 14519e9

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

examples/many_series.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ <h1>flot.tooltip plugin example page</h1>
6565
shifts: {
6666
x: -60,
6767
y: 25
68+
},
69+
onClick: function(item, $tip, isSticky) {
70+
if(isSticky) {
71+
$tip.css("border-color","red");
72+
} else {
73+
$tip.css("border-color","black");
74+
}
75+
6876
}
6977
}
7078
};

js/jquery.flot.tooltip.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* author: Krzysztof Urbas @krzysu [myviews.pl]
77
* website: https://github.com/krzysu/flot.tooltip
88
*
9-
* build on 2013-12-04
9+
* build on 2013-12-09
1010
* released under MIT License, 2012
1111
*/
1212
(function ($) {
@@ -32,7 +32,8 @@
3232
stickyable: false,
3333

3434
// callbacks
35-
onHover: function(flotItem, $tooltipEl) {}
35+
onHover: function(flotItem, $tooltipEl) {},
36+
onClick: function(flotItem, $tooltipEl, isSticky) {}
3637
}
3738
};
3839

@@ -107,7 +108,7 @@
107108
.show();
108109

109110
// run callback
110-
if(typeof that.tooltipOptions.onHover !== 'function') {
111+
if(typeof that.tooltipOptions.onHover === 'function') {
111112
that.tooltipOptions.onHover(item, $tip);
112113
}
113114
}
@@ -123,10 +124,16 @@
123124
if(item && !that.stickyItem) {
124125
that.stickyItem = item;
125126
that.plot.highlight(item.seriesIndex, item.dataIndex);
127+
if(typeof that.tooltipOptions.onClick === 'function') {
128+
that.tooltipOptions.onClick(item, $tip, true);
129+
}
126130
}
127131
else {
128132
hideTooltip();
129133
plothover(event,pos,item);
134+
if(typeof that.tooltipOptions.onClick === 'function') {
135+
that.tooltipOptions.onClick(item, $tip, false);
136+
}
130137
}
131138
}
132139

js/jquery.flot.tooltip.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/jquery.flot.tooltip.source.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
stickyable: false,
2222

2323
// callbacks
24-
onHover: function(flotItem, $tooltipEl) {}
24+
onHover: function(flotItem, $tooltipEl) {},
25+
onClick: function(flotItem, $tooltipEl, isSticky) {}
2526
}
2627
};
2728

@@ -96,7 +97,7 @@
9697
.show();
9798

9899
// run callback
99-
if(typeof that.tooltipOptions.onHover !== 'function') {
100+
if(typeof that.tooltipOptions.onHover === 'function') {
100101
that.tooltipOptions.onHover(item, $tip);
101102
}
102103
}
@@ -112,10 +113,16 @@
112113
if(item && !that.stickyItem) {
113114
that.stickyItem = item;
114115
that.plot.highlight(item.seriesIndex, item.dataIndex);
116+
if(typeof that.tooltipOptions.onClick === 'function') {
117+
that.tooltipOptions.onClick(item, $tip, true);
118+
}
115119
}
116120
else {
117121
hideTooltip();
118122
plothover(event,pos,item);
123+
if(typeof that.tooltipOptions.onClick === 'function') {
124+
that.tooltipOptions.onClick(item, $tip, false);
125+
}
119126
}
120127
}
121128

0 commit comments

Comments
 (0)