Skip to content

Commit

Permalink
Added three "new" externally visible API functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Roundaround committed Aug 4, 2014
1 parent 78cd8c8 commit 3b3138c
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 102 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,16 @@ when the pull request is merged and how many other changes were made at the same
## Changelog


### What's new in v0.8.3?
### What's new in v0.8.4?

- merged pull request [#87](https://github.com/krzysu/flot.tooltip/pull/87), adding compatibility with jQuery < 1.2.6
- added new API functions to Flot's base plot object:
- `setTooltipPosition(pos)`
- `showTooltip(item, pos)`
- `hideTooltip()`
- cleaned a lot of the source code for better maintainability and development

### v0.8.3

- 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)
- pull request #86 introduced support for showing tooltips when hovering over the lines between points
Expand Down Expand Up @@ -234,7 +243,7 @@ From now on also minified version is available.
- [@ilvalle](https://github.com/ilvalle) - pull request [#77](https://github.com/krzysu/flot.tooltip/pull/77), added time zone support by using $.plot.dateGenerator
- [@willianganzert](https://github.com/willianganzert) - pull request [#83](https://github.com/krzysu/flot.tooltip/pull/83), Add "id" to tooltip element
- [@larsenmtl](https://github.com/larsenmtl) - pull request [#85](https://github.com/krzysu/flot.tooltip/pull/85), Support for stacked percent plugin
- [@RoboterHund](https://github.com/RoboterHund) - pull request [#86](https://github.com/krzysu/flot.tooltip/pull/86), Compatibility fix for older versions of jQuery
- [@RoboterHund](https://github.com/RoboterHund) - pull request [#87](https://github.com/krzysu/flot.tooltip/pull/86), Compatibility fix for older versions of jQuery

* * *
Copyright (c) 2011-2014 Krzysztof Urbas (@krzysu) & Evan Steinkerchner (@Roundaround).
Expand Down
98 changes: 49 additions & 49 deletions js/jquery.flot.tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* jquery.flot.tooltip
*
* description: easy-to-use tooltips for Flot charts
* version: 0.8.3
* version: 0.8.4
* authors: Krzysztof Urbas @krzysu [myviews.pl],Evan Steinkerchner @Roundaround
* website: https://github.com/krzysu/flot.tooltip
*
Expand Down Expand Up @@ -104,7 +104,7 @@
var pos = {};
pos.x = e.pageX;
pos.y = e.pageY;
that.updateTooltipPosition(pos);
plot.setTooltipPosition(pos);
}

function plothover(event, pos, item) {
Expand Down Expand Up @@ -138,33 +138,8 @@
}
};

// Quick little function for showing the tooltip.
var showTooltip = function (target, position) {
var $tip = that.getDomElement();

// convert tooltip content template to real tipText
var tipText = that.stringFormat(that.tooltipOptions.content, target);

$tip.html(tipText);
that.updateTooltipPosition({ x: position.pageX, y: position.pageY });
$tip.css({
left: that.tipPosition.x + that.tooltipOptions.shifts.x,
top: that.tipPosition.y + that.tooltipOptions.shifts.y
}).show();

// run callback
if (typeof that.tooltipOptions.onHover === 'function') {
that.tooltipOptions.onHover(target, $tip);
}
};

// Quick little function for hiding the tooltip.
var hideTooltip = function () {
that.getDomElement().hide().html('');
};

if (item) {
showTooltip(item, pos);
plot.showTooltip(item, pos);
} else if (that.plotOptions.series.lines.show && that.tooltipOptions.lines.track === true) {
var closestTrace = {
distance: -1
Expand All @@ -184,7 +159,7 @@
}

if (xAfterIndex === -1) {
hideTooltip();
plot.hideTooltip();
return;
}

Expand Down Expand Up @@ -223,13 +198,54 @@
});

if (closestTrace.distance !== -1)
showTooltip(closestTrace.item, pos);
plot.showTooltip(closestTrace.item, pos);
else
hideTooltip();
plot.hideTooltip();
} else {
hideTooltip();
plot.hideTooltip();
}
}

// Quick little function for setting the tooltip position.
plot.setTooltipPosition = function (pos) {
var $tip = that.getDomElement();

var totalTipWidth = $tip.outerWidth() + that.tooltipOptions.shifts.x;
var totalTipHeight = $tip.outerHeight() + that.tooltipOptions.shifts.y;
if ((pos.x - $(window).scrollLeft()) > ($(window)[that.wfunc]() - totalTipWidth)) {
pos.x -= totalTipWidth;
}
if ((pos.y - $(window).scrollTop()) > ($(window)[that.hfunc]() - totalTipHeight)) {
pos.y -= totalTipHeight;
}
that.tipPosition.x = pos.x;
that.tipPosition.y = pos.y;
};

// Quick little function for showing the tooltip.
plot.showTooltip = function (target, position) {
var $tip = that.getDomElement();

// convert tooltip content template to real tipText
var tipText = that.stringFormat(that.tooltipOptions.content, target);

$tip.html(tipText);
plot.setTooltipPosition({ x: position.pageX, y: position.pageY });
$tip.css({
left: that.tipPosition.x + that.tooltipOptions.shifts.x,
top: that.tipPosition.y + that.tooltipOptions.shifts.y
}).show();

// run callback
if (typeof that.tooltipOptions.onHover === 'function') {
that.tooltipOptions.onHover(target, $tip);
}
};

// Quick little function for hiding the tooltip.
plot.hideTooltip = function () {
that.getDomElement().hide().html('');
};
};

/**
Expand Down Expand Up @@ -260,22 +276,6 @@
return $tip;
};

// as the name says
FlotTooltip.prototype.updateTooltipPosition = function (pos) {
var $tip = $('#' + this.tooltipOptions.id);

var totalTipWidth = $tip.outerWidth() + this.tooltipOptions.shifts.x;
var totalTipHeight = $tip.outerHeight() + this.tooltipOptions.shifts.y;
if ((pos.x - $(window).scrollLeft()) > ($(window)[this.wfunc]() - totalTipWidth)) {
pos.x -= totalTipWidth;
}
if ((pos.y - $(window).scrollTop()) > ($(window)[this.hfunc]() - totalTipHeight)) {
pos.y -= totalTipHeight;
}
this.tipPosition.x = pos.x;
this.tipPosition.y = pos.y;
};

/**
* core function, create tooltip content
* @param {string} content - template with tooltip content
Expand Down Expand Up @@ -484,7 +484,7 @@
init: init,
options: defaultOptions,
name: 'tooltip',
version: '0.8.3'
version: '0.8.4'
});

})(jQuery);
Loading

0 comments on commit 3b3138c

Please sign in to comment.