OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / scripts / jquery / jqplot / plugins / jqplot.highlighter.min.js
1 /**
2  * Copyright (c) 2009 - 2010 Chris Leonello
3  * jqPlot is currently available for use in all personal or commercial projects 
4  * under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL 
5  * version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can 
6  * choose the license that best suits your project and use it accordingly. 
7  *
8  * Although not required, the author would appreciate an email letting him 
9  * know of any substantial use of jqPlot.  You can reach the author at: 
10  * chris at jqplot  or see http://www.jqplot.com/info.php .
11  *
12  * If you are feeling kind and generous, consider supporting the project by
13  * making a donation at: http://www.jqplot.com/donate.php .
14  *
15  * jqPlot includes date instance methods and printf/sprintf functions by other authors:
16  *
17  * Date instance methods contained in jqplot.dateMethods.js:
18  *
19  *     author Ken Snyder (ken d snyder at gmail dot com)
20  *     date 2008-09-10
21  *     version 2.0.2 (http://kendsnyder.com/sandbox/date/)     
22  *     license Creative Commons Attribution License 3.0 (http://creativecommons.org/licenses/by/3.0/)
23  *
24  * JavaScript printf/sprintf functions contained in jqplot.sprintf.js:
25  *
26  *     version 2007.04.27
27  *     author Ash Searle
28  *     http://hexmen.com/blog/2007/03/printf-sprintf/
29  *     http://hexmen.com/js/sprintf.js
30  *     The author (Ash Searle) has placed this code in the public domain:
31  *     "This code is unrestricted: you are free to use it however you like."
32  * 
33  */
34 (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.bringSeriesToFront=false;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.eventCanvas._elem.before(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.stop(true,true).fadeIn(g.tooltipFadeSpeed)}else{v.show()}}function c(h,g,k,j,i){var e=i.plugins.highlighter;var l=i.plugins.cursor;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()}if(e.bringSeriesToFront){i.restorePreviousSeriesOrder()}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&&(!l||!l._zoom.started)){d(i,i.series[j.seriesIndex],j)}if(e.bringSeriesToFront){i.moveSeriesToFront(j.seriesIndex)}}}}})(jQuery);