basb-cli
Version:
Blog as Second Brain!
2 lines (1 loc) • 9.88 kB
JavaScript
import{_ as e,g as t,a9 as a,h as i,ab as n,e as r,aW as o,f as s,u as l,s as u,o as d,a0 as c,bn as h,be as g,v as p,bo as f,b as v,bp as y,a6 as m,x as M,bq as b,C as I,m as w,aJ as x,S as P,d as D,E as A,I as S,J as V,br as _}from"./index.js";import{g as T}from"./sectorHelper.js";import{r as N,a as C,T as R,w as k}from"./Tree.js";import{e as L}from"./enableAriaDecalForTree.js";import{d as F}from"./dataFilter.js";import"./linkSeriesData.js";var j=function(p){function y(e,i,n,r){var o=p.call(this)||this;o.z2=2,o.textConfig={inside:!0},t(o).seriesIndex=i.seriesIndex;var s=new a({z2:4,silent:e.getModel().get(["label","silent"])});return o.setTextContent(s),o.updateData(!0,e,i,n,r),o}return e(y,p),y.prototype.updateData=function(e,a,c,h,g){this.node=a,a.piece=this,c=c||this._seriesModel,h=h||this._ecModel;var p=this;t(p).dataIndex=a.dataIndex;var f=a.getModel(),v=f.getModel("emphasis"),y=a.getLayout(),m=i({},y);m.label=null;var M=a.getVisual("style");M.lineJoin="bevel";var b=a.getVisual("decal");b&&(M.decal=n(b,g));var I=T(f.getModel("itemStyle"),m,!0);i(m,I),r(o,(function(e){var t=p.ensureState(e),a=f.getModel([e,"itemStyle"]);t.style=a.getItemStyle();var i=T(a,m);i&&(t.shape=i)})),e?(p.setShape(m),p.shape.r=y.r0,s(p,{shape:{r:y.r}},c,a.dataIndex)):(l(p,{shape:m},c),u(p)),p.useStyle(M),this._updateLabel(c);var w=f.getShallow("cursor");w&&p.attr("cursor",w),this._seriesModel=c||this._seriesModel,this._ecModel=h||this._ecModel;var x=v.get("focus"),P="ancestor"===x?a.getAncestorsIndices():"descendant"===x?a.getDescendantIndices():x;d(this,P,v.get("blurScope"),v.get("disabled"))},y.prototype._updateLabel=function(e){var t=this,a=this.node.getModel(),i=a.getModel("label"),n=this.node.getLayout(),o=n.endAngle-n.startAngle,s=(n.startAngle+n.endAngle)/2,l=Math.cos(s),u=Math.sin(s),d=this,p=d.getTextContent(),y=this.node.dataIndex,m=i.get("minAngle")/180*Math.PI,M=i.get("show")&&!(null!=m&&Math.abs(o)<m);function b(e,t){var a=e.get(t);return null==a?i.get(t):a}p.ignore=!M,r(g,(function(i){var r="normal"===i?a.getModel("label"):a.getModel([i,"label"]),g="normal"===i,m=g?p:p.ensureState(i),M=e.getFormattedLabel(y,i);g&&(M=M||t.node.name),m.style=c(r,{},null,"normal"!==i,!0),M&&(m.style.text=M);var I=r.get("show");null==I||g||(m.ignore=!I);var w,x=b(r,"position"),P=g?d:d.states[i],D=P.style.fill;P.textConfig={outsideFill:"inherit"===r.get("color")?D:null,inside:"outside"!==x};var A=b(r,"distance")||0,S=b(r,"align"),V=b(r,"rotate"),_=.5*Math.PI,T=1.5*Math.PI,N=h("tangential"===V?Math.PI/2-s:s),C=N>_&&!f(N-_)&&N<T;"outside"===x?(w=n.r+A,S=C?"right":"left"):S&&"center"!==S?"left"===S?(w=n.r0+A,S=C?"right":"left"):"right"===S&&(w=n.r-A,S=C?"left":"right"):(w=o===2*Math.PI&&0===n.r0?0:(n.r+n.r0)/2,S="center"),m.style.align=S,m.style.verticalAlign=b(r,"verticalAlign")||"middle",m.x=w*l+n.cx,m.y=w*u+n.cy;var R=0;"radial"===V?R=h(-s)+(C?Math.PI:0):"tangential"===V?R=h(Math.PI/2-s)+(C?Math.PI:0):v(V)&&(R=V*Math.PI/180),m.rotation=h(R)})),p.dirtyStyle()},y}(p),U="sunburstRootToNode",q="sunburstHighlight",B="sunburstUnhighlight";var E=function(t){function a(){var e=null!==t&&t.apply(this,arguments)||this;return e.type=a.type,e}return e(a,t),a.prototype.render=function(e,t,a,i){var n=this;this.seriesModel=e,this.api=a,this.ecModel=t;var r=e.getData(),o=r.tree.root,s=e.getViewRoot(),l=this.group,u=e.get("renderLabelForZeroData"),d=[];s.eachNode((function(e){d.push(e)}));var c=this._oldChildren||[];!function(i,n){if(0===i.length&&0===n.length)return;function s(e){return e.getId()}function d(s,d){!function(i,n){u||!i||i.getValue()||(i=null);if(i!==o&&n!==o)if(n&&n.piece)i?(n.piece.updateData(!1,i,e,t,a),r.setItemGraphicEl(i.dataIndex,n.piece)):function(e){if(!e)return;e.piece&&(l.remove(e.piece),e.piece=null)}(n);else if(i){var s=new j(i,e,t,a);l.add(s),r.setItemGraphicEl(i.dataIndex,s)}}(null==s?null:i[s],null==d?null:n[d])}new m(n,i,s,s).add(d).update(d).remove(M(d,null)).execute()}(d,c),function(i,r){r.depth>0?(n.virtualPiece?n.virtualPiece.updateData(!1,i,e,t,a):(n.virtualPiece=new j(i,e,t,a),l.add(n.virtualPiece)),r.piece.off("click"),n.virtualPiece.on("click",(function(e){n._rootToNode(r.parentNode)}))):n.virtualPiece&&(l.remove(n.virtualPiece),n.virtualPiece=null)}(o,s),this._initEvents(),this._oldChildren=d},a.prototype._initEvents=function(){var e=this;this.group.off("click"),this.group.on("click",(function(t){var a=!1;e.seriesModel.getViewRoot().eachNode((function(i){if(!a&&i.piece&&i.piece===t.target){var n=i.getModel().get("nodeClick");if("rootToNode"===n)e._rootToNode(i);else if("link"===n){var r=i.getModel(),o=r.get("link");if(o){var s=r.get("target",!0)||"_blank";b(o,s)}}a=!0}}))}))},a.prototype._rootToNode=function(e){e!==this.seriesModel.getViewRoot()&&this.api.dispatchAction({type:U,from:this.uid,seriesId:this.seriesModel.id,targetNode:e})},a.prototype.containPoint=function(e,t){var a=t.getData().getItemLayout(0);if(a){var i=e[0]-a.cx,n=e[1]-a.cy,r=Math.sqrt(i*i+n*n);return r<=a.r&&r>=a.r0}},a.type="sunburst",a}(I);function H(e){var t=0;r(e.children,(function(e){H(e);var a=e.value;D(a)&&(a=a[0]),t+=a}));var a=e.value;D(a)&&(a=a[0]),(null==a||isNaN(a))&&(a=t),a<0&&(a=0),D(e.value)?e.value[0]=a:e.value=a}var O=function(t){function a(){var e=null!==t&&t.apply(this,arguments)||this;return e.type=a.type,e.ignoreStyleOnData=!0,e}return e(a,t),a.prototype.getInitialData=function(e,t){var a={name:e.name,children:e.data};H(a);var i=this._levelModels=w(e.levels||[],(function(e){return new x(e,this,t)}),this),n=R.createTree(a,this,(function(e){e.wrapMethod("getItemModel",(function(e,t){var a=n.getNodeByDataIndex(t),r=i[a.depth];return r&&(e.parentModel=r),e}))}));return n.data},a.prototype.optionUpdated=function(){this.resetViewRoot()},a.prototype.getDataParams=function(e){var a=t.prototype.getDataParams.apply(this,arguments),i=this.getData().tree.getNodeByDataIndex(e);return a.treePathInfo=k(i,this),a},a.prototype.getLevelModel=function(e){return this._levelModels&&this._levelModels[e.depth]},a.prototype.getViewRoot=function(){return this._viewRoot},a.prototype.resetViewRoot=function(e){e?this._viewRoot=e:e=this._viewRoot;var t=this.getRawData().tree.root;e&&(e===t||t.contains(e))||(this._viewRoot=t)},a.prototype.enableAriaDecal=function(){L(this)},a.type="series.sunburst",a.defaultOption={z:2,center:["50%","50%"],radius:[0,"75%"],clockwise:!0,startAngle:90,minAngle:0,stillShowZeroSum:!0,nodeClick:"rootToNode",renderLabelForZeroData:!1,label:{rotate:"radial",show:!0,opacity:1,align:"center",position:"inside",distance:5,silent:!0},itemStyle:{borderWidth:1,borderColor:"white",borderType:"solid",shadowBlur:0,shadowColor:"rgba(0, 0, 0, 0.2)",shadowOffsetX:0,shadowOffsetY:0,opacity:1},emphasis:{focus:"descendant"},blur:{itemStyle:{opacity:.2},label:{opacity:.1}},animationType:"expansion",animationDuration:1e3,animationDurationUpdate:500,data:[],sort:"desc"},a}(P),Z=Math.PI/180;function z(e,t,a){t.eachSeriesByType(e,(function(e){var t=e.get("center"),i=e.get("radius");D(i)||(i=[0,i]),D(t)||(t=[t,t]);var n=a.getWidth(),o=a.getHeight(),s=Math.min(n,o),l=A(t[0],n),u=A(t[1],o),d=A(i[0],s/2),c=A(i[1],s/2),h=-e.get("startAngle")*Z,g=e.get("minAngle")*Z,p=e.getData().tree.root,f=e.getViewRoot(),v=f.depth,y=e.get("sort");null!=y&&J(f,y);var m=0;r(f.children,(function(e){!isNaN(e.getValue())&&m++}));var M=f.getValue(),b=Math.PI/(M||m)*2,I=f.depth>0,w=f.height-(I?-1:1),x=(c-d)/(w||1),P=e.get("clockwise"),S=e.get("stillShowZeroSum"),V=P?1:-1,_=function(t,a){if(t){var i=a;if(t!==p){var n=t.getValue(),o=0===M&&S?b:n*b;o<g&&(o=g),i=a+V*o;var c=t.depth-v-(I?-1:1),h=d+x*c,f=d+x*(c+1),y=e.getLevelModel(t);if(y){var m=y.get("r0",!0),w=y.get("r",!0),D=y.get("radius",!0);null!=D&&(m=D[0],w=D[1]),null!=m&&(h=A(m,s/2)),null!=w&&(f=A(w,s/2))}t.setLayout({angle:o,startAngle:a,endAngle:i,clockwise:P,cx:l,cy:u,r0:h,r:f})}if(t.children&&t.children.length){var T=0;r(t.children,(function(e){T+=_(e,a+T)}))}return i-a}};if(I){var T=d,N=d+x,C=2*Math.PI;p.setLayout({angle:C,startAngle:h,endAngle:h+C,clockwise:P,cx:l,cy:u,r0:T,r:N})}_(f,h)}))}function J(e,t){var a=e.children||[];e.children=function(e,t){if(S(t)){var a=w(e,(function(e,t){var a=e.getValue();return{params:{depth:e.depth,height:e.height,dataIndex:e.dataIndex,getValue:function(){return a}},index:t}}));return a.sort((function(e,a){return t(e.params,a.params)})),w(a,(function(t){return e[t.index]}))}var i="asc"===t;return e.sort((function(e,t){var a=(e.getValue()-t.getValue())*(i?1:-1);return 0===a?(e.dataIndex-t.dataIndex)*(i?-1:1):a}))}(a,t),a.length&&r(e.children,(function(e){J(e,t)}))}function W(e){var t={};e.eachSeriesByType("sunburst",(function(e){var a=e.getData(),n=a.tree;n.eachNode((function(r){var o=r.getModel().getModel("itemStyle").getItemStyle();o.fill||(o.fill=function(e,a,i){for(var n=e;n&&n.depth>1;)n=n.parentNode;var r=a.getColorFromPalette(n.name||n.dataIndex+"",t);return e.depth>1&&V(r)&&(r=_(r,(e.depth-1)/(i-1)*.5)),r}(r,e,n.root.height));var s=a.ensureUniqueItemVisual(r.dataIndex,"style");i(s,o)}))}))}function G(e){e.registerChartView(E),e.registerSeriesModel(O),e.registerLayout(M(z,"sunburst")),e.registerProcessor(M(F,"sunburst")),e.registerVisual(W),function(e){e.registerAction({type:U,update:"updateView"},(function(e,t){t.eachComponent({mainType:"series",subType:"sunburst",query:e},(function(t,a){var i=N(e,[U],t);if(i){var n=t.getViewRoot();n&&(e.direction=C(n,i.node)?"rollUp":"drillDown"),t.resetViewRoot(i.node)}}))})),e.registerAction({type:q,update:"none"},(function(e,t,a){e=i({},e),t.eachComponent({mainType:"series",subType:"sunburst",query:e},(function(t){var a=N(e,[q],t);a&&(e.dataIndex=a.node.dataIndex)})),y("sunburstHighlight","highlight"),a.dispatchAction(i(e,{type:"highlight"}))})),e.registerAction({type:B,update:"updateView"},(function(e,t,a){e=i({},e),y("sunburstUnhighlight","downplay"),a.dispatchAction(i(e,{type:"downplay"}))}))}(e)}export{G as install};