2 lines
7.0 KiB
JavaScript
2 lines
7.0 KiB
JavaScript
!function(a){function c(){return!!document.createElement("canvas").getContext}function d(){if(!c())return!1;var a=document.createElement("canvas"),b=a.getContext("2d");return"function"==typeof b.fillText}function e(){var a=document.createElement("div");return"undefined"!=typeof a.style.MozTransition||"undefined"!=typeof a.style.OTransition||"undefined"!=typeof a.style.webkitTransition||"undefined"!=typeof a.style.transition}function f(a,b,c,d,e){this.axisName=a,this.position=b,this.padding=c,this.plot=d,this.opts=e,this.width=0,this.height=0}function g(a,b,c,d,e){f.prototype.constructor.call(this,a,b,c,d,e)}function h(a,b,c,d,e){f.prototype.constructor.call(this,a,b,c,d,e),this.elem=null}function i(a,b,c,d,e){h.prototype.constructor.call(this,a,b,c,d,e)}function j(a,b,c,d,e){i.prototype.constructor.call(this,a,b,c,d,e),this.requiresResize=!1}function k(b){b.hooks.processOptions.push(function(b,c){if(c.axisLabels.show){var f=!1,k={},m=2;b.hooks.draw.push(function(b,c){var l=!1;f?(f=!1,a.each(b.getAxes(),function(a,c){var d=c.options||b.getOptions()[a];d&&d.axisLabel&&c.show&&k[a].draw(c.box)})):(a.each(b.getAxes(),function(a,c){var f=c.options||b.getOptions()[a];if(a in k&&(c.labelHeight=c.labelHeight-k[a].height,c.labelWidth=c.labelWidth-k[a].width,f.labelHeight=c.labelHeight,f.labelWidth=c.labelWidth,k[a].cleanup(),delete k[a]),f&&f.axisLabel&&c.show){l=!0;var n=null;if(f.axisLabelUseHtml||"Microsoft Internet Explorer"!=navigator.appName)n=f.axisLabelUseHtml||!e()&&!d()&&!f.axisLabelUseCanvas?h:f.axisLabelUseCanvas||!e()?g:i;else{var o=navigator.userAgent,p=new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})");null!=p.exec(o)&&(rv=parseFloat(RegExp.$1)),n=rv>=9&&!f.axisLabelUseCanvas&&!f.axisLabelUseHtml?i:f.axisLabelUseCanvas||f.axisLabelUseHtml?f.axisLabelUseCanvas?g:h:j}var q=void 0===f.axisLabelPadding?m:f.axisLabelPadding;k[a]=new n(a,c.position,q,b,f),k[a].calculateSize(),f.labelHeight=c.labelHeight+k[a].height,f.labelWidth=c.labelWidth+k[a].width}}),l&&(f=!0,b.setupGrid(),b.draw()))})}})}var b={axisLabels:{show:!0}};f.prototype.cleanup=function(){},g.prototype=new f,g.prototype.constructor=g,g.prototype.calculateSize=function(){this.opts.axisLabelFontSizePixels||(this.opts.axisLabelFontSizePixels=14),this.opts.axisLabelFontFamily||(this.opts.axisLabelFontFamily="sans-serif");this.opts.axisLabelFontSizePixels+this.padding,this.opts.axisLabelFontSizePixels+this.padding;"left"==this.position||"right"==this.position?(this.width=this.opts.axisLabelFontSizePixels+this.padding,this.height=0):(this.width=0,this.height=this.opts.axisLabelFontSizePixels+this.padding)},g.prototype.draw=function(a){this.opts.axisLabelColour||(this.opts.axisLabelColour="black");var b=this.plot.getCanvas().getContext("2d");b.save(),b.font=this.opts.axisLabelFontSizePixels+"px "+this.opts.axisLabelFontFamily,b.fillStyle=this.opts.axisLabelColour;var e,f,c=b.measureText(this.opts.axisLabel).width,d=this.opts.axisLabelFontSizePixels,g=0;"top"==this.position?(e=a.left+a.width/2-c/2,f=a.top+.72*d):"bottom"==this.position?(e=a.left+a.width/2-c/2,f=a.top+a.height-.72*d):"left"==this.position?(e=a.left+.72*d,f=a.height/2+a.top+c/2,g=-Math.PI/2):"right"==this.position&&(e=a.left+a.width-.72*d,f=a.height/2+a.top-c/2,g=Math.PI/2),b.translate(e,f),b.rotate(g),b.fillText(this.opts.axisLabel,0,0),b.restore()},h.prototype=new f,h.prototype.constructor=h,h.prototype.calculateSize=function(){var b=a('<div class="axisLabels" style="position:absolute;">'+this.opts.axisLabel+"</div>");this.plot.getPlaceholder().append(b),this.labelWidth=b.outerWidth(!0),this.labelHeight=b.outerHeight(!0),b.remove(),this.width=this.height=0,"left"==this.position||"right"==this.position?this.width=this.labelWidth+this.padding:this.height=this.labelHeight+this.padding},h.prototype.cleanup=function(){this.elem&&this.elem.remove()},h.prototype.draw=function(b){this.plot.getPlaceholder().find("#"+this.axisName+"Label").remove(),this.elem=a('<div id="'+this.axisName+'Label" " class="axisLabels" style="position:absolute;">'+this.opts.axisLabel+"</div>"),this.plot.getPlaceholder().append(this.elem),"top"==this.position?(this.elem.css("left",b.left+b.width/2-this.labelWidth/2+"px"),this.elem.css("top",b.top+"px")):"bottom"==this.position?(this.elem.css("left",b.left+b.width/2-this.labelWidth/2+"px"),this.elem.css("top",b.top+b.height-this.labelHeight+"px")):"left"==this.position?(this.elem.css("top",b.top+b.height/2-this.labelHeight/2+"px"),this.elem.css("left",b.left+"px")):"right"==this.position&&(this.elem.css("top",b.top+b.height/2-this.labelHeight/2+"px"),this.elem.css("left",b.left+b.width-this.labelWidth+"px"))},i.prototype=new h,i.prototype.constructor=i,i.prototype.calculateSize=function(){h.prototype.calculateSize.call(this),this.width=this.height=0,"left"==this.position||"right"==this.position?this.width=this.labelHeight+this.padding:this.height=this.labelHeight+this.padding},i.prototype.transforms=function(a,b,c){var d={"-moz-transform":"","-webkit-transform":"","-o-transform":"","-ms-transform":""};if(0!=b||0!=c){var e=" translate("+b+"px, "+c+"px)";d["-moz-transform"]+=e,d["-webkit-transform"]+=e,d["-o-transform"]+=e,d["-ms-transform"]+=e}if(0!=a){var g=" rotate("+a+"deg)";d["-moz-transform"]+=g,d["-webkit-transform"]+=g,d["-o-transform"]+=g,d["-ms-transform"]+=g}var h="top: 0; left: 0; ";for(var i in d)d[i]&&(h+=i+":"+d[i]+";");return h+=";"},i.prototype.calculateOffsets=function(a){var b={x:0,y:0,degrees:0};return"bottom"==this.position?(b.x=a.left+a.width/2-this.labelWidth/2,b.y=a.top+a.height-this.labelHeight):"top"==this.position?(b.x=a.left+a.width/2-this.labelWidth/2,b.y=a.top):"left"==this.position?(b.degrees=-90,b.x=a.left-this.labelWidth/2+this.labelHeight/2,b.y=a.height/2+a.top):"right"==this.position&&(b.degrees=90,b.x=a.left+a.width-this.labelWidth/2-this.labelHeight/2,b.y=a.height/2+a.top),b.x=Math.round(b.x),b.y=Math.round(b.y),b},i.prototype.draw=function(b){this.plot.getPlaceholder().find("."+this.axisName+"Label").remove();var c=this.calculateOffsets(b);this.elem=a('<div class="axisLabels '+this.axisName+'Label" style="position:absolute; '+this.transforms(c.degrees,c.x,c.y)+'">'+this.opts.axisLabel+"</div>"),this.plot.getPlaceholder().append(this.elem)},j.prototype=new i,j.prototype.constructor=j,j.prototype.transforms=function(a,b,c){var d="";if(0!=a){for(var e=a/90;e<0;)e+=4;d+=" filter: progid:DXImageTransform.Microsoft.BasicImage(rotation="+e+"); ",this.requiresResize="right"==this.position}return 0!=b&&(d+="left: "+b+"px; "),0!=c&&(d+="top: "+c+"px; "),d},j.prototype.calculateOffsets=function(a){var b=i.prototype.calculateOffsets.call(this,a);return"top"==this.position?b.y=a.top+1:"left"==this.position?(b.x=a.left,b.y=a.height/2+a.top-this.labelWidth/2):"right"==this.position&&(b.x=a.left+a.width-this.labelHeight,b.y=a.height/2+a.top-this.labelWidth/2),b},j.prototype.draw=function(a){i.prototype.draw.call(this,a),this.requiresResize&&(this.elem=this.plot.getPlaceholder().find("."+this.axisName+"Label"),this.elem.css("width",this.labelWidth),this.elem.css("height",this.labelHeight))},a.plot.plugins.push({init:k,options:b,name:"axisLabels",version:"2.0"})}(jQuery);
|