Skip to content

Commit

Permalink
Set tooltip not to show when content is empty, and set content to be …
Browse files Browse the repository at this point in the history
…formatted to empty when a boolean value of false is passed. Resolves issue #102.
  • Loading branch information
Roundaround committed May 11, 2015
1 parent 08d3a09 commit ef3916f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
17 changes: 12 additions & 5 deletions js/jquery.flot.tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
var defaultOptions = {
tooltip: {
show: false,
id: "flotTip",
cssClass: "flotTip",
content: "%s | X: %x | Y: %y",
// allowed templates are:
// %s -> series label,
Expand Down Expand Up @@ -227,6 +227,8 @@

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

$tip.html(tipText);
plot.setTooltipPosition({ x: position.pageX, y: position.pageY });
Expand All @@ -252,10 +254,10 @@
* @return jQuery object
*/
FlotTooltip.prototype.getDomElement = function () {
var $tip = $('#' + this.tooltipOptions.id);
var $tip = $('.' + this.tooltipOptions.cssClass);

if( $tip.length === 0 ){
$tip = $('<div />').attr('id', this.tooltipOptions.id);
$tip = $('<div />').addClass(this.tooltipOptions.cssClass);
$tip.appendTo('body').hide().css({position: 'absolute'});

if(this.tooltipOptions.defaultTheme) {
Expand Down Expand Up @@ -322,6 +324,11 @@
content = content(item.series.label, x, y, item);
}

// the case where the passed content is equal to false
if (typeof(content) === 'boolean' && !content) {
return '';
}

// percent match for pie charts and stacked percent
if (typeof (item.series.percent) !== 'undefined') {
p = item.series.percent;
Expand Down Expand Up @@ -474,12 +481,12 @@

// check if flot-axislabels plugin (https://github.com/markrcote/flot-axislabels) is used and that an axis label is given
FlotTooltip.prototype.hasAxisLabel = function (axisName, item) {
return ($.inArray('axisLabels', this.plotPlugins) !== -1 && typeof item.series[axisName].options.axisLabel !== 'undefined' && item.series[axisName].options.axisLabel.length > 0);
return ($.inArray(this.plotPlugins, 'axisLabels') !== -1 && typeof item.series[axisName].options.axisLabel !== 'undefined' && item.series[axisName].options.axisLabel.length > 0);
};

// check whether flot-tickRotor, a plugin which allows rotation of X-axis ticks, is being used
FlotTooltip.prototype.hasRotatedXAxisTicks = function (item) {
return ($.inArray('tickRotor', this.plotPlugins) !== -1 && typeof item.series.xaxis.rotatedTicks !== 'undefined');
return ($.inArray(this.plotPlugins, 'tickRotor') !== -1 && typeof item.series.xaxis.rotatedTicks !== 'undefined');
};

//
Expand Down
2 changes: 1 addition & 1 deletion js/jquery.flot.tooltip.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions js/jquery.flot.tooltip.source.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@

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

$tip.html(tipText);
plot.setTooltipPosition({ x: position.pageX, y: position.pageY });
Expand Down Expand Up @@ -311,6 +313,11 @@
content = content(item.series.label, x, y, item);
}

// the case where the passed content is equal to false
if (typeof(content) === 'boolean' && !content) {
return '';
}

// percent match for pie charts and stacked percent
if (typeof (item.series.percent) !== 'undefined') {
p = item.series.percent;
Expand Down

0 comments on commit ef3916f

Please sign in to comment.