UNPKG

basb-cli

Version:
2 lines (1 loc) 15.4 kB
import{_ as t,e,bm as o,dl as i,N as n,bh as a,aM as r,bV as l,i as s,A as p,dm as c,bU as u,cI as h,X as d,aK as g,J as y,bE as m,ci as f,G as v,as as x,h as _,$ as b,Y as S,c7 as C,g as P,a9 as w,a0 as T,bs as M,U as I,F as A,ca as z,d4 as L,dn as k,dp as B,ap as D,cV as G,b1 as O,ae as V,bQ as E,ah as W,ai as N,bG as R,d as F}from"./index.js";var H=function(l){function s(){var t=null!==l&&l.apply(this,arguments)||this;return t.type=s.type,t.layoutMode="box",t}return t(s,l),s.prototype.init=function(t,e,o){this.mergeDefaultAndTheme(t,o),this._initData()},s.prototype.mergeOption=function(t){l.prototype.mergeOption.apply(this,arguments),this._initData()},s.prototype.setCurrentIndex=function(t){null==t&&(t=this.option.currentIndex);var e=this._data.count();this.option.loop?t=(t%e+e)%e:(t>=e&&(t=e-1),t<0&&(t=0)),this.option.currentIndex=t},s.prototype.getCurrentIndex=function(){return this.option.currentIndex},s.prototype.isIndexMax=function(){return this.getCurrentIndex()>=this._data.count()-1},s.prototype.setPlayState=function(t){this.option.autoPlay=!!t},s.prototype.getPlayState=function(){return!!this.option.autoPlay},s.prototype._initData=function(){var t,l=this.option,s=l.data||[],p=l.axisType,c=this._names=[];"category"===p?(t=[],e(s,(function(e,r){var l,s=o(i(e),"");n(e)?(l=a(e)).value=r:l=r,t.push(l),c.push(s)}))):t=s;var u={category:"ordinal",time:"time",value:"number"}[p]||"number";(this._data=new r([{name:"value",type:u}],this)).initData(t,c)},s.prototype.getData=function(){return this._data},s.prototype.getCategories=function(){if("category"===this.get("axisType"))return this._names.slice()},s.type="timeline",s.defaultOption={z:4,show:!0,axisType:"time",realtime:!0,left:"20%",top:null,right:"20%",bottom:0,width:null,height:40,padding:5,controlPosition:"left",autoPlay:!1,rewind:!1,loop:!0,playInterval:2e3,currentIndex:0,itemStyle:{},label:{color:"#000"},data:[]},s}(l),U=function(e){function o(){var t=null!==e&&e.apply(this,arguments)||this;return t.type=o.type,t}return t(o,e),o.type="timeline.slider",o.defaultOption=s(H.defaultOption,{backgroundColor:"rgba(0,0,0,0)",borderColor:"#ccc",borderWidth:0,orient:"horizontal",inverse:!1,tooltip:{trigger:"item"},symbol:"circle",symbolSize:12,lineStyle:{show:!0,width:2,color:"#DAE1F5"},label:{position:"auto",show:!0,interval:"auto",rotate:0,color:"#A4B1D7"},itemStyle:{color:"#A4B1D7",borderWidth:1},checkpointStyle:{symbol:"circle",symbolSize:15,color:"#316bf3",borderColor:"#fff",borderWidth:2,shadowBlur:2,shadowOffsetX:1,shadowOffsetY:1,shadowColor:"rgba(0, 0, 0, 0.3)",animation:!0,animationDuration:300,animationEasing:"quinticInOut"},controlStyle:{show:!0,showPlayBtn:!0,showPrevBtn:!0,showNextBtn:!0,itemSize:24,itemGap:12,position:"left",playIcon:"path://M31.6,53C17.5,53,6,41.5,6,27.4S17.5,1.8,31.6,1.8C45.7,1.8,57.2,13.3,57.2,27.4S45.7,53,31.6,53z M31.6,3.3 C18.4,3.3,7.5,14.1,7.5,27.4c0,13.3,10.8,24.1,24.1,24.1C44.9,51.5,55.7,40.7,55.7,27.4C55.7,14.1,44.9,3.3,31.6,3.3z M24.9,21.3 c0-2.2,1.6-3.1,3.5-2l10.5,6.1c1.899,1.1,1.899,2.9,0,4l-10.5,6.1c-1.9,1.1-3.5,0.2-3.5-2V21.3z",stopIcon:"path://M30.9,53.2C16.8,53.2,5.3,41.7,5.3,27.6S16.8,2,30.9,2C45,2,56.4,13.5,56.4,27.6S45,53.2,30.9,53.2z M30.9,3.5C17.6,3.5,6.8,14.4,6.8,27.6c0,13.3,10.8,24.1,24.101,24.1C44.2,51.7,55,40.9,55,27.6C54.9,14.4,44.1,3.5,30.9,3.5z M36.9,35.8c0,0.601-0.4,1-0.9,1h-1.3c-0.5,0-0.9-0.399-0.9-1V19.5c0-0.6,0.4-1,0.9-1H36c0.5,0,0.9,0.4,0.9,1V35.8z M27.8,35.8 c0,0.601-0.4,1-0.9,1h-1.3c-0.5,0-0.9-0.399-0.9-1V19.5c0-0.6,0.4-1,0.9-1H27c0.5,0,0.9,0.4,0.9,1L27.8,35.8L27.8,35.8z",nextIcon:"M2,18.5A1.52,1.52,0,0,1,.92,18a1.49,1.49,0,0,1,0-2.12L7.81,9.36,1,3.11A1.5,1.5,0,1,1,3,.89l8,7.34a1.48,1.48,0,0,1,.49,1.09,1.51,1.51,0,0,1-.46,1.1L3,18.08A1.5,1.5,0,0,1,2,18.5Z",prevIcon:"M10,.5A1.52,1.52,0,0,1,11.08,1a1.49,1.49,0,0,1,0,2.12L4.19,9.64,11,15.89a1.5,1.5,0,1,1-2,2.22L1,10.77A1.48,1.48,0,0,1,.5,9.68,1.51,1.51,0,0,1,1,8.58L9,.92A1.5,1.5,0,0,1,10,.5Z",prevBtnSize:18,nextBtnSize:18,color:"#A4B1D7",borderColor:"#A4B1D7",borderWidth:1},emphasis:{label:{show:!0,color:"#6f778d"},itemStyle:{color:"#316BF3"},controlStyle:{color:"#316BF3",borderColor:"#316BF3",borderWidth:2}},progress:{lineStyle:{color:"#316BF3"},itemStyle:{color:"#316BF3"},label:{color:"#6f778d"}},data:[]}),o}(H);p(U,c.prototype);var X=U,Y=function(e){function o(){var t=null!==e&&e.apply(this,arguments)||this;return t.type=o.type,t}return t(o,e),o.type="timeline",o}(u),Z=function(e){function o(t,o,i,n){var a=e.call(this,t,o,i)||this;return a.type=n||"value",a}return t(o,e),o.prototype.getLabelModel=function(){return this.model.getModel("label")},o.prototype.isHorizontal=function(){return"horizontal"===this.model.get("orient")},o}(h),j=Math.PI,q=d();function J(t,e,o,i,n,a){var r=e.get("color");if(n)n.setColor(r),o.add(n),a&&a.onUpdate(n);else{var l=t.get("symbol");(n=V(l,-1,-1,2,2,r)).setStyle("strokeNoScale",!0),o.add(n),a&&a.onCreate(n)}var s=e.getItemStyle(["color"]);n.setStyle(s),i=E({rectHover:!0,z2:100},i,!0);var p=W(t.get("symbolSize"));i.scaleX=p[0]/2,i.scaleY=p[1]/2;var c=N(t.get("symbolOffset"),p);c&&(i.x=(i.x||0)+c[0],i.y=(i.y||0)+c[1]);var u=t.get("symbolRotate");return i.rotation=(u||0)*Math.PI/180||0,n.attr(i),n.updateTransform(),n}function K(t,e,o,i,n,a){if(!t.dragging){var r=n.getModel("checkpointStyle"),l=i.dataToCoord(n.getData().get("value",o));if(a||!r.get("animation",!0))t.attr({x:l,y:0}),e&&e.attr({shape:{x2:l}});else{var s={duration:r.get("animationDuration",!0),easing:r.get("animationEasing",!0)};t.stopAnimation(null,!0),t.animateTo({x:l,y:0},s),e&&e.animateTo({shape:{x2:l}},s)}}}var Q=function(o){function i(){var t=null!==o&&o.apply(this,arguments)||this;return t.type=i.type,t}return t(i,o),i.prototype.init=function(t,e){this.api=e},i.prototype.render=function(t,o,i){if(this.model=t,this.api=i,this.ecModel=o,this.group.removeAll(),t.get("show",!0)){var n=this._layout(t,i),a=this._createGroup("_mainGroup"),r=this._createGroup("_labelGroup"),l=this._axis=this._createAxis(n,t);t.formatTooltip=function(t){var e=l.scale.getLabel({value:t});return g("nameValue",{noName:!0,value:e})},e(["AxisLine","AxisTick","Control","CurrentPointer"],(function(e){this["_render"+e](n,a,l,t)}),this),this._renderAxisLabel(n,r,l,t),this._position(n,t)}this._doPlayStop(),this._updateTicksStatus()},i.prototype.remove=function(){this._clearTimer(),this.group.removeAll()},i.prototype.dispose=function(){this._clearTimer()},i.prototype._layout=function(t,e){var o,i,n,a,r=t.get(["label","position"]),l=t.get("orient"),s=function(t,e){return D(t.getBoxLayoutParams(),{width:e.getWidth(),height:e.getHeight()},t.get("padding"))}(t,e),p={horizontal:"center",vertical:(o=null==r||"auto"===r?"horizontal"===l?s.y+s.height/2<e.getHeight()/2?"-":"+":s.x+s.width/2<e.getWidth()/2?"+":"-":y(r)?{horizontal:{top:"-",bottom:"+"},vertical:{left:"-",right:"+"}}[l][r]:r)>=0||"+"===o?"left":"right"},c={horizontal:o>=0||"+"===o?"top":"bottom",vertical:"middle"},u={horizontal:0,vertical:j/2},h="vertical"===l?s.height:s.width,d=t.getModel("controlStyle"),g=d.get("show",!0),m=g?d.get("itemSize"):0,f=g?d.get("itemGap"):0,v=m+f,x=t.get(["label","rotate"])||0;x=x*j/180;var _=d.get("position",!0),b=g&&d.get("showPlayBtn",!0),S=g&&d.get("showPrevBtn",!0),C=g&&d.get("showNextBtn",!0),P=0,w=h;"left"===_||"bottom"===_?(b&&(i=[0,0],P+=v),S&&(n=[P,0],P+=v),C&&(a=[w-m,0],w-=v)):(b&&(i=[w-m,0],w-=v),S&&(n=[0,0],P+=v),C&&(a=[w-m,0],w-=v));var T=[P,w];return t.get("inverse")&&T.reverse(),{viewRect:s,mainLength:h,orient:l,rotation:u[l],labelRotation:x,labelPosOpt:o,labelAlign:t.get(["label","align"])||p[l],labelBaseline:t.get(["label","verticalAlign"])||t.get(["label","baseline"])||c[l],playPosition:i,prevBtnPosition:n,nextBtnPosition:a,axisExtent:T,controlSize:m,controlGap:f}},i.prototype._position=function(t,e){var o=this._mainGroup,i=this._labelGroup,n=t.viewRect;if("vertical"===t.orient){var a=R(),r=n.x,l=n.y+n.height;m(a,a,[-r,-l]),f(a,a,-j/2),m(a,a,[r,l]),(n=n.clone()).applyTransform(a)}var s=x(n),p=x(o.getBoundingRect()),c=x(i.getBoundingRect()),u=[o.x,o.y],h=[i.x,i.y];h[0]=u[0]=s[0][0];var d,g=t.labelPosOpt;null==g||y(g)?(_(u,p,s,1,d="+"===g?0:1),_(h,c,s,1,1-d)):(_(u,p,s,1,d=g>=0?0:1),h[1]=u[1]+g);function v(t){t.originX=s[0][0]-t.x,t.originY=s[1][0]-t.y}function x(t){return[[t.x,t.x+t.width],[t.y,t.y+t.height]]}function _(t,e,o,i,n){t[i]+=o[i][n]-e[i][n]}o.setPosition(u),i.setPosition(h),o.rotation=i.rotation=t.rotation,v(o),v(i)},i.prototype._createAxis=function(t,e){var o=e.getData(),i=e.get("axisType"),n=function(t,e){if(e=e||t.get("type"),e)switch(e){case"category":return new B({ordinalMeta:t.getCategories(),extent:[1/0,-1/0]});case"time":return new k({locale:t.ecModel.getLocaleModel(),useUTC:t.ecModel.get("useUTC")});default:return new L}}(e,i);n.getTicks=function(){return o.mapArray(["value"],(function(t){return{value:t}}))};var a=o.getDataExtent("value");n.setExtent(a[0],a[1]),n.calcNiceTicks();var r=new Z("value",n,t.axisExtent,i);return r.model=e,r},i.prototype._createGroup=function(t){var e=this[t]=new v;return this.group.add(e),e},i.prototype._renderAxisLine=function(t,e,o,i){var n=o.getExtent();if(i.get(["lineStyle","show"])){var a=new x({shape:{x1:n[0],y1:0,x2:n[1],y2:0},style:_({lineCap:"round"},i.getModel("lineStyle").getLineStyle()),silent:!0,z2:1});e.add(a);var r=this._progressLine=new x({shape:{x1:n[0],x2:this._currentPointer?this._currentPointer.x:n[0],y1:0,y2:0},style:b({lineCap:"round",lineWidth:a.style.lineWidth},i.getModel(["progress","lineStyle"]).getLineStyle()),silent:!0,z2:1});e.add(r)}},i.prototype._renderAxisTick=function(t,o,i,n){var a=this,r=n.getData(),l=i.scale.getTicks();this._tickSymbols=[],e(l,(function(t){var e=i.dataToCoord(t.value),l=r.getItemModel(t.value),s=l.getModel("itemStyle"),p=l.getModel(["emphasis","itemStyle"]),c=l.getModel(["progress","itemStyle"]),u={x:e,y:0,onclick:S(a._changeTimeline,a,t.value)},h=J(l,s,o,u);h.ensureState("emphasis").style=p.getItemStyle(),h.ensureState("progress").style=c.getItemStyle(),C(h);var d=P(h);l.get("tooltip")?(d.dataIndex=t.value,d.dataModel=n):d.dataIndex=d.dataModel=null,a._tickSymbols.push(h)}))},i.prototype._renderAxisLabel=function(t,o,i,n){var a=this;if(i.getLabelModel().get("show")){var r=n.getData(),l=i.getViewLabels();this._tickLabels=[],e(l,(function(e){var n=e.tickValue,l=r.getItemModel(n),s=l.getModel("label"),p=l.getModel(["emphasis","label"]),c=l.getModel(["progress","label"]),u=i.dataToCoord(e.tickValue),h=new w({x:u,y:0,rotation:t.labelRotation-t.rotation,onclick:S(a._changeTimeline,a,n),silent:!1,style:T(s,{text:e.formattedLabel,align:t.labelAlign,verticalAlign:t.labelBaseline})});h.ensureState("emphasis").style=T(p),h.ensureState("progress").style=T(c),o.add(h),C(h),q(h).dataIndex=n,a._tickLabels.push(h)}))}},i.prototype._renderControl=function(t,e,o,i){var n=t.controlSize,a=t.rotation,r=i.getModel("controlStyle").getItemStyle(),l=i.getModel(["emphasis","controlStyle"]).getItemStyle(),s=i.getPlayState(),p=i.get("inverse",!0);function c(t,o,s,p){if(t){var c=M(I(i.get(["controlStyle",o+"BtnSize"]),n),n),u=function(t,e,o,i){var n=i.style,a=G(t.get(["controlStyle",e]),i||{},new O(o[0],o[1],o[2],o[3]));n&&a.setStyle(n);return a}(i,o+"Icon",[0,-c/2,c,c],{x:t[0],y:t[1],originX:n/2,originY:0,rotation:p?-a:0,rectHover:!0,style:r,onclick:s});u.ensureState("emphasis").style=l,e.add(u),C(u)}}c(t.nextBtnPosition,"next",S(this._changeTimeline,this,p?"-":"+")),c(t.prevBtnPosition,"prev",S(this._changeTimeline,this,p?"+":"-")),c(t.playPosition,s?"stop":"play",S(this._handlePlayClick,this,!s),!0)},i.prototype._renderCurrentPointer=function(t,e,o,i){var n=i.getData(),a=i.getCurrentIndex(),r=n.getItemModel(a).getModel("checkpointStyle"),l=this,s={onCreate:function(t){t.draggable=!0,t.drift=S(l._handlePointerDrag,l),t.ondragend=S(l._handlePointerDragend,l),K(t,l._progressLine,a,o,i,!0)},onUpdate:function(t){K(t,l._progressLine,a,o,i)}};this._currentPointer=J(r,r,this._mainGroup,{},this._currentPointer,s)},i.prototype._handlePlayClick=function(t){this._clearTimer(),this.api.dispatchAction({type:"timelinePlayChange",playState:t,from:this.uid})},i.prototype._handlePointerDrag=function(t,e,o){this._clearTimer(),this._pointerChangeTimeline([o.offsetX,o.offsetY])},i.prototype._handlePointerDragend=function(t){this._pointerChangeTimeline([t.offsetX,t.offsetY],!0)},i.prototype._pointerChangeTimeline=function(t,e){var o=this._toAxisCoord(t)[0],i=this._axis,n=A(i.getExtent().slice());o>n[1]&&(o=n[1]),o<n[0]&&(o=n[0]),this._currentPointer.x=o,this._currentPointer.markRedraw();var a=this._progressLine;a&&(a.shape.x2=o,a.dirty());var r=this._findNearestTick(o),l=this.model;(e||r!==l.getCurrentIndex()&&l.get("realtime"))&&this._changeTimeline(r)},i.prototype._doPlayStop=function(){var t=this;this._clearTimer(),this.model.getPlayState()&&(this._timer=setTimeout((function(){var e=t.model;t._changeTimeline(e.getCurrentIndex()+(e.get("rewind",!0)?-1:1))}),this.model.get("playInterval")))},i.prototype._toAxisCoord=function(t){var e=this._mainGroup.getLocalTransform();return z(t,e,!0)},i.prototype._findNearestTick=function(t){var e,o=this.model.getData(),i=1/0,n=this._axis;return o.each(["value"],(function(o,a){var r=n.dataToCoord(o),l=Math.abs(r-t);l<i&&(i=l,e=a)})),e},i.prototype._clearTimer=function(){this._timer&&(clearTimeout(this._timer),this._timer=null)},i.prototype._changeTimeline=function(t){var e=this.model.getCurrentIndex();"+"===t?t=e+1:"-"===t&&(t=e-1),this.api.dispatchAction({type:"timelineChange",currentIndex:t,from:this.uid})},i.prototype._updateTicksStatus=function(){var t=this.model.getCurrentIndex(),e=this._tickSymbols,o=this._tickLabels;if(e)for(var i=0;i<e.length;i++)e&&e[i]&&e[i].toggleState("progress",i<t);if(o)for(i=0;i<o.length;i++)o&&o[i]&&o[i].toggleState("progress",q(o[i]).dataIndex<=t)},i.type="timeline.slider",i}(Y);function $(t){var o=t&&t.timeline;F(o)||(o=o?[o]:[]),e(o,(function(t){t&&function(t){var o=t.type,i={number:"value",time:"time"};i[o]&&(t.axisType=i[o],delete t.type);if(tt(t),et(t,"controlPosition")){var a=t.controlStyle||(t.controlStyle={});et(a,"position")||(a.position=t.controlPosition),"none"!==a.position||et(a,"show")||(a.show=!1,delete a.position),delete t.controlPosition}e(t.data||[],(function(t){n(t)&&!F(t)&&(!et(t,"value")&&et(t,"name")&&(t.value=t.name),tt(t))}))}(t)}))}function tt(t){var o=t.itemStyle||(t.itemStyle={}),i=o.emphasis||(o.emphasis={}),n=t.label||t.label||{},a=n.normal||(n.normal={}),r={normal:1,emphasis:1};e(n,(function(t,e){r[e]||et(a,e)||(a[e]=t)})),i.label&&!et(n,"emphasis")&&(n.emphasis=i.label,delete i.label)}function et(t,e){return t.hasOwnProperty(e)}function ot(t){t.registerComponentModel(X),t.registerComponentView(Q),t.registerSubTypeDefaulter("timeline",(function(){return"slider"})),function(t){t.registerAction({type:"timelineChange",event:"timelineChanged",update:"prepareAndUpdate"},(function(t,e,o){var i=e.getComponent("timeline");return i&&null!=t.currentIndex&&(i.setCurrentIndex(t.currentIndex),!i.get("loop",!0)&&i.isIndexMax()&&i.getPlayState()&&(i.setPlayState(!1),o.dispatchAction({type:"timelinePlayChange",playState:!1,from:t.from}))),e.resetOption("timeline",{replaceMerge:i.get("replaceMerge",!0)}),b({currentIndex:i.option.currentIndex},t)})),t.registerAction({type:"timelinePlayChange",event:"timelinePlayChanged",update:"update"},(function(t,e){var o=e.getComponent("timeline");o&&null!=t.playState&&o.setPlayState(t.playState)}))}(t),t.registerPreprocessor($)}export{ot as install};