Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Series color and adaptation to Flot convention #95

Merged
merged 1 commit into from
Oct 21, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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