grid-axis.js
7.21 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(l){"object"===typeof module&&module.exports?module.exports=l:"function"===typeof define&&define.amd?define(function(){return l}):l(Highcharts)})(function(l){(function(g){var w=function(b){return Array.prototype.slice.call(b,1)},l=g.dateFormat,r=g.defined,B=g.each,C=g.isArray,D=g.isNumber,u=function(b){return g.isObject(b,!0)},E=g.merge,z=g.pick,p=g.wrap,k=g.Axis,F=g.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 b=this,a=-1,c=!0;B(b.chart.axes,function(f,d){f.side!==b.side||f.isNavigatorAxis()||(f===b?a=d:0<=a&&d>a&&(c=!1))});return c};k.prototype.getMaxLabelDimensions=function(b,a){var c={width:0,height:0};B(a,function(a){a=b[a];var d;u(a)&&(d=u(a.label)?a.label:{},a=d.getBBox?d.getBBox().height:0,d=D(d.textPxLength)?d.textPxLength:0,c.height=Math.max(a,c.height),c.width=Math.max(d,c.width))});return c};g.dateFormats={W:function(b){b=new Date(b);var a;b.setHours(0,
0,0,0);b.setDate(b.getDate()-(b.getDay()||7));a=new Date(b.getFullYear(),0,1);return Math.ceil(((b-a)/864E5+1)/7)},E:function(b){return l("%a",b,!0).charAt(0)}};p(k.prototype,"autoLabelAlign",function(b){return this.chart.isStock?"left":b.apply(this,w(arguments))});p(F.prototype,"getLabelPosition",function(b,a,c,f,d,t,v,x){var e=this.axis,h=e.reversed,n=e.chart,m=e.options,g=m&&u(m.grid)?m.grid:{},m=t.align,q=A[e.side],k=e.tickPositions,p=this.pos-v,r=D(k[x+1])?k[x+1]-v:e.max+v,l=e.tickSize("tick",
!0),k=C(l)?l[0]:0,l=l&&l[1]/2,y;!0===g.enabled?("top"===q?(g=e.top+e.offset,y=g-k):"bottom"===q?(y=n.chartHeight-e.bottom+e.offset,g=y+k):(g=e.top+e.len-e.translate(h?r:p),y=e.top+e.len-e.translate(h?p:r)),"right"===q?(q=n.chartWidth-e.right+e.offset,h=q+k):"left"===q?(h=e.left+e.offset,q=h-k):(q=Math.round(e.left+e.translate(h?r:p))-l,h=Math.round(e.left+e.translate(h?p:r))-l),this.slotWidth=h-q,h={x:"left"===m?q:"right"===m?h:q+(h-q)/2,y:y+(g-y)/2},n=n.renderer.fontMetrics(t.style.fontSize,f.element),
m=f.getBBox().height,t.useHTML?h.y+=n.b+-(m/2):(m=Math.round(m/n.h),h.y+=(n.b-(n.h-n.f))/2+-((m-1)*n.h/2)),h.x+=e.horiz&&t.x||0):h=b.apply(this,w(arguments));return h});p(k.prototype,"tickSize",function(b){var a=this.maxLabelDimensions,c=this.options,f=c&&u(c.grid)?c.grid:{},c=b.apply(this,w(arguments));!0===f.enabled&&(f=2*Math.abs(this.defaultLeftAxisOptions.labels.x),a=f+(this.horiz?a.height:a.width),C(c)?c[0]=a:c=[a]);return c});p(k.prototype,"getTitlePosition",function(b){var a=this.options;
if(!0===(a&&u(a.grid)?a.grid:{}).enabled){var c=this.axisTitle,f=c&&c.getBBox().width,d=this.horiz,t=this.left,v=this.top,g=this.width,e=this.height,h=a.title,a=this.opposite,n=this.offset,m=this.tickSize()||[0],k=h.x||0,q=h.y||0,l=z(h.margin,d?5:10),c=this.chart.renderer.fontMetrics(h.style&&h.style.fontSize,c).f,m=(d?v+e:t)+m[0]/2*(a?-1:1)*(d?1:-1)+(this.side===A.bottom?c:0);return{x:d?t-f/2-l+k:m+(a?g:0)+n+k,y:d?m-(a?e:0)+(a?c:-c)/2+n+q:v-l+q}}return b.apply(this,w(arguments))});p(k.prototype,
"unsquish",function(b){var a=this.options;return!0===(a&&u(a.grid)?a.grid:{}).enabled&&this.categories?this.tickInterval:b.apply(this,w(arguments))});g.addEvent(k,"afterSetOptions",function(b){var a=this.options;b=b.userOptions;var c,f=a&&u(a.grid)?a.grid:{};!0===f.enabled&&(c=E(!0,{className:"highcharts-grid-axis "+(b.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]]},b),"xAxis"===this.coll&&(r(b.linkedTo)&&!r(b.tickPixelInterval)&&(c.tickPixelInterval=350),r(b.tickPixelInterval)||!r(b.linkedTo)||r(b.tickPositioner)||r(b.tickInterval)||(c.tickPositioner=function(a,b){var d=this.linkedParent&&this.linkedParent.tickPositions&&this.linkedParent.tickPositions.info;
if(d){var f,e,h,n,m=c.units;for(n=0;n<m.length;n++)if(m[n][0]===d.unitName){f=n;break}if(m[f][1])return m[f+1]&&(h=m[f+1][0],e=(m[f+1][1]||[1])[0]),d=g.timeUnits[h],this.tickInterval=d*e,this.getTimeTicks({unitRange:d,count:e,unitName:h},a,b,this.options.startOfWeek)}})),E(!0,this.options,c),this.horiz&&(a.minPadding=z(b.minPadding,0),a.maxPadding=z(b.maxPadding,0)),D(a.grid.borderWidth)&&(a.tickWidth=a.lineWidth=f.borderWidth))});p(k.prototype,"setAxisTranslation",function(b){var a=this.options,
c=a&&u(a.grid)?a.grid:{},f=this.tickPositions&&this.tickPositions.info,d=this.userOptions.labels||{};this.horiz&&(!0===c.enabled&&B(this.series,function(a){a.options.pointRange=0}),f&&(!1===a.dateTimeLabelFormats[f.unitName].range||1<f.count)&&!r(d.align)&&(a.labels.align="left",r(d.x)||(a.labels.x=3)));b.apply(this,w(arguments))});p(k.prototype,"trimTicks",function(b){var a=this.options,c=a&&u(a.grid)?a.grid:{},f=this.categories,d=this.tickPositions,t=d[0],g=d[d.length-1],k=this.linkedParent&&this.linkedParent.min||
this.min,e=this.linkedParent&&this.linkedParent.max||this.max,h=this.tickInterval,n=t>k,m=g<e,t=t<k&&t+h>k,g=g>e&&g-h<e;!0!==c.enabled||f||!this.horiz&&!this.isLinked||(!n&&!t||a.startOnTick||(d[0]=k),!m&&!g||a.endOnTick||(d[d.length-1]=e));b.apply(this,w(arguments))});p(k.prototype,"render",function(b){var a=this.options,c=a&&u(a.grid)?a.grid:{},f,d,g,k=this.chart.renderer,l=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,a=a.lineWidth,this.rightWall&&this.rightWall.destroy(),b.apply(this),b=this.axisGroup.getBBox(),this.isOuterAxis()&&this.axisLine&&(l&&(c=b.height-1),a)){b=this.getLinePath(a);d=b.indexOf("M")+1;g=b.indexOf("L")+1;a=b.indexOf("M")+2;f=b.indexOf("L")+2;if(this.side===A.top||this.side===A.left)c=-c;l?(b[a]+=c,b[f]+=c):(b[d]+=c,b[g]+=c);this.axisLineExtra?this.axisLineExtra.animate({d:b}):this.axisLineExtra=k.path(b).attr({zIndex:7}).addClass("highcharts-axis-line").add(this.axisGroup);
this.axisLine[this.showAxis?"show":"hide"](!0)}}else b.apply(this)});p(k.prototype,"init",function(b,a,c){function f(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&&u(c.grid)?c.grid:{},l,v,x;if(d.enabled)if(r(d.borderColor)&&(c.tickColor=c.lineColor=d.borderColor),C(d.columns))for(v=
0,x=d.columns.length;x--;)l=E(c,d.columns[x],{type:"category"}),delete l.grid.columns,l=new k(a,l),l.isColumn=!0,l.columnIndex=v,p(l,"labelFormatter",function(a){var b=this.axis,c=b.tickPositions,d=this.value,e=d===c[0],c=d===c[c.length-1],f=g.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)}),v++;else b.apply(this,w(arguments)),f(this);else b.apply(this,w(arguments))})})(l)});
//# sourceMappingURL=grid-axis.js.map