text: define(function(b,e){var f=b("../../util/layout");var g=b("../../coord/axisHelper");var c=b("zrender/core/util");var o=b("./Cartesian2D");var i=b("./Axis2D");var k=c.each;var m=g.ifAxisCrossZero;var j=g.niceScaleExtent;b("./GridModel");function h(q,r,p){return p.getComponent("grid",q.get("gridIndex"))===r}function l(t){var r=t.model;var w=r.getFormattedLabels();var v;var u=1;var p=w.length;if(p>40){u=Math.ceil(p/40)}for(var q=0;q<p;q+=u){if(!t.isLabelIgnored(q)){var s=r.getTextRect(w[q]);v?v.union(s):(v=s)}}return v}function d(r,p,q){this._coordsMap={};this._coordsList=[];this._axesMap={};this._axesList=[];this._initCartesian(r,p,q);this._model=r}var n=d.prototype;n.type="grid";n.getRect=function(){return this._rect};n.update=function(q,s){var r=this._axesMap;this._updateScale(q,this._model);function p(v){var w=r[v];for(var t in w){var u=w[t];if(u&&(u.type==="category"||!m(u))){return true}}return false}k(r.x,function(t){j(t,t.model)});k(r.y,function(t){j(t,t.model)});k(r.x,function(t){if(p("y")){t.onZero=false}});k(r.y,function(t){if(p("x")){t.onZero=false}});this.resize(this._model,s)};n.resize=function(s,q){var p=f.getLayoutRect(s.getBoxLayoutParams(),{width:q.getWidth(),height:q.getHeight()});this._rect=p;var r=this._axesList;t();if(s.get("containLabel")){k(r,function(v){if(!v.model.get("axisLabel.inside")){var u=l(v);if(u){var x=v.isHorizontal()?"height":"width";var w=v.model.get("axisLabel.margin");p[x]-=u[x]+w;if(v.position==="top"){p.y+=u.height+w}else{if(v.position==="left"){p.x+=u.width+w}}}}});t()}function t(){k(r,function(w){var x=w.isHorizontal();var v=x?[0,p.width]:[0,p.height];var u=w.inverse?1:0;w.setExtent(v[u],v[1-u]);a(w,x?p.x:p.y)})}};n.getAxis=function(p,r){var s=this._axesMap[p];if(s!=null){if(r==null){for(var q in s){return s[q]}}return s[r]}};n.getCartesian=function(p,r){var q="x"+p+"y"+r;return this._coordsMap[q]};n._initCartesian=function(u,q,t){var s={left:false,right:false,top:false,bottom:false};var r={x:{},y:{}};var v={x:0,y:0};q.eachComponent("xAxis",p("x"),this);q.eachComponent("yAxis",p("y"),this);if(!v.x||!v.y){this._axesMap={};this._axesList=[];return}this._axesMap=r;k(r.x,function(x,w){k(r.y,function(y,A){var z="x"+w+"y"+A;var B=new o(z);B.grid=this;this._coordsMap[z]=B;this._coordsList.push(B);B.addAxis(x);B.addAxis(y)},this)},this);function p(w){return function(A,x){if(!h(A,u,q)){return}var z=A.get("position");if(w==="x"){if(z!=="top"&&z!=="bottom"){z="bottom"}if(s[z]){z=z==="top"?"bottom":"top"}}else{if(z!=="left"&&z!=="right"){z="left"}if(s[z]){z=z==="left"?"right":"left"}}s[z]=true;var B=new i(w,g.createScaleByModel(A),[0,0],A.get("type"),z);var y=B.type==="category";B.onBand=y&&A.get("boundaryGap");B.inverse=A.get("inverse");B.onZero=A.get("axisLine.onZero");A.axis=B;B.model=A;B.index=x;this._axesList.push(B);r[w][x]=B;v[w]++}}};n._updateScale=function(p,q){c.each(this._axesList,function(s){s.scale.setExtent(Infinity,-Infinity)});p.eachSeries(function(u){if(u.get("coordinateSystem")==="cartesian2d"){var x=u.get("xAxisIndex");var A=u.get("yAxisIndex");var v=p.getComponent("xAxis",x);var z=p.getComponent("yAxis",A);if(!h(v,q,p)||!h(z,q,p)){return}var y=this.getCartesian(x,A);var w=u.getData();var t=y.getAxis("x");var s=y.getAxis("y");if(w.type==="list"){r(w,t,u);r(w,s,u)}}},this);function r(u,t,s){k(s.coordDimToDataDim(t.dim),function(v){t.scale.unionExtent(u.getDataExtent(v,t.scale.type!=="ordinal"))})}};function a(r,p){var s=r.getExtent();var q=s[0]+s[1];r.toGlobalCoord=r.dim==="x"?function(t){return t+p}:function(t){return q-t+p};r.toLocalCoord=r.dim==="x"?function(t){return t-p}:function(t){return q-t+p}}d.create=function(p,q){var r=[];p.eachComponent("grid",function(u,s){var t=new d(u,p,q);t.name="grid_"+s;t.resize(u,q);u.coordinateSystem=t;r.push(t)});p.eachSeries(function(s){if(s.get("coordinateSystem")!=="cartesian2d"){return}var u=s.get("xAxisIndex");var t=p.getComponent("xAxis",u);var v=r[t.get("gridIndex")];s.coordinateSystem=v.getCartesian(u,s.get("yAxisIndex"))});return r};d.dimensions=o.prototype.dimensions;b("../../CoordinateSystem").register("cartesian2d",d);return d});