Skip to content

Commit 3b3138c

Browse files
committed
Added three "new" externally visible API functions.
1 parent 78cd8c8 commit 3b3138c

5 files changed

+111
-102
lines changed

README.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,16 @@ when the pull request is merged and how many other changes were made at the same
9393
## Changelog
9494

9595

96-
### What's new in v0.8.3?
96+
### What's new in v0.8.4?
97+
98+
- merged pull request [#87](https://github.com/krzysu/flot.tooltip/pull/87), adding compatibility with jQuery < 1.2.6
99+
- added new API functions to Flot's base plot object:
100+
- `setTooltipPosition(pos)`
101+
- `showTooltip(item, pos)`
102+
- `hideTooltip()`
103+
- cleaned a lot of the source code for better maintainability and development
104+
105+
### v0.8.3
97106

98107
- merged pull requests: [#86](https://github.com/krzysu/flot.tooltip/pull/86), [#85](https://github.com/krzysu/flot.tooltip/pull/85), [#83](https://github.com/krzysu/flot.tooltip/pull/83)
99108
- pull request #86 introduced support for showing tooltips when hovering over the lines between points
@@ -234,7 +243,7 @@ From now on also minified version is available.
234243
- [@ilvalle](https://github.com/ilvalle) - pull request [#77](https://github.com/krzysu/flot.tooltip/pull/77), added time zone support by using $.plot.dateGenerator
235244
- [@willianganzert](https://github.com/willianganzert) - pull request [#83](https://github.com/krzysu/flot.tooltip/pull/83), Add "id" to tooltip element
236245
- [@larsenmtl](https://github.com/larsenmtl) - pull request [#85](https://github.com/krzysu/flot.tooltip/pull/85), Support for stacked percent plugin
237-
- [@RoboterHund](https://github.com/RoboterHund) - pull request [#86](https://github.com/krzysu/flot.tooltip/pull/86), Compatibility fix for older versions of jQuery
246+
- [@RoboterHund](https://github.com/RoboterHund) - pull request [#87](https://github.com/krzysu/flot.tooltip/pull/86), Compatibility fix for older versions of jQuery
238247

239248
* * *
240249
Copyright (c) 2011-2014 Krzysztof Urbas (@krzysu) & Evan Steinkerchner (@Roundaround).

js/jquery.flot.tooltip.js

+49-49
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* jquery.flot.tooltip
33
*
44
* description: easy-to-use tooltips for Flot charts
5-
* version: 0.8.3
5+
* version: 0.8.4
66
* authors: Krzysztof Urbas @krzysu [myviews.pl],Evan Steinkerchner @Roundaround
77
* website: https://github.com/krzysu/flot.tooltip
88
*
@@ -104,7 +104,7 @@
104104
var pos = {};
105105
pos.x = e.pageX;
106106
pos.y = e.pageY;
107-
that.updateTooltipPosition(pos);
107+
plot.setTooltipPosition(pos);
108108
}
109109

110110
function plothover(event, pos, item) {
@@ -138,33 +138,8 @@
138138
}
139139
};
140140

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-
166141
if (item) {
167-
showTooltip(item, pos);
142+
plot.showTooltip(item, pos);
168143
} else if (that.plotOptions.series.lines.show && that.tooltipOptions.lines.track === true) {
169144
var closestTrace = {
170145
distance: -1
@@ -184,7 +159,7 @@
184159
}
185160

186161
if (xAfterIndex === -1) {
187-
hideTooltip();
162+
plot.hideTooltip();
188163
return;
189164
}
190165

@@ -223,13 +198,54 @@
223198
});
224199

225200
if (closestTrace.distance !== -1)
226-
showTooltip(closestTrace.item, pos);
201+
plot.showTooltip(closestTrace.item, pos);
227202
else
228-
hideTooltip();
203+
plot.hideTooltip();
229204
} else {
230-
hideTooltip();
205+
plot.hideTooltip();
231206
}
232207
}
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+
};
233249
};
234250

235251
/**
@@ -260,22 +276,6 @@
260276
return $tip;
261277
};
262278

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-
279279
/**
280280
* core function, create tooltip content
281281
* @param {string} content - template with tooltip content
@@ -484,7 +484,7 @@
484484
init: init,
485485
options: defaultOptions,
486486
name: 'tooltip',
487-
version: '0.8.3'
487+
version: '0.8.4'
488488
});
489489

490490
})(jQuery);

0 commit comments

Comments
 (0)