blob: bbf74521fe3543db9b3cec1b5e48fed2c9af0c71 [file] [log] [blame]
/**
* Copyright (c) 2009 Chris Leonello
* jqPlot is currently available for use in all personal or commercial projects
* under both the MIT and GPL version 2.0 licenses. This means that you can
* choose the license that best suits your project and use it accordingly.
*
* Although not required, the author would appreciate an email letting him
* know of any substantial use of jqPlot. You can reach the author at:
* chris dot leonello at gmail dot com or see http://www.jqplot.com/info.php .
*
* If you are feeling kind and generous, consider supporting the project by
* making a donation at: http://www.jqplot.com/donate.php .
*/
(function(b){b.jqplot.eventListenerHooks.push(["jqplotMouseMove",c]);b.jqplot.Highlighter=function(e){this.show=b.jqplot.config.enablePlugins;this.markerRenderer=new b.jqplot.MarkerRenderer({shadow:false});this.showMarker=true;this.lineWidthAdjust=2.5;this.sizeAdjust=5;this.showTooltip=true;this.tooltipLocation="nw";this.fadeTooltip=true;this.tooltipFadeSpeed="fast";this.tooltipOffset=2;this.tooltipAxes="both";this.tooltipSeparator=", ";this.useAxesFormatters=true;this.tooltipFormatString="%.5P";this.formatString=null;this.yvalues=1;this._tooltipElem;this.isHighlighting=false;b.extend(true,this,e)};b.jqplot.Highlighter.init=function(h,g,f){var e=f||{};this.plugins.highlighter=new b.jqplot.Highlighter(e.highlighter)};b.jqplot.Highlighter.parseOptions=function(f,e){this.showHighlight=true};b.jqplot.Highlighter.postPlotDraw=function(){this.plugins.highlighter.highlightCanvas=new b.jqplot.GenericCanvas();this.eventCanvas._elem.before(this.plugins.highlighter.highlightCanvas.createElement(this._gridPadding,"jqplot-highlight-canvas",this._plotDimensions));var f=this.plugins.highlighter.highlightCanvas.setContext();var e=this.plugins.highlighter;e._tooltipElem=b('<div class="jqplot-highlighter-tooltip" style="position:absolute;display:none"></div>');this.target.append(e._tooltipElem)};b.jqplot.preInitHooks.push(b.jqplot.Highlighter.init);b.jqplot.preParseSeriesOptionsHooks.push(b.jqplot.Highlighter.parseOptions);b.jqplot.postDrawHooks.push(b.jqplot.Highlighter.postPlotDraw);function a(j,l){var g=j.plugins.highlighter;var m=j.series[l.seriesIndex];var e=m.markerRenderer;var f=g.markerRenderer;f.style=e.style;f.lineWidth=e.lineWidth+g.lineWidthAdjust;f.size=e.size+g.sizeAdjust;var i=b.jqplot.getColorComponents(e.color);var k=[i[0],i[1],i[2]];var h=(i[3]>=0.6)?i[3]*0.6:i[3]*(2-i[3]);f.color="rgba("+k[0]+","+k[1]+","+k[2]+","+h+")";f.init();f.draw(m.gridData[l.pointIndex][0],m.gridData[l.pointIndex][1],g.highlightCanvas._ctx)}function d(s,m,j){var g=s.plugins.highlighter;var v=g._tooltipElem;if(g.useAxesFormatters){var q=m._xaxis._ticks[0].formatter;var e=m._yaxis._ticks[0].formatter;var w=m._xaxis._ticks[0].formatString;var n=m._yaxis._ticks[0].formatString;var r;var o=q(w,j.data[0]);var h=[];for(var t=1;t<g.yvalues+1;t++){h.push(e(n,j.data[t]))}if(g.formatString){switch(g.tooltipAxes){case"both":case"xy":h.unshift(o);h.unshift(g.formatString);r=b.jqplot.sprintf.apply(b.jqplot.sprintf,h);break;case"yx":h.push(o);h.unshift(g.formatString);r=b.jqplot.sprintf.apply(b.jqplot.sprintf,h);break;case"x":r=b.jqplot.sprintf.apply(b.jqplot.sprintf,[g.formatString,o]);break;case"y":h.unshift(g.formatString);r=b.jqplot.sprintf.apply(b.jqplot.sprintf,h);break;default:h.unshift(o);h.unshift(g.formatString);r=b.jqplot.sprintf.apply(b.jqplot.sprintf,h);break}}else{switch(g.tooltipAxes){case"both":case"xy":r=o;for(var t=0;t<h.length;t++){r+=g.tooltipSeparator+h[t]}break;case"yx":r="";for(var t=0;t<h.length;t++){r+=h[t]+g.tooltipSeparator}r+=o;break;case"x":r=o;break;case"y":r="";for(var t=0;t<h.length;t++){r+=h[t]+g.tooltipSeparator}break;default:r=o;for(var t=0;t<h.length;t++){r+=g.tooltipSeparator+h[t]}break}}}else{var r;if(g.tooltipAxes=="both"||g.tooltipAxes=="xy"){r=b.jqplot.sprintf(g.tooltipFormatString,j.data[0])+g.tooltipSeparator+b.jqplot.sprintf(g.tooltipFormatString,j.data[1])}else{if(g.tooltipAxes=="yx"){r=b.jqplot.sprintf(g.tooltipFormatString,j.data[1])+g.tooltipSeparator+b.jqplot.sprintf(g.tooltipFormatString,j.data[0])}else{if(g.tooltipAxes=="x"){r=b.jqplot.sprintf(g.tooltipFormatString,j.data[0])}else{if(g.tooltipAxes=="y"){r=b.jqplot.sprintf(g.tooltipFormatString,j.data[1])}}}}}v.html(r);var u={x:j.gridData[0],y:j.gridData[1]};var p=0;var f=0.707;if(m.markerRenderer.show==true){p=(m.markerRenderer.size+g.sizeAdjust)/2}switch(g.tooltipLocation){case"nw":var l=u.x+s._gridPadding.left-v.outerWidth(true)-g.tooltipOffset-f*p;var k=u.y+s._gridPadding.top-g.tooltipOffset-v.outerHeight(true)-f*p;break;case"n":var l=u.x+s._gridPadding.left-v.outerWidth(true)/2;var k=u.y+s._gridPadding.top-g.tooltipOffset-v.outerHeight(true)-p;break;case"ne":var l=u.x+s._gridPadding.left+g.tooltipOffset+f*p;var k=u.y+s._gridPadding.top-g.tooltipOffset-v.outerHeight(true)-f*p;break;case"e":var l=u.x+s._gridPadding.left+g.tooltipOffset+p;var k=u.y+s._gridPadding.top-v.outerHeight(true)/2;break;case"se":var l=u.x+s._gridPadding.left+g.tooltipOffset+f*p;var k=u.y+s._gridPadding.top+g.tooltipOffset+f*p;break;case"s":var l=u.x+s._gridPadding.left-v.outerWidth(true)/2;var k=u.y+s._gridPadding.top+g.tooltipOffset+p;break;case"sw":var l=u.x+s._gridPadding.left-v.outerWidth(true)-g.tooltipOffset-f*p;var k=u.y+s._gridPadding.top+g.tooltipOffset+f*p;break;case"w":var l=u.x+s._gridPadding.left-v.outerWidth(true)-g.tooltipOffset-p;var k=u.y+s._gridPadding.top-v.outerHeight(true)/2;break;default:var l=u.x+s._gridPadding.left-v.outerWidth(true)-g.tooltipOffset-f*p;var k=u.y+s._gridPadding.top-g.tooltipOffset-v.outerHeight(true)-f*p;break}v.css("left",l);v.css("top",k);if(g.fadeTooltip){v.fadeIn(g.tooltipFadeSpeed)}else{v.show()}}function c(h,g,k,j,i){var e=i.plugins.highlighter;if(e.show){if(j==null&&e.isHighlighting){var f=e.highlightCanvas._ctx;f.clearRect(0,0,f.canvas.width,f.canvas.height);if(e.fadeTooltip){e._tooltipElem.fadeOut(e.tooltipFadeSpeed)}else{e._tooltipElem.hide()}e.isHighlighting=false}if(j!=null&&i.series[j.seriesIndex].showHighlight&&!e.isHighlighting){e.isHighlighting=true;if(e.showMarker){a(i,j)}if(e.showTooltip){d(i,i.series[j.seriesIndex],j)}}}}})(jQuery);