grid-axis.js
7.25 KB
/*
Highcharts JS v6.2.0 (2018-10-17)
GridAxis
(c) 2016 Lars A. V. Cabrera
--- WORK IN PROGRESS ---
License: www.highcharts.com/license
*/
(function(f){"object"===typeof module&&module.exports?module.exports=f:"function"===typeof define&&define.amd?define(function(){return f}):f(Highcharts)})(function(f){(function(h){var v=function(a){return Array.prototype.slice.call(a,1)},f=h.dateFormat,q=h.defined,B=h.each,C=h.isArray,D=h.isNumber,t=function(a){return h.isObject(a,!0)},E=h.merge,z=h.pick,p=h.wrap,k=h.Axis,F=h.Tick,A={top:0,right:1,bottom:2,left:3,0:"top",1:"right",2:"bottom",3:"left"};k.prototype.isNavigatorAxis=function(){return/highcharts-navigator-[xy]axis/.test(this.options.className)};
k.prototype.isOuterAxis=function(){var a=this,b=-1,c=!0;B(a.chart.axes,function(l,d){l.side!==a.side||l.isNavigatorAxis()||(l===a?b=d:0<=b&&d>b&&(c=!1))});return c};k.prototype.getMaxLabelDimensions=function(a,b){var c={width:0,height:0};B(b,function(b){b=a[b];var d;t(b)&&(d=t(b.label)?b.label:{},b=d.getBBox?d.getBBox().height:0,d=D(d.textPxLength)?d.textPxLength:0,c.height=Math.max(b,c.height),c.width=Math.max(d,c.width))});return c};h.dateFormats={W:function(a){a=new Date(a);var b;a.setHours(0,
0,0,0);a.setDate(a.getDate()-(a.getDay()||7));b=new Date(a.getFullYear(),0,1);return Math.ceil(((a-b)/864E5+1)/7)},E:function(a){return f("%a",a,!0).charAt(0)}};p(k.prototype,"autoLabelAlign",function(a){return this.chart.isStock?"left":a.apply(this,v(arguments))});p(F.prototype,"getLabelPosition",function(a,b,c,l,d,x,u,w){var e=this.axis,g=e.reversed,n=e.chart,m=e.options,h=m&&t(m.grid)?m.grid:{},m=x.align,r=A[e.side],k=e.tickPositions,p=this.pos-u,q=D(k[w+1])?k[w+1]-u:e.max+u,f=e.tickSize("tick",
!0),k=C(f)?f[0]:0,f=f&&f[1]/2,y;!0===h.enabled?("top"===r?(h=e.top+e.offset,y=h-k):"bottom"===r?(y=n.chartHeight-e.bottom+e.offset,h=y+k):(h=e.top+e.len-e.translate(g?q:p),y=e.top+e.len-e.translate(g?p:q)),"right"===r?(r=n.chartWidth-e.right+e.offset,g=r+k):"left"===r?(g=e.left+e.offset,r=g-k):(r=Math.round(e.left+e.translate(g?q:p))-f,g=Math.round(e.left+e.translate(g?p:q))-f),this.slotWidth=g-r,g={x:"left"===m?r:"right"===m?g:r+(g-r)/2,y:y+(h-y)/2},n=n.renderer.fontMetrics(x.style.fontSize,l.element),
m=l.getBBox().height,x.useHTML?g.y+=n.b+-(m/2):(m=Math.round(m/n.h),g.y+=(n.b-(n.h-n.f))/2+-((m-1)*n.h/2)),g.x+=e.horiz&&x.x||0):g=a.apply(this,v(arguments));return g});p(k.prototype,"tickSize",function(a){var b=this.maxLabelDimensions,c=this.options,l=c&&t(c.grid)?c.grid:{},c=a.apply(this,v(arguments));!0===l.enabled&&(l=2*Math.abs(this.defaultLeftAxisOptions.labels.x),b=l+(this.horiz?b.height:b.width),C(c)?c[0]=b:c=[b]);return c});p(k.prototype,"getTitlePosition",function(a){var b=this.options;
if(!0===(b&&t(b.grid)?b.grid:{}).enabled){var c=this.axisTitle,l=c&&c.getBBox().width,d=this.horiz,x=this.left,u=this.top,w=this.width,e=this.height,g=b.title,b=this.opposite,n=this.offset,m=this.tickSize()||[0],h=g.x||0,k=g.y||0,f=z(g.margin,d?5:10),c=this.chart.renderer.fontMetrics(g.style&&g.style.fontSize,c).f,m=(d?u+e:x)+m[0]/2*(b?-1:1)*(d?1:-1)+(this.side===A.bottom?c:0);return{x:d?x-l/2-f+h:m+(b?w:0)+n+h,y:d?m-(b?e:0)+(b?c:-c)/2+n+k:u-f+k}}return a.apply(this,v(arguments))});p(k.prototype,
"unsquish",function(a){var b=this.options;return!0===(b&&t(b.grid)?b.grid:{}).enabled&&this.categories?this.tickInterval:a.apply(this,v(arguments))});h.addEvent(k,"afterSetOptions",function(a){var b=this.options;a=a.userOptions;var c,l=b&&t(b.grid)?b.grid:{};!0===l.enabled&&(c=E(!0,{className:"highcharts-grid-axis "+(a.className||""),dateTimeLabelFormats:{hour:{list:["%H:%M","%H"]},day:{list:["%A, %e. %B","%a, %e. %b","%E"]},week:{list:["Week %W","W%W"]},month:{list:["%B","%b","%o"]}},grid:{borderWidth:1},
labels:{padding:2,style:{fontSize:"13px"}},title:{text:null,reserveSpace:!1,rotation:0},units:[["millisecond",[1,10,100]],["second",[1,10]],["minute",[1,5,15]],["hour",[1,6]],["day",[1]],["week",[1]],["month",[1]],["year",null]]},a),"xAxis"===this.coll&&(q(a.linkedTo)&&!q(a.tickPixelInterval)&&(c.tickPixelInterval=350),q(a.tickPixelInterval)||!q(a.linkedTo)||q(a.tickPositioner)||q(a.tickInterval)||(c.tickPositioner=function(a,b){var d=this.linkedParent&&this.linkedParent.tickPositions&&this.linkedParent.tickPositions.info;
if(d){var l,e,g,n,m=c.units;for(n=0;n<m.length;n++)if(m[n][0]===d.unitName){l=n;break}if(m[l][1])return m[l+1]&&(g=m[l+1][0],e=(m[l+1][1]||[1])[0]),d=h.timeUnits[g],this.tickInterval=d*e,this.getTimeTicks({unitRange:d,count:e,unitName:g},a,b,this.options.startOfWeek)}})),E(!0,this.options,c),this.horiz&&(b.minPadding=z(a.minPadding,0),b.maxPadding=z(a.maxPadding,0)),D(b.grid.borderWidth)&&(b.tickWidth=b.lineWidth=l.borderWidth))});p(k.prototype,"setAxisTranslation",function(a){var b=this.options,
c=b&&t(b.grid)?b.grid:{},l=this.tickPositions&&this.tickPositions.info,d=this.userOptions.labels||{};this.horiz&&(!0===c.enabled&&B(this.series,function(a){a.options.pointRange=0}),l&&(!1===b.dateTimeLabelFormats[l.unitName].range||1<l.count)&&!q(d.align)&&(b.labels.align="left",q(d.x)||(b.labels.x=3)));a.apply(this,v(arguments))});p(k.prototype,"trimTicks",function(a){var b=this.options,c=b&&t(b.grid)?b.grid:{},l=this.categories,d=this.tickPositions,h=d[0],k=d[d.length-1],f=this.linkedParent&&this.linkedParent.min||
this.min,e=this.linkedParent&&this.linkedParent.max||this.max,g=this.tickInterval,n=h>f,m=k<e,h=h<f&&h+g>f,k=k>e&&k-g<e;!0!==c.enabled||l||!this.horiz&&!this.isLinked||(!n&&!h||b.startOnTick||(d[0]=f),!m&&!k||b.endOnTick||(d[d.length-1]=e));a.apply(this,v(arguments))});p(k.prototype,"render",function(a){var b=this.options,c=b&&t(b.grid)?b.grid:{},l,d,h,k,f,e=this.chart.renderer,g=this.horiz;if(!0===c.enabled){if(c=2*Math.abs(this.defaultLeftAxisOptions.labels.x),this.maxLabelDimensions=this.getMaxLabelDimensions(this.ticks,
this.tickPositions),c=this.maxLabelDimensions.width+c,l=b.lineWidth,this.rightWall&&this.rightWall.destroy(),a.apply(this),a=this.axisGroup.getBBox(),this.isOuterAxis()&&this.axisLine&&(g&&(c=a.height-1),l)){a=this.getLinePath(l);k=a.indexOf("M")+1;f=a.indexOf("L")+1;d=a.indexOf("M")+2;h=a.indexOf("L")+2;if(this.side===A.top||this.side===A.left)c=-c;g?(a[d]+=c,a[h]+=c):(a[k]+=c,a[f]+=c);this.axisLineExtra?this.axisLineExtra.animate({d:a}):this.axisLineExtra=e.path(a).attr({stroke:b.lineColor,"stroke-width":l,
zIndex:7}).addClass("highcharts-axis-line").add(this.axisGroup);this.axisLine[this.showAxis?"show":"hide"](!0)}}else a.apply(this)});p(k.prototype,"init",function(a,b,c){function l(a){var b=a.options,c=25/11,e=a.chart.renderer.fontMetrics(b.labels.style.fontSize);b.labels||(b.labels={});b.labels.align=z(b.labels.align,"center");a.categories||(b.showLastLabel=!1);a.horiz&&(b.tickLength=d.cellHeight||e.h*c);a.labelRotation=0;b.labels.rotation=0}var d=c&&t(c.grid)?c.grid:{},f,u,w;if(d.enabled)if(q(d.borderColor)&&
(c.tickColor=c.lineColor=d.borderColor),C(d.columns))for(u=0,w=d.columns.length;w--;)f=E(c,d.columns[w],{type:"category"}),delete f.grid.columns,f=new k(b,f),f.isColumn=!0,f.columnIndex=u,p(f,"labelFormatter",function(a){var b=this.axis,c=b.tickPositions,d=this.value,e=d===c[0],c=d===c[c.length-1],f=h.find(b.series[0].options.data,function(a){return a[b.isXAxis?"x":"y"]===d});this.isFirst=e;this.isLast=c;this.point=f;return a.call(this)}),u++;else a.apply(this,v(arguments)),l(this);else a.apply(this,
v(arguments))})})(f)});
//# sourceMappingURL=grid-axis.js.map