UNPKG

basb-cli

Version:
2 lines (1 loc) 11.3 kB
import{_ as t,bW as e,bV as i,d as n,m as o,bX as r,bY as a,R as s,ak as h,J as l,bZ as g,I as f,a9 as p,a0 as d,h as y,E as c,bU as m,b_ as u,b$ as _,e as v,ap as D,c0 as w}from"./index.js";function b(t,e){var i,s=t.cellSize;1===(i=n(s)?s:t.cellSize=[s,s]).length&&(i[1]=i[0]);var h=o([0,1],(function(t){return r(e,t)&&(i[t]="auto"),null!=i[t]&&"auto"!==i[t]}));a(t,e,{type:"box",ignoreSize:h})}var M=function(i){function n(){var t=null!==i&&i.apply(this,arguments)||this;return t.type=n.type,t}return t(n,i),n.prototype.init=function(t,n,o){var r=e(t);i.prototype.init.apply(this,arguments),b(t,r)},n.prototype.mergeOption=function(t){i.prototype.mergeOption.apply(this,arguments),b(this.option,t)},n.prototype.getCellSize=function(){return this.option.cellSize},n.type="calendar",n.defaultOption={z:2,left:80,top:60,cellSize:20,orient:"horizontal",splitLine:{show:!0,lineStyle:{color:"#000",width:1,type:"solid"}},itemStyle:{color:"#fff",borderWidth:1,borderColor:"#ccc"},dayLabel:{show:!0,firstDay:0,position:"start",margin:"50%",color:"#000"},monthLabel:{show:!0,position:"start",margin:5,align:"center",formatter:null,color:"#000"},yearLabel:{show:!0,position:null,margin:30,formatter:null,color:"#ccc",fontFamily:"sans-serif",fontWeight:"bolder",fontSize:20}},n}(i),x=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.type=i.type,t}return t(i,e),i.prototype.render=function(t,e,i){var n=this.group;n.removeAll();var o=t.coordinateSystem,r=o.getRangeInfo(),a=o.getOrient(),s=e.getLocaleModel();this._renderDayRect(t,r,n),this._renderLines(t,r,a,n),this._renderYearText(t,r,a,n),this._renderMonthText(t,s,a,n),this._renderWeekText(t,s,r,a,n)},i.prototype._renderDayRect=function(t,e,i){for(var n=t.coordinateSystem,o=t.getModel("itemStyle").getItemStyle(),r=n.getCellWidth(),a=n.getCellHeight(),h=e.start.time;h<=e.end.time;h=n.getNextNDay(h,1).time){var l=n.dataToRect([h],!1).tl,g=new s({shape:{x:l[0],y:l[1],width:r,height:a},cursor:"default",style:o});i.add(g)}},i.prototype._renderLines=function(t,e,i,n){var o=this,r=t.coordinateSystem,a=t.getModel(["splitLine","lineStyle"]).getLineStyle(),s=t.get(["splitLine","show"]),h=a.lineWidth;this._tlpoints=[],this._blpoints=[],this._firstDayOfMonth=[],this._firstDayPoints=[];for(var l=e.start,g=0;l.time<=e.end.time;g++){p(l.formatedDate),0===g&&(l=r.getDateInfo(e.start.y+"-"+e.start.m));var f=l.date;f.setMonth(f.getMonth()+1),l=r.getDateInfo(f)}function p(e){o._firstDayOfMonth.push(r.getDateInfo(e)),o._firstDayPoints.push(r.dataToRect([e],!1).tl);var h=o._getLinePointsOfOneWeek(t,e,i);o._tlpoints.push(h[0]),o._blpoints.push(h[h.length-1]),s&&o._drawSplitline(h,a,n)}p(r.getNextNDay(e.end.time,1).formatedDate),s&&this._drawSplitline(o._getEdgesPoints(o._tlpoints,h,i),a,n),s&&this._drawSplitline(o._getEdgesPoints(o._blpoints,h,i),a,n)},i.prototype._getEdgesPoints=function(t,e,i){var n=[t[0].slice(),t[t.length-1].slice()],o="horizontal"===i?0:1;return n[0][o]=n[0][o]-e/2,n[1][o]=n[1][o]+e/2,n},i.prototype._drawSplitline=function(t,e,i){var n=new h({z2:20,shape:{points:t},style:e});i.add(n)},i.prototype._getLinePointsOfOneWeek=function(t,e,i){for(var n=t.coordinateSystem,o=n.getDateInfo(e),r=[],a=0;a<7;a++){var s=n.getNextNDay(o.time,a),h=n.dataToRect([s.time],!1);r[2*s.day]=h.tl,r[2*s.day+1]=h["horizontal"===i?"bl":"tr"]}return r},i.prototype._formatterLabel=function(t,e){return l(t)&&t?g(t,e):f(t)?t(e):e.nameMap},i.prototype._yearTextPositionControl=function(t,e,i,n,o){var r=e[0],a=e[1],s=["center","bottom"];"bottom"===n?(a+=o,s=["center","top"]):"left"===n?r-=o:"right"===n?(r+=o,s=["center","top"]):a-=o;var h=0;return"left"!==n&&"right"!==n||(h=Math.PI/2),{rotation:h,x:r,y:a,style:{align:s[0],verticalAlign:s[1]}}},i.prototype._renderYearText=function(t,e,i,n){var o=t.getModel("yearLabel");if(o.get("show")){var r=o.get("margin"),a=o.get("position");a||(a="horizontal"!==i?"top":"left");var s=[this._tlpoints[this._tlpoints.length-1],this._blpoints[0]],h=(s[0][0]+s[1][0])/2,l=(s[0][1]+s[1][1])/2,g="horizontal"===i?0:1,f={top:[h,s[g][1]],bottom:[h,s[1-g][1]],left:[s[1-g][0],l],right:[s[g][0],l]},y=e.start.y;+e.end.y>+e.start.y&&(y=y+"-"+e.end.y);var c=o.get("formatter"),m={start:e.start.y,end:e.end.y,nameMap:y},u=this._formatterLabel(c,m),_=new p({z2:30,style:d(o,{text:u})});_.attr(this._yearTextPositionControl(_,f[a],i,a,r)),n.add(_)}},i.prototype._monthTextPositionControl=function(t,e,i,n,o){var r="left",a="top",s=t[0],h=t[1];return"horizontal"===i?(h+=o,e&&(r="center"),"start"===n&&(a="bottom")):(s+=o,e&&(a="middle"),"start"===n&&(r="right")),{x:s,y:h,align:r,verticalAlign:a}},i.prototype._renderMonthText=function(t,e,i,n){var o=t.getModel("monthLabel");if(o.get("show")){var r=o.get("nameMap"),a=o.get("margin"),s=o.get("position"),h=o.get("align"),g=[this._tlpoints,this._blpoints];r&&!l(r)||(r&&(e=u(r)||e),r=e.get(["time","monthAbbr"])||[]);var f="start"===s?0:1,c="horizontal"===i?0:1;a="start"===s?-a:a;for(var m="center"===h,_=0;_<g[f].length-1;_++){var v=g[f][_].slice(),D=this._firstDayOfMonth[_];if(m){var w=this._firstDayPoints[_];v[c]=(w[c]+g[0][_+1][c])/2}var b=o.get("formatter"),M=r[+D.m-1],x={yyyy:D.y,yy:(D.y+"").slice(2),MM:D.m,M:+D.m,nameMap:M},S=this._formatterLabel(b,x),I=new p({z2:30,style:y(d(o,{text:S}),this._monthTextPositionControl(v,m,i,s,a))});n.add(I)}}},i.prototype._weekTextPositionControl=function(t,e,i,n,o){var r="center",a="middle",s=t[0],h=t[1],l="start"===i;return"horizontal"===e?(s=s+n+(l?1:-1)*o[0]/2,r=l?"right":"left"):(h=h+n+(l?1:-1)*o[1]/2,a=l?"bottom":"top"),{x:s,y:h,align:r,verticalAlign:a}},i.prototype._renderWeekText=function(t,e,i,n,r){var a=t.getModel("dayLabel");if(a.get("show")){var s=t.coordinateSystem,h=a.get("position"),g=a.get("nameMap"),f=a.get("margin"),m=s.getFirstDayOfWeek();if(!g||l(g))g&&(e=u(g)||e),g=e.get(["time","dayOfWeekShort"])||o(e.get(["time","dayOfWeekAbbr"]),(function(t){return t[0]}));var _=s.getNextNDay(i.end.time,7-i.lweek).time,v=[s.getCellWidth(),s.getCellHeight()];f=c(f,Math.min(v[1],v[0])),"start"===h&&(_=s.getNextNDay(i.start.time,-(7+i.fweek)).time,f=-f);for(var D=0;D<7;D++){var w,b=s.getNextNDay(_,D),M=s.dataToRect([b.time],!1).center;w=Math.abs((D+m)%7);var x=new p({z2:30,style:y(d(a,{text:g[w]}),this._weekTextPositionControl(M,n,h,f,v))});r.add(x)}}},i.type="calendar",i}(m),S=864e5;function I(t){var e=t.calendarModel,i=t.seriesModel;return e?e.coordinateSystem:i?i.coordinateSystem:null}var k=function(){function t(e,i,n){this.type="calendar",this.dimensions=t.dimensions,this.getDimensionsInfo=t.getDimensionsInfo,this._model=e}return t.getDimensionsInfo=function(){return[{name:"time",type:"time"},"value"]},t.prototype.getRangeInfo=function(){return this._rangeInfo},t.prototype.getModel=function(){return this._model},t.prototype.getRect=function(){return this._rect},t.prototype.getCellWidth=function(){return this._sw},t.prototype.getCellHeight=function(){return this._sh},t.prototype.getOrient=function(){return this._orient},t.prototype.getFirstDayOfWeek=function(){return this._firstDayOfWeek},t.prototype.getDateInfo=function(t){var e=(t=_(t)).getFullYear(),i=t.getMonth()+1,n=i<10?"0"+i:""+i,o=t.getDate(),r=o<10?"0"+o:""+o,a=t.getDay();return{y:e+"",m:n,d:r,day:a=Math.abs((a+7-this.getFirstDayOfWeek())%7),time:t.getTime(),formatedDate:e+"-"+n+"-"+r,date:t}},t.prototype.getNextNDay=function(t,e){return 0===(e=e||0)||(t=new Date(this.getDateInfo(t).time)).setDate(t.getDate()+e),this.getDateInfo(t)},t.prototype.update=function(t,e){this._firstDayOfWeek=+this._model.getModel("dayLabel").get("firstDay"),this._orient=this._model.get("orient"),this._lineWidth=this._model.getModel("itemStyle").getItemStyle().lineWidth||0,this._rangeInfo=this._getRangeInfo(this._initRangeOption());var i=this._rangeInfo.weeks||1,n=["width","height"],o=this._model.getCellSize().slice(),r=this._model.getBoxLayoutParams(),a="horizontal"===this._orient?[i,7]:[7,i];v([0,1],(function(t){l(o,t)&&(r[n[t]]=o[t]*a[t])}));var s={width:e.getWidth(),height:e.getHeight()},h=this._rect=D(r,s);function l(t,e){return null!=t[e]&&"auto"!==t[e]}v([0,1],(function(t){l(o,t)||(o[t]=h[n[t]]/a[t])})),this._sw=o[0],this._sh=o[1]},t.prototype.dataToPoint=function(t,e){n(t)&&(t=t[0]),null==e&&(e=!0);var i=this.getDateInfo(t),o=this._rangeInfo,r=i.formatedDate;if(e&&!(i.time>=o.start.time&&i.time<o.end.time+S))return[NaN,NaN];var a=i.day,s=this._getRangeInfo([o.start.time,r]).nthWeek;return"vertical"===this._orient?[this._rect.x+a*this._sw+this._sw/2,this._rect.y+s*this._sh+this._sh/2]:[this._rect.x+s*this._sw+this._sw/2,this._rect.y+a*this._sh+this._sh/2]},t.prototype.pointToData=function(t){var e=this.pointToDate(t);return e&&e.time},t.prototype.dataToRect=function(t,e){var i=this.dataToPoint(t,e);return{contentShape:{x:i[0]-(this._sw-this._lineWidth)/2,y:i[1]-(this._sh-this._lineWidth)/2,width:this._sw-this._lineWidth,height:this._sh-this._lineWidth},center:i,tl:[i[0]-this._sw/2,i[1]-this._sh/2],tr:[i[0]+this._sw/2,i[1]-this._sh/2],br:[i[0]+this._sw/2,i[1]+this._sh/2],bl:[i[0]-this._sw/2,i[1]+this._sh/2]}},t.prototype.pointToDate=function(t){var e=Math.floor((t[0]-this._rect.x)/this._sw)+1,i=Math.floor((t[1]-this._rect.y)/this._sh)+1,n=this._rangeInfo.range;return"vertical"===this._orient?this._getDateByWeeksAndDay(i,e-1,n):this._getDateByWeeksAndDay(e,i-1,n)},t.prototype.convertToPixel=function(t,e,i){var n=I(e);return n===this?n.dataToPoint(i):null},t.prototype.convertFromPixel=function(t,e,i){var n=I(e);return n===this?n.pointToData(i):null},t.prototype.containPoint=function(t){return console.warn("Not implemented."),!1},t.prototype._initRangeOption=function(){var t,e=this._model.get("range");if(n(e)&&1===e.length&&(e=e[0]),n(e))t=e;else{var i=e.toString();if(/^\d{4}$/.test(i)&&(t=[i+"-01-01",i+"-12-31"]),/^\d{4}[\/|-]\d{1,2}$/.test(i)){var o=this.getDateInfo(i),r=o.date;r.setMonth(r.getMonth()+1);var a=this.getNextNDay(r,-1);t=[o.formatedDate,a.formatedDate]}/^\d{4}[\/|-]\d{1,2}[\/|-]\d{1,2}$/.test(i)&&(t=[i,i])}if(!t)return w("Invalid date range."),e;var s=this._getRangeInfo(t);return s.start.time>s.end.time&&t.reverse(),t},t.prototype._getRangeInfo=function(t){var e,i=[this.getDateInfo(t[0]),this.getDateInfo(t[1])];i[0].time>i[1].time&&(e=!0,i.reverse());var n=Math.floor(i[1].time/S)-Math.floor(i[0].time/S)+1,o=new Date(i[0].time),r=o.getDate(),a=i[1].date.getDate();o.setDate(r+n-1);var s=o.getDate();if(s!==a)for(var h=o.getTime()-i[1].time>0?1:-1;(s=o.getDate())!==a&&(o.getTime()-i[1].time)*h>0;)n-=h,o.setDate(s-h);var l=Math.floor((n+i[0].day+6)/7),g=e?1-l:l-1;return e&&i.reverse(),{range:[i[0].formatedDate,i[1].formatedDate],start:i[0],end:i[1],allDay:n,weeks:l,nthWeek:g,fweek:i[0].day,lweek:i[1].day}},t.prototype._getDateByWeeksAndDay=function(t,e,i){var n=this._getRangeInfo(i);if(t>n.weeks||0===t&&e<n.fweek||t===n.weeks&&e>n.lweek)return null;var o=7*(t-1)-n.fweek+e,r=new Date(n.start.time);return r.setDate(+n.start.d+o),this.getDateInfo(r)},t.create=function(e,i){var n=[];return e.eachComponent("calendar",(function(e){var i=new t(e);n.push(i),e.coordinateSystem=i})),e.eachSeries((function(t){"calendar"===t.get("coordinateSystem")&&(t.coordinateSystem=n[t.get("calendarIndex")||0])})),n},t.dimensions=["time","value"],t}();function W(t){t.registerComponentModel(M),t.registerComponentView(x),t.registerCoordinateSystem("calendar",k)}export{W as install};