OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
openproject/assets/javascripts/jquery.jqplot/plugins/jqplot.cursor.min.js

14 lines
14 KiB

/**
* 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(i){i.jqplot.Cursor=function(o){this.style="crosshair";this.previousCursor="auto";this.show=i.jqplot.config.enablePlugins;this.showTooltip=true;this.followMouse=false;this.tooltipLocation="se";this.tooltipOffset=6;this.showTooltipGridPosition=false;this.showTooltipUnitPosition=true;this.showTooltipDataPosition=false;this.tooltipFormatString="%.4P, %.4P";this.useAxesFormatters=true;this.tooltipAxisGroups=[];this.zoom=false;this.zoomProxy=false;this.zoomTarget=false;this.clickReset=false;this.dblClickReset=true;this.showVerticalLine=false;this.showHorizontalLine=false;this.constrainZoomTo="none";this.shapeRenderer=new i.jqplot.ShapeRenderer();this._zoom={start:[],end:[],started:false,zooming:false,isZoomed:false,axes:{start:{},end:{}}};this._tooltipElem;this.zoomCanvas;this.cursorCanvas;this.intersectionThreshold=2;this.showCursorLegend=false;this.cursorLegendFormatString=i.jqplot.Cursor.cursorLegendFormatString;i.extend(true,this,o)};i.jqplot.Cursor.cursorLegendFormatString="%s x:%s, y:%s";i.jqplot.Cursor.init=function(t,r,q){var o=q||{};this.plugins.cursor=new i.jqplot.Cursor(o.cursor);var u=this.plugins.cursor;if(u.show){i.jqplot.eventListenerHooks.push(["jqplotMouseEnter",b]);i.jqplot.eventListenerHooks.push(["jqplotMouseLeave",f]);i.jqplot.eventListenerHooks.push(["jqplotMouseMove",h]);if(u.showCursorLegend){q.legend=q.legend||{};q.legend.renderer=i.jqplot.CursorLegendRenderer;q.legend.formatString=this.plugins.cursor.cursorLegendFormatString;q.legend.show=true}if(u.zoom){i.jqplot.eventListenerHooks.push(["jqplotMouseDown",a]);i.jqplot.eventListenerHooks.push(["jqplotMouseUp",n]);if(u.clickReset){i.jqplot.eventListenerHooks.push(["jqplotClick",j])}if(u.dblClickReset){i.jqplot.eventListenerHooks.push(["jqplotDblClick",c])}}this.resetZoom=function(){var x=this.axes;if(!u.zoomProxy){for(var w in x){x[w].reset()}this.redraw()}else{var v=this.plugins.cursor.zoomCanvas._ctx;v.clearRect(0,0,v.canvas.width,v.canvas.height)}this.plugins.cursor._zoom.isZoomed=false;this.target.trigger("jqplotResetZoom",[this,this.plugins.cursor])};if(u.showTooltipDataPosition){u.showTooltipUnitPosition=false;u.showTooltipGridPosition=false;if(o.cursor.tooltipFormatString==undefined){u.tooltipFormatString=i.jqplot.Cursor.cursorLegendFormatString}}}};i.jqplot.Cursor.postDraw=function(){var w=this.plugins.cursor;w.zoomCanvas=new i.jqplot.GenericCanvas();this.eventCanvas._elem.before(w.zoomCanvas.createElement(this._gridPadding,"jqplot-zoom-canvas",this._plotDimensions));var v=w.zoomCanvas.setContext();w._tooltipElem=i('<div class="jqplot-cursor-tooltip" style="position:absolute;display:none"></div>');w.zoomCanvas._elem.before(w._tooltipElem);if(w.showVerticalLine||w.showHorizontalLine){w.cursorCanvas=new i.jqplot.GenericCanvas();this.eventCanvas._elem.before(w.cursorCanvas.createElement(this._gridPadding,"jqplot-cursor-canvas",this._plotDimensions));var v=w.cursorCanvas.setContext()}if(w.showTooltipUnitPosition){if(w.tooltipAxisGroups.length===0){var r=this.series;var t;var o=[];for(var q=0;q<r.length;q++){t=r[q];var u=t.xaxis+","+t.yaxis;if(i.inArray(u,o)==-1){o.push(u)}}for(var q=0;q<o.length;q++){w.tooltipAxisGroups.push(o[q].split(","))}}}};i.jqplot.Cursor.zoomProxy=function(v,q){var o=v.plugins.cursor;var u=q.plugins.cursor;o.zoomTarget=true;o.zoom=true;o.style="auto";o.dblClickReset=false;u.zoom=true;u.zoomProxy=true;q.target.bind("jqplotZoom",t);q.target.bind("jqplotResetZoom",r);function t(x,w,z,y,A){o.doZoom(w,z,v,A)}function r(w,x,y){v.resetZoom()}};i.jqplot.Cursor.prototype.resetZoom=function(u,v){var t=u.axes;var r=v._zoom.axes;if(!u.plugins.cursor.zoomProxy&&v._zoom.isZoomed){for(var q in t){t[q]._ticks=[];t[q].min=r[q].min;t[q].max=r[q].max;t[q].numberTicks=r[q].numberTicks;t[q].tickInterval=r[q].tickInterval;t[q].daTickInterval=r[q].daTickInterval}u.redraw();v._zoom.isZoomed=false}else{var o=v.zoomCanvas._ctx;o.clearRect(0,0,o.canvas.width,o.canvas.height)}u.target.trigger("jqplotResetZoom",[u,v])};i.jqplot.Cursor.resetZoom=function(o){o.resetZoom()};i.jqplot.Cursor.prototype.doZoom=function(w,t,x,B){var z=B;var y=x.axes;var q=z._zoom.axes;var r=q.start;var u=q.end;var v,A;var C=x.plugins.cursor.zoomCanvas._ctx;if((z.constrainZoomTo=="none"&&Math.abs(w.x-z._zoom.start[0])>6&&Math.abs(w.y-z._zoom.start[1])>6)||(z.constrainZoomTo=="x"&&Math.abs(w.x-z._zoom.start[0])>6)||(z.constrainZoomTo=="y"&&Math.abs(w.y-z._zoom.start[1])>6)){if(!x.plugins.cursor.zoomProxy){for(var o in t){if(z._zoom.axes[o]==undefined){z._zoom.axes[o]={};z._zoom.axes[o].numberTicks=y[o].numberTicks;z._zoom.axes[o].tickInterval=y[o].tickInterval;z._zoom.axes[o].daTickInterval=y[o].daTickInterval;z._zoom.axes[o].min=y[o].min;z._zoom.axes[o].max=y[o].max}if((z.constrainZoomTo=="none")||(z.constrainZoomTo=="x"&&o.charAt(0)=="x")||(z.constrainZoomTo=="y"&&o.charAt(0)=="y")){dp=t[o];if(dp!=null){if(dp>r[o]){y[o].min=r[o];y[o].max=dp}else{span=r[o]-dp;y[o].max=r[o];y[o].min=dp}y[o].tickInterval=null;y[o].daTickInterval=null;y[o]._ticks=[]}}}C.clearRect(0,0,C.canvas.width,C.canvas.height);x.redraw();z._zoom.isZoomed=true}x.target.trigger("jqplotZoom",[w,t,x,B])}};i.jqplot.preInitHooks.push(i.jqplot.Cursor.init);i.jqplot.postDrawHooks.push(i.jqplot.Cursor.postDraw);function e(D,q,A){var F=A.plugins.cursor;var v="";var J=false;if(F.showTooltipGridPosition){v=D.x+", "+D.y;J=true}if(F.showTooltipUnitPosition){var C;for(var B=0;B<F.tooltipAxisGroups.length;B++){C=F.tooltipAxisGroups[B];if(J){v+="<br />"}if(F.useAxesFormatters){var z=A.axes[C[0]]._ticks[0].formatter;var o=A.axes[C[1]]._ticks[0].formatter;var G=A.axes[C[0]]._ticks[0].formatString;var u=A.axes[C[1]]._ticks[0].formatString;v+=z(G,q[C[0]])+", "+o(u,q[C[1]])}else{v+=i.jqplot.sprintf(F.tooltipFormatString,q[C[0]],q[C[1]])}J=true}}if(F.showTooltipDataPosition){var t=A.series;var I=d(A,D.x,D.y);var J=false;for(var B=0;B<t.length;B++){if(t[B].show){var x=t[B].index;var r=t[B].label.toString();var E=i.inArray(x,I.indices);var y=undefined;var w=undefined;if(E!=-1){var H=I.data[E].data;if(F.useAxesFormatters){var z=t[B]._xaxis._ticks[0].formatter;var o=t[B]._yaxis._ticks[0].formatter;var G=t[B]._xaxis._ticks[0].formatString;var u=t[B]._yaxis._ticks[0].formatString;y=z(G,H[0]);w=o(u,H[1])}else{y=H[0];w=H[1]}if(J){v+="<br />"}v+=i.jqplot.sprintf(F.tooltipFormatString,r,y,w);J=true}}}}F._tooltipElem.html(v)}function g(C,A){var E=A.plugins.cursor;var z=E.cursorCanvas._ctx;z.clearRect(0,0,z.canvas.width,z.canvas.height);if(E.showVerticalLine){E.shapeRenderer.draw(z,[[C.x,0],[C.x,z.canvas.height]])}if(E.showHorizontalLine){E.shapeRenderer.draw(z,[[0,C.y],[z.canvas.width,C.y]])}var G=d(A,C.x,C.y);if(E.showCursorLegend){var q=i(A.targetId+" td.jqplot-cursor-legend-label");for(var B=0;B<q.length;B++){var v=i(q[B]).data("seriesIndex");var t=A.series[v];var r=t.label.toString();var D=i.inArray(v,G.indices);var x=undefined;var w=undefined;if(D!=-1){var H=G.data[D].data;if(E.useAxesFormatters){var y=t._xaxis._ticks[0].formatter;var o=t._yaxis._ticks[0].formatter;var F=t._xaxis._ticks[0].formatString;var u=t._yaxis._ticks[0].formatString;x=y(F,H[0]);w=o(u,H[1])}else{x=H[0];w=H[1]}}if(A.legend.escapeHtml){i(q[B]).text(i.jqplot.sprintf(E.cursorLegendFormatString,r,x,w))}else{i(q[B]).html(i.jqplot.sprintf(E.cursorLegendFormatString,r,x,w))}}}}function d(w,D,C){var z={indices:[],data:[]};var E,u,q,A,t,o;var v;var B=w.plugins.cursor;for(var u=0;u<w.series.length;u++){E=w.series[u];o=E.renderer;if(E.show){v=B.intersectionThreshold;if(E.showMarker){v+=E.markerRenderer.size/2}for(var t=0;t<E.gridData.length;t++){p=E.gridData[t];if(B.showVerticalLine){if(Math.abs(D-p[0])<=v){z.indices.push(u);z.data.push({seriesIndex:u,pointIndex:t,gridData:p,data:E.data[t]})}}}}}return z}function m(q,t){var v=t.plugins.cursor;var r=v._tooltipElem;switch(v.tooltipLocation){case"nw":var o=q.x+t._gridPadding.left-r.outerWidth(true)-v.tooltipOffset;var u=q.y+t._gridPadding.top-v.tooltipOffset-r.outerHeight(true);break;case"n":var o=q.x+t._gridPadding.left-r.outerWidth(true)/2;var u=q.y+t._gridPadding.top-v.tooltipOffset-r.outerHeight(true);break;case"ne":var o=q.x+t._gridPadding.left+v.tooltipOffset;var u=q.y+t._gridPadding.top-v.tooltipOffset-r.outerHeight(true);break;case"e":var o=q.x+t._gridPadding.left+v.tooltipOffset;var u=q.y+t._gridPadding.top-r.outerHeight(true)/2;break;case"se":var o=q.x+t._gridPadding.left+v.tooltipOffset;var u=q.y+t._gridPadding.top+v.tooltipOffset;break;case"s":var o=q.x+t._gridPadding.left-r.outerWidth(true)/2;var u=q.y+t._gridPadding.top+v.tooltipOffset;break;case"sw":var o=q.x+t._gridPadding.left-r.outerWidth(true)-v.tooltipOffset;var u=q.y+t._gridPadding.top+v.tooltipOffset;break;case"w":var o=q.x+t._gridPadding.left-r.outerWidth(true)-v.tooltipOffset;var u=q.y+t._gridPadding.top-r.outerHeight(true)/2;break;default:var o=q.x+t._gridPadding.left+v.tooltipOffset;var u=q.y+t._gridPadding.top+v.tooltipOffset;break}v._tooltipElem.css("left",o);v._tooltipElem.css("top",u)}function l(u){var r=u._gridPadding;var v=u.plugins.cursor;var t=v._tooltipElem;switch(v.tooltipLocation){case"nw":var q=r.left+v.tooltipOffset;var o=r.top+v.tooltipOffset;t.css("left",q);t.css("top",o);break;case"n":var q=(r.left+(u._plotDimensions.width-r.right))/2-t.outerWidth(true)/2;var o=r.top+v.tooltipOffset;t.css("left",q);t.css("top",o);break;case"ne":var q=r.right+v.tooltipOffset;var o=r.top+v.tooltipOffset;t.css({right:q,top:o});break;case"e":var q=r.right+v.tooltipOffset;var o=(r.top+(u._plotDimensions.height-r.bottom))/2-t.outerHeight(true)/2;t.css({right:q,top:o});break;case"se":var q=r.right+v.tooltipOffset;var o=r.bottom+v.tooltipOffset;t.css({right:q,bottom:o});break;case"s":var q=(r.left+(u._plotDimensions.width-r.right))/2-t.outerWidth(true)/2;var o=r.bottom+v.tooltipOffset;t.css({left:q,bottom:o});break;case"sw":var q=r.left+v.tooltipOffset;var o=r.bottom+v.tooltipOffset;t.css({left:q,bottom:o});break;case"w":var q=r.left+v.tooltipOffset;var o=(r.top+(u._plotDimensions.height-r.bottom))/2-t.outerHeight(true)/2;t.css({left:q,top:o});break;default:var q=r.right-v.tooltipOffset;var o=r.bottom+v.tooltipOffset;t.css({right:q,bottom:o});break}}function j(q,o,u,t,r){q.stopPropagation();q.preventDefault();var v=r.plugins.cursor;if(v.clickReset){v.resetZoom(r,v)}return false}function c(q,o,u,t,r){q.stopPropagation();q.preventDefault();var v=r.plugins.cursor;if(v.dblClickReset){v.resetZoom(r,v)}return false}function f(w,t,o,z,u){var v=u.plugins.cursor;if(v.show){i(w.target).css("cursor",v.previousCursor);if(v.showTooltip){v._tooltipElem.hide()}if(v.zoom){v._zoom.started=false;v._zoom.zooming=false;if(!v.zoomProxy){var B=v.zoomCanvas._ctx;B.clearRect(0,0,B.canvas.width,B.canvas.height)}}if(v.showVerticalLine||v.showHorizontalLine){var B=v.cursorCanvas._ctx;B.clearRect(0,0,B.canvas.width,B.canvas.height)}if(v.showCursorLegend){var A=i(u.targetId+" td.jqplot-cursor-legend-label");for(var r=0;r<A.length;r++){var y=i(A[r]).data("seriesIndex");var q=u.series[y];var x=q.label.toString();if(u.legend.escapeHtml){i(A[r]).text(i.jqplot.sprintf(v.cursorLegendFormatString,x,undefined,undefined))}else{i(A[r]).html(i.jqplot.sprintf(v.cursorLegendFormatString,x,undefined,undefined))}}}}}function b(q,o,u,t,r){var v=r.plugins.cursor;if(v.show){v.previousCursor=q.target.style.cursor;q.target.style.cursor=v.style;if(v.showTooltip){e(o,u,r);if(v.followMouse){m(o,r)}else{l(r)}v._tooltipElem.show()}if(v.showVerticalLine||v.showHorizontalLine){g(o,r)}}}function h(r,q,v,u,t){var w=t.plugins.cursor;var o=w.zoomCanvas._ctx;if(w.show){if(w.showTooltip){e(q,v,t);if(w.followMouse){m(q,t)}}if(w.zoom&&w._zoom.started&&!w.zoomTarget){w._zoom.zooming=true;if(w.constrainZoomTo=="x"){w._zoom.end=[q.x,o.canvas.height]}else{if(w.constrainZoomTo=="y"){w._zoom.end=[o.canvas.width,q.y]}else{w._zoom.end=[q.x,q.y]}}k.call(w)}if(w.showVerticalLine||w.showHorizontalLine){g(q,t)}}}function a(w,r,q,x,t){var v=t.plugins.cursor;var u=t.axes;if(v.zoom){if(!v.zoomProxy){var y=v.zoomCanvas._ctx;y.clearRect(0,0,y.canvas.width,y.canvas.height)}if(v.constrainZoomTo=="x"){v._zoom.start=[r.x,0]}else{if(v.constrainZoomTo=="y"){v._zoom.start=[0,r.y]}else{v._zoom.start=[r.x,r.y]}}v._zoom.started=true;for(var o in q){v._zoom.axes.start[o]=q[o]}}}function n(q,o,u,t,r){var v=r.plugins.cursor;if(v.zoom&&v._zoom.zooming&&!v.zoomTarget){v.doZoom(o,u,r,v)}v._zoom.started=false;v._zoom.zooming=false}function k(){var y=this._zoom.start;var u=this._zoom.end;var r=this.zoomCanvas._ctx;var q,v,x,o;if(u[0]>y[0]){q=y[0];o=u[0]-y[0]}else{q=u[0];o=y[0]-u[0]}if(u[1]>y[1]){v=y[1];x=u[1]-y[1]}else{v=u[1];x=y[1]-u[1]}r.fillStyle="rgba(0,0,0,0.2)";r.strokeStyle="#999999";r.lineWidth=1;r.clearRect(0,0,r.canvas.width,r.canvas.height);r.fillRect(0,0,r.canvas.width,r.canvas.height);r.clearRect(q,v,o,x);r.strokeRect(q,v,o,x)}i.jqplot.CursorLegendRenderer=function(o){i.jqplot.TableLegendRenderer.call(this,o);this.formatString="%s"};i.jqplot.CursorLegendRenderer.prototype=new i.jqplot.TableLegendRenderer();i.jqplot.CursorLegendRenderer.prototype.constructor=i.jqplot.CursorLegendRenderer;i.jqplot.CursorLegendRenderer.prototype.draw=function(){if(this.show){var u=this._series;this._elem=i('<table class="jqplot-legend jqplot-cursor-legend" style="position:absolute"></table>');var x=false;for(var t=0;t<u.length;t++){s=u[t];if(s.show){var o=i.jqplot.sprintf(this.formatString,s.label.toString());if(o){var q=s.color;if(s._stack&&!s.fill){q=""}v.call(this,o,q,x,t);x=true}for(var r=0;r<i.jqplot.addLegendRowHooks.length;r++){var w=i.jqplot.addLegendRowHooks[r].call(this,s);if(w){v.call(this,w.label,w.color,x);x=true}}}}}function v(B,A,D,y){var z=(D)?this.rowSpacing:"0";var C=i('<tr class="jqplot-legend jqplot-cursor-legend"></tr>').appendTo(this._elem);C.data("seriesIndex",y);i('<td class="jqplot-legend jqplot-cursor-legend-swatch" style="padding-top:'+z+';"><div style="border:1px solid #cccccc;padding:0.2em;"><div class="jqplot-cursor-legend-swatch" style="background-color:'+A+';"></div></div></td>').appendTo(C);var E=i('<td class="jqplot-legend jqplot-cursor-legend-label" style="vertical-align:middle;padding-top:'+z+';"></td>');E.appendTo(C);E.data("seriesIndex",y);if(this.escapeHtml){E.text(B)}else{E.html(B)}}return this._elem}})(jQuery);