UNPKG

basb-cli

Version:
2 lines (1 loc) 6.54 kB
import{_ as t,m as e,$ as n,bQ as i,bh as a,J as r,I as o,aJ as s,A as c,cH as l,bV as u,e as d,d as h,b6 as p,d2 as m,ak as g,am as x,d3 as f,bU as y,cI as v,E as A,d4 as b,b as w}from"./index.js";import{a as M}from"./axisDefault.js";import{A as T}from"./AxisBuilder.js";import{a as _}from"./axisAlignTicks.js";import"./labelLayoutHelper.js";var L=M.value;function I(t,e){return n({show:e},t)}var N=function(u){function d(){var t=null!==u&&u.apply(this,arguments)||this;return t.type=d.type,t}return t(d,u),d.prototype.optionUpdated=function(){var t=this.get("boundaryGap"),u=this.get("splitNumber"),d=this.get("scale"),h=this.get("axisLine"),p=this.get("axisTick"),m=this.get("axisLabel"),g=this.get("axisName"),x=this.get(["axisName","show"]),f=this.get(["axisName","formatter"]),y=this.get("axisNameGap"),v=this.get("triggerEvent"),A=e(this.get("indicator")||[],(function(e){null!=e.max&&e.max>0&&!e.min?e.min=0:null!=e.min&&e.min<0&&!e.max&&(e.max=0);var A=g;null!=e.color&&(A=n({color:e.color},g));var b=i(a(e),{boundaryGap:t,splitNumber:u,scale:d,axisLine:h,axisTick:p,axisLabel:m,name:e.text,showName:x,nameLocation:"end",nameGap:y,nameTextStyle:A,triggerEvent:v},!1);if(r(f)){var w=b.name;b.name=f.replace("{value}",null!=w?w:"")}else o(f)&&(b.name=f(b.name,b));var M=new s(b,null,this.ecModel);return c(M,l.prototype),M.mainType="radar",M.componentIndex=this.componentIndex,M}),this);this._indicatorModels=A},d.prototype.getIndicatorModels=function(){return this._indicatorModels},d.type="radar",d.defaultOption={z:0,center:["50%","50%"],radius:"75%",startAngle:90,axisName:{show:!0},boundaryGap:[0,0],splitNumber:5,axisNameGap:15,scale:!1,shape:"polygon",axisLine:i({lineStyle:{color:"#bbb"}},L.axisLine),axisLabel:I(L.axisLabel,!1),axisTick:I(L.axisTick,!1),splitLine:I(L.splitLine,!0),splitArea:I(L.splitArea,!0),indicator:[]},d}(u),S=["axisLine","axisTickLabel","axisName"],k=function(i){function a(){var t=null!==i&&i.apply(this,arguments)||this;return t.type=a.type,t}return t(a,i),a.prototype.render=function(t,e,n){this.group.removeAll(),this._buildAxes(t),this._buildSplitLineAndArea(t)},a.prototype._buildAxes=function(t){var n=t.coordinateSystem,i=n.getIndicatorAxes(),a=e(i,(function(t){var e=t.model.get("showName")?t.name:"";return new T(t.model,{axisName:e,position:[n.cx,n.cy],rotation:t.angle,labelDirection:-1,tickDirection:-1,nameDirection:1})}));d(a,(function(t){d(S,t.add,t),this.group.add(t.getGroup())}),this)},a.prototype._buildSplitLineAndArea=function(t){var i=t.coordinateSystem,a=i.getIndicatorAxes();if(a.length){var r=t.get("shape"),o=t.getModel("splitLine"),s=t.getModel("splitArea"),c=o.getModel("lineStyle"),l=s.getModel("areaStyle"),u=o.get("show"),y=s.get("show"),v=c.get("color"),A=l.get("color"),b=h(v)?v:[v],w=h(A)?A:[A],M=[],T=[];if("circle"===r)for(var _=a[0].getTicksCoords(),L=i.cx,I=i.cy,N=0;N<_.length;N++){if(u)M[j(M,b,N)].push(new p({shape:{cx:L,cy:I,r:_[N].coord}}));if(y&&N<_.length-1)T[j(T,w,N)].push(new m({shape:{cx:L,cy:I,r0:_[N].coord,r:_[N+1].coord}}))}else{var S,k=e(a,(function(t,n){var a=t.getTicksCoords();return S=null==S?a.length-1:Math.min(a.length-1,S),e(a,(function(t){return i.coordToPoint(t.coord,n)}))})),D=[];for(N=0;N<=S;N++){for(var C=[],P=0;P<a.length;P++)C.push(k[P][N]);if(C[0]?C.push(C[0].slice()):console.error("Can't draw value axis "+N),u)M[j(M,b,N)].push(new g({shape:{points:C}}));if(y&&D)T[j(T,w,N-1)].push(new x({shape:{points:C.concat(D)}}));D=C.slice().reverse()}}var E=c.getLineStyle(),G=l.getAreaStyle();d(T,(function(t,e){this.group.add(f(t,{style:n({stroke:"none",fill:w[e%w.length]},G),silent:!0}))}),this),d(M,(function(t,e){this.group.add(f(t,{style:n({fill:"none",stroke:b[e%b.length]},E),silent:!0}))}),this)}function j(t,e,n){var i=n%e.length;return t[i]=t[i]||[],i}},a.type="radar",a}(y),D=function(e){function n(t,n,i){var a=e.call(this,t,n,i)||this;return a.type="value",a.angle=0,a.name="",a}return t(n,e),n}(v),C=function(){function t(t,n,i){this.dimensions=[],this._model=t,this._indicatorAxes=e(t.getIndicatorModels(),(function(t,e){var n="indicator_"+e,i=new D(n,new b);return i.name=t.get("name"),i.model=t,t.axis=i,this.dimensions.push(n),i}),this),this.resize(t,i)}return t.prototype.getIndicatorAxes=function(){return this._indicatorAxes},t.prototype.dataToPoint=function(t,e){var n=this._indicatorAxes[e];return this.coordToPoint(n.dataToCoord(t),e)},t.prototype.coordToPoint=function(t,e){var n=this._indicatorAxes[e].angle;return[this.cx+t*Math.cos(n),this.cy-t*Math.sin(n)]},t.prototype.pointToData=function(t){var e=t[0]-this.cx,n=t[1]-this.cy,i=Math.sqrt(e*e+n*n);e/=i,n/=i;for(var a,r=Math.atan2(-n,e),o=1/0,s=-1,c=0;c<this._indicatorAxes.length;c++){var l=this._indicatorAxes[c],u=Math.abs(r-l.angle);u<o&&(a=l,s=c,o=u)}return[s,+(a&&a.coordToData(i))]},t.prototype.resize=function(t,e){var n=t.get("center"),i=e.getWidth(),a=e.getHeight(),o=Math.min(i,a)/2;this.cx=A(n[0],i),this.cy=A(n[1],a),this.startAngle=t.get("startAngle")*Math.PI/180;var s=t.get("radius");(r(s)||w(s))&&(s=[0,s]),this.r0=A(s[0],o),this.r=A(s[1],o),d(this._indicatorAxes,(function(t,e){t.setExtent(this.r0,this.r);var n=this.startAngle+e*Math.PI*2/this._indicatorAxes.length;n=Math.atan2(Math.sin(n),Math.cos(n)),t.angle=n}),this)},t.prototype.update=function(t,e){var n=this._indicatorAxes,i=this._model;d(n,(function(t){t.scale.setExtent(1/0,-1/0)})),t.eachSeriesByType("radar",(function(e,a){if("radar"===e.get("coordinateSystem")&&t.getComponent("radar",e.get("radarIndex"))===i){var r=e.getData();d(n,(function(t){t.scale.unionExtentFromData(r,r.mapDimension(t.dim))}))}}),this);var a=i.get("splitNumber"),r=new b;r.setExtent(0,a),r.setInterval(1),d(n,(function(t,e){_(t.scale,t.model,r)}))},t.prototype.convertToPixel=function(t,e,n){return console.warn("Not implemented."),null},t.prototype.convertFromPixel=function(t,e,n){return console.warn("Not implemented."),null},t.prototype.containPoint=function(t){return console.warn("Not implemented."),!1},t.create=function(e,n){var i=[];return e.eachComponent("radar",(function(a){var r=new t(a,e,n);i.push(r),a.coordinateSystem=r})),e.eachSeriesByType("radar",(function(t){"radar"===t.get("coordinateSystem")&&(t.coordinateSystem=i[t.get("radarIndex")||0])})),i},t.dimensions=[],t}();function P(t){t.registerCoordinateSystem("radar",C),t.registerComponentModel(N),t.registerComponentView(k),t.registerVisual({seriesType:"radar",reset:function(t){var e=t.getData();e.each((function(t){e.setItemVisual(t,"legendIcon","roundRect")})),e.setVisual("legendIcon","roundRect")}})}export{P as install};