basb-cli
Version:
Blog as Second Brain!
2 lines (1 loc) • 7.28 kB
JavaScript
import{_ as t,ak as e,a9 as i,s as o,f as n,u as a,p as r,o as l,k as s,j as h,al as u,am as p,r as g,C as c,Y as d,x as f,an as m,ao as y,S as v,E as b,ap as x,I as L,aq as z}from"./index.js";import{s as w,g as S}from"./labelGuideHelper.js";import{c as D}from"./createSeriesDataSimply.js";import{L as I}from"./LegendVisualProvider.js";import{d as M}from"./dataFilter.js";var P=["itemStyle","opacity"],k=function(p){function g(t,o){var n=p.call(this)||this,a=n,r=new e,l=new i;return a.setTextContent(l),n.setTextGuideLine(r),n.updateData(t,o,!0),n}return t(g,p),g.prototype.updateData=function(t,e,i){var s=this,h=t.hostModel,u=t.getItemModel(e),p=t.getItemLayout(e),g=u.getModel("emphasis"),c=u.get(P);c=null==c?1:c,i||o(s),s.useStyle(t.getItemVisual(e,"style")),s.style.lineJoin="round",i?(s.setShape({points:p.points}),s.style.opacity=0,n(s,{style:{opacity:c}},h,e)):a(s,{style:{opacity:c},shape:{points:p.points}},h,e),r(s,u),this._updateLabel(t,e),l(this,g.get("focus"),g.get("blurScope"),g.get("disabled"))},g.prototype._updateLabel=function(t,e){var i=this,o=this.getTextGuideLine(),n=i.getTextContent(),r=t.hostModel,l=t.getItemModel(e),p=t.getItemLayout(e).label,g=t.getItemVisual(e,"style"),c=g.fill;s(n,h(l),{labelFetcher:t.hostModel,labelDataIndex:e,defaultOpacity:g.opacity,defaultText:t.getName(e)},{normal:{align:p.textAlign,verticalAlign:p.verticalAlign}}),i.setTextConfig({local:!0,inside:!!p.inside,insideStroke:c,outsideFill:c});var d=p.linePoints;o.setShape({points:d}),i.textGuideLineConfig={anchor:d?new u(d[0][0],d[0][1]):null},a(n,{style:{x:p.x,y:p.y}},r,e),n.attr({rotation:p.rotation,originX:p.x,originY:p.y,z2:10}),w(i,S(l),{stroke:c})},g}(p),A=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t.type=i.type,t.ignoreLabelLineUpdate=!0,t}return t(i,e),i.prototype.render=function(t,e,i){var o=t.getData(),n=this._data,a=this.group;o.diff(n).add((function(t){var e=new k(o,t);o.setItemGraphicEl(t,e),a.add(e)})).update((function(t,e){var i=n.getItemGraphicEl(e);i.updateData(o,t),a.add(i),o.setItemGraphicEl(t,i)})).remove((function(e){var i=n.getItemGraphicEl(e);g(i,t,e)})).execute(),this._data=o},i.prototype.remove=function(){this.group.removeAll(),this._data=null},i.prototype.dispose=function(){},i.type="funnel",i}(c),T=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.init=function(t){e.prototype.init.apply(this,arguments),this.legendVisualProvider=new I(d(this.getData,this),d(this.getRawData,this)),this._defaultLabelLine(t)},i.prototype.getInitialData=function(t,e){return D(this,{coordDimensions:["value"],encodeDefaulter:f(m,this)})},i.prototype._defaultLabelLine=function(t){y(t,"labelLine",["show"]);var e=t.labelLine,i=t.emphasis.labelLine;e.show=e.show&&t.label.show,i.show=i.show&&t.emphasis.label.show},i.prototype.getDataParams=function(t){var i=this.getData(),o=e.prototype.getDataParams.call(this,t),n=i.mapDimension("value"),a=i.getSum(n);return o.percent=a?+(i.get(n,t)/a*100).toFixed(2):0,o.$vars.push("percent"),o},i.type="series.funnel",i.defaultOption={z:2,legendHoverLink:!0,colorBy:"data",left:80,top:60,right:80,bottom:60,minSize:"0%",maxSize:"100%",sort:"descending",orient:"vertical",gap:0,funnelAlign:"center",label:{show:!0,position:"outer"},labelLine:{show:!0,length:20,lineStyle:{width:1}},itemStyle:{borderColor:"#fff",borderWidth:1},emphasis:{label:{show:!0}},select:{itemStyle:{borderColor:"#212121"}}},i}(v);function C(t,e){t.eachSeriesByType("funnel",(function(t){var i=t.getData(),o=i.mapDimension("value"),n=t.get("sort"),a=function(t,e){return x(t.getBoxLayoutParams(),{width:e.getWidth(),height:e.getHeight()})}(t,e),r=t.get("orient"),l=a.width,s=a.height,h=function(t,e){for(var i=t.mapDimension("value"),o=t.mapArray(i,(function(t){return t})),n=[],a="ascending"===e,r=0,l=t.count();r<l;r++)n[r]=r;return L(e)?n.sort(e):"none"!==e&&n.sort((function(t,e){return a?o[t]-o[e]:o[e]-o[t]})),n}(i,n),u=a.x,p=a.y,g="horizontal"===r?[b(t.get("minSize"),s),b(t.get("maxSize"),s)]:[b(t.get("minSize"),l),b(t.get("maxSize"),l)],c=i.getDataExtent(o),d=t.get("min"),f=t.get("max");null==d&&(d=Math.min(c[0],0)),null==f&&(f=c[1]);var m=t.get("funnelAlign"),y=t.get("gap"),v=(("horizontal"===r?l:s)-y*(i.count()-1))/i.count(),w=function(t,e){if("horizontal"===r){var n=i.get(o,t)||0,a=z(n,[d,f],g,!0),h=void 0;switch(m){case"top":h=p;break;case"center":h=p+(s-a)/2;break;case"bottom":h=p+(s-a)}return[[e,h],[e,h+a]]}var c,y=i.get(o,t)||0,v=z(y,[d,f],g,!0);switch(m){case"left":c=u;break;case"center":c=u+(l-v)/2;break;case"right":c=u+l-v}return[[c,e],[c+v,e]]};"ascending"===n&&(v=-v,y=-y,"horizontal"===r?u+=l:p+=s,h=h.reverse());for(var S=0;S<h.length;S++){var D=h[S],I=h[S+1],M=i.getItemModel(D);if("horizontal"===r){var P=M.get(["itemStyle","width"]);null==P?P=v:(P=b(P,l),"ascending"===n&&(P=-P));var k=w(D,u),A=w(I,u+P);u+=P+y,i.setItemLayout(D,{points:k.concat(A.slice().reverse())})}else{var T=M.get(["itemStyle","height"]);null==T?T=v:(T=b(T,s),"ascending"===n&&(T=-T));k=w(D,p),A=w(I,p+T);p+=T+y,i.setItemLayout(D,{points:k.concat(A.slice().reverse())})}}!function(t){var e=t.hostModel.get("orient");t.each((function(i){var o,n,a,r,l=t.getItemModel(i),s=l.getModel("label").get("position"),h=l.getModel("labelLine"),u=t.getItemLayout(i),p=u.points,g="inner"===s||"inside"===s||"center"===s||"insideLeft"===s||"insideRight"===s;if(g)"insideLeft"===s?(n=(p[0][0]+p[3][0])/2+5,a=(p[0][1]+p[3][1])/2,o="left"):"insideRight"===s?(n=(p[1][0]+p[2][0])/2-5,a=(p[1][1]+p[2][1])/2,o="right"):(n=(p[0][0]+p[1][0]+p[2][0]+p[3][0])/4,a=(p[0][1]+p[1][1]+p[2][1]+p[3][1])/4,o="center"),r=[[n,a],[n,a]];else{var c=void 0,d=void 0,f=void 0,m=void 0,y=h.get("length");"vertical"===e&&["top","bottom"].indexOf(s)>-1&&(s="left",console.warn("Position error: Funnel chart on vertical orient dose not support top and bottom.")),"horizontal"===e&&["left","right"].indexOf(s)>-1&&(s="bottom",console.warn("Position error: Funnel chart on horizontal orient dose not support left and right.")),"left"===s?(c=(p[3][0]+p[0][0])/2,d=(p[3][1]+p[0][1])/2,n=(f=c-y)-5,o="right"):"right"===s?(c=(p[1][0]+p[2][0])/2,d=(p[1][1]+p[2][1])/2,n=(f=c+y)+5,o="left"):"top"===s?(c=(p[3][0]+p[0][0])/2,a=(m=(d=(p[3][1]+p[0][1])/2)-y)-5,o="center"):"bottom"===s?(c=(p[1][0]+p[2][0])/2,a=(m=(d=(p[1][1]+p[2][1])/2)+y)+5,o="center"):"rightTop"===s?(c="horizontal"===e?p[3][0]:p[1][0],d="horizontal"===e?p[3][1]:p[1][1],"horizontal"===e?(a=(m=d-y)-5,o="center"):(n=(f=c+y)+5,o="top")):"rightBottom"===s?(c=p[2][0],d=p[2][1],"horizontal"===e?(a=(m=d+y)+5,o="center"):(n=(f=c+y)+5,o="bottom")):"leftTop"===s?(c=p[0][0],d="horizontal"===e?p[0][1]:p[1][1],"horizontal"===e?(a=(m=d-y)-5,o="center"):(n=(f=c-y)-5,o="right")):"leftBottom"===s?(c="horizontal"===e?p[1][0]:p[3][0],d="horizontal"===e?p[1][1]:p[2][1],"horizontal"===e?(a=(m=d+y)+5,o="center"):(n=(f=c-y)-5,o="right")):(c=(p[1][0]+p[2][0])/2,d=(p[1][1]+p[2][1])/2,"horizontal"===e?(a=(m=d+y)+5,o="center"):(n=(f=c+y)+5,o="left")),"horizontal"===e?n=f=c:a=m=d,r=[[c,d],[f,m]]}u.label={linePoints:r,x:n,y:a,verticalAlign:"middle",textAlign:o,inside:g}}))}(i)}))}function G(t){t.registerChartView(A),t.registerSeriesModel(T),t.registerLayout(C),t.registerProcessor(M("funnel"))}export{G as install};