basb-cli
Version:
Blog as Second Brain!
2 lines (1 loc) • 12.6 kB
JavaScript
import{e as t,bA as e,N as i,bQ as a,_ as n,Y as o,bT as s,c4 as r,h as l,bU as p,bk as u,bV as h,cI as d,b8 as x,cK as c,cO as f,ap as m,ci as y,bE as v,ca as g,bh as _,at as E,bG as b,bt as A,bD as w,F as C,A as S,cH as W,G as M,cP as I,b1 as D,m as L}from"./index.js";import{s as T}from"./sliderMove.js";import{a as P}from"./axisModelCreator.js";import{A as B}from"./AxisBuilder.js";import{B as k,m as j,a as z,b as G}from"./brushHelper.js";import"./axisDefault.js";import"./labelLayoutHelper.js";import"./interactionMutex.js";import"./cursorHelper.js";function O(n){!function(e){if(e.parallel)return;var i=!1;t(e.series,(function(t){t&&"parallel"===t.type&&(i=!0)})),i&&(e.parallel=[{}])}(n),function(n){var o=e(n.parallelAxis);t(o,(function(t){if(i(t)){var o=t.parallelIndex||0,s=e(n.parallel)[o];s&&s.parallelAxisDefault&&a(t,s.parallelAxisDefault,!1)}}))}(n)}var N=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.type=i.type,t}return n(i,e),i.prototype.render=function(e,i,a){this._model=e,this._api=a,this._handlers||(this._handlers={},t(H,(function(t,e){a.getZr().on(e,this._handlers[e]=o(t,this))}),this)),s(this,"_throttledDispatchExpand",e.get("axisExpandRate"),"fixRate")},i.prototype.dispose=function(e,i){r(this,"_throttledDispatchExpand"),t(this._handlers,(function(t,e){i.getZr().off(e,t)})),this._handlers=null},i.prototype._throttledDispatchExpand=function(t){this._dispatchExpand(t)},i.prototype._dispatchExpand=function(t){t&&this._api.dispatchAction(l({type:"parallelAxisExpand"},t))},i.type="parallel",i}(p),H={mousedown:function(t){X(this,"click")&&(this._mouseDownPoint=[t.offsetX,t.offsetY])},mouseup:function(t){var e=this._mouseDownPoint;if(X(this,"click")&&e){var i=[t.offsetX,t.offsetY];if(Math.pow(e[0]-i[0],2)+Math.pow(e[1]-i[1],2)>5)return;var a=this._model.coordinateSystem.getSlidedAxisExpandWindow([t.offsetX,t.offsetY]);"none"!==a.behavior&&this._dispatchExpand({axisExpandWindow:a.axisExpandWindow})}this._mouseDownPoint=null},mousemove:function(t){if(!this._mouseDownPoint&&X(this,"mousemove")){var e=this._model,i=e.coordinateSystem.getSlidedAxisExpandWindow([t.offsetX,t.offsetY]),a=i.behavior;"jump"===a&&this._throttledDispatchExpand.debounceNextCall(e.get("axisExpandDebounce")),this._throttledDispatchExpand("none"===a?null:{axisExpandWindow:i.axisExpandWindow,animation:"jump"===a?null:{duration:0}})}}};function X(t,e){var i=t._model;return i.get("axisExpandable")&&i.get("axisExpandTriggerOn")===e}var R=N,Y=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.type=i.type,t}return n(i,e),i.prototype.init=function(){e.prototype.init.apply(this,arguments),this.mergeOption({})},i.prototype.mergeOption=function(t){var e=this.option;t&&a(e,t,!0),this._initDimensions()},i.prototype.contains=function(t,e){var i=t.get("parallelIndex");return null!=i&&e.getComponent("parallel",i)===this},i.prototype.setAxisExpand=function(e){t(["axisExpandable","axisExpandCenter","axisExpandCount","axisExpandWidth","axisExpandWindow"],(function(t){e.hasOwnProperty(t)&&(this.option[t]=e[t])}),this)},i.prototype._initDimensions=function(){var e=this.dimensions=[],i=this.parallelAxisIndex=[],a=u(this.ecModel.queryComponents({mainType:"parallelAxis"}),(function(t){return(t.get("parallelIndex")||0)===this.componentIndex}),this);t(a,(function(t){e.push("dim"+t.get("dim")),i.push(t.componentIndex)}))},i.type="parallel",i.dependencies=["parallelAxis"],i.layoutMode="box",i.defaultOption={z:0,left:80,top:60,right:80,bottom:60,layout:"horizontal",axisExpandable:!1,axisExpandCenter:null,axisExpandCount:0,axisExpandWidth:50,axisExpandRate:17,axisExpandDebounce:50,axisExpandSlideTriggerArea:[-.15,.05,.4],axisExpandTriggerOn:"click",parallelAxisDefault:null},i}(h),q=function(t){function e(e,i,a,n,o){var s=t.call(this,e,i,a)||this;return s.type=n||"value",s.axisIndex=o,s}return n(e,t),e.prototype.isHorizontal=function(){return"horizontal"!==this.coordinateSystem.getModel().get("layout")},e}(d),F=t,V=Math.min,Z=Math.max,K=Math.floor,Q=Math.ceil,U=E,J=Math.PI,$=function(){function e(t,e,i){this.type="parallel",this._axesMap=x(),this._axesLayout={},this.dimensions=t.dimensions,this._model=t,this._init(t,e,i)}return e.prototype._init=function(t,e,i){var a=t.dimensions,n=t.parallelAxisIndex;F(a,(function(t,i){var a=n[i],o=e.getComponent("parallelAxis",a),s=this._axesMap.set(t,new q(t,c(o),[0,0],o.get("type"),a)),r="category"===s.type;s.onBand=r&&o.get("boundaryGap"),s.inverse=o.get("inverse"),o.axis=s,s.model=o,s.coordinateSystem=o.coordinateSystem=this}),this)},e.prototype.update=function(t,e){this._updateAxesFromSeries(this._model,t)},e.prototype.containPoint=function(t){var e=this._makeLayoutInfo(),i=e.axisBase,a=e.layoutBase,n=e.pixelDimIndex,o=t[1-n],s=t[n];return o>=i&&o<=i+e.axisLength&&s>=a&&s<=a+e.layoutLength},e.prototype.getModel=function(){return this._model},e.prototype._updateAxesFromSeries=function(t,e){e.eachSeries((function(i){if(t.contains(i,e)){var a=i.getData();F(this.dimensions,(function(t){var e=this._axesMap.get(t);e.scale.unionExtentFromData(a,a.mapDimension(t)),f(e.scale,e.model)}),this)}}),this)},e.prototype.resize=function(t,e){this._rect=m(t.getBoxLayoutParams(),{width:e.getWidth(),height:e.getHeight()}),this._layoutAxes()},e.prototype.getRect=function(){return this._rect},e.prototype._makeLayoutInfo=function(){var t,e=this._model,i=this._rect,a=["x","y"],n=["width","height"],o=e.get("layout"),s="horizontal"===o?0:1,r=i[n[s]],l=[0,r],p=this.dimensions.length,u=tt(e.get("axisExpandWidth"),l),h=tt(e.get("axisExpandCount")||0,[0,p]),d=e.get("axisExpandable")&&p>3&&p>h&&h>1&&u>0&&r>0,x=e.get("axisExpandWindow");x?(t=tt(x[1]-x[0],l),x[1]=x[0]+t):(t=tt(u*(h-1),l),(x=[u*(e.get("axisExpandCenter")||K(p/2))-t/2])[1]=x[0]+t);var c=(r-t)/(p-h);c<3&&(c=0);var f=[K(U(x[0]/u,1))+1,Q(U(x[1]/u,1))-1],m=c/u*x[0];return{layout:o,pixelDimIndex:s,layoutBase:i[a[s]],layoutLength:r,axisBase:i[a[1-s]],axisLength:i[n[1-s]],axisExpandable:d,axisExpandWidth:u,axisCollapseWidth:c,axisExpandWindow:x,axisCount:p,winInnerIndices:f,axisExpandWindow0Pos:m}},e.prototype._layoutAxes=function(){var t=this._rect,e=this._axesMap,i=this.dimensions,a=this._makeLayoutInfo(),n=a.layout;e.each((function(t){var e=[0,a.axisLength],i=t.inverse?1:0;t.setExtent(e[i],e[1-i])})),F(i,(function(e,i){var o=(a.axisExpandable?it:et)(i,a),s={horizontal:{x:o.position,y:a.axisLength},vertical:{x:0,y:o.position}},r={horizontal:J/2,vertical:0},l=[s[n].x+t.x,s[n].y+t.y],p=r[n],u=b();y(u,u,p),v(u,u,l),this._axesLayout[e]={position:l,rotation:p,transform:u,axisNameAvailableWidth:o.axisNameAvailableWidth,axisLabelShow:o.axisLabelShow,nameTruncateMaxWidth:o.nameTruncateMaxWidth,tickDirection:1,labelDirection:1}}),this)},e.prototype.getAxis=function(t){return this._axesMap.get(t)},e.prototype.dataToPoint=function(t,e){return this.axisCoordToPoint(this._axesMap.get(e).dataToCoord(t),e)},e.prototype.eachActiveState=function(e,i,a,n){null==a&&(a=0),null==n&&(n=e.count());var o=this._axesMap,s=this.dimensions,r=[],l=[];t(s,(function(t){r.push(e.mapDimension(t)),l.push(o.get(t).model)}));for(var p=this.hasAxisBrushed(),u=a;u<n;u++){var h=void 0;if(p){h="active";for(var d=e.getValues(r,u),x=0,c=s.length;x<c;x++){if("inactive"===l[x].getActiveState(d[x])){h="inactive";break}}}else h="normal";i(h,u)}},e.prototype.hasAxisBrushed=function(){for(var t=this.dimensions,e=this._axesMap,i=!1,a=0,n=t.length;a<n;a++)"normal"!==e.get(t[a]).model.getActiveState()&&(i=!0);return i},e.prototype.axisCoordToPoint=function(t,e){var i=this._axesLayout[e];return g([t,0],i.transform)},e.prototype.getAxisLayout=function(t){return _(this._axesLayout[t])},e.prototype.getSlidedAxisExpandWindow=function(t){var e=this._makeLayoutInfo(),i=e.pixelDimIndex,a=e.axisExpandWindow.slice(),n=a[1]-a[0],o=[0,e.axisExpandWidth*(e.axisCount-1)];if(!this.containPoint(t))return{behavior:"none",axisExpandWindow:a};var s,r=t[i]-e.layoutBase-e.axisExpandWindow0Pos,l="slide",p=e.axisCollapseWidth,u=this._model.get("axisExpandSlideTriggerArea"),h=null!=u[0];if(p)h&&p&&r<n*u[0]?(l="jump",s=r-n*u[2]):h&&p&&r>n*(1-u[0])?(l="jump",s=r-n*(1-u[2])):(s=r-n*u[1])>=0&&(s=r-n*(1-u[1]))<=0&&(s=0),(s*=e.axisExpandWidth/p)?T(s,a,o,"all"):l="none";else{var d=a[1]-a[0];(a=[Z(0,o[1]*r/d-d/2)])[1]=V(o[1],a[0]+d),a[0]=a[1]-d}return{axisExpandWindow:a,behavior:l}},e}();function tt(t,e){return V(Z(t,e[0]),e[1])}function et(t,e){var i=e.layoutLength/(e.axisCount-1);return{position:i*t,axisNameAvailableWidth:i,axisLabelShow:!0}}function it(t,e){var i,a,n=e.layoutLength,o=e.axisExpandWidth,s=e.axisCount,r=e.axisCollapseWidth,l=e.winInnerIndices,p=r,u=!1;return t<l[0]?(i=t*r,a=r):t<=l[1]?(i=e.axisExpandWindow0Pos+t*o-e.axisExpandWindow[0],p=o,u=!0):(i=n-(s-1-t)*r,a=r),{position:i,axisNameAvailableWidth:p,axisLabelShow:u,nameTruncateMaxWidth:a}}var at={create:function(t,e){var i=[];return t.eachComponent("parallel",(function(a,n){var o=new $(a,t,e);o.name="parallel_"+n,o.resize(a,e),a.coordinateSystem=o,o.model=a,i.push(o)})),t.eachSeries((function(t){if("parallel"===t.get("coordinateSystem")){var e=t.getReferringComponents("parallel",A).models[0];t.coordinateSystem=e.coordinateSystem}})),i}},nt=function(t){function e(){var i=null!==t&&t.apply(this,arguments)||this;return i.type=e.type,i.activeIntervals=[],i}return n(e,t),e.prototype.getAreaSelectStyle=function(){return w([["fill","color"],["lineWidth","borderWidth"],["stroke","borderColor"],["width","width"],["opacity","opacity"]])(this.getModel("areaSelectStyle"))},e.prototype.setActiveIntervals=function(t){var e=this.activeIntervals=_(t);if(e)for(var i=e.length-1;i>=0;i--)C(e[i])},e.prototype.getActiveState=function(t){var e=this.activeIntervals;if(!e.length)return"normal";if(null==t||isNaN(+t))return"inactive";if(1===e.length){var i=e[0];if(i[0]<=t&&t<=i[1])return"active"}else for(var a=0,n=e.length;a<n;a++)if(e[a][0]<=t&&t<=e[a][1])return"active";return"inactive"},e}(h);S(nt,W);var ot=nt,st=["axisLine","axisTickLabel","axisName"];var rt=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.type=i.type,t}return n(i,e),i.prototype.init=function(t,i){e.prototype.init.apply(this,arguments),(this._brushController=new k(i.getZr())).on("brush",o(this._onBrush,this))},i.prototype.render=function(e,i,a,n){if(!function(t,e,i){return i&&"axisAreaSelect"===i.type&&e.findComponents({mainType:"parallelAxis",query:i})[0]===t}(e,i,n)){this.axisModel=e,this.api=a,this.group.removeAll();var o=this._axisGroup;if(this._axisGroup=new M,this.group.add(this._axisGroup),e.get("show")){var s=function(t,e){return e.getComponent("parallel",t.get("parallelIndex"))}(e,i),r=s.coordinateSystem,p=e.getAreaSelectStyle(),u=p.width,h=e.axis.dim,d=r.getAxisLayout(h),x=l({strokeContainThreshold:u},d),c=new B(e,x);t(st,c.add,c),this._axisGroup.add(c.getGroup()),this._refreshBrushController(x,p,e,s,u,a),I(o,this._axisGroup,e)}}},i.prototype._refreshBrushController=function(t,e,i,a,n,o){var s=i.axis.getExtent(),r=s[1]-s[0],l=Math.min(30,.1*Math.abs(r)),p=D.create({x:s[0],y:-n/2,width:r,height:n});p.x-=l,p.width+=2*l,this._brushController.mount({enableGlobalPan:!0,rotation:t.rotation,x:t.position[0],y:t.position[1]}).setPanels([{panelId:"pl",clipPath:j(p),isTargetByCursor:z(p,o,a),getLinearBrushOtherExtent:G(p,0)}]).enableBrush({brushType:"lineX",brushStyle:e,removeOnClick:!0}).updateCovers(function(t){var e=t.axis;return L(t.activeIntervals,(function(t){return{brushType:"lineX",panelId:"pl",range:[e.dataToCoord(t[0],!0),e.dataToCoord(t[1],!0)]}}))}(i))},i.prototype._onBrush=function(t){var e=t.areas,i=this.axisModel,a=i.axis,n=L(e,(function(t){return[a.coordToData(t.range[0],!0),a.coordToData(t.range[1],!0)]}));(!i.option.realtime===t.isEnd||t.removeOnClick)&&this.api.dispatchAction({type:"axisAreaSelect",parallelAxisId:i.id,intervals:n})},i.prototype.dispose=function(){this._brushController.dispose()},i.type="parallelAxis",i}(p),lt={type:"axisAreaSelect",event:"axisAreaSelected"};var pt={type:"value",areaSelectStyle:{width:20,borderWidth:1,borderColor:"rgba(160,197,232)",color:"rgba(160,197,232)",opacity:.3},realtime:!0,z:10};function ut(t){t.registerComponentView(R),t.registerComponentModel(Y),t.registerCoordinateSystem("parallel",at),t.registerPreprocessor(O),t.registerComponentModel(ot),t.registerComponentView(rt),P(t,"parallel",ot,pt),function(t){t.registerAction(lt,(function(t,e){e.eachComponent({mainType:"parallelAxis",query:t},(function(e){e.axis.model.setActiveIntervals(t.intervals)}))})),t.registerAction("parallelAxisExpand",(function(t,e){e.eachComponent({mainType:"parallel",query:t},(function(e){e.setAxisExpand(t)}))}))}(t)}export{ut as install};