basb-cli
Version:
Blog as Second Brain!
2 lines (1 loc) • 15.7 kB
JavaScript
import{g as t,l as e,m as i,A as a,c as n}from"./AxisView.js";import{X as o,G as r,x as s,B as l,a9 as d,cV as u,cb as p,d as c,bT as h,c4 as f,u as g,N as x,e as v,bh as m,Y as y,da as I,db as _,a0 as b,dc as A,J as P,I as T,ci as w,bE as D,ca as M,bG as S,_ as C,bV as E,dd as O,bU as B,aS as H,m as k,h as z}from"./index.js";import{A as V}from"./AxisBuilder.js";var L=o(),G=m,R=y,N=function(){function e(){this._dragging=!1,this.animationThreshold=15}return e.prototype.render=function(t,e,i,a){var n=e.get("value"),o=e.get("status");if(this._axisModel=t,this._axisPointerModel=e,this._api=i,a||this._lastValue!==n||this._lastStatus!==o){this._lastValue=n,this._lastStatus=o;var l=this._group,d=this._handle;if(!o||"hide"===o)return l&&l.hide(),void(d&&d.hide());l&&l.show(),d&&d.show();var u={};this.makeElOption(u,n,t,e,i);var p=u.graphicKey;p!==this._lastGraphicKey&&this.clear(i),this._lastGraphicKey=p;var c=this._moveAnimation=this.determineAnimation(t,e);if(l){var h=s(X,e,c);this.updatePointerEl(l,u,h),this.updateLabelEl(l,u,h,e)}else l=this._group=new r,this.createPointerEl(l,u,t,e),this.createLabelEl(l,u,t,e),i.getZr().add(l);K(l,e,!0),this._renderHandle(n)}},e.prototype.remove=function(t){this.clear(t)},e.prototype.dispose=function(t){this.clear(t)},e.prototype.determineAnimation=function(e,i){var a=i.get("animation"),n=e.axis,o="category"===n.type,r=i.get("snap");if(!r&&!o)return!1;if("auto"===a||null==a){var s=this.animationThreshold;if(o&&n.getBandWidth()>s)return!0;if(r){var l=t(e).seriesDataCount,d=n.getExtent();return Math.abs(d[0]-d[1])/l>s}return!1}return!0===a},e.prototype.makeElOption=function(t,e,i,a,n){},e.prototype.createPointerEl=function(t,e,i,a){var n=e.pointer;if(n){var o=L(t).pointerEl=new l[n.type](G(e.pointer));t.add(o)}},e.prototype.createLabelEl=function(t,e,i,a){if(e.label){var n=L(t).labelEl=new d(G(e.label));t.add(n),Z(n,a)}},e.prototype.updatePointerEl=function(t,e,i){var a=L(t).pointerEl;a&&e.pointer&&(a.setStyle(e.pointer.style),i(a,{shape:e.pointer.shape}))},e.prototype.updateLabelEl=function(t,e,i,a){var n=L(t).labelEl;n&&(n.setStyle(e.label.style),i(n,{x:e.label.x,y:e.label.y}),Z(n,a))},e.prototype._renderHandle=function(t){if(!this._dragging&&this.updateHandleTransform){var e,i=this._axisPointerModel,a=this._api.getZr(),n=this._handle,o=i.getModel("handle"),r=i.get("status");if(!o.get("show")||!r||"hide"===r)return n&&a.remove(n),void(this._handle=null);this._handle||(e=!0,n=this._handle=u(o.get("icon"),{cursor:"move",draggable:!0,onmousemove:function(t){p(t.event)},onmousedown:R(this._onHandleDragMove,this,0,0),drift:R(this._onHandleDragMove,this),ondragend:R(this._onHandleDragEnd,this)}),a.add(n)),K(n,i,!1),n.setStyle(o.getItemStyle(null,["color","borderColor","borderWidth","opacity","shadowColor","shadowBlur","shadowOffsetX","shadowOffsetY"]));var s=o.get("size");c(s)||(s=[s,s]),n.scaleX=s[0]/2,n.scaleY=s[1]/2,h(this,"_doDispatchAxisPointer",o.get("throttle")||0,"fixRate"),this._moveHandleToValue(t,e)}},e.prototype._moveHandleToValue=function(t,e){X(this._axisPointerModel,!e&&this._moveAnimation,this._handle,j(this.getHandleTransform(t,this._axisModel,this._axisPointerModel)))},e.prototype._onHandleDragMove=function(t,e){var i=this._handle;if(i){this._dragging=!0;var a=this.updateHandleTransform(j(i),[t,e],this._axisModel,this._axisPointerModel);this._payloadInfo=a,i.stopAnimation(),i.attr(j(a)),L(i).lastProp=null,this._doDispatchAxisPointer()}},e.prototype._doDispatchAxisPointer=function(){if(this._handle){var t=this._payloadInfo,e=this._axisModel;this._api.dispatchAction({type:"updateAxisPointer",x:t.cursorPoint[0],y:t.cursorPoint[1],tooltipOption:t.tooltipOption,axesInfo:[{axisDim:e.axis.dim,axisIndex:e.componentIndex}]})}},e.prototype._onHandleDragEnd=function(){if(this._dragging=!1,this._handle){var t=this._axisPointerModel.get("value");this._moveHandleToValue(t),this._api.dispatchAction({type:"hideTip"})}},e.prototype.clear=function(t){this._lastValue=null,this._lastStatus=null;var e=t.getZr(),i=this._group,a=this._handle;e&&i&&(this._lastGraphicKey=null,i&&e.remove(i),a&&e.remove(a),this._group=null,this._handle=null,this._payloadInfo=null),f(this,"_doDispatchAxisPointer")},e.prototype.doClear=function(){},e.prototype.buildLabel=function(t,e,i){return{x:t[i=i||0],y:t[1-i],width:e[i],height:e[1-i]}},e}();function X(t,e,i,a){Y(L(i).lastProp,a)||(L(i).lastProp=a,e?g(i,a,t):(i.stopAnimation(),i.attr(a)))}function Y(t,e){if(x(t)&&x(e)){var i=!0;return v(e,(function(e,a){i=i&&Y(t[a],e)})),!!i}return t===e}function Z(t,e){t[e.get(["label","show"])?"show":"hide"]()}function j(t){return{x:t.x||0,y:t.y||0,rotation:t.rotation||0}}function K(t,e,i){var a=e.get("z"),n=e.get("zlevel");t&&t.traverse((function(t){"group"!==t.type&&(null!=a&&(t.z=a),null!=n&&(t.zlevel=n),t.silent=i)}))}var W=N;function U(t){var e,i=t.get("type"),a=t.getModel(i+"Style");return"line"===i?(e=a.getLineStyle()).fill=null:"shadow"===i&&((e=a.getAreaStyle()).stroke=null),e}function F(t,e,i,a,n){var o=J(i.get("value"),e.axis,e.ecModel,i.get("seriesDataIndices"),{precision:i.get(["label","precision"]),formatter:i.get(["label","formatter"])}),r=i.getModel("label"),s=I(r.get("padding")||0),l=r.getFont(),d=_(o,l),u=n.position,p=d.width+s[1]+s[3],c=d.height+s[0]+s[2],h=n.align;"right"===h&&(u[0]-=p),"center"===h&&(u[0]-=p/2);var f=n.verticalAlign;"bottom"===f&&(u[1]-=c),"middle"===f&&(u[1]-=c/2),function(t,e,i,a){var n=a.getWidth(),o=a.getHeight();t[0]=Math.min(t[0]+e,n)-e,t[1]=Math.min(t[1]+i,o)-i,t[0]=Math.max(t[0],0),t[1]=Math.max(t[1],0)}(u,p,c,a);var g=r.get("backgroundColor");g&&"auto"!==g||(g=e.get(["axisLine","lineStyle","color"])),t.label={x:u[0],y:u[1],style:b(r,{text:o,font:l,fill:r.getTextColor(),padding:s,backgroundColor:g}),z2:10}}function J(t,e,i,a,n){t=e.scale.parse(t);var o=e.scale.getLabel({value:t},{precision:n.precision}),r=n.formatter;if(r){var s={value:A(e,{value:t}),axisDimension:e.dim,axisIndex:e.index,seriesData:[]};v(a,(function(t){var e=i.getSeriesByIndex(t.seriesIndex),a=t.dataIndexInside,n=e&&e.getDataParams(a);n&&s.seriesData.push(n)})),P(r)?o=r.replace("{value}",o):T(r)&&(o=r(s))}return o}function q(t,e,i){var a=S();return w(a,a,i.rotation),D(a,a,i.position),M([t.dataToCoord(e),(i.labelOffset||0)+(i.labelDirection||1)*(i.labelMargin||0)],a)}function Q(t,e,i,a,n,o){var r=V.innerTextLayout(i.rotation,0,i.labelDirection);i.labelMargin=n.get(["label","margin"]),F(e,a,n,o,{position:q(a.axis,t,i),align:r.textAlign,verticalAlign:r.textVerticalAlign})}function $(t,e,i){return{x1:t[i=i||0],y1:t[1-i],x2:e[i],y2:e[1-i]}}function tt(t,e,i){return{x:t[i=i||0],y:t[1-i],width:e[i],height:e[1-i]}}function et(t,e,i,a,n,o){return{cx:t,cy:e,r0:i,r:a,startAngle:n,endAngle:o,clockwise:!0}}var it=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return C(i,t),i.prototype.makeElOption=function(t,i,a,n,o){var r=a.axis,s=r.grid,l=n.get("type"),d=at(s,r).getOtherAxis(r).getGlobalExtent(),u=r.toGlobalCoord(r.dataToCoord(i,!0));if(l&&"none"!==l){var p=U(n),c=nt[l](r,u,d);c.style=p,t.graphicKey=c.type,t.pointer=c}Q(i,t,e(s.model,a),a,n,o)},i.prototype.getHandleTransform=function(t,i,a){var n=e(i.axis.grid.model,i,{labelInside:!1});n.labelMargin=a.get(["handle","margin"]);var o=q(i.axis,t,n);return{x:o[0],y:o[1],rotation:n.rotation+(n.labelDirection<0?Math.PI:0)}},i.prototype.updateHandleTransform=function(t,e,i,a){var n=i.axis,o=n.grid,r=n.getGlobalExtent(!0),s=at(o,n).getOtherAxis(n).getGlobalExtent(),l="x"===n.dim?0:1,d=[t.x,t.y];d[l]+=e[l],d[l]=Math.min(r[1],d[l]),d[l]=Math.max(r[0],d[l]);var u=(s[1]+s[0])/2,p=[u,u];p[l]=d[l];return{x:d[0],y:d[1],rotation:t.rotation,cursorPoint:p,tooltipOption:[{verticalAlign:"middle"},{align:"center"}][l]}},i}(W);function at(t,e){var i={};return i[e.dim+"AxisIndex"]=e.index,t.getCartesian(i)}var nt={line:function(t,e,i){return{type:"Line",subPixelOptimize:!0,shape:$([e,i[0]],[e,i[1]],ot(t))}},shadow:function(t,e,i){var a=Math.max(1,t.getBandWidth()),n=i[1]-i[0];return{type:"Rect",shape:tt([e-a/2,i[0]],[a,n],ot(t))}}};function ot(t){return"x"===t.dim?0:1}var rt=it,st=function(t){function e(){var i=null!==t&&t.apply(this,arguments)||this;return i.type=e.type,i}return C(e,t),e.type="axisPointer",e.defaultOption={show:"auto",z:50,type:"line",snap:!1,triggerTooltip:!0,triggerEmphasis:!0,value:null,status:null,link:[],animation:null,animationDurationUpdate:200,lineStyle:{color:"#B9BEC9",width:1,type:"dashed"},shadowStyle:{color:"rgba(210,219,238,0.2)"},label:{show:!0,formatter:null,precision:"auto",margin:3,color:"#fff",padding:[5,7,5,7],backgroundColor:"auto",borderColor:null,borderWidth:0,borderRadius:3},handle:{show:!1,icon:"M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4h1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7v-1.2h6.6z M13.3,22H6.7v-1.2h6.6z M13.3,19.6H6.7v-1.2h6.6z",size:45,margin:50,color:"#333",shadowBlur:3,shadowColor:"#aaa",shadowOffsetX:0,shadowOffsetY:2,throttle:40}},e}(E),lt=o(),dt=v;function ut(t,e,i){if(!O.node){var a=e.getZr();lt(a).records||(lt(a).records={}),function(t,e){if(lt(t).initialized)return;function i(i,a){t.on(i,(function(i){var n=function(t){var e={showTip:[],hideTip:[]},i=function(a){var n=e[a.type];n?n.push(a):(a.dispatchAction=i,t.dispatchAction(a))};return{dispatchAction:i,pendings:e}}(e);dt(lt(t).records,(function(t){t&&a(t,i,n.dispatchAction)})),function(t,e){var i,a=t.showTip.length,n=t.hideTip.length;a?i=t.showTip[a-1]:n&&(i=t.hideTip[n-1]);i&&(i.dispatchAction=null,e.dispatchAction(i))}(n.pendings,e)}))}lt(t).initialized=!0,i("click",s(ct,"click")),i("mousemove",s(ct,"mousemove")),i("globalout",pt)}(a,e),(lt(a).records[t]||(lt(a).records[t]={})).handler=i}}function pt(t,e,i){t.handler("leave",null,i)}function ct(t,e,i,a){e.handler(t,i,a)}function ht(t,e){if(!O.node){var i=e.getZr();(lt(i).records||{})[t]&&(lt(i).records[t]=null)}}var ft=function(t){function e(){var i=null!==t&&t.apply(this,arguments)||this;return i.type=e.type,i}return C(e,t),e.prototype.render=function(t,e,i){var a=e.getComponent("tooltip"),n=t.get("triggerOn")||a&&a.get("triggerOn")||"mousemove|click";ut("axisPointer",i,(function(t,e,i){"none"!==n&&("leave"===t||n.indexOf(t)>=0)&&i({type:"updateAxisPointer",currTrigger:t,x:e&&e.offsetX,y:e&&e.offsetY})}))},e.prototype.remove=function(t,e){ht("axisPointer",e)},e.prototype.dispose=function(t,e){ht("axisPointer",e)},e.type="axisPointer",e}(B);function gt(t,e){var i,a=[],n=t.seriesIndex;if(null==n||!(i=e.getSeriesByIndex(n)))return{point:[]};var o=i.getData(),r=H(o,t);if(null==r||r<0||c(r))return{point:[]};var s=o.getItemGraphicEl(r),l=i.coordinateSystem;if(i.getTooltipPosition)a=i.getTooltipPosition(r)||[];else if(l&&l.dataToPoint)if(t.isStacked){var d=l.getBaseAxis(),u=l.getOtherAxis(d).dim,p=d.dim,h="x"===u||"radius"===u?1:0,f=o.mapDimension(p),g=[];g[h]=o.get(f,r),g[1-h]=o.get(o.getCalculationInfo("stackResultDimension"),r),a=l.dataToPoint(g)||[]}else a=l.dataToPoint(o.getValues(k(l.dimensions,(function(t){return o.mapDimension(t)})),r))||[];else if(s){var x=s.getBoundingRect().clone();x.applyTransform(s.transform),a=[x.x+x.width/2,x.y+x.height/2]}return{point:a,el:s}}var xt=o();function vt(t,e,i){var a=t.currTrigger,n=[t.x,t.y],o=t,r=t.dispatchAction||y(i.dispatchAction,i),l=e.getComponent("axisPointer").coordSysAxesInfo;if(l){bt(n)&&(n=gt({seriesIndex:o.seriesIndex,dataIndex:o.dataIndex},e).point);var d=bt(n),u=o.axesInfo,p=l.axesInfo,c="leave"===a||bt(n),h={},f={},g={list:[],map:{}},x={showPointer:s(yt,f),showTooltip:s(It,g)};v(l.coordSysMap,(function(t,e){var i=d||t.containPoint(n);v(l.coordSysAxesInfo[e],(function(t,e){var a=t.axis,o=function(t,e){for(var i=0;i<(t||[]).length;i++){var a=t[i];if(e.axis.dim===a.axisDim&&e.axis.model.componentIndex===a.axisIndex)return a}}(u,t);if(!c&&i&&(!u||o)){var r=o&&o.value;null!=r||d||(r=a.pointToData(n)),null!=r&&mt(t,r,x,!1,h)}}))}));var m={};return v(p,(function(t,e){var i=t.linkGroup;i&&!f[e]&&v(i.axesInfo,(function(e,a){var n=f[a];if(e!==t&&n){var o=n.value;i.mapper&&(o=t.axis.scale.parse(i.mapper(o,_t(e),_t(t)))),m[t.key]=o}}))})),v(m,(function(t,e){mt(p[e],t,x,!0,h)})),function(t,e,i){var a=i.axesInfo=[];v(e,(function(e,i){var n=e.axisPointerModel.option,o=t[i];o?(!e.useHandle&&(n.status="show"),n.value=o.value,n.seriesDataIndices=(o.payloadBatch||[]).slice()):!e.useHandle&&(n.status="hide"),"show"===n.status&&a.push({axisDim:e.axis.dim,axisIndex:e.axis.model.componentIndex,value:n.value})}))}(f,p,h),function(t,e,i,a){if(bt(e)||!t.list.length)return void a({type:"hideTip"});var n=((t.list[0].dataByAxis[0]||{}).seriesDataIndices||[])[0]||{};a({type:"showTip",escapeConnect:!0,x:e[0],y:e[1],tooltipOption:i.tooltipOption,position:i.position,dataIndexInside:n.dataIndexInside,dataIndex:n.dataIndex,seriesIndex:n.seriesIndex,dataByCoordSys:t.list})}(g,n,t,r),function(t,e,i){var a=i.getZr(),n="axisPointerLastHighlights",o=xt(a)[n]||{},r=xt(a)[n]={};v(t,(function(t,e){var i=t.axisPointerModel.option;"show"===i.status&&t.triggerEmphasis&&v(i.seriesDataIndices,(function(t){var e=t.seriesIndex+" | "+t.dataIndex;r[e]=t}))}));var s=[],l=[];v(o,(function(t,e){!r[e]&&l.push(t)})),v(r,(function(t,e){!o[e]&&s.push(t)})),l.length&&i.dispatchAction({type:"downplay",escapeConnect:!0,notBlur:!0,batch:l}),s.length&&i.dispatchAction({type:"highlight",escapeConnect:!0,notBlur:!0,batch:s})}(p,0,i),h}}function mt(t,e,i,a,n){var o=t.axis;if(!o.scale.isBlank()&&o.containData(e))if(t.involveSeries){var r=function(t,e){var i=e.axis,a=i.dim,n=t,o=[],r=Number.MAX_VALUE,s=-1;return v(e.seriesModels,(function(e,l){var d,u,p=e.getData().mapDimensionsAll(a);if(e.getAxisTooltipData){var c=e.getAxisTooltipData(p,t,i);u=c.dataIndices,d=c.nestestValue}else{if(!(u=e.getData().indicesOfNearest(p[0],t,"category"===i.type?.5:null)).length)return;d=e.getData().get(p[0],u[0])}if(null!=d&&isFinite(d)){var h=t-d,f=Math.abs(h);f<=r&&((f<r||h>=0&&s<0)&&(r=f,s=h,n=d,o.length=0),v(u,(function(t){o.push({seriesIndex:e.seriesIndex,dataIndexInside:t,dataIndex:e.getData().getRawIndex(t)})})))}})),{payloadBatch:o,snapToValue:n}}(e,t),s=r.payloadBatch,l=r.snapToValue;s[0]&&null==n.seriesIndex&&z(n,s[0]),!a&&t.snap&&o.containData(l)&&null!=l&&(e=l),i.showPointer(t,e,s),i.showTooltip(t,r,l)}else i.showPointer(t,e)}function yt(t,e,i,a){t[e.key]={value:i,payloadBatch:a}}function It(t,e,a,n){var o=a.payloadBatch,r=e.axis,s=r.model,l=e.axisPointerModel;if(e.triggerTooltip&&o.length){var d=e.coordSys.model,u=i(d),p=t.map[u];p||(p=t.map[u]={coordSysId:d.id,coordSysIndex:d.componentIndex,coordSysType:d.type,coordSysMainType:d.mainType,dataByAxis:[]},t.list.push(p)),p.dataByAxis.push({axisDim:r.dim,axisIndex:s.componentIndex,axisType:s.type,axisId:s.id,value:n,valueLabelOpt:{precision:l.get(["label","precision"]),formatter:l.get(["label","formatter"])},seriesDataIndices:o.slice()})}}function _t(t){var e=t.axis.model,i={},a=i.axisDim=t.axis.dim;return i.axisIndex=i[a+"AxisIndex"]=e.componentIndex,i.axisName=i[a+"AxisName"]=e.name,i.axisId=i[a+"AxisId"]=e.id,i}function bt(t){return!t||null==t[0]||isNaN(t[0])||null==t[1]||isNaN(t[1])}function At(t){a.registerAxisPointerClass("CartesianAxisPointer",rt),t.registerComponentModel(st),t.registerComponentView(ft),t.registerPreprocessor((function(t){if(t){(!t.axisPointer||0===t.axisPointer.length)&&(t.axisPointer={});var e=t.axisPointer.link;e&&!c(e)&&(t.axisPointer.link=[e])}})),t.registerProcessor(t.PRIORITY.PROCESSOR.STATISTIC,(function(t,e){t.getComponent("axisPointer").coordSysAxesInfo=n(t,e)})),t.registerAction({type:"updateAxisPointer",event:"updateAxisPointer",update:":updateAxisPointer"},vt)}var Pt=Object.freeze({__proto__:null,install:At});export{W as B,F as a,U as b,et as c,Q as d,tt as e,gt as f,q as g,J as h,At as i,Pt as j,$ as m,ut as r,ht as u};