UNPKG

basb-cli

Version:
2 lines (1 loc) 7.86 kB
import{aY as t,_ as i,G as e,e as o,cP as n,as as r,cQ as s,d3 as a,$ as l,bV as p,A as h,cH as c,cI as u,cK as d,cO as g,ap as y,bt as f,bU as x,b9 as m}from"./index.js";import{A as v}from"./AxisBuilder.js";import{A}from"./AxisView.js";import{r as b,a as w}from"./axisSplitHelper.js";import{a as S}from"./axisModelCreator.js";import{b as _,d as C,g as T,B as z,m as D,e as L,i as P}from"./install23.js";import"./labelLayoutHelper.js";import"./axisDefault.js";function M(i,e){e=e||{};var o=i.coordinateSystem,n=i.axis,r={},s=n.position,a=n.orient,l=o.getRect(),p=[l.x,l.x+l.width,l.y,l.y+l.height],h={horizontal:{top:p[2],bottom:p[3]},vertical:{left:p[0],right:p[1]}};r.position=["vertical"===a?h.vertical[s]:p[0],"horizontal"===a?h.horizontal[s]:p[3]];r.rotation=Math.PI/2*{horizontal:0,vertical:1}[a];r.labelDirection=r.tickDirection=r.nameDirection={top:-1,bottom:1,right:1,left:-1}[s],i.get(["axisTick","inside"])&&(r.tickDirection=-r.tickDirection),t(e.labelInside,i.get(["axisLabel","inside"]))&&(r.labelDirection=-r.labelDirection);var c=e.rotate;return null==c&&(c=i.get(["axisLabel","rotate"])),r.labelRotation="top"===s?-c:c,r.z2=1,r}var k=["axisLine","axisTickLabel","axisName"],G=["splitArea","splitLine"],H=function(t){function r(){var i=null!==t&&t.apply(this,arguments)||this;return i.type=r.type,i.axisPointerClass="SingleAxisPointer",i}return i(r,t),r.prototype.render=function(i,r,s,a){var l=this.group;l.removeAll();var p=this._axisGroup;this._axisGroup=new e;var h=M(i),c=new v(i,h);o(k,c.add,c),l.add(this._axisGroup),l.add(c.getGroup()),o(G,(function(t){i.get([t,"show"])&&j[t](this,this.group,this._axisGroup,i)}),this),n(p,this._axisGroup,i),t.prototype.render.call(this,i,r,s,a)},r.prototype.remove=function(){b(this)},r.type="singleAxis",r}(A),j={splitLine:function(t,i,e,o){var n=o.axis;if(!n.scale.isBlank()){var p=o.getModel("splitLine"),h=p.getModel("lineStyle"),c=h.get("color");c=c instanceof Array?c:[c];for(var u=h.get("width"),d=o.coordinateSystem.getRect(),g=n.isHorizontal(),y=[],f=0,x=n.getTicksCoords({tickModel:p}),m=[],v=[],A=0;A<x.length;++A){var b=n.toGlobalCoord(x[A].coord);g?(m[0]=b,m[1]=d.y,v[0]=b,v[1]=d.y+d.height):(m[0]=d.x,m[1]=b,v[0]=d.x+d.width,v[1]=b);var w=new r({shape:{x1:m[0],y1:m[1],x2:v[0],y2:v[1]},silent:!0});s(w.shape,u);var S=f++%c.length;y[S]=y[S]||[],y[S].push(w)}var _=h.getLineStyle(["color"]);for(A=0;A<y.length;++A)i.add(a(y[A],{style:l({stroke:c[A%c.length]},_),silent:!0}))}},splitArea:function(t,i,e,o){w(t,e,o,o)}},R=H,B=function(t){function e(){var i=null!==t&&t.apply(this,arguments)||this;return i.type=e.type,i}return i(e,t),e.prototype.getCoordSysModel=function(){return this},e.type="singleAxis",e.layoutMode="box",e.defaultOption={left:"5%",top:"5%",right:"5%",bottom:"5%",type:"value",position:"bottom",orient:"horizontal",axisLine:{show:!0,lineStyle:{width:1,type:"solid"}},tooltip:{show:!0},axisTick:{show:!0,length:6,lineStyle:{width:1}},axisLabel:{show:!0,interval:"auto"},splitLine:{show:!0,lineStyle:{type:"dashed",opacity:.2}}},e}(p);h(B,c.prototype);var O=B,E=function(t){function e(i,e,o,n,r){var s=t.call(this,i,e,o)||this;return s.type=n||"value",s.position=r||"bottom",s}return i(e,t),e.prototype.isHorizontal=function(){var t=this.position;return"top"===t||"bottom"===t},e.prototype.pointToData=function(t,i){return this.coordinateSystem.pointToData(t)[0]},e}(u),I=["single"],V=function(){function t(t,i,e){this.type="single",this.dimension="single",this.dimensions=I,this.axisPointerEnabled=!0,this.model=t,this._init(t,i,e)}return t.prototype._init=function(t,i,e){var o=this.dimension,n=new E(o,d(t),[0,0],t.get("type"),t.get("position")),r="category"===n.type;n.onBand=r&&t.get("boundaryGap"),n.inverse=t.get("inverse"),n.orient=t.get("orient"),t.axis=n,n.model=t,n.coordinateSystem=this,this._axis=n},t.prototype.update=function(t,i){t.eachSeries((function(t){if(t.coordinateSystem===this){var i=t.getData();o(i.mapDimensionsAll(this.dimension),(function(t){this._axis.scale.unionExtentFromData(i,t)}),this),g(this._axis.scale,this._axis.model)}}),this)},t.prototype.resize=function(t,i){this._rect=y({left:t.get("left"),top:t.get("top"),right:t.get("right"),bottom:t.get("bottom"),width:t.get("width"),height:t.get("height")},{width:i.getWidth(),height:i.getHeight()}),this._adjustAxis()},t.prototype.getRect=function(){return this._rect},t.prototype._adjustAxis=function(){var t=this._rect,i=this._axis,e=i.isHorizontal(),o=e?[0,t.width]:[0,t.height],n=i.inverse?1:0;i.setExtent(o[n],o[1-n]),this._updateAxisTransform(i,e?t.x:t.y)},t.prototype._updateAxisTransform=function(t,i){var e=t.getExtent(),o=e[0]+e[1],n=t.isHorizontal();t.toGlobalCoord=n?function(t){return t+i}:function(t){return o-t+i},t.toLocalCoord=n?function(t){return t-i}:function(t){return o-t+i}},t.prototype.getAxis=function(){return this._axis},t.prototype.getBaseAxis=function(){return this._axis},t.prototype.getAxes=function(){return[this._axis]},t.prototype.getTooltipAxes=function(){return{baseAxes:[this.getAxis()],otherAxes:[]}},t.prototype.containPoint=function(t){var i=this.getRect(),e=this.getAxis();return"horizontal"===e.orient?e.contain(e.toLocalCoord(t[0]))&&t[1]>=i.y&&t[1]<=i.y+i.height:e.contain(e.toLocalCoord(t[1]))&&t[0]>=i.y&&t[0]<=i.y+i.height},t.prototype.pointToData=function(t){var i=this.getAxis();return[i.coordToData(i.toLocalCoord(t["horizontal"===i.orient?0:1]))]},t.prototype.dataToPoint=function(t){var i=this.getAxis(),e=this.getRect(),o=[],n="horizontal"===i.orient?0:1;return t instanceof Array&&(t=t[0]),o[n]=i.toGlobalCoord(i.dataToCoord(+t)),o[1-n]=0===n?e.y+e.height/2:e.x+e.width/2,o},t.prototype.convertToPixel=function(t,i,e){return F(i)===this?this.dataToPoint(e):null},t.prototype.convertFromPixel=function(t,i,e){return F(i)===this?this.pointToData(e):null},t}();function F(t){var i=t.seriesModel,e=t.singleAxisModel;return e&&e.coordinateSystem||i&&i.coordinateSystem}var K={create:function(t,i){var e=[];return t.eachComponent("singleAxis",(function(o,n){var r=new V(o,t,i);r.name="single_"+n,r.resize(o,i),o.coordinateSystem=r,e.push(r)})),t.eachSeries((function(t){if("singleAxis"===t.get("coordinateSystem")){var i=t.getReferringComponents("singleAxis",f).models[0];t.coordinateSystem=i&&i.coordinateSystem}})),e},dimensions:I},W=["x","y"],N=["width","height"],Q=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return i(e,t),e.prototype.makeElOption=function(t,i,e,o,n){var r=e.axis,s=r.coordinateSystem,a=$(s,1-Y(r)),l=s.dataToPoint(i)[0],p=o.get("type");if(p&&"none"!==p){var h=_(o),c=U[p](r,l,a);c.style=h,t.graphicKey=c.type,t.pointer=c}var u=M(e);C(i,t,u,e,o,n)},e.prototype.getHandleTransform=function(t,i,e){var o=M(i,{labelInside:!1});o.labelMargin=e.get(["handle","margin"]);var n=T(i.axis,t,o);return{x:n[0],y:n[1],rotation:o.rotation+(o.labelDirection<0?Math.PI:0)}},e.prototype.updateHandleTransform=function(t,i,e,o){var n=e.axis,r=n.coordinateSystem,s=Y(n),a=$(r,s),l=[t.x,t.y];l[s]+=i[s],l[s]=Math.min(a[1],l[s]),l[s]=Math.max(a[0],l[s]);var p=$(r,1-s),h=(p[1]+p[0])/2,c=[h,h];return c[s]=l[s],{x:l[0],y:l[1],rotation:t.rotation,cursorPoint:c,tooltipOption:{verticalAlign:"middle"}}},e}(z),U={line:function(t,i,e){return{type:"Line",subPixelOptimize:!0,shape:D([i,e[0]],[i,e[1]],Y(t))}},shadow:function(t,i,e){var o=t.getBandWidth(),n=e[1]-e[0];return{type:"Rect",shape:L([i-o/2,e[0]],[o,n],Y(t))}}};function Y(t){return t.isHorizontal()?0:1}function $(t,i){var e=t.getRect();return[e[W[i]],e[W[i]]+e[N[i]]]}var q=Q,J=function(t){function e(){var i=null!==t&&t.apply(this,arguments)||this;return i.type=e.type,i}return i(e,t),e.type="single",e}(x);function X(t){m(P),A.registerAxisPointerClass("SingleAxisPointer",q),t.registerComponentView(J),t.registerComponentView(R),t.registerComponentModel(O),S(t,"single",O,O.defaultOption),t.registerCoordinateSystem("single",K)}export{X as install};