UNPKG

basb-cli

Version:
2 lines (1 loc) 16.5 kB
import{_ as e,c as t,e as r,S as a,i,a as n,b as o,d as s,w as l,t as d,f as h,u,s as c,l as g,r as p,G as f,m,g as y,C as v,R as b,h as A,j as x,k as _,n as S,o as w,p as I,P as k,q as L,v as C,x as M,y as R,z as D}from"./index.js";import{d as O}from"./dataSample.js";import{c as E}from"./createClipPathFromCoordSys.js";import{S as T}from"./sausage.js";import{i as P}from"./CoordinateSystem.js";import{g as N,a as V}from"./labelHelper.js";import{g as z}from"./sectorHelper.js";var G=function(a){function i(){var e=null!==a&&a.apply(this,arguments)||this;return e.type=i.type,e}return e(i,a),i.prototype.getInitialData=function(e,r){return t(null,this,{useEncodeDefaulter:!0})},i.prototype.getMarkerPosition=function(e,t,a){var i=this.coordinateSystem;if(i&&i.clampData){var n=i.clampData(e),o=i.dataToPoint(n);if(a)r(i.getAxes(),(function(e,r){if("category"===e.type&&null!=t){var a=e.getTicksCoords(),i=e.getTickModel().get("alignWithLabel"),s=n[r],l="x1"===t[r]||"y1"===t[r];if(l&&!i&&(s+=1),a.length<2)return;if(2===a.length)return void(o[r]=e.toGlobalCoord(e.getExtent()[l?1:0]));for(var d=void 0,h=void 0,u=1,c=0;c<a.length;c++){var g=a[c].coord,p=c===a.length-1?a[c-1].tickValue+u:a[c].tickValue;if(p===s){h=g;break}if(p<s)d=g;else if(null!=d&&p>s){h=(g+d)/2;break}1===c&&(u=p-a[0].tickValue)}null==h&&(d?d&&(h=a[a.length-1].coord):h=a[0].coord),o[r]=e.toGlobalCoord(h)}}));else{var s=this.getData(),l=s.getLayout("offset"),d=s.getLayout("size"),h=i.getBaseAxis().isHorizontal()?0:1;o[h]+=l+d/2}return o}return[NaN,NaN]},i.type="series.__base_bar__",i.defaultOption={z:2,coordinateSystem:"cartesian2d",legendHoverLink:!0,barMinHeight:0,barMinAngle:0,large:!1,largeThreshold:400,progressive:3e3,progressiveChunkMode:"mod"},i}(a);a.registerClass(G);var B=function(r){function a(){var e=null!==r&&r.apply(this,arguments)||this;return e.type=a.type,e}return e(a,r),a.prototype.getInitialData=function(){return t(null,this,{useEncodeDefaulter:!0,createInvertedIndices:!!this.get("realtimeSort",!0)||null})},a.prototype.getProgressive=function(){return!!this.get("large")&&this.get("progressive")},a.prototype.getProgressiveThreshold=function(){var e=this.get("progressiveThreshold"),t=this.get("largeThreshold");return t>e&&(e=t),e},a.prototype.brushSelector=function(e,t,r){return r.rect(t.getItemLayout(e))},a.type="series.bar",a.dependencies=["grid","polar"],a.defaultOption=i(G.defaultOption,{clip:!0,roundCap:!1,showBackground:!1,backgroundStyle:{color:"rgba(180, 180, 180, 0.2)",borderColor:null,borderWidth:0,borderType:"solid",borderRadius:0,shadowBlur:0,shadowColor:null,shadowOffsetX:0,shadowOffsetY:0,opacity:1},select:{itemStyle:{borderColor:"#212121"}},realtimeSort:!1}),a}(G);function W(e,t,r){return t*Math.sin(e)*(r?-1:1)}function F(e,t,r){return t*Math.cos(e)*(r?1:-1)}var H=Math.max,j=Math.min;var U=function(t){function r(){var e=t.call(this)||this;return e.type=r.type,e._isFirstFrame=!0,e}return e(r,t),r.prototype.render=function(e,t,r,a){this._model=e,this._removeOnRenderedListener(r),this._updateDrawMode(e);var i=e.get("coordinateSystem");"cartesian2d"===i||"polar"===i?(this._progressiveEls=null,this._isLargeDraw?this._renderLarge(e,t,r):this._renderNormal(e,t,r,a)):l("Only cartesian2d and polar supported for bar.")},r.prototype.incrementalPrepareRender=function(e){this._clear(),this._updateDrawMode(e),this._updateLargeClip(e)},r.prototype.incrementalRender=function(e,t){this._progressiveEls=[],this._incrementalRenderLarge(e,t)},r.prototype.eachRendered=function(e){d(this._progressiveEls||this.group,e)},r.prototype._updateDrawMode=function(e){var t=e.pipelineContext.large;null!=this._isLargeDraw&&t===this._isLargeDraw||(this._isLargeDraw=t,this._clear())},r.prototype._renderNormal=function(e,t,r,a){var i,n=this.group,o=e.getData(),s=this._data,d=e.coordinateSystem,m=d.getBaseAxis();"cartesian2d"===d.type?i=m.isHorizontal():"polar"===d.type&&(i="angle"===m.dim);var y=e.isAnimationEnabled()?e:null,v=function(e,t){var r=e.get("realtimeSort",!0),a=t.getBaseAxis();r&&("category"!==a.type&&l("`realtimeSort` will not work because this bar series is not based on a category axis."),"cartesian2d"!==t.type&&l("`realtimeSort` will not work because this bar series is not on cartesian2d."));if(r&&"category"===a.type&&"cartesian2d"===t.type)return{baseAxis:a,otherAxis:t.getOtherAxis(a)}}(e,d);v&&this._enableRealtimeSort(v,o,r);var A=e.get("clip",!0)||v,x=function(e,t){var r=e.getArea&&e.getArea();if(P(e,"cartesian2d")){var a=e.getBaseAxis();if("category"!==a.type||!a.onBand){var i=t.getLayout("bandWidth");a.isHorizontal()?(r.x-=i,r.width+=2*i):(r.y-=i,r.height+=2*i)}}return r}(d,o);n.removeClipPath();var _=e.get("roundCap",!0),S=e.get("showBackground",!0),w=e.getModel("backgroundStyle"),I=w.get("borderRadius")||0,k=[],L=this._backgroundEls,M=a&&a.isInitSort,R=a&&"changeAxisOrder"===a.type;function D(e){var t=$[d.type](o,e),r=function(e,t,r){var a="polar"===e.type?C:b;return new a({shape:oe(t,r,e),silent:!0,z2:0})}(d,i,t);return r.useStyle(w.getItemStyle()),"cartesian2d"===d.type?r.setShape("r",I):r.setShape("cornerRadius",I),k[e]=r,r}o.diff(s).add((function(t){var r=o.getItemModel(t),a=$[d.type](o,t,r);if(S&&D(t),o.hasValue(t)&&Q[d.type](a)){var s=!1;A&&(s=Y[d.type](x,a));var l=X[d.type](e,o,t,a,i,y,m.model,!1,_);v&&(l.forceLabelAnimation=!0),te(l,o,t,r,a,e,i,"polar"===d.type),M?l.attr({shape:a}):v?q(v,y,l,a,t,i,!1,!1):h(l,{shape:a},e,t),o.setItemGraphicEl(t,l),n.add(l),l.ignore=s}})).update((function(t,r){var a=o.getItemModel(t),l=$[d.type](o,t,a);if(S){var h=void 0;0===L.length?h=D(r):((h=L[r]).useStyle(w.getItemStyle()),"cartesian2d"===d.type?h.setShape("r",I):h.setShape("cornerRadius",I),k[t]=h);var p=$[d.type](o,t),f=oe(i,p,d);u(h,{shape:f},y,t)}var b=s.getItemGraphicEl(r);if(o.hasValue(t)&&Q[d.type](l)){var C=!1;if(A&&(C=Y[d.type](x,l))&&n.remove(b),b?c(b):b=X[d.type](e,o,t,l,i,y,m.model,!!b,_),v&&(b.forceLabelAnimation=!0),R){var O=b.getTextContent();if(O){var E=g(O);null!=E.prevValue&&(E.prevValue=E.value)}}else te(b,o,t,a,l,e,i,"polar"===d.type);M?b.attr({shape:l}):v?q(v,y,b,l,t,i,!0,R):u(b,{shape:l},e,t,null),o.setItemGraphicEl(t,b),b.ignore=C,n.add(b)}else n.remove(b)})).remove((function(t){var r=s.getItemGraphicEl(t);r&&p(r,e,t)})).execute();var O=this._backgroundGroup||(this._backgroundGroup=new f);O.removeAll();for(var E=0;E<k.length;++E)O.add(k[E]);n.add(O),this._backgroundEls=k,this._data=o},r.prototype._renderLarge=function(e,t,r){this._clear(),ie(e,this.group),this._updateLargeClip(e)},r.prototype._incrementalRenderLarge=function(e,t){this._removeBackground(),ie(t,this.group,this._progressiveEls,!0)},r.prototype._updateLargeClip=function(e){var t=e.get("clip",!0)&&E(e.coordinateSystem,!1,e),r=this.group;t?r.setClipPath(t):r.removeClipPath()},r.prototype._enableRealtimeSort=function(e,t,r){var a=this;if(t.count()){var i=e.baseAxis;if(this._isFirstFrame)this._dispatchInitSort(t,e,r),this._isFirstFrame=!1;else{var n=function(e){var r=t.getItemGraphicEl(e),a=r&&r.shape;return a&&Math.abs(i.isHorizontal()?a.height:a.width)||0};this._onRendered=function(){a._updateSortWithinSameData(t,n,i,r)},r.getZr().on("rendered",this._onRendered)}}},r.prototype._dataSort=function(e,t,r){var a=[];return e.each(e.mapDimension(t.dim),(function(e,t){var i=r(t);i=null==i?NaN:i,a.push({dataIndex:t,mappedValue:i,ordinalNumber:e})})),a.sort((function(e,t){return t.mappedValue-e.mappedValue})),{ordinalNumbers:m(a,(function(e){return e.ordinalNumber}))}},r.prototype._isOrderChangedWithinSameData=function(e,t,r){for(var a=r.scale,i=e.mapDimension(r.dim),n=Number.MAX_VALUE,o=0,s=a.getOrdinalMeta().categories.length;o<s;++o){var l=e.rawIndexOf(i,a.getRawOrdinalNumber(o)),d=l<0?Number.MIN_VALUE:t(e.indexOfRawIndex(l));if(d>n)return!0;n=d}return!1},r.prototype._isOrderDifferentInView=function(e,t){for(var r=t.scale,a=r.getExtent(),i=Math.max(0,a[0]),n=Math.min(a[1],r.getOrdinalMeta().categories.length-1);i<=n;++i)if(e.ordinalNumbers[i]!==r.getRawOrdinalNumber(i))return!0},r.prototype._updateSortWithinSameData=function(e,t,r,a){if(this._isOrderChangedWithinSameData(e,t,r)){var i=this._dataSort(e,r,t);this._isOrderDifferentInView(i,r)&&(this._removeOnRenderedListener(a),a.dispatchAction({type:"changeAxisOrder",componentType:r.dim+"Axis",axisId:r.index,sortInfo:i}))}},r.prototype._dispatchInitSort=function(e,t,r){var a=t.baseAxis,i=this._dataSort(e,a,(function(r){return e.get(e.mapDimension(t.otherAxis.dim),r)}));r.dispatchAction({type:"changeAxisOrder",componentType:a.dim+"Axis",isInitSort:!0,axisId:a.index,sortInfo:i})},r.prototype.remove=function(e,t){this._clear(this._model),this._removeOnRenderedListener(t)},r.prototype.dispose=function(e,t){this._removeOnRenderedListener(t)},r.prototype._removeOnRenderedListener=function(e){this._onRendered&&(e.getZr().off("rendered",this._onRendered),this._onRendered=null)},r.prototype._clear=function(e){var t=this.group,r=this._data;e&&e.isAnimationEnabled()&&r&&!this._isLargeDraw?(this._removeBackground(),this._backgroundEls=[],r.eachItemGraphicEl((function(t){p(t,e,y(t).dataIndex)}))):t.removeAll(),this._data=null,this._isFirstFrame=!0},r.prototype._removeBackground=function(){this.group.remove(this._backgroundGroup),this._backgroundGroup=null},r.type="bar",r}(v),Y={cartesian2d:function(e,t){var r=t.width<0?-1:1,a=t.height<0?-1:1;r<0&&(t.x+=t.width,t.width=-t.width),a<0&&(t.y+=t.height,t.height=-t.height);var i=e.x+e.width,n=e.y+e.height,o=H(t.x,e.x),s=j(t.x+t.width,i),l=H(t.y,e.y),d=j(t.y+t.height,n),h=s<o,u=d<l;return t.x=h&&o>i?s:o,t.y=u&&l>n?d:l,t.width=h?0:s-o,t.height=u?0:d-l,r<0&&(t.x+=t.width,t.width=-t.width),a<0&&(t.y+=t.height,t.height=-t.height),h||u},polar:function(e,t){var r=t.r0<=t.r?1:-1;if(r<0){var a=t.r;t.r=t.r0,t.r0=a}var i=j(t.r,e.r),n=H(t.r0,e.r0);t.r=i,t.r0=n;var o=i-n<0;if(r<0){a=t.r;t.r=t.r0,t.r0=a}return o}},X={cartesian2d:function(e,t,r,a,i,n,o,s,l){var d=new b({shape:A({},a),z2:1});(d.__dataIndex=r,d.name="item",n)&&(d.shape[i?"height":"width"]=0);return d},polar:function(e,t,r,a,i,o,s,l,d){var c=!i&&d?T:C,g=new c({shape:a,z2:1});g.name="item";var p,f,m=ee(i);if(g.calculateTextPosition=(p=m,f=({isRoundCap:c===T}||{}).isRoundCap,function(e,t,r){var a=t.position;if(!a||a instanceof Array)return n(e,t,r);var i=p(a),o=null!=t.distance?t.distance:5,s=this.shape,l=s.cx,d=s.cy,h=s.r,u=s.r0,c=(h+u)/2,g=s.startAngle,m=s.endAngle,y=(g+m)/2,v=f?Math.abs(h-u)/2:0,b=Math.cos,A=Math.sin,x=l+h*b(g),_=d+h*A(g),S="left",w="top";switch(i){case"startArc":x=l+(u-o)*b(y),_=d+(u-o)*A(y),S="center",w="top";break;case"insideStartArc":x=l+(u+o)*b(y),_=d+(u+o)*A(y),S="center",w="bottom";break;case"startAngle":x=l+c*b(g)+W(g,o+v,!1),_=d+c*A(g)+F(g,o+v,!1),S="right",w="middle";break;case"insideStartAngle":x=l+c*b(g)+W(g,-o+v,!1),_=d+c*A(g)+F(g,-o+v,!1),S="left",w="middle";break;case"middle":x=l+c*b(y),_=d+c*A(y),S="center",w="middle";break;case"endArc":x=l+(h+o)*b(y),_=d+(h+o)*A(y),S="center",w="bottom";break;case"insideEndArc":x=l+(h-o)*b(y),_=d+(h-o)*A(y),S="center",w="top";break;case"endAngle":x=l+c*b(m)+W(m,o+v,!0),_=d+c*A(m)+F(m,o+v,!0),S="left",w="middle";break;case"insideEndAngle":x=l+c*b(m)+W(m,-o+v,!0),_=d+c*A(m)+F(m,-o+v,!0),S="right",w="middle";break;default:return n(e,t,r)}return(e=e||{}).x=x,e.y=_,e.align=S,e.verticalAlign=w,e}),o){var y=i?"r":"endAngle",v={};g.shape[y]=i?a.r0:a.startAngle,v[y]=a[y],(l?u:h)(g,{shape:v},o)}return g}};function q(e,t,r,a,i,n,o,s){var l,d;n?(d={x:a.x,width:a.width},l={y:a.y,height:a.height}):(d={y:a.y,height:a.height},l={x:a.x,width:a.width}),s||(o?u:h)(r,{shape:l},t,i,null);var c=t?e.baseAxis.model:null;(o?u:h)(r,{shape:d},c,i)}function Z(e,t){for(var r=0;r<t.length;r++)if(!isFinite(e[t[r]]))return!0;return!1}var J=["x","y","width","height"],K=["cx","cy","r","startAngle","endAngle"],Q={cartesian2d:function(e){return!Z(e,J)},polar:function(e){return!Z(e,K)}},$={cartesian2d:function(e,t,r){var a=e.getItemLayout(t),i=r?function(e,t){var r=e.get(["itemStyle","borderColor"]);if(!r||"none"===r)return 0;var a=e.get(["itemStyle","borderWidth"])||0,i=isNaN(t.width)?Number.MAX_VALUE:Math.abs(t.width),n=isNaN(t.height)?Number.MAX_VALUE:Math.abs(t.height);return Math.min(a,i,n)}(r,a):0,n=a.width>0?1:-1,o=a.height>0?1:-1;return{x:a.x+n*i/2,y:a.y+o*i/2,width:a.width-n*i,height:a.height-o*i}},polar:function(e,t,r){var a=e.getItemLayout(t);return{cx:a.cx,cy:a.cy,r0:a.r0,r:a.r,startAngle:a.startAngle,endAngle:a.endAngle,clockwise:a.clockwise}}};function ee(e){return function(e){var t=e?"Arc":"Angle";return function(e){switch(e){case"start":case"insideStart":case"end":case"insideEnd":return e+t;default:return e}}}(e)}function te(e,t,a,i,n,l,d,h){var u=t.getItemVisual(a,"style");if(h){if(!l.get("roundCap")){var c=e.shape,g=z(i.getModel("itemStyle"),c,!0);A(c,g),e.setShape(c)}}else{var p=i.get(["itemStyle","borderRadius"])||0;e.setShape("r",p)}e.useStyle(u);var f=i.getShallow("cursor");f&&e.attr("cursor",f);var m=h?d?n.r>=n.r0?"endArc":"startArc":n.endAngle>=n.startAngle?"endAngle":"startAngle":d?n.height>=0?"bottom":"top":n.width>=0?"right":"left",y=x(i);_(e,y,{labelFetcher:l,labelDataIndex:a,defaultText:N(l.getData(),a),inheritColor:u.fill,defaultOpacity:u.opacity,defaultOutsidePosition:m});var v=e.getTextContent();if(h&&v){var b=i.get(["label","position"]);e.textConfig.inside="middle"===b||null,function(e,t,r,a){if(o(a))e.setTextConfig({rotation:a});else if(s(t))e.setTextConfig({rotation:0});else{var i,n=e.shape,l=n.clockwise?n.startAngle:n.endAngle,d=n.clockwise?n.endAngle:n.startAngle,h=(l+d)/2,u=r(t);switch(u){case"startArc":case"insideStartArc":case"middle":case"insideEndArc":case"endArc":i=h;break;case"startAngle":case"insideStartAngle":i=l;break;case"endAngle":case"insideEndAngle":i=d;break;default:return void e.setTextConfig({rotation:0})}var c=1.5*Math.PI-i;"middle"===u&&c>Math.PI/2&&c<1.5*Math.PI&&(c-=Math.PI),e.setTextConfig({rotation:c})}}(e,"outside"===b?m:b,ee(d),i.get(["label","rotate"]))}S(v,y,l.getRawValue(a),(function(e){return V(t,e)}));var k=i.getModel(["emphasis"]);w(e,k.get("focus"),k.get("blurScope"),k.get("disabled")),I(e,i),function(e){return null!=e.startAngle&&null!=e.endAngle&&e.startAngle===e.endAngle}(n)&&(e.style.fill="none",e.style.stroke="none",r(e.states,(function(e){e.style&&(e.style.fill=e.style.stroke="none")})))}var re=function(){},ae=function(t){function r(e){var r=t.call(this,e)||this;return r.type="largeBar",r}return e(r,t),r.prototype.getDefaultShape=function(){return new re},r.prototype.buildPath=function(e,t){for(var r=t.points,a=this.baseDimIdx,i=1-this.baseDimIdx,n=[],o=[],s=this.barWidth,l=0;l<r.length;l+=3)o[a]=s,o[i]=r[l+2],n[a]=r[l+a],n[i]=r[l+i],e.rect(n[0],n[1],o[0],o[1])},r}(k);function ie(e,t,r,a){var i=e.getData(),n=i.getLayout("valueAxisHorizontal")?1:0,o=i.getLayout("largeDataIndices"),s=i.getLayout("size"),l=e.getModel("backgroundStyle"),d=i.getLayout("largeBackgroundPoints");if(d){var h=new ae({shape:{points:d},incremental:!!a,silent:!0,z2:0});h.baseDimIdx=n,h.largeDataIndices=o,h.barWidth=s,h.useStyle(l.getItemStyle()),t.add(h),r&&r.push(h)}var u=new ae({shape:{points:i.getLayout("largePoints")},incremental:!!a,ignoreCoarsePointer:!0,z2:1});u.baseDimIdx=n,u.largeDataIndices=o,u.barWidth=s,t.add(u),u.useStyle(i.getVisual("style")),y(u).seriesIndex=e.seriesIndex,e.get("silent")||(u.on("mousedown",ne),u.on("mousemove",ne)),r&&r.push(u)}var ne=L((function(e){var t=function(e,t,r){for(var a=e.baseDimIdx,i=1-a,n=e.shape.points,o=e.largeDataIndices,s=[],l=[],d=e.barWidth,h=0,u=n.length/3;h<u;h++){var c=3*h;if(l[a]=d,l[i]=n[c+2],s[a]=n[c+a],s[i]=n[c+i],l[i]<0&&(s[i]+=l[i],l[i]=-l[i]),t>=s[0]&&t<=s[0]+l[0]&&r>=s[1]&&r<=s[1]+l[1])return o[h]}return-1}(this,e.offsetX,e.offsetY);y(this).dataIndex=t>=0?t:null}),30,!1);function oe(e,t,r){if(P(r,"cartesian2d")){var a=t,i=r.getArea();return{x:e?a.x:i.x,y:e?i.y:a.y,width:e?a.width:i.width,height:e?i.height:a.height}}var n=t;return{cx:(i=r.getArea()).cx,cy:i.cy,r0:e?i.r0:n.r0,r:e?i.r:n.r,startAngle:e?n.startAngle:0,endAngle:e?n.endAngle:2*Math.PI}}var se=U;function le(e){e.registerChartView(se),e.registerSeriesModel(B),e.registerLayout(e.PRIORITY.VISUAL.LAYOUT,M(R,"bar")),e.registerLayout(e.PRIORITY.VISUAL.PROGRESSIVE_LAYOUT,D("bar")),e.registerProcessor(e.PRIORITY.PROCESSOR.STATISTIC,O("bar")),e.registerAction({type:"changeAxisOrder",event:"changeAxisOrder",update:"update"},(function(e,t){var r=e.componentType||"series";t.eachComponent({mainType:r,query:e},(function(t){e.sortInfo&&t.axis.setCategorySortInfo(e.sortInfo)}))}))}export{le as install};