Skip to content

Commit

Permalink
Merge pull request #63 from LoicUV/categories-mode-support
Browse files Browse the repository at this point in the history
support for categories plugin when using custom ticks labels on y axis
  • Loading branch information
Kris Urbas committed Feb 10, 2014
2 parents e73390f + 1450be1 commit 744ea16
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
23 changes: 14 additions & 9 deletions js/jquery.flot.tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* author: Krzysztof Urbas @krzysu [myviews.pl]
* website: https://github.com/krzysu/flot.tooltip
*
* build on 2014-02-07
* build on 2014-02-10
* released under MIT License, 2012
*/
(function ($) {
Expand Down Expand Up @@ -68,13 +68,13 @@
// bind event
$( plot.getPlaceholder() ).bind("plothover", plothover);

$(eventHolder).bind('mousemove', mouseMove);
$(eventHolder).bind('mousemove', mouseMove);
});

plot.hooks.shutdown.push(function (plot, eventHolder){
$(plot.getPlaceholder()).unbind("plothover", plothover);
$(eventHolder).unbind("mousemove", mouseMove);
});
plot.hooks.shutdown.push(function (plot, eventHolder){
$(plot.getPlaceholder()).unbind("plothover", plothover);
$(eventHolder).unbind("mousemove", mouseMove);
});

function mouseMove(e){
var pos = {};
Expand All @@ -83,8 +83,8 @@
that.updateTooltipPosition(pos);
}

function plothover(event, pos, item) {
var $tip = that.getDomElement();
function plothover(event, pos, item) {
var $tip = that.getDomElement();
if (item) {
var tipText;

Expand Down Expand Up @@ -232,7 +232,8 @@
if(typeof item.series.yaxis.ticks !== 'undefined') {
for (var index in item.series.yaxis.ticks) {
if (item.series.yaxis.ticks.hasOwnProperty(index)) {
if (item.series.yaxis.ticks[index].v === y) {
var value = (this.isCategoriesMode('yaxis', item)) ? item.series.yaxis.ticks[index].label : item.series.yaxis.ticks[index].v;
if (value === y) {
content = content.replace(yPattern, item.series.yaxis.ticks[index].label);
}
}
Expand Down Expand Up @@ -265,6 +266,10 @@
return (typeof this.tooltipOptions.yDateFormat !== 'undefined' && this.tooltipOptions.yDateFormat !== null);
};

FlotTooltip.prototype.isCategoriesMode = function(axisName, item) {
return (typeof item.series[axisName].options.mode !== 'undefined' && item.series[axisName].options.mode === 'categories');
};

//
FlotTooltip.prototype.timestampToDate = function(tmst, dateFormat) {
var theDate = new Date(tmst*1);
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.flot.tooltip.min.js

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

21 changes: 13 additions & 8 deletions js/jquery.flot.tooltip.source.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@
// bind event
$( plot.getPlaceholder() ).bind("plothover", plothover);

$(eventHolder).bind('mousemove', mouseMove);
$(eventHolder).bind('mousemove', mouseMove);
});

plot.hooks.shutdown.push(function (plot, eventHolder){
$(plot.getPlaceholder()).unbind("plothover", plothover);
$(eventHolder).unbind("mousemove", mouseMove);
});
plot.hooks.shutdown.push(function (plot, eventHolder){
$(plot.getPlaceholder()).unbind("plothover", plothover);
$(eventHolder).unbind("mousemove", mouseMove);
});

function mouseMove(e){
var pos = {};
Expand All @@ -72,8 +72,8 @@
that.updateTooltipPosition(pos);
}

function plothover(event, pos, item) {
var $tip = that.getDomElement();
function plothover(event, pos, item) {
var $tip = that.getDomElement();
if (item) {
var tipText;

Expand Down Expand Up @@ -221,7 +221,8 @@
if(typeof item.series.yaxis.ticks !== 'undefined') {
for (var index in item.series.yaxis.ticks) {
if (item.series.yaxis.ticks.hasOwnProperty(index)) {
if (item.series.yaxis.ticks[index].v === y) {
var value = (this.isCategoriesMode('yaxis', item)) ? item.series.yaxis.ticks[index].label : item.series.yaxis.ticks[index].v;
if (value === y) {
content = content.replace(yPattern, item.series.yaxis.ticks[index].label);
}
}
Expand Down Expand Up @@ -254,6 +255,10 @@
return (typeof this.tooltipOptions.yDateFormat !== 'undefined' && this.tooltipOptions.yDateFormat !== null);
};

FlotTooltip.prototype.isCategoriesMode = function(axisName, item) {
return (typeof item.series[axisName].options.mode !== 'undefined' && item.series[axisName].options.mode === 'categories');
};

//
FlotTooltip.prototype.timestampToDate = function(tmst, dateFormat) {
var theDate = new Date(tmst*1);
Expand Down

0 comments on commit 744ea16

Please sign in to comment.