|
2 | 2 | * jquery.flot.tooltip
|
3 | 3 | *
|
4 | 4 | * description: easy-to-use tooltips for Flot charts
|
5 |
| - * version: 0.8.3 |
| 5 | + * version: 0.8.4 |
6 | 6 | * authors: Krzysztof Urbas @krzysu [myviews.pl],Evan Steinkerchner @Roundaround
|
7 | 7 | * website: https://github.com/krzysu/flot.tooltip
|
8 | 8 | *
|
|
104 | 104 | var pos = {};
|
105 | 105 | pos.x = e.pageX;
|
106 | 106 | pos.y = e.pageY;
|
107 |
| - that.updateTooltipPosition(pos); |
| 107 | + plot.setTooltipPosition(pos); |
108 | 108 | }
|
109 | 109 |
|
110 | 110 | function plothover(event, pos, item) {
|
|
138 | 138 | }
|
139 | 139 | };
|
140 | 140 |
|
141 |
| - // Quick little function for showing the tooltip. |
142 |
| - var showTooltip = function (target, position) { |
143 |
| - var $tip = that.getDomElement(); |
144 |
| - |
145 |
| - // convert tooltip content template to real tipText |
146 |
| - var tipText = that.stringFormat(that.tooltipOptions.content, target); |
147 |
| - |
148 |
| - $tip.html(tipText); |
149 |
| - that.updateTooltipPosition({ x: position.pageX, y: position.pageY }); |
150 |
| - $tip.css({ |
151 |
| - left: that.tipPosition.x + that.tooltipOptions.shifts.x, |
152 |
| - top: that.tipPosition.y + that.tooltipOptions.shifts.y |
153 |
| - }).show(); |
154 |
| - |
155 |
| - // run callback |
156 |
| - if (typeof that.tooltipOptions.onHover === 'function') { |
157 |
| - that.tooltipOptions.onHover(target, $tip); |
158 |
| - } |
159 |
| - }; |
160 |
| - |
161 |
| - // Quick little function for hiding the tooltip. |
162 |
| - var hideTooltip = function () { |
163 |
| - that.getDomElement().hide().html(''); |
164 |
| - }; |
165 |
| - |
166 | 141 | if (item) {
|
167 |
| - showTooltip(item, pos); |
| 142 | + plot.showTooltip(item, pos); |
168 | 143 | } else if (that.plotOptions.series.lines.show && that.tooltipOptions.lines.track === true) {
|
169 | 144 | var closestTrace = {
|
170 | 145 | distance: -1
|
|
184 | 159 | }
|
185 | 160 |
|
186 | 161 | if (xAfterIndex === -1) {
|
187 |
| - hideTooltip(); |
| 162 | + plot.hideTooltip(); |
188 | 163 | return;
|
189 | 164 | }
|
190 | 165 |
|
|
223 | 198 | });
|
224 | 199 |
|
225 | 200 | if (closestTrace.distance !== -1)
|
226 |
| - showTooltip(closestTrace.item, pos); |
| 201 | + plot.showTooltip(closestTrace.item, pos); |
227 | 202 | else
|
228 |
| - hideTooltip(); |
| 203 | + plot.hideTooltip(); |
229 | 204 | } else {
|
230 |
| - hideTooltip(); |
| 205 | + plot.hideTooltip(); |
231 | 206 | }
|
232 | 207 | }
|
| 208 | + |
| 209 | + // Quick little function for setting the tooltip position. |
| 210 | + plot.setTooltipPosition = function (pos) { |
| 211 | + var $tip = that.getDomElement(); |
| 212 | + |
| 213 | + var totalTipWidth = $tip.outerWidth() + that.tooltipOptions.shifts.x; |
| 214 | + var totalTipHeight = $tip.outerHeight() + that.tooltipOptions.shifts.y; |
| 215 | + if ((pos.x - $(window).scrollLeft()) > ($(window)[that.wfunc]() - totalTipWidth)) { |
| 216 | + pos.x -= totalTipWidth; |
| 217 | + } |
| 218 | + if ((pos.y - $(window).scrollTop()) > ($(window)[that.hfunc]() - totalTipHeight)) { |
| 219 | + pos.y -= totalTipHeight; |
| 220 | + } |
| 221 | + that.tipPosition.x = pos.x; |
| 222 | + that.tipPosition.y = pos.y; |
| 223 | + }; |
| 224 | + |
| 225 | + // Quick little function for showing the tooltip. |
| 226 | + plot.showTooltip = function (target, position) { |
| 227 | + var $tip = that.getDomElement(); |
| 228 | + |
| 229 | + // convert tooltip content template to real tipText |
| 230 | + var tipText = that.stringFormat(that.tooltipOptions.content, target); |
| 231 | + |
| 232 | + $tip.html(tipText); |
| 233 | + plot.setTooltipPosition({ x: position.pageX, y: position.pageY }); |
| 234 | + $tip.css({ |
| 235 | + left: that.tipPosition.x + that.tooltipOptions.shifts.x, |
| 236 | + top: that.tipPosition.y + that.tooltipOptions.shifts.y |
| 237 | + }).show(); |
| 238 | + |
| 239 | + // run callback |
| 240 | + if (typeof that.tooltipOptions.onHover === 'function') { |
| 241 | + that.tooltipOptions.onHover(target, $tip); |
| 242 | + } |
| 243 | + }; |
| 244 | + |
| 245 | + // Quick little function for hiding the tooltip. |
| 246 | + plot.hideTooltip = function () { |
| 247 | + that.getDomElement().hide().html(''); |
| 248 | + }; |
233 | 249 | };
|
234 | 250 |
|
235 | 251 | /**
|
|
260 | 276 | return $tip;
|
261 | 277 | };
|
262 | 278 |
|
263 |
| - // as the name says |
264 |
| - FlotTooltip.prototype.updateTooltipPosition = function (pos) { |
265 |
| - var $tip = $('#' + this.tooltipOptions.id); |
266 |
| - |
267 |
| - var totalTipWidth = $tip.outerWidth() + this.tooltipOptions.shifts.x; |
268 |
| - var totalTipHeight = $tip.outerHeight() + this.tooltipOptions.shifts.y; |
269 |
| - if ((pos.x - $(window).scrollLeft()) > ($(window)[this.wfunc]() - totalTipWidth)) { |
270 |
| - pos.x -= totalTipWidth; |
271 |
| - } |
272 |
| - if ((pos.y - $(window).scrollTop()) > ($(window)[this.hfunc]() - totalTipHeight)) { |
273 |
| - pos.y -= totalTipHeight; |
274 |
| - } |
275 |
| - this.tipPosition.x = pos.x; |
276 |
| - this.tipPosition.y = pos.y; |
277 |
| - }; |
278 |
| - |
279 | 279 | /**
|
280 | 280 | * core function, create tooltip content
|
281 | 281 | * @param {string} content - template with tooltip content
|
|
484 | 484 | init: init,
|
485 | 485 | options: defaultOptions,
|
486 | 486 | name: 'tooltip',
|
487 |
| - version: '0.8.3' |
| 487 | + version: '0.8.4' |
488 | 488 | });
|
489 | 489 |
|
490 | 490 | })(jQuery);
|
0 commit comments