Skip to content

Commit

Permalink
Merge pull request #95 from Outsidaz/patch-1
Browse files Browse the repository at this point in the history
Series color and adaptation to Flot convention
  • Loading branch information
Roundaround committed Oct 21, 2014
2 parents 17fc8ad + 04114b4 commit bf9683d
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions js/jquery.flot.tooltip.source.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
(function ($) {
// plugin options, default values
var defaultOptions = {
tooltip: false,
tooltipOpts: {
tooltip: {
show: false,
id: "flotTip",
content: "%s | X: %x | Y: %y",
// allowed templates are:
// %s -> series label,
// %c -> series color,
// %lx -> x axis label (requires flot-axislabels plugin https://github.com/markrcote/flot-axislabels),
// %ly -> y axis label (requires flot-axislabels plugin https://github.com/markrcote/flot-axislabels),
// %x -> X value,
Expand Down Expand Up @@ -59,10 +60,10 @@
that.plotOptions = plot.getOptions();

// if not enabled return
if (that.plotOptions.tooltip === false || typeof that.plotOptions.tooltip === 'undefined') return;
if (that.plotOptions.tooltip.show === false || typeof that.plotOptions.tooltip.show === 'undefined') return;

// shortcut to access tooltip options
that.tooltipOptions = that.plotOptions.tooltipOpts;
that.tooltipOptions = that.plotOptions.tooltip;

if (that.tooltipOptions.$compat) {
that.wfunc = 'width';
Expand Down Expand Up @@ -273,6 +274,7 @@

var percentPattern = /%p\.{0,1}(\d{0,})/;
var seriesPattern = /%s/;
var colorPattern = /%c/;
var xLabelPattern = /%lx/; // requires flot-axislabels plugin https://github.com/markrcote/flot-axislabels, will be ignored if plugin isn't loaded
var yLabelPattern = /%ly/; // requires flot-axislabels plugin https://github.com/markrcote/flot-axislabels, will be ignored if plugin isn't loaded
var xPattern = /%x\.{0,1}(\d{0,})/;
Expand Down Expand Up @@ -326,6 +328,14 @@
//remove %s if label is undefined
content = content.replace(seriesPattern, "");
}

// color match
if (typeof(item.series.color) !== 'undefined') {
content = content.replace(colorPattern, item.series.color);
} else {
//remove %s if color is undefined
content = content.replace(colorPattern, "");
}

// x axis label match
if (this.hasAxisLabel('xaxis', item)) {
Expand Down

0 comments on commit bf9683d

Please sign in to comment.