(function(k){k.jqplot.CategoryAxisRenderer=function(){k.jqplot.LinearAxisRenderer.call(this);this.sortMergedLabels=false};k.jqplot.CategoryAxisRenderer.prototype=new k.jqplot.LinearAxisRenderer;k.jqplot.CategoryAxisRenderer.prototype.constructor=k.jqplot.CategoryAxisRenderer;k.jqplot.CategoryAxisRenderer.prototype.init=function(d){this.groups=1;this.groupLabels=[];this._groupLabels=[];this._grouped=false;this._barsPerGroup=null;k.extend(true,this,{tickOptions:{formatString:"%d"}},d);d=this._dataBounds;
for(var b=0;b<this._series.length;b++){var a=this._series[b];if(a.groups)this.groups=a.groups;a=a.data;for(var g=0;g<a.length;g++)if(this.name=="xaxis"||this.name=="x2axis"){if(a[g][0]<d.min||d.min==null)d.min=a[g][0];if(a[g][0]>d.max||d.max==null)d.max=a[g][0]}else{if(a[g][1]<d.min||d.min==null)d.min=a[g][1];if(a[g][1]>d.max||d.max==null)d.max=a[g][1]}}if(this.groupLabels.length)this.groups=this.groupLabels.length};k.jqplot.CategoryAxisRenderer.prototype.createTicks=function(){var d=this.ticks,b=
this.name,a,g;if(d.length){if(this.groups>1&&!this._grouped){var e=d.length,f=parseInt(e/this.groups,10),j=0;for(b=f;b<e;b+=f){d.splice(b+j,0," ");j++}this._grouped=true}this.min=0.5;this.max=d.length+0.5;e=this.max-this.min;this.numberTicks=2*d.length+1;for(b=0;b<d.length;b++){g=this.min+2*b*e/(this.numberTicks-1);a=new this.tickRenderer(this.tickOptions);a.showLabel=false;a.setTick(g,this.name);this._ticks.push(a);a=new this.tickRenderer(this.tickOptions);a.label=d[b];a.showMark=false;a.showGridline=
false;a.setTick(g+0.5,this.name);this._ticks.push(a)}a=new this.tickRenderer(this.tickOptions);a.showLabel=false;a.setTick(g+1,this.name);this._ticks.push(a)}else{a=b=="xaxis"||b=="x2axis"?this._plotDimensions.width:this._plotDimensions.height;if(this.min!=null&&this.max!=null&&this.numberTicks!=null)this.tickInterval=null;if(this.min!=null&&this.max!=null&&this.tickInterval!=null)if(parseInt((this.max-this.min)/this.tickInterval,10)!=(this.max-this.min)/this.tickInterval)this.tickInterval=null;d=
[];g=0;var l=false;for(b=0;b<this._series.length;b++){f=this._series[b];for(e=0;e<f.data.length;e++){j=this.name=="xaxis"||this.name=="x2axis"?f.data[e][0]:f.data[e][1];if(k.inArray(j,d)==-1){l=true;g+=1;d.push(j)}}}l&&this.sortMergedLabels&&d.sort(function(h,i){return h-i});this.ticks=d;for(b=0;b<this._series.length;b++){f=this._series[b];for(e=0;e<f.data.length;e++){j=this.name=="xaxis"||this.name=="x2axis"?f.data[e][0]:f.data[e][1];j=k.inArray(j,d)+1;if(this.name=="xaxis"||this.name=="x2axis")f.data[e][0]=
j;else f.data[e][1]=j}}if(this.groups>1&&!this._grouped){e=d.length;f=parseInt(e/this.groups,10);j=0;for(b=f;b<e;b+=f+1)d[b]=" ";this._grouped=true}b=g+0.5;if(this.numberTicks==null)this.numberTicks=2*g+1;e=b-0.5;this.min=0.5;this.max=b;j=0;b=parseInt(3+a/10,10);f=parseInt(g/b,10);if(this.tickInterval==null)this.tickInterval=e/(this.numberTicks-1);for(b=0;b<this.numberTicks;b++){g=this.min+b*this.tickInterval;a=new this.tickRenderer(this.tickOptions);if(b/2==parseInt(b/2,10)){a.showLabel=false;a.showMark=
true}else{if(f>0&&j<f){a.showLabel=false;j+=1}else{a.showLabel=true;j=0}a.label=a.formatter(a.formatString,d[(b-1)/2]);a.showMark=false;a.showGridline=false}a.setTick(g,this.name);this._ticks.push(a)}}};k.jqplot.CategoryAxisRenderer.prototype.draw=function(d,b){if(this.show){this.renderer.createTicks.call(this);this._elem&&this._elem.emptyForce();this._elem=this._elem||k('<div class="jqplot-axis jqplot-'+this.name+'" style="position:absolute;"></div>');this.name=="xaxis"||this.name=="x2axis"?this._elem.width(this._plotDimensions.width):
this._elem.height(this._plotDimensions.height);this.labelOptions.axis=this.name;this._label=new this.labelRenderer(this.labelOptions);if(this._label.show){var a=this._label.draw(d,b);a.appendTo(this._elem)}for(var g=this._ticks,e=0;e<g.length;e++){a=g[e];if(a.showLabel&&(!a.isMinorTick||this.showMinorTicks)){a=a.draw(d,b);a.appendTo(this._elem)}}this._groupLabels=[];for(e=0;e<this.groupLabels.length;e++){a=k('<div style="position:absolute;" class="jqplot-'+this.name+'-groupLabel"></div>');a.html(this.groupLabels[e]);
this._groupLabels.push(a);a.appendTo(this._elem)}}return this._elem};k.jqplot.CategoryAxisRenderer.prototype.set=function(){var d=0,b,a=0,g=0,e=this._label==null?false:this._label.show;if(this.show){for(var f=this._ticks,j=0;j<f.length;j++){b=f[j];if(b.showLabel&&(!b.isMinorTick||this.showMinorTicks)){b=this.name=="xaxis"||this.name=="x2axis"?b._elem.outerHeight(true):b._elem.outerWidth(true);if(b>d)d=b}}for(j=f=0;j<this._groupLabels.length;j++){b=this._groupLabels[j];b=this.name=="xaxis"||this.name==
"x2axis"?b.outerHeight(true):b.outerWidth(true);if(b>f)f=b}if(e){a=this._label._elem.outerWidth(true);g=this._label._elem.outerHeight(true)}if(this.name=="xaxis"){d+=f+g;this._elem.css({height:d+"px",left:"0px",bottom:"0px"})}else if(this.name=="x2axis"){d+=f+g;this._elem.css({height:d+"px",left:"0px",top:"0px"})}else{if(this.name=="yaxis"){d+=f+a;this._elem.css({width:d+"px",left:"0px",top:"0px"})}else{d+=f+a;this._elem.css({width:d+"px",right:"0px",top:"0px"})}e&&this._label.constructor==k.jqplot.AxisLabelRenderer&&
this._label._elem.css("width",a+"px")}}};k.jqplot.CategoryAxisRenderer.prototype.pack=function(d,b){var a=this._ticks,g=this.max,e=this.min,f=b.max,j=b.min,l=this._label==null?false:this._label.show,h,i;for(i in d)this._elem.css(i,d[i]);this._offsets=b;var o=f-j,p=g-e;this.p2u=function(m){return(m-j)*p/o+e};this.u2p=function(m){return(m-e)*o/p+j};if(this.name=="xaxis"||this.name=="x2axis"){this.series_u2p=function(m){return(m-e)*o/p};this.series_p2u=function(m){return m*p/o+e}}else{this.series_u2p=
function(m){return(m-g)*o/p};this.series_p2u=function(m){return m*p/o+g}}if(this.show)if(this.name=="xaxis"||this.name=="x2axis"){for(h=0;h<a.length;h++){var c=a[h];if(c.show&&c.showLabel){if(c.constructor==k.jqplot.CanvasAxisTickRenderer&&c.angle){i=this.name=="xaxis"?1:-1;switch(c.labelPosition){case "auto":i=i*c.angle<0?-c.getWidth()+c._textRenderer.height*Math.sin(-c._textRenderer.angle)/2:-c._textRenderer.height*Math.sin(c._textRenderer.angle)/2;break;case "end":i=-c.getWidth()+c._textRenderer.height*
Math.sin(-c._textRenderer.angle)/2;break;case "start":i=-c._textRenderer.height*Math.sin(c._textRenderer.angle)/2;break;case "middle":i=-c.getWidth()/2+c._textRenderer.height*Math.sin(-c._textRenderer.angle)/2;break;default:i=-c.getWidth()/2+c._textRenderer.height*Math.sin(-c._textRenderer.angle)/2}}else i=-c.getWidth()/2;i=this.u2p(c.value)+i+"px";c._elem.css("left",i);c.pack()}}a=["bottom",0];if(l){h=this._label._elem.outerWidth(true);this._label._elem.css("left",j+o/2-h/2+"px");if(this.name=="xaxis"){this._label._elem.css("bottom",
"0px");a=["bottom",this._label._elem.outerHeight(true)]}else{this._label._elem.css("top","0px");a=["top",this._label._elem.outerHeight(true)]}this._label.pack()}f=parseInt(this._ticks.length/this.groups,10);for(h=0;h<this._groupLabels.length;h++){for(var q=l=0,n=h*f;n<=(h+1)*f;n++)if(this._ticks[n]._elem&&this._ticks[n].label!=" "){c=this._ticks[n]._elem;i=c.position();l+=i.left+c.outerWidth(true)/2;q++}l/=q;this._groupLabels[h].css({left:l-this._groupLabels[h].outerWidth(true)/2});this._groupLabels[h].css(a[0],
a[1])}}else{for(h=0;h<a.length;h++){c=a[h];if(c.show&&c.showLabel){if(c.constructor==k.jqplot.CanvasAxisTickRenderer&&c.angle){i=this.name=="yaxis"?1:-1;switch(c.labelPosition){case "auto":case "end":i=i*c.angle<0?-c._textRenderer.height*Math.cos(-c._textRenderer.angle)/2:-c.getHeight()+c._textRenderer.height*Math.cos(c._textRenderer.angle)/2;break;case "start":i=c.angle>0?-c._textRenderer.height*Math.cos(-c._textRenderer.angle)/2:-c.getHeight()+c._textRenderer.height*Math.cos(c._textRenderer.angle)/
2;break;case "middle":i=-c.getHeight()/2;break;default:i=-c.getHeight()/2}}else i=-c.getHeight()/2;i=this.u2p(c.value)+i+"px";c._elem.css("top",i);c.pack()}}a=["left",0];if(l){h=this._label._elem.outerHeight(true);this._label._elem.css("top",f-o/2-h/2+"px");if(this.name=="yaxis"){this._label._elem.css("left","0px");a=["left",this._label._elem.outerWidth(true)]}else{this._label._elem.css("right","0px");a=["right",this._label._elem.outerWidth(true)]}this._label.pack()}f=parseInt(this._ticks.length/
this.groups,10);for(h=0;h<this._groupLabels.length;h++){q=l=0;for(n=h*f;n<=(h+1)*f;n++)if(this._ticks[n]._elem&&this._ticks[n].label!=" "){c=this._ticks[n]._elem;i=c.position();l+=i.top+c.outerHeight()/2;q++}l/=q;this._groupLabels[h].css({top:l-this._groupLabels[h].outerHeight()/2});this._groupLabels[h].css(a[0],a[1])}}}})(jQuery);
