10 lines
21 KiB
JavaScript
10 lines
21 KiB
JavaScript
import{D as vt,J as Ut,Oa as bt,b as Wt,c as Ft,eb as St,fb as wt,gb as Lt,h as X,hb as At,ib as Et,jb as Tt,kb as Ct,l as _t,lb as Mt,nb as Q,pb as Ot}from"./chunk-YEACHCAA.min.js";import{d as ot}from"./chunk-XUHMPXWX.min.js";function G(t,n){let o;if(n===void 0)for(let l of t)l!=null&&(o<l||o===void 0&&l>=l)&&(o=l);else{let l=-1;for(let f of t)(f=n(f,++l,t))!=null&&(o<f||o===void 0&&f>=f)&&(o=f)}return o}function $(t,n){let o;if(n===void 0)for(let l of t)l!=null&&(o>l||o===void 0&&l>=l)&&(o=l);else{let l=-1;for(let f of t)(f=n(f,++l,t))!=null&&(o>f||o===void 0&&f>=f)&&(o=f)}return o}function B(t,n){let o=0;if(n===void 0)for(let l of t)(l=+l)&&(o+=l);else{let l=-1;for(let f of t)(f=+n(f,++l,t))&&(o+=f)}return o}function qt(t){return t.target.depth}function st(t){return t.depth}function it(t,n){return n-1-t.height}function K(t,n){return t.sourceLinks.length?t.depth:n-1}function at(t){return t.targetLinks.length?t.depth:t.sourceLinks.length?$(t.sourceLinks,qt)-1:0}function V(t){return function(){return t}}function It(t,n){return J(t.source,n.source)||t.index-n.index}function Nt(t,n){return J(t.target,n.target)||t.index-n.index}function J(t,n){return t.y0-n.y0}function lt(t){return t.value}function Yt(t){return t.index}function Ht(t){return t.nodes}function Xt(t){return t.links}function Pt(t,n){let o=t.get(n);if(!o)throw new Error("missing: "+n);return o}function Rt({nodes:t}){for(let n of t){let o=n.y0,l=o;for(let f of n.sourceLinks)f.y0=o+f.width/2,o+=f.width;for(let f of n.targetLinks)f.y1=l+f.width/2,l+=f.width}}function Z(){let t=0,n=0,o=1,l=1,f=24,k=8,y,m=Yt,r=K,i,u,g=Ht,b=Xt,d=6;function _(){let e={nodes:g.apply(null,arguments),links:b.apply(null,arguments)};return A(e),L(e),E(e),M(e),w(e),Rt(e),e}_.update=function(e){return Rt(e),e},_.nodeId=function(e){return arguments.length?(m=typeof e=="function"?e:V(e),_):m},_.nodeAlign=function(e){return arguments.length?(r=typeof e=="function"?e:V(e),_):r},_.nodeSort=function(e){return arguments.length?(i=e,_):i},_.nodeWidth=function(e){return arguments.length?(f=+e,_):f},_.nodePadding=function(e){return arguments.length?(k=y=+e,_):k},_.nodes=function(e){return arguments.length?(g=typeof e=="function"?e:V(e),_):g},_.links=function(e){return arguments.length?(b=typeof e=="function"?e:V(e),_):b},_.linkSort=function(e){return arguments.length?(u=e,_):u},_.size=function(e){return arguments.length?(t=n=0,o=+e[0],l=+e[1],_):[o-t,l-n]},_.extent=function(e){return arguments.length?(t=+e[0][0],o=+e[1][0],n=+e[0][1],l=+e[1][1],_):[[t,n],[o,l]]},_.iterations=function(e){return arguments.length?(d=+e,_):d};function A({nodes:e,links:h}){for(let[c,s]of e.entries())s.index=c,s.sourceLinks=[],s.targetLinks=[];let a=new Map(e.map((c,s)=>[m(c,s,e),c]));for(let[c,s]of h.entries()){s.index=c;let{source:x,target:v}=s;typeof x!="object"&&(x=s.source=Pt(a,x)),typeof v!="object"&&(v=s.target=Pt(a,v)),x.sourceLinks.push(s),v.targetLinks.push(s)}if(u!=null)for(let{sourceLinks:c,targetLinks:s}of e)c.sort(u),s.sort(u)}function L({nodes:e}){for(let h of e)h.value=h.fixedValue===void 0?Math.max(B(h.sourceLinks,lt),B(h.targetLinks,lt)):h.fixedValue}function E({nodes:e}){let h=e.length,a=new Set(e),c=new Set,s=0;for(;a.size;){for(let x of a){x.depth=s;for(let{target:v}of x.sourceLinks)c.add(v)}if(++s>h)throw new Error("circular link");a=c,c=new Set}}function M({nodes:e}){let h=e.length,a=new Set(e),c=new Set,s=0;for(;a.size;){for(let x of a){x.height=s;for(let{source:v}of x.targetLinks)c.add(v)}if(++s>h)throw new Error("circular link");a=c,c=new Set}}function N({nodes:e}){let h=G(e,s=>s.depth)+1,a=(o-t-f)/(h-1),c=new Array(h);for(let s of e){let x=Math.max(0,Math.min(h-1,Math.floor(r.call(null,s,h))));s.layer=x,s.x0=t+x*a,s.x1=s.x0+f,c[x]?c[x].push(s):c[x]=[s]}if(i)for(let s of c)s.sort(i);return c}function z(e){let h=$(e,a=>(l-n-(a.length-1)*y)/B(a,lt));for(let a of e){let c=n;for(let s of a){s.y0=c,s.y1=c+s.value*h,c=s.y1+y;for(let x of s.sourceLinks)x.width=x.value*h}c=(l-c+y)/(a.length+1);for(let s=0;s<a.length;++s){let x=a[s];x.y0+=c*(s+1),x.y1+=c*(s+1)}P(a)}}function w(e){let h=N(e);y=Math.min(k,(l-n
|
|||
|
|
`+w.showPosition()+`
|
||
|
|
Expecting `+s.join(", ")+", got '"+(this.terminals_[S]||S)+"'":x="Parse error on line "+(L+1)+": Unexpected "+(S==N?"end of input":"'"+(this.terminals_[S]||S)+"'"),this.parseError(x,{text:w.match,token:this.terminals_[S]||S,line:w.yylineno,loc:O,expected:s})}if(T[0]instanceof Array&&T.length>1)throw new Error("Parse Error: multiple actions possible at state: "+P+", token: "+S);switch(T[0]){case 1:u.push(S),b.push(w.yytext),d.push(w.yylloc),u.push(T[1]),S=null,E=w.yyleng,A=w.yytext,L=w.yylineno,O=w.yylloc;break;case 2:if(a=this.productions_[T[1]][1],e.$=b[b.length-a],e._$={first_line:d[d.length-(a||1)].first_line,last_line:d[d.length-1].last_line,first_column:d[d.length-(a||1)].first_column,last_column:d[d.length-1].last_column},I&&(e._$.range=[d[d.length-(a||1)].range[0],d[d.length-1].range[1]]),F=this.performAction.apply(e,[A,E,L,C.yy,T[1],b,d].concat(z)),typeof F<"u")return F;a&&(u=u.slice(0,-1*a*2),b=b.slice(0,-1*a),d=d.slice(0,-1*a)),u.push(this.productions_[T[1]][0]),b.push(e.$),d.push(e._$),c=_[u[u.length-2]][u[u.length-1]],u.push(c);break;case 3:return!0}}return!0}},k=function(){var m={EOF:1,parseError:function(i,u){if(this.yy.parser)this.yy.parser.parseError(i,u);else throw new Error(i)},setInput:function(r,i){return this.yy=i||this.yy||{},this._input=r,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var r=this._input[0];this.yytext+=r,this.yyleng++,this.offset++,this.match+=r,this.matched+=r;var i=r.match(/(?:\r\n?|\n).*/g);return i?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),r},unput:function(r){var i=r.length,u=r.split(/(?:\r\n?|\n)/g);this._input=r+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-i),this.offset-=i;var g=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),u.length-1&&(this.yylineno-=u.length-1);var b=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:u?(u.length===g.length?this.yylloc.first_column:0)+g[g.length-u.length].length-u[0].length:this.yylloc.first_column-i},this.options.ranges&&(this.yylloc.range=[b[0],b[0]+this.yyleng-i]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){if(this.options.backtrack_lexer)this._backtrack=!0;else return this.parseError("Lexical error on line "+(this.yylineno+1)+`. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).
|
||
|
|
`+this.showPosition(),{text:"",token:null,line:this.yylineno});return this},less:function(r){this.unput(this.match.slice(r))},pastInput:function(){var r=this.matched.substr(0,this.matched.length-this.match.length);return(r.length>20?"...":"")+r.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var r=this.match;return r.length<20&&(r+=this._input.substr(0,20-r.length)),(r.substr(0,20)+(r.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var r=this.pastInput(),i=new Array(r.length+1).join("-");return r+this.upcomingInput()+`
|
||
|
|
`+i+"^"},test_match:function(r,i){var u,g,b;if(this.options.backtrack_lexer&&(b={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(b.yylloc.range=this.yylloc.range.slice(0))),g=r[0].match(/(?:\r\n?|\n).*/g),g&&(this.yylineno+=g.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:g?g[g.length-1].length-g[g.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+r[0].length},this.yytext+=r[0],this.match+=r[0],this.matches=r,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(r[0].length),this.matched+=r[0],u=this.performAction.call(this,this.yy,this,i,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),u)return u;if(this._backtrack){for(var d in b)this[d]=b[d];return!1}return!1},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var r,i,u,g;this._more||(this.yytext="",this.match="");for(var b=this._currentRules(),d=0;d<b.length;d++)if(u=this._input.match(this.rules[b[d]]),u&&(!i||u[0].length>i[0].length)){if(i=u,g=d,this.options.backtrack_lexer){if(r=this.test_match(u,b[d]),r!==!1)return r;if(this._backtrack){i=!1;continue}else return!1}else if(!this.options.flex)break}return i?(r=this.test_match(i,b[g]),r!==!1?r:!1):this._input===""?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+`. Unrecognized text.
|
||
|
|
`+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var i=this.next();return i||this.lex()},begin:function(i){this.conditionStack.push(i)},popState:function(){var i=this.conditionStack.length-1;return i>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(i){return i=this.conditionStack.length-1-Math.abs(i||0),i>=0?this.conditionStack[i]:"INITIAL"},pushState:function(i){this.begin(i)},stateStackSize:function(){return this.conditionStack.length},options:{"case-insensitive":!0},performAction:function(i,u,g,b){switch(g){case 0:return this.pushState("csv"),4;case 1:return 10;case 2:return 5;case 3:return 12;case 4:return this.pushState("escaped_text"),18;case 5:return 20;case 6:return this.popState("escaped_text"),18;case 7:return 19}},rules:[/^(?:sankey-beta\b)/i,/^(?:$)/i,/^(?:((\u000D\u000A)|(\u000A)))/i,/^(?:(\u002C))/i,/^(?:(\u0022))/i,/^(?:([\u0020-\u0021\u0023-\u002B\u002D-\u007E])*)/i,/^(?:(\u0022)(?!(\u0022)))/i,/^(?:(([\u0020-\u0021\u0023-\u002B\u002D-\u007E])|(\u002C)|(\u000D)|(\u000A)|(\u0022)(\u0022))*)/i],conditions:{csv:{rules:[1,2,3,4,5,6,7],inclusive:!1},escaped_text:{rules:[6,7],inclusive:!1},INITIAL:{rules:[0,1,2,3,4,5,6,7],inclusive:!0}}};return m}();f.lexer=k;function y(){this.yy={}}return y.prototype=f,f.Parser=y,new y}();mt.parser=mt;var tt=mt,et=[],nt=[],W={},ne=()=>{et=[],nt=[],W={},wt()},gt=class{constructor(n,o,l=0){this.source=n,this.target=o,this.value=l}},re=(t,n,o)=>{et.push(new gt(t,n,o))},xt=class{constructor(n){this.ID=n}},oe=t=>(t=bt.sanitizeText(t,Q()),W[t]||(W[t]=new xt(t),nt.push(W[t])),W[t]),se=()=>nt,ie=()=>et,ae=()=>({nodes:nt.map(t=>({id:t.ID})),links:et.map(t=>({source:t.source.ID,target:t.target.ID,value:t.value}))}),le={nodesMap:W,getConfig:()=>Q().sankey,getNodes:se,getLinks:ie,getGraph:ae,addLink:re,findOrCreateNode:oe,getAccTitle:At,setAccTitle:Lt,getAccDescription:Tt,setAccDescription:Et,getDiagramTitle:Mt,setDiagramTitle:Ct,clear:ne},Vt=class kt{static next(n){return new kt(n+ ++kt.count)}constructor(n){this.id=n,this.href=`#${n}`}toString(){return"url("+this.href+")"}};Vt.count=0;var Bt=Vt,ue={left:st,right:it,center:at,justify:K},fe=function(t,n,o,l){let{securityLevel:f,sankey:k}=Q(),y=Ot.sankey,m;f==="sandbox"&&(m=X("#i"+n));let r=f==="sandbox"?X(m.nodes()[0].contentDocument.body):X("body"),i=f==="sandbox"?r.select(`[id="${n}"]`):X(`[id="${n}"]`),u=k?.width??y.width,g=k?.height??y.width,b=k?.useMaxWidth??y.useMaxWidth,d=k?.nodeAlignment??y.nodeAlignment,_=k?.prefix??y.prefix,A=k?.suffix??y.suffix,L=k?.showValues??y.showValues,E=l.db.getGraph(),M=ue[d];Z().nodeId(p=>p.id).nodeWidth(10).nodePadding(10+(L?15:0)).nodeAlign(M).extent([[0,0],[u,g]])(E);let w=_t(vt);i.append("g").attr("class","nodes").selectAll(".node").data(E.nodes).join("g").attr("class","node").attr("id",p=>(p.uid=Bt.next("node-")).id).attr("transform",function(p){return"translate("+p.x0+","+p.y0+")"}).attr("x",p=>p.x0).attr("y",p=>p.y0).append("rect").attr("height",p=>p.y1-p.y0).attr("width",p=>p.x1-p.x0).attr("fill",p=>w(p.id));let C=({id:p,value:S})=>L?`${p}
|
||
|
|
${_}${Math.round(S*100)/100}${A}`:p;i.append("g").attr("class","node-labels").attr("font-family","sans-serif").attr("font-size",14).selectAll("text").data(E.nodes).join("text").attr("x",p=>p.x0<u/2?p.x1+6:p.x0-6).attr("y",p=>(p.y1+p.y0)/2).attr("dy",`${L?"0":"0.35"}em`).attr("text-anchor",p=>p.x0<u/2?"start":"end").text(C);let R=i.append("g").attr("class","links").attr("fill","none").attr("stroke-opacity",.5).selectAll(".link").data(E.links).join("g").attr("class","link").style("mix-blend-mode","multiply"),O=k?.linkColor||"gradient";if(O==="gradient"){let p=R.append("linearGradient").attr("id",S=>(S.uid=Bt.next("linearGradient-")).id).attr("gradientUnits","userSpaceOnUse").attr("x1",S=>S.source.x1).attr("x2",S=>S.target.x0);p.append("stop").attr("offset","0%").attr("stop-color",S=>w(S.source.id)),p.append("stop").attr("offset","100%").attr("stop-color",S=>w(S.target.id))}let I;switch(O){case"gradient":I=p=>p.uid;break;case"source":I=p=>w(p.source.id);break;case"target":I=p=>w(p.target.id);break;default:I=O}R.append("path").attr("d",yt()).attr("stroke",I).attr("stroke-width",p=>Math.max(1,p.width)),St(void 0,i,0,b)},ce={draw:fe},he=t=>t.replaceAll(/^[^\S\n\r]+|[^\S\n\r]+$/g,"").replaceAll(/([\n\r])+/g,`
|
||
|
|
`).trim(),de=tt.parse.bind(tt);tt.parse=t=>de(he(t));var nn={parser:tt,db:le,renderer:ce};export{nn as diagram};
|
||
|
|
//# sourceMappingURL=sankeyDiagram-707fac0f-3GVBJS6H.min.js.map
|