semiotic 3.0.0-beta.4 → 3.0.0-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CLAUDE.md +81 -126
  2. package/README.md +6 -3
  3. package/ai/cli.js +72 -0
  4. package/dist/CategoryColors.d.ts +48 -0
  5. package/dist/ChartGrid.d.ts +37 -0
  6. package/dist/ContextLayout.d.ts +38 -0
  7. package/dist/charts/index.d.ts +2 -0
  8. package/dist/charts/shared/statisticalOverlays.d.ts +76 -0
  9. package/dist/charts/shared/types.d.ts +4 -0
  10. package/dist/charts/shared/validateChartData.d.ts +3 -0
  11. package/dist/charts/shared/withChartWrapper.d.ts +18 -0
  12. package/dist/charts/xy/AreaChart.d.ts +22 -1
  13. package/dist/charts/xy/ConnectedScatterplot.d.ts +60 -0
  14. package/dist/charts/xy/LineChart.d.ts +12 -0
  15. package/dist/network.min.js +1 -1
  16. package/dist/network.module.min.js +1 -1
  17. package/dist/ordinal.min.js +1 -1
  18. package/dist/ordinal.module.min.js +1 -1
  19. package/dist/realtime.min.js +1 -1
  20. package/dist/realtime.module.min.js +1 -1
  21. package/dist/semiotic-ai.d.ts +8 -0
  22. package/dist/semiotic-ai.min.js +1 -1
  23. package/dist/semiotic-ai.module.min.js +1 -1
  24. package/dist/semiotic-data.min.js +1 -1
  25. package/dist/semiotic-data.module.min.js +1 -1
  26. package/dist/semiotic-xy.d.ts +1 -0
  27. package/dist/semiotic.d.ts +9 -3
  28. package/dist/semiotic.min.js +1 -1
  29. package/dist/semiotic.module.min.js +1 -1
  30. package/dist/server.min.js +1 -1
  31. package/dist/server.module.min.js +1 -1
  32. package/dist/stream/DataSourceAdapter.d.ts +3 -0
  33. package/dist/stream/PipelineStore.d.ts +6 -0
  34. package/dist/stream/SceneGraph.d.ts +1 -1
  35. package/dist/stream/keyboardNav.d.ts +39 -0
  36. package/dist/stream/networkTypes.d.ts +2 -0
  37. package/dist/stream/ordinalTypes.d.ts +2 -0
  38. package/dist/stream/types.d.ts +24 -0
  39. package/dist/stream/useResponsiveSize.d.ts +10 -0
  40. package/dist/xy.min.js +1 -1
  41. package/dist/xy.module.min.js +1 -1
  42. package/package.json +6 -2
@@ -1 +1 @@
1
- import*as t from"react";import{forwardRef as e,useMemo as r,useRef as n,useState as o,useCallback as a,useEffect as i,useImperativeHandle as c,createContext as l,useContext as s,useLayoutEffect as u,useId as d}from"react";import{interpolateNumber as h}from"d3-interpolate";import{min as f,groups as y,max as g,sum as p,mean as v,group as m}from"d3-array";import{schemeCategory10 as b,interpolatePlasma as x,interpolateViridis as k,interpolatePurples as w,interpolateOranges as L,interpolateGreens as E,interpolateReds as D,interpolateBlues as A,schemeSet3 as P,schemeTableau10 as S}from"d3-scale-chromatic";import{forceLink as T,forceSimulation as O,forceManyBody as $,forceX as _,forceY as I}from"d3-force";import{scaleLinear as N,scaleOrdinal as W}from"d3-scale";import{ribbon as M,chord as j}from"d3-chord";import{arc as R}from"d3-shape";import{hierarchy as C,partition as B,pack as z,treemap as F,treemapBinary as Y,cluster as X,tree as H}from"d3-hierarchy";const G={weightChange:.1,newEdge:.5,newNode:1,threshold:3,transitionDuration:500},q={radius:3,opacity:.7,speedMultiplier:1,maxPerEdge:50,spawnRate:.1};class V{constructor(t){this.capacity=t,this.particles=Array(t);for(let e=0;t>e;e++)this.particles[e]={t:0,offset:0,edgeIndex:0,active:!1,x:0,y:0}}spawn(t){for(let e=0;this.capacity>e;e++){const r=this.particles[e];if(!r.active)return r.active=!0,r.t=0,r.offset=Math.random()-.5,r.edgeIndex=t,r.x=0,r.y=0,r}return null}step(t,e,r,n){var o;for(let a=0;this.capacity>a;a++){const i=this.particles[a];if(!i.active)continue;const c=r[i.edgeIndex];if(!c||!c.bezier){i.active=!1;continue}const l=n&&null!==(o=n[i.edgeIndex])&&void 0!==o?o:1;if(i.t+=t*e*l*(c.bezier.circular?.3:1),i.t>=1){i.active=!1;continue}const s=Z(c.bezier,i.t,i.offset);i.x=s.x,i.y=s.y}}countForEdge(t){let e=0;for(let r=0;this.capacity>r;r++)this.particles[r].active&&this.particles[r].edgeIndex===t&&e++;return e}clear(){for(let t=0;this.capacity>t;t++)this.particles[t].active=!1}resize(t){if(this.capacity>=t)return;const e=this.particles;this.particles=Array(t);for(let r=0;t>r;r++)this.particles[r]=e.length>r?e[r]:{t:0,offset:0,edgeIndex:0,active:!1,x:0,y:0};this.capacity=t}}function Z(t,e,r){if(t.circular&&t.segments)return function(t,e,r,n){const o=t.length,a=e*o,i=Math.min(Math.floor(a),o-1),c=a-i,[l,s,u,d]=t[i],h=K(l,s,u,d,c),f=d.x-l.x,y=d.y-l.y,g=Math.sqrt(f*f+y*y);if(g>.001){const t=f/g;h.x+=-y/g*r*n*2,h.y+=t*r*n*2}return h}(t.segments,e,r,t.halfWidth);if(!t.points)return{x:0,y:0};const[n,o,a,i]=t.points,c=K(n,o,a,i,e),l=i.x-n.x,s=i.y-n.y,u=Math.sqrt(l*l+s*s);if(u>.001){const e=l/u;c.x+=-s/u*r*t.halfWidth*2,c.y+=e*r*t.halfWidth*2}return c}function K(t,e,r,n,o){const a=1-o,i=a*a,c=i*a,l=o*o,s=l*o;return{x:c*t.x+3*i*o*e.x+3*a*l*r.x+s*n.x,y:c*t.y+3*i*o*e.y+3*a*l*r.y+s*n.y}}function Q(t,e){var r=t.get(e);if(!r)throw Error("missing: "+e);return r}function J(t,e){var r,n=[],o=[],a=[],i={},c=[];function l(t){a[t]=!1,i.hasOwnProperty(t)&&Object.keys(i[t]).forEach(function(e){delete i[t][e],a[e]&&l(e)})}function s(t){var e,n,d=!1;for(o.push(t),a[t]=!0,e=0;c[t].length>e;e++)(n=c[t][e])===r?(u(r,o),d=!0):a[n]||(d=s(n));if(d)l(t);else for(e=0;c[t].length>e;e++){var h=i[n=c[t][e]];h||(i[n]=h={}),h[n]=!0}return o.pop(),d}function u(t,e){var r=[].concat(e).concat(t);n.push(r)}function d(e){!function(e){for(var r=0;t.length>r;r++)r>=e&&t[r]||(t[r]=[]),t[r]=t[r].filter(function(t){return t>=e})}(e);for(var r,n=function(t){for(var e=t.length,r=Array(e),n=Array(e),o=Array(e),a=Array(e),i=Array(e),c=Array(e),l=0;e>l;++l)r[l]=-1,n[l]=0,o[l]=!1,a[l]=0,i[l]=-1,c[l]=[];var s,u=0,d=[],h=[];function f(e){var l=[e],s=[e];for(r[e]=n[e]=u,o[e]=!0,u+=1;s.length>0;){var f=t[e=s[s.length-1]];if(f.length>a[e]){for(var y=a[e];f.length>y;++y){var g=f[y];if(0>r[g]){r[g]=n[g]=u,o[g]=!0,u+=1,l.push(g),s.push(g);break}o[g]&&(n[e]=0|Math.min(n[e],n[g])),0>i[g]||c[e].push(i[g])}a[e]=y}else{if(n[e]===r[e]){var p=[],v=[],m=0;for(y=l.length-1;y>=0;--y){var b=l[y];if(o[b]=!1,p.push(b),v.push(c[b]),m+=c[b].length,i[b]=d.length,b===e){l.length=y;break}}d.push(p);var x=Array(m);for(y=0;v.length>y;y++)for(var k=0;v[y].length>k;k++)x[--m]=v[y][k];h.push(x)}s.pop()}}}for(l=0;e>l;++l)0>r[l]&&f(l);for(l=0;h.length>l;l++){var y=h[l];if(0!==y.length){y.sort(function(t,e){return t-e}),s=[y[0]];for(var g=1;y.length>g;g++)y[g]!==y[g-1]&&s.push(y[g]);h[l]=s}}return{components:d,adjacencyList:h}}(t),o=n.components.filter(function(t){return t.length>1}),a=1/0,i=0;o.length>i;i++)for(var c=0;o[i].length>c;c++)a>o[i][c]&&(a=o[i][c],r=i);var l=o[r];if(!l)return!1;var s=t.map(function(t,e){return-1===l.indexOf(e)?[]:t.filter(function(t){return-1!==l.indexOf(t)})});return{leastVertex:a,adjList:s}}r=0;for(var h=t.length;h>r;){var f=d(r);if(r=f.leastVertex,c=f.adjList){for(var y=0;c.length>y;y++)for(var g=0;c[y].length>g;g++){var p=c[y][g];a[+p]=!1,i[p]={}}s(r),r+=1}else r=h}return n}function U(t){return t.y0-t.y1>0?"up":"down"}function tt(t,e){return e(t.source)==e(t.target)}function et(t){var e=0;t.source.sourceLinks.forEach(function(t){e=t.circular?e+1:e});var r=0;return t.target.targetLinks.forEach(function(t){r=t.circular?r+1:r}),1>=e&&1>=r}function rt(t){return t.target.x0-t.source.x1}function nt(t,e){var r=at(t),n=rt(e)/Math.tan(r);return"up"==U(t)?t.y1-n:t.y1+n}function ot(t,e){var r=at(t),n=rt(e)/Math.tan(r);return"up"==U(t)?t.y1+n:t.y1-n}function at(t){var e=Math.abs(t.y1-t.y0);return Math.atan(Math.abs(t.target.x0-t.source.x1)/e)}function it(t,e){return e(t)}function ct(t){return st(t.source)}function lt(t){return st(t.target)}function st(t){return(t.y0+t.y1)/2}function ut(t){return t.virtual?0:t.value}function dt(t,e){var r=0;t.sourceLinks.forEach(function(t){r=t.circular&&!tt(t,e)?r+1:r});var n=0;return t.targetLinks.forEach(function(t){n=t.circular&&!tt(t,e)?n+1:n}),r+n}function ht(t){return t.target.depth}function ft(t,e){return t.sourceLinks.length?t.depth:e-1}function yt(t,e){return t.y0-e.y0}function gt(t,e){return e.y0-t.y0}function pt(t,e){return t.y1-e.y1}function vt(t,e){return e.y1-t.y1}function mt(t,e){return xt(t.source,e.source)||t.index-e.index}function bt(t,e){return xt(t.target,e.target)||t.index-e.index}function xt(t,e){return t.partOfCycle===e.partOfCycle?t.y0-e.y0:"top"===t.circularLinkType||"bottom"===e.circularLinkType?-1:1}function kt(t,e){return wt(t)==wt(e)?"bottom"==t.circularLinkType?gt(t,e):yt(t,e):wt(e)-wt(t)}function wt(t){return t.target.column-t.source.column}function Lt(t,e){return Et(t)==Et(e)}function Et(t){return t.y0-t.y1>0?"up":"down"}function Dt(t,e,r,n,o){let a=t;var i=Math.max(8,.15*(a.y1-a.y0));a.links.forEach(function(t){t.circular&&(t._circularWidth=Math.min(t.width,i))});var c=f(a.links,function(t){return t.source.y0});a.links.forEach(function(t){t.circular&&(t.circularPathData={})});var l=a.links.filter(function(t){return t.circular});return l.sort(function(t,e){return e.value-t.value}),l.forEach(function(t,e){t._circularStub=e>=4}),At(a.links.filter(function(t){return"top"==t.circularLinkType}),e,r),At(a.links.filter(function(t){return"bottom"==t.circularLinkType}),e,r),a.links.forEach(function(t){if(t.circular){if(t.circularPathData.arcRadius=t._circularWidth+n,t.circularPathData.rightNodeBuffer=5,t.circularPathData.leftNodeBuffer=5,t.circularPathData.sourceWidth=t.source.x1-t.source.x0,t.circularPathData.sourceX=t.source.x0+t.circularPathData.sourceWidth,t.circularPathData.targetX=t.target.x0,t.circularPathData.sourceY=t.y0,t.circularPathData.targetY=t.y1,tt(t,e)&&et(t))t.circularPathData.rightSmallArcRadius=n+t._circularWidth/2,t.circularPathData.rightLargeArcRadius=n+t._circularWidth/2,t.circularPathData.leftSmallArcRadius=n+t._circularWidth/2,t.circularPathData.leftLargeArcRadius=n+t._circularWidth/2,"bottom"==t.circularLinkType?(t.circularPathData.verticalFullExtent=t.source.y1+o+t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.leftLargeArcRadius):(t.circularPathData.verticalFullExtent=t.source.y0-o-t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.leftLargeArcRadius);else{var i=t.source.column,l=t.circularLinkType,s=a.links.filter(function(t){return t.source.column==i&&t.circularLinkType==l});s.sort("bottom"==t.circularLinkType?gt:yt);var u=0;s.forEach(function(e,o){e.circularLinkID==t.circularLinkID&&(t.circularPathData.rightSmallArcRadius=n+t._circularWidth/2+u,t.circularPathData.rightLargeArcRadius=n+t._circularWidth/2+o*r+u),u+=e._circularWidth||e.width}),i=t.target.column,(s=a.links.filter(function(t){return t.target.column==i&&t.circularLinkType==l})).sort("bottom"==t.circularLinkType?vt:pt),u=0,s.forEach(function(e,o){e.circularLinkID==t.circularLinkID&&(t.circularPathData.leftSmallArcRadius=n+t._circularWidth/2+u,t.circularPathData.leftLargeArcRadius=n+t._circularWidth/2+o*r+u),u+=e._circularWidth||e.width}),"bottom"==t.circularLinkType?(t.circularPathData.verticalFullExtent=Math.max(a.y1,t.source.y1,t.target.y1)+o+t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.leftLargeArcRadius):(t.circularPathData.verticalFullExtent=c-o-t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.leftLargeArcRadius)}t.circularPathData.rightInnerExtent=t.circularPathData.sourceX+t.circularPathData.rightNodeBuffer,t.circularPathData.leftInnerExtent=t.circularPathData.targetX-t.circularPathData.leftNodeBuffer,t.circularPathData.rightFullExtent=t.circularPathData.sourceX+t.circularPathData.rightLargeArcRadius+t.circularPathData.rightNodeBuffer,t.circularPathData.leftFullExtent=t.circularPathData.targetX-t.circularPathData.leftLargeArcRadius-t.circularPathData.leftNodeBuffer}t.path=t.circular?function(t){return"top"==t.circularLinkType?"M"+t.circularPathData.sourceX+" "+t.circularPathData.sourceY+" L"+t.circularPathData.rightInnerExtent+" "+t.circularPathData.sourceY+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightSmallArcRadius+" 0 0 0 "+t.circularPathData.rightFullExtent+" "+(t.circularPathData.sourceY-t.circularPathData.rightSmallArcRadius)+" L"+t.circularPathData.rightFullExtent+" "+t.circularPathData.verticalRightInnerExtent+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightLargeArcRadius+" 0 0 0 "+t.circularPathData.rightInnerExtent+" "+t.circularPathData.verticalFullExtent+" L"+t.circularPathData.leftInnerExtent+" "+t.circularPathData.verticalFullExtent+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftLargeArcRadius+" 0 0 0 "+t.circularPathData.leftFullExtent+" "+t.circularPathData.verticalLeftInnerExtent+" L"+t.circularPathData.leftFullExtent+" "+(t.circularPathData.targetY-t.circularPathData.leftSmallArcRadius)+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftSmallArcRadius+" 0 0 0 "+t.circularPathData.leftInnerExtent+" "+t.circularPathData.targetY+" L"+t.circularPathData.targetX+" "+t.circularPathData.targetY:"M"+t.circularPathData.sourceX+" "+t.circularPathData.sourceY+" L"+t.circularPathData.rightInnerExtent+" "+t.circularPathData.sourceY+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightSmallArcRadius+" 0 0 1 "+t.circularPathData.rightFullExtent+" "+(t.circularPathData.sourceY+t.circularPathData.rightSmallArcRadius)+" L"+t.circularPathData.rightFullExtent+" "+t.circularPathData.verticalRightInnerExtent+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightLargeArcRadius+" 0 0 1 "+t.circularPathData.rightInnerExtent+" "+t.circularPathData.verticalFullExtent+" L"+t.circularPathData.leftInnerExtent+" "+t.circularPathData.verticalFullExtent+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftLargeArcRadius+" 0 0 1 "+t.circularPathData.leftFullExtent+" "+t.circularPathData.verticalLeftInnerExtent+" L"+t.circularPathData.leftFullExtent+" "+(t.circularPathData.targetY+t.circularPathData.leftSmallArcRadius)+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftSmallArcRadius+" 0 0 1 "+t.circularPathData.leftInnerExtent+" "+t.circularPathData.targetY+" L"+t.circularPathData.targetX+" "+t.circularPathData.targetY}(t):function(t){var e=t.source.x1,r=t.y0,n=t.target.x0,o=t.y1,a=(e+n)/2;return"M"+e+","+r+"C"+a+","+r+" "+a+","+o+" "+n+","+o}(t)}),a}function At(t,e,r){t.sort(kt);var n=t.filter(function(t){return!t._circularStub});return t.forEach(function(t,o){var a=0;if(t._circularStub)t.circularPathData.verticalBuffer=0;else if(tt(t,e)&&et(t))t.circularPathData.verticalBuffer=a+t._circularWidth/2;else{for(var i=0;n.length>i;i++){var c=n[i];if(c!==t&&c.circularPathData&&void 0!==c.circularPathData.verticalBuffer&&Pt(t,c)){var l=c.circularPathData.verticalBuffer+(c._circularWidth||c.width)/2+r;a=l>a?l:a}}t.circularPathData.verticalBuffer=a+t._circularWidth/2}}),t}function Pt(t,e){return t.source.column>=e.target.column&&e.source.column>=t.target.column}function St(t){return function(){return t}}function Tt(t){return t.index}function Ot(t){return t.nodes}function $t(t){return t.links}function _t(t,e,r){var n=y(t.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]});n.forEach(function(o){var a=o.length;o.sort(e||function(t,e){return t.circularLinkType==e.circularLinkType?dt(e,r)-dt(t,r):"top"==t.circularLinkType&&"bottom"==e.circularLinkType||"top"==t.circularLinkType&&0==e.partOfCycle||0==t.partOfCycle&&"bottom"==e.circularLinkType?-1:0}),o.forEach(function(e,o){e.depth==n.length-1&&1==a||0==e.depth&&1==a?(e.y0=t.y1/2-e.value*t.ky,e.y1=e.y0+e.value*t.ky):e.partOfCycle?0==dt(e,r)?(e.y0=t.y1/2+o,e.y1=e.y0+e.value*t.ky):"top"==e.circularLinkType?(e.y0=t.y0+o,e.y1=e.y0+e.value*t.ky):(e.y0=t.y1-e.value*t.ky-o,e.y1=e.y0+e.value*t.ky):0==t.y0||0==t.y1?(e.y0=(t.y1-t.y0)/a*o,e.y1=e.y0+e.value*t.ky):(e.y0=(t.y1-t.y0)/2-a/2+o,e.y1=e.y0+e.value*t.ky)})})}function It(t,e,r,n,o,a){var i=y(t.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]});u();for(var c=1,l=a;l>0;--l)s(c*=.99,r),u();function s(e,r){var n=i.length;i.forEach(function(o){var a=o.length,i=o[0].depth;o.forEach(function(o){var c;if(o.sourceLinks.length||o.targetLinks.length)if(o.partOfCycle&&dt(o,r)>0){var l=v(o.sourceLinks,lt),s=v(o.targetLinks,ct),u=l&&s?(l+s)/2:l||s;if(u){var d=(u-st(o))*e*.3;o.y0+=d,o.y1+=d}}else if(0==i&&1==a)o.y0=t.y1/2-(c=o.y1-o.y0)/2,o.y1=t.y1/2+c/2;else if(i==n-1&&1==a)o.y0=t.y1/2-(c=o.y1-o.y0)/2,o.y1=t.y1/2+c/2;else if(1==o.targetLinks.length&&1==o.targetLinks[0].source.sourceLinks.length)c=o.y1-o.y0,o.y0=o.targetLinks[0].source.y0,o.y1=o.y0+c;else{var h=v(o.sourceLinks,lt),f=v(o.targetLinks,ct),y=((h&&f?(h+f)/2:h||f)-st(o))*e;o.y0+=y,o.y1+=y}})})}function u(){i.forEach(function(r){var a,i,c,l=t.y0,s=r.length;for(r.sort(e||xt),c=0;s>c;++c)(i=l-(a=r[c]).y0)>0&&(a.y0+=i,a.y1+=i),l=a.y1+n;if((i=l-n-t.y1)>0)for(l=a.y0-=i,a.y1-=i,c=s-2;c>=0;--c)(i=(a=r[c]).y1+o-l)>0&&(a.y0-=i,a.y1-=i),l=a.y0})}}function Nt(t){t.nodes.forEach(function(t){t.sourceLinks.sort(bt),t.targetLinks.sort(mt)}),t.nodes.forEach(function(t){var e=t.y0,r=e,n=t.y1,o=n;t.sourceLinks.forEach(function(t){t.circular?(t.y0=n-t.width/2,n-=t.width):(t.y0=e+t.width/2,e+=t.width)}),t.targetLinks.forEach(function(t){t.circular?(t.y1=o-t.width/2,o-=t.width):(t.y1=r+t.width/2,r+=t.width)})})}function Wt(){var t=0,e=0,r=1,n=1,o=24,a=8,i=null,c=Tt,l=ft,s=void 0,u=32,d=2,h=Ot,v=$t;function b(){var b={nodes:h.apply(null,arguments),links:v.apply(null,arguments)};return function(h){h.x0=t,h.y0=e,h.x1=r,h.y1=n,h.py=0,function(t,e){t.nodes.forEach(function(t,e){t.index=e,t.sourceLinks=[],t.targetLinks=[]});var r=function(t,e){var r=new Map;return m(t,e).forEach(function(t,e){r.set(e,t[0])}),r}(t.nodes,e);t.links.forEach(function(t,e){t.index=e;var n=t.source,o=t.target;"object"!=typeof n&&(n=t.source=Q(r,n)),"object"!=typeof o&&(o=t.target=Q(r,o)),n.sourceLinks.push(t),o.targetLinks.push(t)})}(h,c),function(t,e){var r=0;if(null==e){for(var n=[],o=0;t.links.length>o;o++){var a=t.links[o],i=a.source.index,c=a.target.index;n[i]||(n[i]=[]),n[c]||(n[c]=[]),-1===n[i].indexOf(c)&&n[i].push(c)}var l=J(n);l.sort(function(t,e){return t.length-e.length});var s={};for(o=0;l.length>o;o++){var u=l[o].slice(-2);s[u[0]]||(s[u[0]]={}),s[u[0]][u[1]]=!0}t.links.forEach(function(t){var e=t.target.index,n=t.source.index;e===n||s[n]&&s[n][e]?(t.circular=!0,t.circularLinkID=r++):t.circular=!1})}else t.links.forEach(function(t){e(t.source)<e(t.target)?t.circular=!1:(t.circular=!0,t.circularLinkID=r++)})}(h,s),function(t,e){var r=0,n=0;t.links.forEach(function(o){o.circular&&(o.circularLinkType=o.source.circularLinkType||o.target.circularLinkType?o.source.circularLinkType?o.source.circularLinkType:o.target.circularLinkType:n>r?"top":"bottom","top"==o.circularLinkType?r++:n++,t.nodes.forEach(function(t){it(t,e)!=it(o.source,e)&&it(t,e)!=it(o.target,e)||(t.circularLinkType=o.circularLinkType)}))}),t.links.forEach(function(t){t.circular&&(t.source.circularLinkType==t.target.circularLinkType&&(t.circularLinkType=t.source.circularLinkType),tt(t,e)&&(t.circularLinkType=t.source.circularLinkType))})}(h,c),function(t){t.nodes.forEach(function(t){t.partOfCycle=!1,t.value=Math.max(p(t.sourceLinks,ut),p(t.targetLinks,ut)),t.sourceLinks.forEach(function(e){e.circular&&(t.partOfCycle=!0,t.circularLinkType=e.circularLinkType)}),t.targetLinks.forEach(function(e){e.circular&&(t.partOfCycle=!0,t.circularLinkType=e.circularLinkType)})})}(h),function(t,e,r){var n,o,a;if(null!=e){t.nodes.sort(function(t,r){return e(t)<e(r)?-1:1});var i=0,c=e(t.nodes[0]);t.nodes.forEach(function(t){i=e(t)==c?i:i+1,c=e(t)==c?c:e(t),t.column=i})}for(n=t.nodes,o=[],a=0;n.length;++a,n=o,o=[])n.forEach(function(t){t.depth=a,t.sourceLinks.forEach(function(t){0>o.indexOf(t.target)&&!t.circular&&o.push(t.target)})});for(n=t.nodes,o=[],a=0;n.length;++a,n=o,o=[])n.forEach(function(t){t.height=a,t.targetLinks.forEach(function(t){0>o.indexOf(t.source)&&!t.circular&&o.push(t.source)})});t.nodes.forEach(function(t){t.column=null==e?r(t,a):t.column})}(h,s,l);var v=a;if(null!==i){var b=y(h.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]}),x=g(b,function(t){return t.length});x>1&&(v=Math.max(1,(n-e)*i/(x-1)))}(function(t,e,r){var n=y(t.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]});t.py=e;var o=f(n,function(e){return(t.y1-t.y0-(e.length-1)*t.py)/p(e,function(t){return t.value})});t.ky=o,t.links.forEach(function(e){e.width=e.value*t.ky});var a=g(t.nodes,function(t){return t.column});t.nodes.forEach(a>0?function(e){e.x0=t.x0+e.column*((t.x1-t.x0-r)/a),e.x1=e.x0+r}:function(e){e.x0=t.x0,e.x1=e.x0+r})})(h,v,o),_t(h,s,c),It(h,s,c,v,v,u),Nt(h),Dt(h,c,d,10,8),_t(h,s,c),It(h,s,c,v,v,u),Nt(h),Dt(h,c,d,10,8),function(t,e){let r=t;r.nodes.forEach(function(t){t.y+(t.y1-t.y0)>r.y1&&(t.y=t.y-(t.y+(t.y1-t.y0)-r.y1));var n=r.links.filter(function(r){return it(r.source,e)==it(t,e)}),o=n.length;o>1&&n.sort(function(t,e){if(!t.circular&&!e.circular){if(t.target.column==e.target.column)return t.y1-e.y1;if(!Lt(t,e))return t.y1-e.y1;if(t.target.column>e.target.column){var r=nt(e,t);return t.y1-r}if(e.target.column>t.target.column)return nt(t,e)-e.y1}return t.circular&&!e.circular?"top"==t.circularLinkType?-1:1:e.circular&&!t.circular?"top"==e.circularLinkType?1:-1:t.circular&&e.circular?t.circularLinkType===e.circularLinkType&&"top"==t.circularLinkType?t.target.column===e.target.column?t.target.y1-e.target.y1:e.target.column-t.target.column:t.circularLinkType===e.circularLinkType&&"bottom"==t.circularLinkType?t.target.column===e.target.column?e.target.y1-t.target.y1:t.target.column-e.target.column:"top"==t.circularLinkType?-1:1:void 0});var a=t.y0;n.forEach(function(t){t.y0=a+t.width/2,a+=t.width}),n.forEach(function(e,r){if("bottom"==e.circularLinkType){for(var a=r+1,i=0;o>a;a++)i+=n[a].width;e.y0=t.y1-i-e.width/2}})})}(h,c),function(t,e){let r=t;r.nodes.forEach(function(t){var n=r.links.filter(function(r){return it(r.target,e)==it(t,e)}),o=n.length;o>1&&n.sort(function(t,e){if(!t.circular&&!e.circular){if(t.source.column==e.source.column)return t.y0-e.y0;if(!Lt(t,e))return t.y0-e.y0;if(t.source.column>e.source.column){var r=ot(e,t);return t.y0-r}if(e.source.column>t.source.column)return ot(t,e)-e.y0}return t.circular&&!e.circular?"top"==t.circularLinkType?-1:1:e.circular&&!t.circular?"top"==e.circularLinkType?1:-1:t.circular&&e.circular?t.circularLinkType===e.circularLinkType&&"top"==t.circularLinkType?t.source.column===e.source.column?t.source.y1-e.source.y1:t.source.column-e.source.column:t.circularLinkType===e.circularLinkType&&"bottom"==t.circularLinkType?t.source.column===e.source.column?t.source.y1-e.source.y1:e.source.column-t.source.column:"top"==t.circularLinkType?-1:1:void 0});var a=t.y0;n.forEach(function(t){t.y1=a+t.width/2,a+=t.width}),n.forEach(function(e,r){if("bottom"==e.circularLinkType){for(var a=r+1,i=0;o>a;a++)i+=n[a].width;e.y1=t.y1-i-e.width/2}})})}(h,c),function(t){var e=t.nodes,r=t.links,n=!1,o=!1;if(r.forEach(function(t){"top"==t.circularLinkType?n=!0:"bottom"==t.circularLinkType&&(o=!0)}),0==n||0==o){var a=f(e,function(t){return t.y0}),i=g(e,function(t){return t.y1}),c=(t.y1-t.y0)/(i-a);function l(e){return(e-a)/(i-a)*(t.y1-t.y0)+t.y0}1>c?(e.forEach(function(t){t.y0=l(t.y0),t.y1=l(t.y1)}),r.forEach(function(t){t.y0=l(t.y0),t.y1=l(t.y1),t.width=t.width*c})):e.forEach(function(t){var e=t.y1-t.y0,r=l(t.y0)-t.y0;t.y0=l(t.y0),t.y1=t.y0+e,t.sourceLinks.forEach(function(t){t.y0=t.y0+r}),t.targetLinks.forEach(function(t){t.y1=t.y1+r})})}}(h),Dt(h,c,d,10,8)}(b),b}return b.update=function(t){return Nt(t),Dt(t,c,d,10,8),t},b.nodeWidth=function(t){return arguments.length?(o=+t,b):o},b.nodePadding=function(t){return arguments.length?(a=+t,b):a},b.nodePaddingRatio=function(t){return arguments.length?(i=+t,b):i},b.nodes=function(t){return arguments.length?(h="function"==typeof t?t:St(t),b):h},b.links=function(t){return arguments.length?(v="function"==typeof t?t:St(t),b):v},b.nodeId=function(t){return arguments.length?(c="function"==typeof t?t:St(t),b):c},b.nodeAlign=function(t){return arguments.length?(l="function"==typeof t?t:St(t),b):l},b.nodeSort=function(t){return arguments.length?(s=t,b):s},b.iterations=function(t){return arguments.length?(u=+t,b):u},b.circularLinkGap=function(t){return arguments.length?(d=+t,b):d},b.extent=function(o){return arguments.length?(t=+o[0][0],e=+o[0][1],r=+o[1][0],n=+o[1][1],b):[[t,e],[r,n]]},b.size=function(o){return arguments.length?(t=e=0,r=+o[0],n=+o[1],b):[r-t,n-e]},b}const Mt=t=>{let e,r,n,o,a,i,c,l,s;return"down"===t.direction?(e=t.y0-t.sankeyWidth/2,r=t.y1-t.sankeyWidth/2,n=t.y1+t.sankeyWidth/2,o=t.y0+t.sankeyWidth/2,a=t.source.y1,i=t.target.y0,c=h(a,i),l=c(.5),s=c(.5),`M${e},${a}C${e},${l} ${r},${s} ${r},${i}L${n},${i}C${n},${s} ${o},${l} ${o},${a}Z`):(e=t.source.x1,r=t.target.x0,c=h(e,r),n=c(.5),o=c(.5),a=t.y0-t.sankeyWidth/2,i=t.y1-t.sankeyWidth/2,l=t.y1+t.sankeyWidth/2,s=t.y0+t.sankeyWidth/2,`M${e},${a}C${n},${a} ${o},${i} ${r},${i}L${r},${l}C${o},${l} ${n},${s} ${e},${s}Z`)};function jt(t){var e;const r=t.sankeyWidth/2,n=(null!==(e=t._circularWidth)&&void 0!==e?e:t.sankeyWidth)/2,o=t.circularPathData;if(!o)return null;if("down"===t.direction)return null;if(t._circularStub){const e=o.sourceX,n=o.sourceY,a=o.targetX,i=o.targetY;if("object"!=typeof t.source||!t.source||"object"!=typeof t.target||!t.target)return null;const c=Math.max(15,Math.min(40,.33*(o.rightFullExtent-e))),l=Math.max(15,Math.min(40,.33*(a-o.leftFullExtent)));return`M${e},${n-r}L${e+c},${n-r}L${e+c},${n+r}L${e},${n+r}ZM${a},${i-r}L${a-l},${i-r}L${a-l},${i+r}L${a},${i+r}Z`}const a=o.sourceX,i=o.sourceY,c=o.targetX,l=o.targetY,s=o.rightFullExtent,u=o.leftFullExtent,d=o.verticalFullExtent,h="bottom"===t.circularLinkType?1:-1,f=Math.max(4,Math.min(n,15));return`M${a},${i-h*r}L${s},${i-h*r}L${s+n},${i-h*r+h*f}L${s+n},${d+h*n-h*f}L${s+n-f},${d+h*n}L${u-n+f},${d+h*n}L${u-n},${d+h*n-h*f}L${u-n},${l-h*r+h*f}L${u-n+f},${l-h*r}L${c},${l-h*r}L${c},${l+h*r}L${u},${l+h*r}L${u},${d-h*n}L${s},${d-h*n}L${s},${i+h*r}L${a},${i+h*r}Z`}const Rt={left:function(t){return t.depth},right:function(t,e){return e-1-t.height},center:function(t){return t.targetLinks.length?t.depth:t.sourceLinks.length?Math.min.apply(Math,t.sourceLinks.map(ht))-1:0},justify:ft},Ct={supportsStreaming:!0,hierarchical:!1,computeLayout(t,e,r,n){var o,a,i,c,l,s,u;if(0===t.length)return;const d="vertical"===r.orientation?"down":"right",h=r.nodeAlign||"justify",f=null!==(o=r.nodeWidth)&&void 0!==o?o:15,y=null!==(a=r.nodePaddingRatio)&&void 0!==a?a:.05,g=null!==(i=r.iterations)&&void 0!==i?i:100,p=t.map(t=>Object.assign({},t)),v=e.map(t=>Object.assign(Object.assign({},t),{source:"string"==typeof t.source?t.source:t.source.id,target:"string"==typeof t.target?t.target:t.target.id,value:Math.sqrt(Math.max(1,t.value||1))}));let m;m="down"===d?[[0,0],[n[1],n[0]]]:[[0,0],[n[0],n[1]]];const b=Wt().extent(m).links(v).nodes(p).nodeAlign(Rt[h]||ft).nodeId(t=>t.id).nodeWidth(f).iterations(g);b.nodePaddingRatio&&b.nodePaddingRatio(y),b();{let t=1/0,e=-1/0,r=1/0,o=-1/0;for(const n of p)t>n.x0&&(t=n.x0),n.x1>e&&(e=n.x1),r>n.y0&&(r=n.y0),n.y1>o&&(o=n.y1);for(const n of v){if(!n.circular||!n.circularPathData)continue;const a=n.circularPathData,i=(null!==(l=null!==(c=n._circularWidth)&&void 0!==c?c:n.width)&&void 0!==l?l:0)/2;t>a.leftFullExtent-i&&(t=a.leftFullExtent-i),a.rightFullExtent+i>e&&(e=a.rightFullExtent+i),r>a.verticalFullExtent-i&&(r=a.verticalFullExtent-i),a.verticalFullExtent+i>o&&(o=a.verticalFullExtent+i)}const a=e-t,i=o-r,u=n[0],d=n[1];if(a>0&&i>0&&(0>t||0>r||e>u||o>d)){const e=Math.min(u/a,d/i),n=-t*e+(u-a*e)/2,o=-r*e+(d-i*e)/2;for(const t of p)t.x0=t.x0*e+n,t.x1=t.x1*e+n,t.y0=t.y0*e+o,t.y1=t.y1*e+o;for(const t of v)if(t.y0=t.y0*e+o,t.y1=t.y1*e+o,t.width=(null!==(s=t.width)&&void 0!==s?s:0)*e,t._circularWidth&&(t._circularWidth*=e),t.circular&&t.circularPathData){const r=t.circularPathData;r.sourceX=r.sourceX*e+n,r.targetX=r.targetX*e+n,r.sourceY=r.sourceY*e+o,r.targetY=r.targetY*e+o,r.rightFullExtent=r.rightFullExtent*e+n,r.leftFullExtent=r.leftFullExtent*e+n,r.verticalFullExtent=r.verticalFullExtent*e+o,r.rightInnerExtent=r.rightInnerExtent*e+n,r.leftInnerExtent=r.leftInnerExtent*e+n,r.verticalRightInnerExtent=r.verticalRightInnerExtent*e+o,r.verticalLeftInnerExtent=r.verticalLeftInnerExtent*e+o,r.rightSmallArcRadius*=e,r.rightLargeArcRadius*=e,r.leftSmallArcRadius*=e,r.leftLargeArcRadius*=e,r.sourceWidth*=e,r.rightNodeBuffer*=e,r.leftNodeBuffer*=e,r.arcRadius*=e}}}const x=new Map;for(const e of t)x.set(e.id,e);for(const t of p){const e=x.get(t.id);e&&(e.x0=t.x0,e.x1=t.x1,e.y0=t.y0,e.y1=t.y1,e.value=t.value,e.depth=t.depth,e.sourceLinks=t.sourceLinks,e.targetLinks=t.targetLinks,e.width=t.x1-t.x0,e.height=t.y1-t.y0,e.x=t.x0+(t.x1-t.x0)/2,e.y=t.y0+(t.y1-t.y0)/2)}const k=new Map;for(const t of e)k.set(`${"string"==typeof t.source?t.source:t.source.id}\0${"string"==typeof t.target?t.target:t.target.id}`,t);for(const t of v){const e=t.source,r=t.target,n="object"==typeof e&&null!==e?e.id:e+"",o="object"==typeof r&&null!==r?r.id:r+"",a=k.get(`${n}\0${o}`);if(a){a.y0=t.y0,a.y1=t.y1,a.sankeyWidth=null!==(u=t.width)&&void 0!==u?u:0,a.circular=!!t.circular,a.circularPathData=t.circularPathData,a._circularWidth=t._circularWidth,a._circularStub=t._circularStub,a.path=t.path,a.circularLinkType=t.circularLinkType,a.direction=d;const e=x.get(n),r=x.get(o);e&&(a.source=e),r&&(a.target=r)}}},buildScene(t,e,r,n){var o,a,i,c;const l="vertical"===r.orientation?"down":"right",s=r.nodeStyle,u=r.edgeStyle,d=null!==(o=r.edgeOpacity)&&void 0!==o?o:.5,h=r.edgeColorBy||"source",f=Array.isArray(r.colorScheme)?r.colorScheme:b,y=new Map;t.forEach((t,e)=>{y.set(t.id,f[e%f.length])});const g=[],p=[],v=[];for(const e of t){const t=e.x1-e.x0,r=e.y1-e.y0;if(0>=t||0>=r)continue;const n=s?s(e):{},o={fill:n.fill||y.get(e.id)||"#4d430c",stroke:n.stroke,strokeWidth:n.strokeWidth,opacity:n.opacity};g.push({type:"rect",x:e.x0,y:e.y0,w:t,h:r,style:o,datum:e,id:e.id,label:e.id})}const m=[...e].sort((t,e)=>(e.sankeyWidth||0)-(t.sankeyWidth||0));for(const t of m){if(!t.sankeyWidth||0>=t.sankeyWidth)continue;const e="object"==typeof t.source?t.source:null,r="object"==typeof t.target?t.target:null;if(!e||!r)continue;let n="#999";u?n=u(t).fill||n:"target"===h&&r?n=y.get(r.id)||n:e&&(n=y.get(e.id)||n);const o=u?u(t):{};if(t._circularStub&&t.circular&&t.circularPathData){const e=t.circularPathData,r=t.sankeyWidth/2,c=Math.max(15,Math.min(40,.33*(e.rightFullExtent-e.sourceX))),l=Math.max(15,Math.min(40,.33*(e.targetX-e.leftFullExtent))),s=o.fill||n;p.push({type:"bezier",pathD:`M${e.sourceX},${e.sourceY-r}L${e.sourceX+c},${e.sourceY-r}L${e.sourceX+c},${e.sourceY+r}L${e.sourceX},${e.sourceY+r}Z`,style:{fill:s,fillOpacity:null!==(a=o.fillOpacity)&&void 0!==a?a:d,stroke:"none",opacity:o.opacity},datum:t,_gradient:{direction:"right",from:1,to:0,x0:e.sourceX,x1:e.sourceX+c}}),p.push({type:"bezier",pathD:`M${e.targetX},${e.targetY-r}L${e.targetX-l},${e.targetY-r}L${e.targetX-l},${e.targetY+r}L${e.targetX},${e.targetY+r}Z`,style:{fill:s,fillOpacity:null!==(i=o.fillOpacity)&&void 0!==i?i:d,stroke:"none",opacity:o.opacity},datum:t,_gradient:{direction:"left",from:0,to:1,x0:e.targetX-l,x1:e.targetX}});continue}let l;if(l=t.circular&&t.circularPathData?jt(t):Mt(t),!l)continue;const s={fill:o.fill||n,fillOpacity:null!==(c=o.fillOpacity)&&void 0!==c?c:d,stroke:o.stroke||"none",strokeWidth:o.strokeWidth,opacity:o.opacity};p.push({type:"bezier",pathD:l,bezierCache:t.bezier,style:s,datum:t})}if(!1!==r.showLabels){const e=(x=r.nodeLabel)?"function"==typeof x?x:t=>t[x]||t.id:null;for(const r of t){const t=r.x1-r.x0,o=r.y1-r.y0;if(0>=t||0>=o)continue;const a=e?e(r):r.id;if(!a)continue;let i,c,s;"down"===l?(i=r.x0+t/2,c=r.y1+14,s="middle"):(n[0]/2>r.x0+t/2?(i=r.x0-6,s="end"):(i=r.x1+6,s="start"),c=r.y0+o/2),v.push({x:i,y:c,text:a+"",anchor:s,baseline:"middle",fontSize:11})}}var x;return{sceneNodes:g,sceneEdges:p,labels:v}}},Bt={supportsStreaming:!1,hierarchical:!1,computeLayout(t,e,r,n){var o,a;if(0===t.length)return;const i=null!==(o=r.iterations)&&void 0!==o?o:Math.max(50,Math.min(300,Math.floor(300-2*(t.length-30)))),c=null!==(a=r.forceStrength)&&void 0!==a?a:.1,l=n[0]/2,s=n[1]/2;for(let e=0;t.length>e;e++){const r=t[e];if(null==r.x||null==r.y||0===r.x&&0===r.y){const t=10*Math.sqrt(e+.5),n=2.399963229728653*e;r.x=l+t*Math.cos(n),r.y=s+t*Math.sin(n)}}const u=zt(r.nodeSize,r.nodeSizeRange,t),d=T().strength(t=>Math.min(2.5,t.weight?t.weight*c:c)).id(t=>t.id),h=n[1]/n[0],f=O().force("charge",$().strength(t=>-25*(t=>u(t))(t))).force("x",_(n[0]/2).strength(.1*h)).force("y",I(n[1]/2).strength(.1));if(f.nodes(t),e.length>0){const t=e.map(t=>Object.assign(Object.assign({},t),{source:"string"==typeof t.source?t.source:t.source.id,target:"string"==typeof t.target?t.target:t.target.id}));f.force("link",d),f.force("link").links(t)}.1>f.alpha()&&f.alpha(1),f.stop();for(let t=0;i>t;++t)f.tick();const y=new Map;for(const e of t)y.set(e.id,e);for(const t of e){if("string"==typeof t.source){const e=y.get(t.source);e&&(t.source=e)}if("string"==typeof t.target){const e=y.get(t.target);e&&(t.target=e)}}},buildScene(t,e,r,n){var o,a,i;const c=r.nodeStyle,l=r.edgeStyle,s=zt(r.nodeSize,r.nodeSizeRange,t),u=Array.isArray(r.colorScheme)?r.colorScheme:b,d=new Map;t.forEach((t,e)=>{d.set(t.id,u[e%u.length])});const h=[],f=[],y=[];for(const e of t){if(null==e.x||null==e.y)continue;const t=s(e),r=c?c(e):{},n={fill:r.fill||d.get(e.id)||"#007bff",stroke:r.stroke||"#fff",strokeWidth:null!==(o=r.strokeWidth)&&void 0!==o?o:2,opacity:r.opacity};h.push({type:"circle",cx:e.x,cy:e.y,r:t,style:n,datum:e,id:e.id,label:e.id})}const g=new Map;for(const e of t)g.set(e.id,e);for(const t of e){const e="object"==typeof t.source?t.source:g.get(t.source),r="object"==typeof t.target?t.target:g.get(t.target);if(!e||!r)continue;if(null==e.x||null==e.y)continue;if(null==r.x||null==r.y)continue;const n=l?l(t):{},o={stroke:n.stroke||"#999",strokeWidth:null!==(a=n.strokeWidth)&&void 0!==a?a:1,opacity:null!==(i=n.opacity)&&void 0!==i?i:.6};f.push({type:"line",x1:e.x,y1:e.y,x2:r.x,y2:r.y,style:o,datum:t})}if(!1!==r.showLabels){const e=(p=r.nodeLabel)?"function"==typeof p?p:t=>t[p]||t.id:null;for(const r of t){if(null==r.x||null==r.y)continue;const t=e?e(r):r.id;if(!t)continue;const n=s(r);y.push({x:r.x,y:r.y-n-4,text:t+"",anchor:"middle",baseline:"auto",fontSize:11})}}var p;return{sceneNodes:h,sceneEdges:f,labels:y}}};function zt(t,e,r){var n,o;if(null==t)return()=>8;if("number"==typeof t)return()=>t;if("function"==typeof t)return e=>t(e)||8;const a=e||[5,20],i=r.map(e=>{var r;return null===(r=e.data)||void 0===r?void 0:r[t]}).filter(t=>null!=t&&"number"==typeof t);if(0===i.length)return()=>a[0];const c=null!==(n=f(i))&&void 0!==n?n:0,l=null!==(o=g(i))&&void 0!==o?o:1;if(c===l)return()=>(a[0]+a[1])/2;const s=N().domain([c,l]).range(a).clamp(!0);return e=>{var r;const n=null===(r=e.data)||void 0===r?void 0:r[t];return null==n||"number"!=typeof n?a[0]:s(n)}}const Ft=b,Yt={supportsStreaming:!1,hierarchical:!1,computeLayout(t,e,r,n){if(0===t.length)return;const{padAngle:o=.01,groupWidth:a=20,sortGroups:i}=r,c=Math.min(n[0],n[1])/2,l=c-a,s=n[0]/2,u=n[1]/2,d=(h=r.valueAccessor)?"function"==typeof h?h:t=>{var e;return null!==(e=t[h])&&void 0!==e?e:1}:t=>{var e;return null!==(e=t.value)&&void 0!==e?e:1};var h;const f=new Map;for(let e=0;t.length>e;e++)f.set(t[e].id,e);const y=t.length,g=Array.from({length:y},()=>Array.from({length:y},()=>0));for(const t of e){const e="string"==typeof t.target?t.target:t.target.id,r=f.get("string"==typeof t.source?t.source:t.source.id),n=f.get(e);if(void 0===r||void 0===n)continue;const o=d(t);g[r][n]=o}const p=j().padAngle(o);i&&p.sortGroups(i);const v=p(g),m=v.groups,b=R().innerRadius(l).outerRadius(c);for(const e of m){const r=t[e.index],n=b.centroid(e);r.x=n[0]+s,r.y=n[1]+u,r.arcData={startAngle:e.startAngle,endAngle:e.endAngle}}const x=new Map;for(const e of t)x.set(e.id,e);for(const t of e){const e="string"==typeof t.target?t.target:t.target.id,r=x.get("string"==typeof t.source?t.source:t.source.id),n=x.get(e);r&&(t.source=r),n&&(t.target=n)}const k=new Map;for(const t of e)k.set(`${"string"==typeof t.source?t.source:t.source.id}\0${"string"==typeof t.target?t.target:t.target.id}`,t);for(const e of v){const r=t[e.source.index].id,n=t[e.target.index].id,o=k.get(`${r}\0${n}`)||k.get(`${n}\0${r}`);o&&(o.chordData=e)}},buildScene(t,e,r,n){var o,a;const{groupWidth:i=20,edgeOpacity:c=.5}=r,l=Math.min(n[0],n[1])/2,s=l-i,u=n[0]/2,d=n[1]/2,h=r.nodeStyle,f=r.edgeStyle,y=r.edgeColorBy||"source",g=Array.isArray(r.colorScheme)?r.colorScheme:Ft,p=new Map;t.forEach((t,e)=>{p.set(t.id,g[e%g.length])});const v=M().radius(s),m=[],b=[],x=[];for(let e=0;t.length>e;e++){const r=t[e],n=r.arcData;if(!n)continue;let a;a=h?h(r).fill||p.get(r.id)||g[e%g.length]:p.get(r.id)||g[e%g.length];const i=h?h(r):{},c={fill:a,stroke:i.stroke||"black",strokeWidth:null!==(o=i.strokeWidth)&&void 0!==o?o:1,opacity:i.opacity};m.push({type:"arc",cx:u,cy:d,innerR:s,outerR:l,startAngle:n.startAngle-Math.PI/2,endAngle:n.endAngle-Math.PI/2,style:c,datum:r,id:r.id,label:r.id})}for(const t of e){const e=t.chordData;if(!e)continue;const r=v(e);if(!r)continue;const n=Xt(r,u,d);let o="#999";if(f)o=f(t).fill||o;else{const e="object"==typeof t.source?t.source:null,r="object"==typeof t.target?t.target:null;"target"===y&&r?o=p.get(r.id)||o:e&&(o=p.get(e.id)||o)}const i=f?f(t):{},l={fill:o,fillOpacity:null!==(a=i.fillOpacity)&&void 0!==a?a:c,stroke:i.stroke||"none",strokeWidth:i.strokeWidth,opacity:i.opacity};b.push({type:"ribbon",pathD:n,style:l,datum:t})}if(!1!==r.showLabels){const e=(k=r.nodeLabel)?"function"==typeof k?k:t=>t[k]||t.id:null,n=l+12;for(const r of t){const t=r.arcData;if(!t)continue;const o=e?e(r):r.id;if(!o)continue;const a=(t.startAngle+t.endAngle)/2,i=a-Math.PI/2;x.push({x:u+Math.cos(i)*n,y:d+Math.sin(i)*n,text:o+"",anchor:a>Math.PI?"end":"start",baseline:"middle",fontSize:11})}}var k;return{sceneNodes:m,sceneEdges:b,labels:x}}};function Xt(t,e,r){const n=t.match(/[a-zA-Z]|[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?/g);if(!n)return t;const o=[];let a=0;for(;n.length>a;){const t=n[a];if("M"===t||"L"===t)for(o.push(t),a++;n.length>a&&!isNaN(Number(n[a]));)o.push(Number(n[a])+e+""),a++,n.length>a&&!isNaN(Number(n[a]))&&(o.push(Number(n[a])+r+""),a++);else if("C"===t)for(o.push(t),a++;n.length>a&&!isNaN(Number(n[a]));)for(let t=0;3>t&&n.length>a&&!isNaN(Number(n[a]));t++)o.push(Number(n[a])+e+""),a++,n.length>a&&!isNaN(Number(n[a]))&&(o.push(Number(n[a])+r+""),a++);else if("Q"===t)for(o.push(t),a++;n.length>a&&!isNaN(Number(n[a]));)for(let t=0;2>t&&n.length>a&&!isNaN(Number(n[a]));t++)o.push(Number(n[a])+e+""),a++,n.length>a&&!isNaN(Number(n[a]))&&(o.push(Number(n[a])+r+""),a++);else if("A"===t)for(o.push(t),a++;n.length>a&&!isNaN(Number(n[a]));)o.push(n[a++]),n.length>a&&o.push(n[a++]),n.length>a&&o.push(n[a++]),n.length>a&&o.push(n[a++]),n.length>a&&o.push(n[a++]),n.length>a&&(o.push(Number(n[a])+e+""),a++),n.length>a&&(o.push(Number(n[a])+r+""),a++);else"Z"===t||"z"===t?(o.push(t),a++):(o.push(n[a]),a++)}return o.join(" ")}const Ht={supportsStreaming:!1,hierarchical:!0,computeLayout(t,e,r,n){var o;const a=r.__hierarchyRoot;if(!a)return;const i=r.chartType,c=(l=r.childrenAccessor)?"function"==typeof l?l:t=>t[l]:void 0;var l;const s=r.hierarchySum||(t=>{var e;return null!==(e=t.value)&&void 0!==e?e:0}),u=C(a,c);u.sum(s),u.sort((t,e)=>{var r,n;return(null!==(r=e.value)&&void 0!==r?r:0)-(null!==(n=t.value)&&void 0!==n?n:0)});const[d,h]=n;switch(i){case"tree":!function(t,e,r,n){const o=e.treeOrientation||"vertical",a=H();a.size("horizontal"===o?[n,r]:"radial"===o?[2*Math.PI,Math.min(r,n)/2*.8]:[r,n]),a(t)}(u,r,d,h);break;case"cluster":!function(t,e,r,n){const o=e.treeOrientation||"vertical",a=X();a.size("horizontal"===o?[n,r]:"radial"===o?[2*Math.PI,Math.min(r,n)/2*.8]:[r,n]),a(t)}(u,r,d,h);break;case"treemap":!function(t,e,r,n){var o,a;const i=null!==(o=e.padding)&&void 0!==o?o:4,c=null!==(a=e.paddingTop)&&void 0!==a?a:0,l=F().size([r,n]).tile(Y).padding(i);c>0&&l.paddingTop(c),l(t)}(u,r,d,h);break;case"circlepack":!function(t,e,r,n){var o;const a=null!==(o=e.padding)&&void 0!==o?o:4;z().size([r,n]).padding(a)(t)}(u,r,d,h);break;case"partition":!function(t,e,r,n){var o;B().size([r,n]).padding(null!==(o=e.padding)&&void 0!==o?o:1)(t)}(u,r,d,h)}const f=u.descendants();t.length=0,e.length=0;const y=new Map;for(let e=0;f.length>e;e++){const n=f[e],a={id:Kt(n,r,e),x:0,y:0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:null!==(o=n.value)&&void 0!==o?o:0,depth:n.depth,data:n.data,createdByFrame:!0};"tree"===i||"cluster"===i?Gt(a,n,r):"treemap"===i||"partition"===i?qt(a,n):"circlepack"===i&&Vt(a,n),a.__hierarchyNode=n,t.push(a),y.set(n,a)}if("tree"===i||"cluster"===i)for(const t of f)if(t.parent){const r=y.get(t.parent),n=y.get(t);r&&n&&e.push({source:r,target:n,value:1,y0:0,y1:0,sankeyWidth:0,data:{depth:t.depth}})}},buildScene(t,e,r,n){const o=r.nodeStyle||(()=>({})),a=r.edgeStyle||(()=>({}));switch(r.chartType){case"tree":case"cluster":return function(t,e,r,n,o,a){var i,c,l,s,u;const d=[],h=[],f=[],y=r.treeOrientation||"vertical",g="radial"===y,p=n[0]/2,v=n[1]/2,m="number"==typeof(x=r.nodeSize)?x:5,b=["#e8d5b7","#b8d4e3","#d4e3b8","#e3c4d4","#d4d4e3","#e3d4b8","#b8e3d4","#e3b8b8"];var x;for(const e of t){let t=e.x,n=e.y;g&&(t+=p,n+=v);const a=o(e);let c=a.fill||"#4d430c";r.colorByDepth&&void 0!==e.depth&&(c=b[e.depth%b.length]);const l={fill:c,stroke:a.stroke||"#fff",strokeWidth:null!==(i=a.strokeWidth)&&void 0!==i?i:1,opacity:a.opacity};d.push({type:"circle",cx:t,cy:n,r:m,style:l,datum:e,id:e.id,label:e.id,depth:e.depth})}const k=null!==(c=r.edgeOpacity)&&void 0!==c?c:.5;for(const t of e){const e="object"==typeof t.source?t.source:null,r="object"==typeof t.target?t.target:null;if(!e||!r)continue;let n=e.x,o=e.y,i=r.x,c=r.y;g&&(n+=p,o+=v,i+=p,c+=v);const u=Zt(n,o,i,c,y),d=a(t),f={fill:"none",stroke:d.stroke||"#999",strokeWidth:null!==(l=d.strokeWidth)&&void 0!==l?l:1.5,opacity:null!==(s=d.opacity)&&void 0!==s?s:k};h.push({type:"curved",pathD:u,style:f,datum:t})}if(!1!==r.showLabels){const e=Qt(r.nodeLabel);for(const r of t){const t=e?e(r):r.id;if(!t)continue;let n,o,a,i=r.x,c=r.y;if(g&&(i+=p,c+=v),g){const t=i-p,e=c-v,r=Math.sqrt(t*t+e*e);r>0?(n=i+t/r*10,o=c+e/r*10,a=0>t?"end":"start"):(n=i,o=c-12,a="middle")}else"horizontal"===y?((null===(u=r.data)||void 0===u?void 0:u.children)&&0!==r.data.children.length?(n=i-m-6,a="end"):(n=i+m+6,a="start"),o=c):(n=i,o=c+m+14,a="middle");f.push({x:n,y:o,text:t+"",anchor:a,baseline:"middle",fontSize:11})}}return{sceneNodes:d,sceneEdges:h,labels:f}}(t,e,r,n,o,a);case"treemap":case"partition":return function(t,e,r,n){var o,a;const i=[],c=[],l=["#e8d5b7","#b8d4e3","#d4e3b8","#e3c4d4","#d4d4e3","#e3d4b8","#b8e3d4","#e3b8b8"];for(const r of t){const t=r.x1-r.x0,a=r.y1-r.y0;if(0>=t||0>=a)continue;const c=n(r);let s=c.fill||"#4d430c";e.colorByDepth&&void 0!==r.depth&&(s=l[r.depth%l.length]);const u={fill:s,stroke:c.stroke||"#fff",strokeWidth:null!==(o=c.strokeWidth)&&void 0!==o?o:1,opacity:c.opacity};i.push({type:"rect",x:r.x0,y:r.y0,w:t,h:a,style:u,datum:r,id:r.id,label:r.id,depth:r.depth})}if(!1!==e.showLabels){const r=Qt(e.nodeLabel);for(const n of t){const t=n.x1-n.x0,o=n.y1-n.y0;if(0>=t||0>=o)continue;if((null===(a=n.data)||void 0===a?void 0:a.children)&&n.data.children.length>0&&"partition"!==e.chartType)continue;const i=r?r(n):n.id;i&&(30>t||16>o||c.push({x:n.x0+t/2,y:n.y0+o/2,text:i+"",anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,Math.min(t,o)/6))}))}}return{sceneNodes:i,sceneEdges:[],labels:c}}(t,r,0,o);case"circlepack":return function(t,e,r,n){var o,a,i,c,l;const s=[],u=[],d=["#e8d5b7","#b8d4e3","#d4e3b8","#e3c4d4","#d4d4e3","#e3d4b8","#b8e3d4","#e3b8b8"];for(const r of t){const t=null!==(o=r.__radius)&&void 0!==o?o:5;if(0>=t)continue;const c=n(r);let l=c.fill||"#4d430c";e.colorByDepth&&void 0!==r.depth&&(l=d[r.depth%d.length]);const u={fill:l,stroke:c.stroke||"#fff",strokeWidth:null!==(a=c.strokeWidth)&&void 0!==a?a:1,opacity:null!==(i=c.opacity)&&void 0!==i?i:.7};s.push({type:"circle",cx:r.x,cy:r.y,r:t,style:u,datum:r,id:r.id,label:r.id,depth:r.depth})}if(!1!==e.showLabels){const r=Qt(e.nodeLabel);for(const e of t){const t=null!==(c=e.__radius)&&void 0!==c?c:5,n=r?r(e):e.id;if(!n)continue;if(15>t)continue;const o=!((null===(l=e.data)||void 0===l?void 0:l.children)&&e.data.children.length>0);u.push({x:e.x,y:o?e.y:e.y-t+14,text:n+"",anchor:"middle",baseline:o?"middle":"hanging",fontSize:Math.min(11,Math.max(8,t/3)),fill:o?void 0:"#000",stroke:o?void 0:"#fff",strokeWidth:o?void 0:3,paintOrder:o?void 0:"stroke"})}}return{sceneNodes:s,sceneEdges:[],labels:u}}(t,r,0,o);default:return{sceneNodes:[],sceneEdges:[],labels:[]}}}};function Gt(t,e,r){const n=r.treeOrientation||"vertical";if("radial"===n){const r=e.x,n=e.y;t.x=n*Math.cos(r-Math.PI/2),t.y=n*Math.sin(r-Math.PI/2)}else"horizontal"===n?(t.x=e.y,t.y=e.x):(t.x=e.x,t.y=e.y);t.x0=t.x-5,t.x1=t.x+5,t.y0=t.y-5,t.y1=t.y+5,t.width=10,t.height=10}function qt(t,e){t.x0=e.x0,t.x1=e.x1,t.y0=e.y0,t.y1=e.y1,t.x=(e.x0+e.x1)/2,t.y=(e.y0+e.y1)/2,t.width=e.x1-e.x0,t.height=e.y1-e.y0}function Vt(t,e){var r;const n=null!==(r=e.r)&&void 0!==r?r:0;t.x=e.x,t.y=e.y,t.x0=e.x-n,t.x1=e.x+n,t.y0=e.y-n,t.y1=e.y+n,t.width=2*n,t.height=2*n,t.__radius=n}function Zt(t,e,r,n,o){if("horizontal"===o){const o=(t+r)/2;return`M ${t},${e} C ${o},${e} ${o},${n} ${r},${n}`}if("radial"===o){const o=(t+r)/2;return`M ${t},${e} Q ${o},${e} ${o},${(e+n)/2} T ${r},${n}`}{const o=(e+n)/2;return`M ${t},${e} C ${t},${o} ${r},${o} ${r},${n}`}}function Kt(t,e,r){const n=e.nodeIDAccessor;return"function"==typeof n?n(t.data)+"":"string"==typeof n&&void 0!==t.data[n]?t.data[n]+"":void 0!==t.data.name?t.data.name+"":void 0!==t.data.id?t.data.id+"":"node-"+r}function Qt(t){return t?"function"==typeof t?t:e=>{var r;return(null===(r=e.data)||void 0===r?void 0:r[t])||e[t]||e.id}:null}const Jt={sankey:Ct,force:Bt,chord:Yt,tree:Ht,cluster:Ht,treemap:Ht,circlepack:Ht,partition:Ht};function Ut(t){return Jt[t]}class te{constructor(t){this.nodes=new Map,this.edges=new Map,this.tension=0,this.layoutVersion=0,this.sceneNodes=[],this.sceneEdges=[],this.labels=[],this.particlePool=null,this.transition=null,this.lastIngestTime=0,this.nodeTimestamps=new Map,this.edgeTimestamps=new Map,this.addedNodes=new Set,this.removedNodes=new Set,this.addedEdges=new Set,this.removedEdges=new Set,this.lastTopologyChangeTime=0,this.previousNodeIds=new Set,this.previousEdgeKeys=new Set,this.config=t,this.tensionConfig=Object.assign(Object.assign({},G),t.tensionConfig),"sankey"===t.chartType&&t.showParticles&&(this.particlePool=new V(2e3))}updateConfig(t){this.config=t,this.tensionConfig=Object.assign(Object.assign({},G),t.tensionConfig),"sankey"===t.chartType&&t.showParticles?this.particlePool||(this.particlePool=new V(2e3)):this.particlePool=null}ingestHierarchy(t,e){this.nodes.clear(),this.edges.clear(),this.config.__hierarchyRoot=t,this.runLayout(e)}ingestBounded(t,e,r){const{nodeIDAccessor:n="id",sourceAccessor:o="source",targetAccessor:a="target",valueAccessor:i="value"}=this.config,c="function"==typeof n?n:t=>t[n],l="function"==typeof o?o:t=>t[o],s="function"==typeof a?a:t=>t[a],u="function"==typeof i?i:t=>{var e;return null!==(e=t[i])&&void 0!==e?e:1};this.nodes.clear(),this.edges.clear();for(const e of t){const t=c(e)+"";this.nodes.set(t,Object.assign(Object.assign({},ee(t)),{data:e}))}for(const t of e){const e=l(t)+"",r=s(t)+"",n=Number(u(t))||1;this.nodes.has(e)||this.nodes.set(e,Object.assign(Object.assign({},ee(e)),{data:t})),this.nodes.has(r)||this.nodes.set(r,Object.assign(Object.assign({},ee(r)),{data:t})),this.edges.set(`${e}\0${r}`,{source:e,target:r,value:n,y0:0,y1:0,sankeyWidth:0,data:t})}this.runLayout(r)}edgeKey(t,e){return`${t}\0${e}`}ingestEdge(t){const{source:e,target:r,value:n}=t,o=0===this.nodes.size;let a=!1;const i="undefined"!=typeof performance?performance.now():Date.now();this.lastIngestTime=i,this.nodes.has(e)||(this.nodes.set(e,ee(e)),this.nodeTimestamps.set(e,i),this.tension+=this.tensionConfig.newNode,a=!0),this.nodes.has(r)||(this.nodes.set(r,ee(r)),this.nodeTimestamps.set(r,i),this.tension+=this.tensionConfig.newNode,a=!0);const c=this.edgeKey(e,r),l=this.edges.get(c);return l?(l.value+=n,this.edgeTimestamps.set(c,i),this.tension+=this.tensionConfig.weightChange):(this.edges.set(c,{source:e,target:r,value:n,y0:0,y1:0,sankeyWidth:0}),this.edgeTimestamps.set(c,i),this.tension+=this.tensionConfig.newEdge,a=!0),o||a||this.tension>=this.tensionConfig.threshold}runLayout(t){const e=Ut(this.config.chartType);if(!e)return;let r=Array.from(this.nodes.values()),n=Array.from(this.edges.values());if(0===r.length&&!e.hierarchical)return;if(this.prepareForRelayout(),e.computeLayout(r,n,this.config,t),e.hierarchical&&r.length>0){this.nodes.clear(),this.edges.clear();for(const t of r)this.nodes.set(t.id,t);for(const t of n)this.edges.set(`${"string"==typeof t.source?t.source:t.source.id}\0${"string"==typeof t.target?t.target:t.target.id}`,t)}this.finalizeLayout(),this.saveTargetPositions(),r.some(t=>void 0!==t._prevX0&&(0!==t._prevX0||0!==t._prevX1||0!==t._prevY0||0!==t._prevY1))&&this.tensionConfig.transitionDuration>0&&(this.restorePreviousPositions(),this.transition={startTime:performance.now(),duration:this.tensionConfig.transitionDuration});const o=new Set(this.nodes.keys()),a=new Set(this.edges.keys());this.addedNodes=new Set,this.removedNodes=new Set,this.addedEdges=new Set,this.removedEdges=new Set;for(const t of o)this.previousNodeIds.has(t)||this.addedNodes.add(t);for(const t of this.previousNodeIds)o.has(t)||this.removedNodes.add(t);for(const t of a)this.previousEdgeKeys.has(t)||this.addedEdges.add(t);for(const t of this.previousEdgeKeys)a.has(t)||this.removedEdges.add(t);(this.addedNodes.size>0||this.removedNodes.size>0||this.addedEdges.size>0||this.removedEdges.size>0)&&(this.lastTopologyChangeTime="undefined"!=typeof performance?performance.now():Date.now()),this.previousNodeIds=o,this.previousEdgeKeys=a,this.layoutVersion++}buildScene(t){const e=Ut(this.config.chartType);if(!e)return;const r=Array.from(this.nodes.values()),n=Array.from(this.edges.values()),{sceneNodes:o,sceneEdges:a,labels:i}=e.buildScene(r,n,this.config,t);this.sceneNodes=o,this.sceneEdges=a,this.labels=i}advanceTransition(t){if(!this.transition)return!1;const e=Math.min((t-this.transition.startTime)/this.transition.duration,1),r=1-Math.pow(1-e,3);for(const t of this.nodes.values())void 0===t._targetX0||void 0===t._prevX0||0===t._prevX0&&0===t._prevX1||(t.x0=t._prevX0+(t._targetX0-t._prevX0)*r,t.x1=t._prevX1+(t._targetX1-t._prevX1)*r,t.y0=t._prevY0+(t._targetY0-t._prevY0)*r,t.y1=t._prevY1+(t._targetY1-t._prevY1)*r);for(const t of this.edges.values())void 0!==t._targetY0&&void 0!==t._prevY0&&void 0!==t._prevSankeyWidth&&t._prevSankeyWidth>0&&(t.y0=t._prevY0+(t._targetY0-t._prevY0)*r,t.y1=t._prevY1+(t._targetY1-t._prevY1)*r,t.sankeyWidth=t._prevSankeyWidth+(t._targetSankeyWidth-t._prevSankeyWidth)*r);return this.rebuildAllBeziers(),1>e||(this.snapToTargets(),this.transition=null,!1)}prepareForRelayout(){for(const t of this.nodes.values())t._prevX0=t.x0,t._prevX1=t.x1,t._prevY0=t.y0,t._prevY1=t.y1;for(const t of this.edges.values())t._prevY0=t.y0,t._prevY1=t.y1,t._prevSankeyWidth=t.sankeyWidth}finalizeLayout(){const t="vertical"===this.config.orientation?"down":"right";for(const t of this.nodes.values())if(0!==t.x0||0!==t.x1||0!==t.y0||0!==t.y1)t.width=t.x1-t.x0,t.height=t.y1-t.y0,t.x=t.x0+t.width/2,t.y=t.y0+t.height/2;else{const e=5;t.x0=t.x-e,t.x1=t.x+e,t.y0=t.y-e,t.y1=t.y+e,t.width=2*e,t.height=2*e}for(const e of this.edges.values())e.direction=t,this.updateEdgeBezier(e);this.tension=0}saveTargetPositions(){for(const t of this.nodes.values())t._targetX0=t.x0,t._targetX1=t.x1,t._targetY0=t.y0,t._targetY1=t.y1;for(const t of this.edges.values())t._targetY0=t.y0,t._targetY1=t.y1,t._targetSankeyWidth=t.sankeyWidth}restorePreviousPositions(){for(const t of this.nodes.values())void 0===t._prevX0||0===t._prevX0&&0===t._prevX1||(t.x0=t._prevX0,t.x1=t._prevX1,t.y0=t._prevY0,t.y1=t._prevY1);for(const t of this.edges.values())void 0!==t._prevY0&&void 0!==t._prevSankeyWidth&&t._prevSankeyWidth>0&&(t.y0=t._prevY0,t.y1=t._prevY1,t.sankeyWidth=t._prevSankeyWidth);this.rebuildAllBeziers()}snapToTargets(){for(const t of this.nodes.values())void 0!==t._targetX0&&(t.x0=t._targetX0,t.x1=t._targetX1,t.y0=t._targetY0,t.y1=t._targetY1);for(const t of this.edges.values())void 0!==t._targetY0&&(t.y0=t._targetY0,t.y1=t._targetY1,t.sankeyWidth=t._targetSankeyWidth);this.rebuildAllBeziers()}updateEdgeBezier(t){const e="string"==typeof t.source?this.nodes.get(t.source):t.source,r="string"==typeof t.target?this.nodes.get(t.target):t.target;e&&r&&(t.bezier=t.circular&&t.circularPathData?this.buildCircularBezier(t):this.buildStandardBezier(t,e,r))}buildStandardBezier(t,e,r){const n=(t.sankeyWidth||1)/2;if("down"===t.direction){const o=e.y1,a=r.y0,i=h(o,a);return{circular:!1,points:[{x:t.y0,y:o},{x:t.y0,y:i(.5)},{x:t.y1,y:i(.5)},{x:t.y1,y:a}],halfWidth:n}}const o=e.x1,a=r.x0,i=h(o,a);return{circular:!1,points:[{x:o,y:t.y0},{x:i(.5),y:t.y0},{x:i(.5),y:t.y1},{x:a,y:t.y1}],halfWidth:n}}buildCircularBezier(t){const e=(t._circularWidth||t.sankeyWidth||1)/2,r=t.circularPathData;if(t._circularStub){const t=Math.max(15,Math.min(40,.33*(r.rightFullExtent-r.sourceX))),n=Math.max(15,Math.min(40,.33*(r.targetX-r.leftFullExtent)));return{circular:!0,segments:[[{x:r.sourceX,y:r.sourceY},{x:r.sourceX+.33*t,y:r.sourceY},{x:r.sourceX+.66*t,y:r.sourceY},{x:r.sourceX+t,y:r.sourceY}],[{x:r.targetX-n,y:r.targetY},{x:r.targetX-.66*n,y:r.targetY},{x:r.targetX-.33*n,y:r.targetY},{x:r.targetX,y:r.targetY}]],halfWidth:e}}let n;n="down"===t.direction?[{x:r.sourceY,y:r.sourceX},{x:r.sourceY,y:r.rightFullExtent},{x:r.verticalFullExtent,y:r.rightFullExtent},{x:r.verticalFullExtent,y:r.leftFullExtent},{x:r.targetY,y:r.leftFullExtent},{x:r.targetY,y:r.targetX}]:[{x:r.sourceX,y:r.sourceY},{x:r.rightFullExtent,y:r.sourceY},{x:r.rightFullExtent,y:r.verticalFullExtent},{x:r.leftFullExtent,y:r.verticalFullExtent},{x:r.leftFullExtent,y:r.targetY},{x:r.targetX,y:r.targetY}];const o=[];for(let t=0;n.length-1>t;t++){const e=n[t],r=n[t+1],a=r.x-e.x,i=r.y-e.y;o.push([e,{x:e.x+a/3,y:e.y+i/3},{x:e.x+2*a/3,y:e.y+2*i/3},r])}return{circular:!0,segments:o,halfWidth:e}}rebuildAllBeziers(){for(const t of this.nodes.values())t.width=t.x1-t.x0,t.height=t.y1-t.y0,t.x=t.x0+t.width/2,t.y=t.y0+t.height/2;for(const t of this.edges.values())this.updateEdgeBezier(t)}applyPulse(t){var e,r,n,o,a;const i=this.config.pulse;if(!i)return;const c=null!==(e=i.duration)&&void 0!==e?e:500,l=null!==(r=i.color)&&void 0!==r?r:"rgba(255,255,255,0.6)",s=null!==(n=i.glowRadius)&&void 0!==n?n:4;for(const e of this.sceneNodes){const r=e.id;if(!r)continue;const n=this.nodeTimestamps.get(r);if(!n)continue;const o=t-n;c>o&&(e._pulseIntensity=1-o/c,e._pulseColor=l,e._pulseGlowRadius=s)}for(const e of this.sceneEdges){const r=e.datum;if(!r)continue;const n="object"==typeof r.source?null===(o=r.source)||void 0===o?void 0:o.id:r.source,i="object"==typeof r.target?null===(a=r.target)||void 0===a?void 0:a.id:r.target;if(!n||!i)continue;const s=this.edgeTimestamps.get(`${n}\0${i}`);if(!s)continue;const u=t-s;c>u&&(e._pulseIntensity=1-u/c,e._pulseColor=l)}}applyDecay(){var t,e,r,n,o;const a=this.config.decay;if(!a)return;const i=null!==(t=a.minOpacity)&&void 0!==t?t:.1,c=this.nodeTimestamps.size;if(1>=c)return;const l=Array.from(this.nodeTimestamps.entries()).sort((t,e)=>t[1]-e[1]),s=new Map;for(let t=0;l.length>t;t++)s.set(l[t][0],t);for(const t of this.sceneNodes){const l=t.id;if(!l)continue;const u=s.get(l);if(void 0===u)continue;const d=c-1-u;let h;switch(a.type){case"linear":h=i+(1-d/(c-1))*(1-i);break;case"exponential":{const t=null!==(e=a.halfLife)&&void 0!==e?e:c/2;h=i+Math.pow(.5,d/t)*(1-i);break}case"step":h=(null!==(r=a.stepThreshold)&&void 0!==r?r:.5*c)>d?1:i;break;default:h=1}const f=null!==(o=null===(n=t.style)||void 0===n?void 0:n.opacity)&&void 0!==o?o:1;t.style=Object.assign(Object.assign({},t.style),{opacity:f*h})}}applyTopologyDiff(t){var e;if(0===this.addedNodes.size)return;const r=t-this.lastTopologyChangeTime;if(r>=2e3)return;const n=1-r/2e3;for(const t of this.sceneNodes){const r=t.id;r&&this.addedNodes.has(r)&&(t._pulseIntensity=Math.max(null!==(e=t._pulseIntensity)&&void 0!==e?e:0,n),t._pulseColor="rgba(34, 197, 94, 0.7)",t._pulseGlowRadius=8)}}get hasActiveTopologyDiff(){return 0!==this.addedNodes.size&&2e3>("undefined"!=typeof performance?performance.now():Date.now())-this.lastTopologyChangeTime}applyThresholds(t){var e,r;const n=this.config.thresholds;if(!n)return;const o=null!==(e=n.warningColor)&&void 0!==e?e:"#f59e0b",a=null!==(r=n.criticalColor)&&void 0!==r?r:"#ef4444",i=!1!==n.pulse;for(const e of this.sceneNodes){const r=e.id;if(!r)continue;const c=this.nodes.get(r);if(!c)continue;const l=n.metric(c);let s=null;void 0===n.critical||n.critical>l?void 0===n.warning||n.warning>l||(s=o):s=a,s&&(e.style=Object.assign(Object.assign({},e.style),{fill:s}),i&&(e._pulseIntensity=.6+.4*Math.sin(t/300),e._pulseColor=s,e._pulseGlowRadius=6))}}get hasActiveThresholds(){const t=this.config.thresholds;if(!t)return!1;for(const e of this.nodes.values()){const r=t.metric(e);if(void 0!==t.warning&&r>=t.warning||void 0!==t.critical&&r>=t.critical)return!0}return!1}get hasActivePulses(){var t;const e=this.config.pulse;if(!e||0===this.lastIngestTime)return!1;const r="undefined"!=typeof performance?performance.now():Date.now();return(null!==(t=e.duration)&&void 0!==t?t:500)>r-this.lastIngestTime}getLayoutData(){return{nodes:Array.from(this.nodes.values()),edges:Array.from(this.edges.values())}}clear(){this.nodes.clear(),this.edges.clear(),this.tension=0,this.layoutVersion=0,this.sceneNodes=[],this.sceneEdges=[],this.labels=[],this.transition=null,this.lastIngestTime=0,this.nodeTimestamps.clear(),this.edgeTimestamps.clear(),this.particlePool&&this.particlePool.clear()}}function ee(t){return{id:t,x0:0,x1:0,y0:0,y1:0,x:0,y:0,width:0,height:0,value:0,createdByFrame:!0}}function re(t,e,r,n,o=30){let a=null,i=o,c=1/0;for(const e of t){const t=ne(e,r,n);if(t)if("rect"===e.type){const r=e.w*e.h;c>r&&(a=t,c=r)}else i>t.distance&&(a=t,i=t.distance)}if(a)return a;for(const t of e){const e=oe(t,r,n);e&&i>e.distance&&(a=e,i=e.distance)}return a}function ne(t,e,r){switch(t.type){case"circle":return function(t,e,r){const n=e-t.cx,o=r-t.cy,a=Math.sqrt(n*n+o*o);return a>Math.max(t.r,5)+5?null:{type:"node",datum:t.datum,x:t.cx,y:t.cy,distance:a}}(t,e,r);case"rect":return function(t,e,r){return t.x>e||e>t.x+t.w||t.y>r||r>t.y+t.h?null:{type:"node",datum:t.datum,x:t.x+t.w/2,y:t.y+t.h/2,distance:0}}(t,e,r);case"arc":return function(t,e,r){const n=e-t.cx,o=r-t.cy,a=Math.sqrt(n*n+o*o);if(t.innerR-2>a||a>t.outerR+2)return null;let i=Math.atan2(o,n);0>i&&(i+=2*Math.PI);let c,l=t.startAngle,s=t.endAngle;if(0>l&&(l+=2*Math.PI),0>s&&(s+=2*Math.PI),c=l>s?i>=l||s>=i:i>=l&&s>=i,c){const e=(t.startAngle+t.endAngle)/2,r=(t.innerR+t.outerR)/2;return{type:"node",datum:t.datum,x:t.cx+r*Math.cos(e),y:t.cy+r*Math.sin(e),distance:0}}return null}(t,e,r);default:return null}}function oe(t,e,r){switch(t.type){case"bezier":return function(t,e,r){var n,o;if(!t.pathD)return null;try{const a=new Path2D(t.pathD),i=document.createElement("canvas").getContext("2d");if(!i)return null;if(i.isPointInPath(a,e,r)){const a="object"==typeof(null===(n=t.datum)||void 0===n?void 0:n.source)?t.datum.source:null,i="object"==typeof(null===(o=t.datum)||void 0===o?void 0:o.target)?t.datum.target:null;return{type:"edge",datum:t.datum,x:a&&i?(a.x1+i.x0)/2:e,y:t.datum?(t.datum.y0+t.datum.y1)/2:r,distance:0}}}catch(t){}return null}(t,e,r);case"line":return function(t,e,r){const n=t.x2-t.x1,o=t.y2-t.y1,a=n*n+o*o;if(0===a)return null;let i=((e-t.x1)*n+(r-t.y1)*o)/a;i=Math.max(0,Math.min(1,i));const c=t.x1+i*n,l=t.y1+i*o,s=Math.sqrt(Math.pow(e-c,2)+Math.pow(r-l,2));return s>5?null:{type:"edge",datum:t.datum,x:c,y:l,distance:s}}(t,e,r);case"ribbon":case"curved":return function(t,e,r){if(!t.pathD)return null;try{const n=new Path2D(t.pathD),o=document.createElement("canvas").getContext("2d");if(!o)return null;if(o.isPointInPath(n,e,r))return{type:"edge",datum:t.datum,x:e,y:r,distance:0}}catch(t){}return null}(t,e,r);default:return null}}function ae(e){const{width:r,height:n,totalWidth:o,totalHeight:a,margin:i,labels:c,title:l,legend:s,foregroundGraphics:u,annotations:d,svgAnnotationRules:h}=e;return t.createElement("svg",{width:o,height:a,style:{position:"absolute",top:0,left:0,pointerEvents:"none"}},t.createElement("g",{transform:`translate(${i.left},${i.top})`},c.map((e,r)=>t.createElement("text",{key:"label-"+r,x:e.x,y:e.y,textAnchor:e.anchor||"start",dominantBaseline:e.baseline||"middle",fontSize:e.fontSize||11,fontWeight:e.fontWeight,fill:e.fill||"currentColor",stroke:e.stroke,strokeWidth:e.strokeWidth,paintOrder:e.paintOrder,style:{pointerEvents:"none"}},e.text)),d&&h&&d.map((e,o)=>{const a=h(e,o,{width:r,height:n});return a?t.createElement(t.Fragment,{key:"annotation-"+o},a):null}),u),l&&"string"==typeof l?t.createElement("text",{x:o/2,y:16,textAnchor:"middle",fontSize:14,fontWeight:600,fill:"currentColor"},l):l?t.createElement("foreignObject",{x:0,y:0,width:o,height:i.top},l):null,s&&"object"==typeof s&&"legendGroups"in s?t.createElement("g",{transform:`translate(${o-i.right+10},${i.top})`},s.legendGroups.map((e,r)=>{var n;return t.createElement("g",{key:"legend-group-"+r},null===(n=e.items)||void 0===n?void 0:n.map((e,r)=>t.createElement("g",{key:"legend-item-"+r,transform:`translate(0,${20*r})`},t.createElement("rect",{x:0,y:0,width:12,height:12,fill:e.color,rx:2}),t.createElement("text",{x:18,y:10,fontSize:11,fill:"currentColor"},e.label))))})):s?t.createElement("g",{transform:`translate(${o-i.right+10},${i.top})`},s):null)}function ie(t,e){var r,n,o,a,i,c;if(!e.pathD)return;t.save();const l=new Path2D(e.pathD);if(e.style.fill&&"none"!==e.style.fill){const i=e._gradient;if(i){const o=t.createLinearGradient(i.x0,0,i.x1,0),a=null!==(n=null!==(r=e.style.fillOpacity)&&void 0!==r?r:e.style.opacity)&&void 0!==n?n:.5,c=e.style.fill;o.addColorStop(0,1===i.from?c:"transparent"),o.addColorStop(1,1===i.to?c:"transparent"),t.fillStyle=o,t.globalAlpha=a}else t.fillStyle=e.style.fill,t.globalAlpha=null!==(a=null!==(o=e.style.fillOpacity)&&void 0!==o?o:e.style.opacity)&&void 0!==a?a:.5;t.fill(l)}e.style.stroke&&"none"!==e.style.stroke&&(t.strokeStyle=e.style.stroke,t.lineWidth=null!==(i=e.style.strokeWidth)&&void 0!==i?i:.5,t.globalAlpha=.5*(null!==(c=e.style.opacity)&&void 0!==c?c:1),t.stroke(l)),e._pulseIntensity&&e._pulseIntensity>0&&(t.fillStyle=e._pulseColor||"rgba(255,255,255,0.6)",t.globalAlpha=.2*e._pulseIntensity,t.fill(l)),t.restore()}function ce(t,e){var r,n;t.save(),t.strokeStyle=e.style.stroke||"#999",t.lineWidth=null!==(r=e.style.strokeWidth)&&void 0!==r?r:1,void 0!==e.style.opacity&&(t.globalAlpha=e.style.opacity),e.style.strokeDasharray&&t.setLineDash(e.style.strokeDasharray.split(/[\s,]+/).map(Number)),t.beginPath(),t.moveTo(e.x1,e.y1),t.lineTo(e.x2,e.y2),t.stroke(),e._pulseIntensity&&e._pulseIntensity>0&&(t.setLineDash([]),t.strokeStyle=e._pulseColor||"rgba(255,255,255,0.6)",t.lineWidth=(null!==(n=e.style.strokeWidth)&&void 0!==n?n:1)+3*e._pulseIntensity,t.globalAlpha=.4*e._pulseIntensity,t.beginPath(),t.moveTo(e.x1,e.y1),t.lineTo(e.x2,e.y2),t.stroke()),t.restore()}function le(t,e){var r,n,o,a;if(!e.pathD)return;t.save();const i=new Path2D(e.pathD);e.style.fill&&"none"!==e.style.fill&&(t.fillStyle=e.style.fill,t.globalAlpha=null!==(n=null!==(r=e.style.fillOpacity)&&void 0!==r?r:e.style.opacity)&&void 0!==n?n:.5,t.fill(i)),e.style.stroke&&"none"!==e.style.stroke&&(t.strokeStyle=e.style.stroke,t.lineWidth=null!==(o=e.style.strokeWidth)&&void 0!==o?o:.5,t.globalAlpha=.3*(null!==(a=e.style.opacity)&&void 0!==a?a:1),t.stroke(i)),t.restore()}function se(t,e){var r,n;if(!e.pathD)return;t.save();const o=new Path2D(e.pathD);t.strokeStyle=e.style.stroke||"#999",t.lineWidth=null!==(r=e.style.strokeWidth)&&void 0!==r?r:1,void 0!==e.style.opacity&&(t.globalAlpha=e.style.opacity),t.stroke(o),e.style.fill&&"none"!==e.style.fill&&(t.fillStyle=e.style.fill,t.globalAlpha=null!==(n=e.style.fillOpacity)&&void 0!==n?n:.1,t.fill(o)),t.restore()}ae.displayName="NetworkSVGOverlay";const ue={category10:b,tableau10:S,set3:P,blues:A,reds:D,greens:E,oranges:L,purples:w,viridis:k,plasma:x},de=b,he=["#f0f0f0","#b5d4ea","#f4c2a1","#b8dab2","#d4b5e0","#f9e0a2","#a8d8d8"];function fe(t,e,r){if("function"==typeof e)return e(t);const n=t[e];return r?r(n):de[Math.abs(function(t){let e=0;for(let r=0;t.length>r;r++)e=(e<<5)-e+t.charCodeAt(r),e&=e;return Math.abs(e)}(n+""))%de.length]}function ye(t,e,r="category10"){const n=Array.from(new Set(t.map(t=>t[e]))),o=n.every(t=>"number"==typeof t||!isNaN(Number(t)));if(Array.isArray(r))return W().domain(n).range(r).unknown("#999");const a=ue[r]||ue.category10;if(o&&"function"==typeof a)return t=>a(Number(t)/Math.max(...n.map(Number)));{const t=Array.isArray(a)?a:de;return W().domain(n).range(t).unknown("#999")}}const ge={top:20,right:80,bottom:20,left:80},pe={top:40,right:40,bottom:40,left:40},ve=new Set(["chord","force","circlepack"]),me=[800,600],be={background:"rgba(0, 0, 0, 0.85)",color:"white",padding:"6px 10px",borderRadius:4,fontSize:12,lineHeight:1.5,boxShadow:"0 2px 8px rgba(0, 0, 0, 0.15)",pointerEvents:"none",whiteSpace:"nowrap"};function xe({data:e}){var r,n,o,a,i,c;if("edge"===e.type){const r=e.data;return t.createElement("div",{className:"semiotic-tooltip",style:be},t.createElement("div",{style:{fontWeight:600}},"object"==typeof r.source?r.source.id:r.source," → ","object"==typeof r.target?r.target.id:r.target),null!=r.value&&t.createElement("div",{style:{marginTop:4,opacity:.8}},"Value:"," ","number"==typeof r.value?r.value.toLocaleString():r.value+""))}const l=e.data,s=null==l?void 0:l.__hierarchyNode;if(s){const e=[];let i=s;for(;i;){const t=null!==(a=null!==(n=null===(r=i.data)||void 0===r?void 0:r.name)&&void 0!==n?n:null===(o=i.data)||void 0===o?void 0:o.id)&&void 0!==a?a:l.id;null!=t&&e.unshift(t+""),i=i.parent}e.length>1&&e.shift();const c=e.length-1;return t.createElement("div",{className:"semiotic-tooltip",style:be},t.createElement("div",null,e.map((e,r)=>t.createElement("span",{key:r},r>0&&t.createElement("span",{style:{margin:"0 3px",opacity:.5}}," → "),r===c?t.createElement("strong",null,e):t.createElement("span",{style:{opacity:.7}},e)))),null!=l.value&&l.value>0&&t.createElement("div",{style:{marginTop:4,opacity:.8}},"number"==typeof l.value?l.value.toLocaleString():l.value+""))}const u=((null===(i=l.sourceLinks)||void 0===i?void 0:i.length)||0)+((null===(c=l.targetLinks)||void 0===c?void 0:c.length)||0),d=(l.sourceLinks||[]).reduce((t,e)=>t+(e.value||0),0)+(l.targetLinks||[]).reduce((t,e)=>t+(e.value||0),0);return t.createElement("div",{className:"semiotic-tooltip",style:be},t.createElement("div",{style:{fontWeight:600}},l.id),null!=l.value&&l.value>0&&t.createElement("div",{style:{marginTop:4,opacity:.8}},"Total:"," ","number"==typeof l.value?l.value.toLocaleString():l.value+""),u>0&&t.createElement("div",{style:{marginTop:4,opacity:.8}},"Connections: ",u,d!==u&&` (weighted: ${d.toLocaleString()})`))}const ke=e(function(e,l){const{chartType:s,nodes:u,edges:d,data:h,initialEdges:f,nodeIDAccessor:y="id",sourceAccessor:g="source",targetAccessor:p="target",valueAccessor:v="value",childrenAccessor:m,hierarchySum:b,orientation:x="horizontal",nodeAlign:k="justify",nodePaddingRatio:w=.05,nodeWidth:L=15,iterations:E=300,forceStrength:D=.1,padAngle:A=.01,groupWidth:P=20,sortGroups:S,edgeSort:T,treeOrientation:O="vertical",edgeType:$="curve",padding:_,paddingTop:I,tensionConfig:N,showParticles:W=!1,particleStyle:M,nodeStyle:j,edgeStyle:R,colorBy:C,colorScheme:B="category10",edgeColorBy:z="source",edgeOpacity:F=.5,colorByDepth:Y=!1,nodeSize:X=8,nodeSizeRange:H=[5,20],nodeLabel:V,showLabels:Z=!0,size:K=me,margin:Q,className:J,background:U,enableHover:tt=!0,tooltipContent:et,customHoverBehavior:rt,customClickBehavior:nt,onObservation:ot,chartId:at,onTopologyChange:it,annotations:ct,svgAnnotationRules:lt,legend:st,title:ut,foregroundGraphics:dt,backgroundGraphics:ht,decay:ft,pulse:yt,staleness:gt,thresholds:pt}=e,vt=ve.has(s)?pe:ge,mt=Object.assign(Object.assign({},vt),Q),bt=K[0]-mt.left-mt.right,xt=K[1]-mt.top-mt.bottom,kt=r(()=>Object.assign(Object.assign({},G),N),[N]),wt=r(()=>Object.assign(Object.assign({},q),M),[M]),Lt=r(()=>({chartType:s,nodeIDAccessor:y,sourceAccessor:g,targetAccessor:p,valueAccessor:v,childrenAccessor:m,hierarchySum:b,orientation:x,nodeAlign:k,nodePaddingRatio:w,nodeWidth:L,iterations:E,forceStrength:D,padAngle:A,groupWidth:P,sortGroups:S,edgeSort:T,treeOrientation:O,edgeType:$,padding:_,paddingTop:I,tensionConfig:kt,showParticles:W,particleStyle:wt,nodeStyle:j,edgeStyle:R,nodeLabel:V,showLabels:Z,colorBy:C,colorScheme:B,edgeColorBy:z,edgeOpacity:F,colorByDepth:Y,nodeSize:X,nodeSizeRange:H,decay:ft,pulse:yt,staleness:gt,thresholds:pt}),[s,y,g,p,v,m,b,x,k,w,L,E,D,A,P,S,T,O,$,_,I,kt,W,wt,j,R,V,Z,C,B,z,F,Y,X,H,ft,yt,gt,pt]),Et=n(null),Dt=n(0),At=n(0),Pt=n(!0),St=n(()=>{}),Tt=n(null);Tt.current||(Tt.current=new te(Lt));const[Ot,$t]=o(null),[_t,It]=o(0),[Nt,Wt]=o(0),[Mt,jt]=o(!1),Rt=n(null),Ct=n(new Map),Bt=n(0),zt=a(t=>{if("function"==typeof C)return C(t);if("string"==typeof C&&t.data){const e=t.data[C];if(void 0!==e){if(!Ct.current.has(e+"")){const t=Array.isArray(B)?B:de;Ct.current.set(e+"",t[Bt.current++%t.length])}return Ct.current.get(e+"")}}if(!Ct.current.has(t.id)){const e=Array.isArray(B)?B:de;Ct.current.set(t.id,e[Bt.current++%e.length])}return Ct.current.get(t.id)},[C,B]),Ft=a(t=>{if("function"==typeof z)return z(t);const e="object"==typeof t.source?t.source:null,r="object"==typeof t.target?t.target:null;return"target"===z&&r?zt(r):e?zt(e):"#999"},[z,zt]),Yt=a(t=>{if(!(null==M?void 0:M.colorBy))return Ft(t);const e="object"==typeof t.source?t.source:null,r="object"==typeof t.target?t.target:null;return"target"===wt.colorBy&&r?zt(r):e?zt(e):"#999"},[null==M?void 0:M.colorBy,wt.colorBy,zt,Ft]),Xt="sankey"===s&&W||!!yt,Ht=a(()=>{Dt.current&&!Xt||Dt.current||(Dt.current=requestAnimationFrame(()=>St.current()))},[Xt]);i(()=>{var t;null===(t=Tt.current)||void 0===t||t.updateConfig(Lt),Pt.current=!0,Ht()},[Lt,Ht]);const Gt=a(()=>{const t=Tt.current;if(!t)return;t.runLayout([bt,xt]),t.buildScene([bt,xt]),Pt.current=!0;const e=Array.isArray(B)?B:de,r=Array.from(t.nodes.values());for(let t=0;r.length>t;t++){const n=r[t];Ct.current.has(n.id)||Ct.current.set(n.id,e[t%e.length])}if(Bt.current=r.length,It(t.layoutVersion),it){const{nodes:e,edges:r}=t.getLayoutData();it(e,r)}},[bt,xt,it,B]),qt=a(t=>{const e=Tt.current;e&&(e.ingestEdge(t)&&Gt(),Ht())},[Gt,Ht]),Vt=a(t=>{const e=Tt.current;if(!e)return;let r=!1;for(const n of t)e.ingestEdge(n)&&(r=!0);r&&Gt(),Ht()},[Gt,Ht]),Zt=a(()=>{var t;null===(t=Tt.current)||void 0===t||t.clear(),Ct.current.clear(),Bt.current=0,It(0),$t(null),Rt.current=null,Pt.current=!0,Ht()},[Ht]),Kt=a(()=>{const t=Tt.current;t&&(t.tension+=999,Gt(),Ht())},[Gt,Ht]);c(l,()=>({push:qt,pushMany:Vt,clear:Zt,getTopology:()=>{var t,e;return null!==(e=null===(t=Tt.current)||void 0===t?void 0:t.getLayoutData())&&void 0!==e?e:{nodes:[],edges:[]}},getTopologyDiff:()=>{const t=Tt.current;return t?{addedNodes:Array.from(t.addedNodes),removedNodes:Array.from(t.removedNodes),addedEdges:Array.from(t.addedEdges),removedEdges:Array.from(t.removedEdges)}:{addedNodes:[],removedNodes:[],addedEdges:[],removedEdges:[]}},relayout:Kt,getTension:()=>{var t,e;return null!==(e=null===(t=Tt.current)||void 0===t?void 0:t.tension)&&void 0!==e?e:0}}),[qt,Vt,Zt,Kt]);const Qt=["tree","cluster","treemap","circlepack","partition"].includes(s),Jt=Qt?h||(Array.isArray(d)?void 0:d):void 0;i(()=>{const t=Tt.current;if(t)if(Qt&&Jt)t.ingestHierarchy(Jt,[bt,xt]),t.buildScene([bt,xt]),Pt.current=!0,Ht();else{const e=u||[],r=Array.isArray(d)?d:[];if(0===e.length&&0===r.length)return;t.ingestBounded(e,r,[bt,xt]),t.buildScene([bt,xt]);const n=Array.isArray(B)?B:de,o=Array.from(t.nodes.values());for(let t=0;o.length>t;t++){const e=o[t];Ct.current.has(e.id)||Ct.current.set(e.id,n[t%n.length])}Bt.current=o.length,Pt.current=!0,Ht()}},[u,d,h,Jt,Qt,bt,xt,Lt,Ht,B]),i(()=>{f&&f.length>0&&Vt(f)},[]);const Ut=a(t=>{if(rt&&rt(t),ot){const e=Date.now();ot(t?{type:"hover",datum:t.data||{},x:t.x,y:t.y,timestamp:e,chartType:"StreamNetworkFrame",chartId:at}:{type:"hover-end",timestamp:e,chartType:"StreamNetworkFrame",chartId:at})}},[rt,ot,at]),ee=a(t=>{if(nt&&nt(t),ot){const e=Date.now();ot(t?{type:"click",datum:t.data||{},x:t.x,y:t.y,timestamp:e,chartType:"StreamNetworkFrame",chartId:at}:{type:"click-end",timestamp:e,chartType:"StreamNetworkFrame",chartId:at})}},[nt,ot,at]),ne=n(()=>{}),oe=n(()=>{});ne.current=t=>{if(!tt)return;const e=Et.current;if(!e)return;const r=e.getBoundingClientRect(),n=t.clientX-r.left-mt.left,o=t.clientY-r.top-mt.top;if(0>n||n>bt||0>o||o>xt)return void(Rt.current&&(Rt.current=null,$t(null),Ut&&Ut(null),Ht()));const a=Tt.current;if(!a)return;const i=re(a.sceneNodes,a.sceneEdges,n,o);if(!i)return void(Rt.current&&(Rt.current=null,$t(null),Ut&&Ut(null),Ht()));const c={type:i.type,data:i.datum,x:i.x,y:i.y};Rt.current=c,$t(c),Ut&&Ut(c),Ht()},oe.current=()=>{Rt.current&&(Rt.current=null,$t(null),Ut&&Ut(null),Ht())};const ue=n(()=>{});ue.current=t=>{if(!nt&&!ot)return;const e=Et.current;if(!e)return;const r=e.getBoundingClientRect(),n=t.clientX-r.left-mt.left,o=t.clientY-r.top-mt.top;if(0>n||n>bt||0>o||o>xt)return;const a=Tt.current;if(!a)return;const i=re(a.sceneNodes,a.sceneEdges,n,o);ee(i?{type:i.type,data:i.datum,x:i.x,y:i.y}:null)};const he=a(t=>ne.current(t),[]),fe=a(()=>oe.current(),[]),ye=a(t=>ue.current(t),[]);St.current=()=>{var t,e,r;Dt.current=0;const n=Et.current;if(!n)return;const o=n.getContext("2d");if(!o)return;const a=Tt.current;if(!a)return;const i=performance.now(),c=At.current?Math.min((i-At.current)/1e3,.1):.016;At.current=i;const l=a.advanceTransition(i);(l||Pt.current)&&a.buildScene([bt,xt]);const s="undefined"!=typeof window&&window.devicePixelRatio||1;n.width=K[0]*s,n.height=K[1]*s,n.style.width=K[0]+"px",n.style.height=K[1]+"px",o.scale(s,s),o.translate(mt.left,mt.top),o.clearRect(-mt.left,-mt.top,K[0],K[1]),U&&(o.fillStyle=U,o.fillRect(0,0,bt,xt)),ft&&a.applyDecay(),yt&&a.applyPulse(i),pt&&a.applyThresholds(i),a.applyTopologyDiff(i);const u=null!==(t=null==gt?void 0:gt.threshold)&&void 0!==t?t:5e3,d=gt&&a.lastIngestTime>0&&i-a.lastIngestTime>u;if(d&&(o.globalAlpha=null!==(e=null==gt?void 0:gt.dimOpacity)&&void 0!==e?e:.5),function(t,e){for(const r of e)switch(r.type){case"bezier":ie(t,r);break;case"line":ce(t,r);break;case"ribbon":le(t,r);break;case"curved":se(t,r)}}(o,a.sceneEdges),function(t,e){var r,n,o;for(const a of e){if("rect"!==a.type)continue;const e=a;e.w>0&&e.h>0&&(t.save(),void 0!==e.style.opacity&&(t.globalAlpha=e.style.opacity),e.style.fill&&(t.fillStyle=e.style.fill,void 0!==e.style.fillOpacity&&(t.globalAlpha=(null!==(r=e.style.opacity)&&void 0!==r?r:1)*e.style.fillOpacity),t.fillRect(e.x,e.y,e.w,e.h)),e.style.stroke&&"none"!==e.style.stroke&&(t.strokeStyle=e.style.stroke,t.lineWidth=null!==(n=e.style.strokeWidth)&&void 0!==n?n:1,t.globalAlpha=null!==(o=e.style.opacity)&&void 0!==o?o:1,t.strokeRect(e.x,e.y,e.w,e.h)),e._pulseIntensity&&e._pulseIntensity>0&&(t.globalAlpha=.3*e._pulseIntensity,t.fillStyle=e._pulseColor||"rgba(255,255,255,0.6)",t.fillRect(e.x,e.y,e.w,e.h)),t.restore())}}(o,a.sceneNodes),function(t,e){var r,n,o,a;for(const i of e){if("circle"!==i.type)continue;const e=i;if(e.r>0){if(t.save(),void 0!==e.style.opacity&&(t.globalAlpha=e.style.opacity),t.beginPath(),t.arc(e.cx,e.cy,e.r,0,2*Math.PI),e.style.fill&&(t.fillStyle=e.style.fill,void 0!==e.style.fillOpacity&&(t.globalAlpha=(null!==(r=e.style.opacity)&&void 0!==r?r:1)*e.style.fillOpacity),t.fill()),e.style.stroke&&"none"!==e.style.stroke&&(t.strokeStyle=e.style.stroke,t.lineWidth=null!==(n=e.style.strokeWidth)&&void 0!==n?n:1,t.globalAlpha=null!==(o=e.style.opacity)&&void 0!==o?o:1,t.stroke()),e._pulseIntensity&&e._pulseIntensity>0){const r=null!==(a=e._pulseGlowRadius)&&void 0!==a?a:4,n=e.r+r*e._pulseIntensity;t.beginPath(),t.arc(e.cx,e.cy,n,0,2*Math.PI),t.strokeStyle=e._pulseColor||"rgba(255,255,255,0.6)",t.lineWidth=2*e._pulseIntensity,t.globalAlpha=.6*e._pulseIntensity,t.stroke()}t.restore()}}}(o,a.sceneNodes),function(t,e){var r,n,o;for(const a of e){if("arc"!==a.type)continue;const e=a;t.save(),void 0!==e.style.opacity&&(t.globalAlpha=e.style.opacity),t.beginPath(),t.arc(e.cx,e.cy,e.outerR,e.startAngle,e.endAngle),t.arc(e.cx,e.cy,e.innerR,e.endAngle,e.startAngle,!0),t.closePath(),e.style.fill&&(t.fillStyle=e.style.fill,void 0!==e.style.fillOpacity&&(t.globalAlpha=(null!==(r=e.style.opacity)&&void 0!==r?r:1)*e.style.fillOpacity),t.fill()),e.style.stroke&&"none"!==e.style.stroke&&(t.strokeStyle=e.style.stroke,t.lineWidth=null!==(n=e.style.strokeWidth)&&void 0!==n?n:1,t.globalAlpha=null!==(o=e.style.opacity)&&void 0!==o?o:1,t.stroke()),t.restore()}}(o,a.sceneNodes),W&&a.particlePool&&!d){const t=Array.from(a.edges.values());if(t.length>0){!function(t,e,r,n){var o,a;const i=null!==(o=n.spawnRate)&&void 0!==o?o:q.spawnRate,c=null!==(a=n.maxPerEdge)&&void 0!==a?a:q.maxPerEdge;for(let n=0;e.length>n;n++){const o=e[n];if(!o.bezier)continue;if(t.countForEdge(n)>=c)continue;const a=o.value*i*r*(o.bezier.circular?.3:1),l=Math.floor(a),s=a-l;let u=l;Math.random()<s&&u++;for(let e=0;u>e&&t.countForEdge(n)<c;e++)t.spawn(n)}}(a.particlePool,t,c,wt);const e=.5*(null!==(r=wt.speedMultiplier)&&void 0!==r?r:1);let n;if(wt.proportionalSpeed){const e=t.reduce((t,e)=>Math.max(t,e.value||1),1);n=t.map(t=>.3+(t.value||1)/e*1.7)}a.particlePool.step(c,e,t,n),function(t,e,r,n,o){var a,i;const c=null!==(a=n.radius)&&void 0!==a?a:q.radius,l=null!==(i=n.opacity)&&void 0!==i?i:q.opacity;t.globalAlpha=l;for(let a=0;e.particles.length>a;a++){const i=e.particles[a];if(!i.active)continue;const l=r[i.edgeIndex];if(l){if("function"==typeof n.color){const e="object"==typeof l.source?l.source:null;t.fillStyle=e?n.color(l,e):"#666"}else t.fillStyle=n.color&&"inherit"!==n.color?n.color:o(l);t.beginPath(),t.arc(i.x,i.y,c,0,2*Math.PI),t.fill()}}t.globalAlpha=1}(o,a.particlePool,t,wt,Yt)}}d&&(o.globalAlpha=1);const h=Pt.current;Pt.current=!1,(h||l)&&Wt(t=>t+1),(Xt||l||a.hasActivePulses||a.hasActiveThresholds||a.hasActiveTopologyDiff)&&(Dt.current=requestAnimationFrame(()=>St.current()))},i(()=>(Ht(),()=>{Dt.current&&cancelAnimationFrame(Dt.current)}),[Ht]),i(()=>{Pt.current=!0,Ht()},[s,bt,xt,U,Ht]),i(()=>{if(!gt)return;const t=setInterval(()=>{var t;const e=Tt.current;if(!e||0===e.lastIngestTime)return;const r="undefined"!=typeof performance?performance.now():Date.now(),n=null!==(t=gt.threshold)&&void 0!==t?t:5e3,o=r-e.lastIngestTime>n;o!==Mt&&(jt(o),Pt.current=!0,Ht())},1e3);return()=>clearInterval(t)},[gt,Mt,Ht]);const be=tt&&Ot?t.createElement("div",{className:"stream-network-tooltip",style:{position:"absolute",left:mt.left+Ot.x,top:mt.top+Ot.y,transform:`translate(${Ot.x>.6*bt?"calc(-100% - 12px)":"12px"}, ${.3*xt>Ot.y?"4px":"calc(-100% - 4px)"})`,pointerEvents:"none",zIndex:2}},et?et(Ot):t.createElement(xe,{data:Ot})):null,ke=Tt.current;return t.createElement("div",{className:"stream-network-frame"+(J?" "+J:""),role:"img","aria-label":"string"==typeof ut?ut:"Network chart",style:{position:"relative",width:K[0],height:K[1]},onMouseMove:tt?he:void 0,onMouseLeave:tt?fe:void 0,onClick:nt||ot?ye:void 0},ht&&t.createElement("svg",{style:{position:"absolute",top:0,left:0,width:K[0],height:K[1],pointerEvents:"none"}},t.createElement("g",{transform:`translate(${mt.left},${mt.top})`},ht)),t.createElement("canvas",{ref:Et,style:{position:"absolute",top:0,left:0}}),t.createElement(ae,{width:bt,height:xt,totalWidth:K[0],totalHeight:K[1],margin:mt,labels:(null==ke?void 0:ke.labels)||[],title:ut,legend:st,foregroundGraphics:dt,annotations:ct,svgAnnotationRules:lt,annotationFrame:Nt}),be,(null==gt?void 0:gt.showBadge)&&t.createElement("div",{className:"stream-staleness-badge",style:Object.assign(Object.assign({position:"absolute"},"top-left"===gt.badgePosition?{top:4,left:4}:"bottom-left"===gt.badgePosition?{bottom:4,left:4}:"bottom-right"===gt.badgePosition?{bottom:4,right:4}:{top:4,right:4}),{background:Mt?"#dc3545":"#28a745",color:"white",fontSize:10,fontWeight:700,padding:"2px 6px",borderRadius:3,letterSpacing:"0.05em",zIndex:3,pointerEvents:"none"})},Mt?"STALE":"LIVE"))});ke.displayName="StreamNetworkFrame";const we={background:"rgba(0, 0, 0, 0.85)",color:"white",padding:"8px 12px",borderRadius:"4px",fontSize:"14px",lineHeight:"1.5",boxShadow:"0 2px 8px rgba(0, 0, 0, 0.15)",pointerEvents:"none",maxWidth:"300px",wordWrap:"break-word"};function Le(t,e){return"function"==typeof e?e(t):t[e]}function Ee(t,e){return e?e(t):null==t?"":"number"==typeof t?t.toLocaleString():t instanceof Date?t.toLocaleDateString():"object"==typeof t&&null!==t?void 0!==t.id?t.id+"":void 0!==t.name?t.name+"":JSON.stringify(t):t+""}function De(e){return!0===e||("function"==typeof e?e:!1!==e&&void 0!==e&&("object"!=typeof e||null===e||!("fields"in e)&&!("title"in e)||function(e={}){const{fields:r,title:n,format:o,style:a={},className:i=""}=e;return e=>{if(!e||"object"!=typeof e)return null;let c;const l=[];if(n){const t=Le(e,n);c=Ee(t,o)}if(r&&r.length>0)r.forEach(t=>{let r,n,a;"string"==typeof t?(r=t,n=t,a=o):(r=t.label,n=t.accessor||t.key||"",a=t.format||o);const i=Le(e,n);l.push({label:r,value:Ee(i,a)})});else if(!n){const t=["value","y","name","id","label"];for(const r of t)if(void 0!==e[r]){c=Ee(e[r],o);break}if(!c){const t=Object.keys(e).filter(t=>!t.startsWith("_"));t.length>0&&(c=Ee(e[t[0]],o))}}const s=Object.assign(Object.assign({},we),a);return t.createElement("div",{className:("semiotic-tooltip "+i).trim(),style:s},c&&t.createElement("div",{style:{fontWeight:l.length>0?"bold":"normal"}},c),l.map((e,r)=>t.createElement("div",{key:r,style:{marginTop:0===r&&c?"4px":0}},e.label&&t.createElement("span",null,e.label,": "),e.value)))}}(e)))}function Ae(e){const n=l(null),a=Pe(e);return[function({children:o}){const a=r(()=>Pe(e),[]);return t.createElement(n.Provider,{value:a,children:o})},t=>{var e;const r=null!==(e=s(n))&&void 0!==e?e:a;return function(t,e){const[r,n]=o(e);return u(()=>t(()=>n(e)),[t]),r}(r.subscribe,()=>t(r.getState()))}]}function Pe(t){const e=new EventTarget;let r=t(function(t){r=Object.assign(Object.assign({},r),t(r)),e.dispatchEvent(new CustomEvent("update"))});return{getState:()=>r,subscribe:function(t){return e.addEventListener("update",t),()=>e.removeEventListener("update",t)}}}function Se(t){const e=[];for(const[r,n]of Object.entries(t.fields))if("point"===n.type)e.push(t=>n.values.has(t[r]));else{const[t,o]=n.range;e.push(e=>{const n=e[r];return n>=t&&o>=n})}return t=>e.every(e=>e(t))}function Te(t,e){let r=t.get(e);return r||(r={name:e,resolution:"union",clauses:new Map},t.set(e,r)),r}const[Oe,$e]=Ae(t=>({selections:new Map,setClause(e,r){t(t=>{const n=new Map(t.selections),o=Te(n,e),a=new Map(o.clauses);return a.set(r.clientId,r),n.set(e,Object.assign(Object.assign({},o),{clauses:a})),{selections:n}})},clearClause(e,r){t(t=>{const n=t.selections.get(e);if(!n)return{};const o=new Map(t.selections),a=new Map(n.clauses);return a.delete(r),o.set(e,Object.assign(Object.assign({},n),{clauses:a})),{selections:o}})},setResolution(e,r){t(t=>{const n=new Map(t.selections),o=Te(n,e);return n.set(e,Object.assign(Object.assign({},o),{resolution:r})),{selections:n}})},clearSelection(e){t(t=>{const r=new Map(t.selections),n=r.get(e);return n&&r.set(e,Object.assign(Object.assign({},n),{clauses:new Map})),{selections:r}})}}));function _e(t){const e=d(),n=t.clientId||e,{name:o}=t,i=$e(t=>t.selections.get(o)),c=$e(t=>t.setClause),l=$e(t=>t.clearClause),s=r(()=>!!i&&i.clauses.size>0,[i]);return{predicate:r(()=>i&&0!==i.clauses.size?function(t,e){const r=[];for(const[n,o]of t.clauses)"crossfilter"===t.resolution&&n===e||r.push(Se(o));return 0===r.length?()=>!0:"intersect"===t.resolution?t=>r.every(e=>e(t)):t=>r.some(e=>e(t))}(i,n):()=>!0,[i,n]),isActive:s,selectPoints:a(t=>{const e={};for(const[r,n]of Object.entries(t))e[r]={type:"point",values:new Set(n)};c(o,{clientId:n,type:"point",fields:e})},[n,o,c]),selectInterval:a(t=>{const e={};for(const[r,n]of Object.entries(t))e[r]={type:"interval",range:n};c(o,{clientId:n,type:"interval",fields:e})},[n,o,c]),clear:a(()=>{l(o,n)},[l,o,n]),clientId:n}}const[Ie,Ne]=Ae(t=>({observations:[],maxObservations:100,version:0,pushObservation(e){t(t=>{const r=t.observations;return r.push(e),r.length>t.maxObservations&&r.shift(),{version:t.version+1}})},clearObservations(){t(()=>({observations:[],version:0}))}})),We="#007bff";function Me(t,e,n="category10"){return r(()=>{if(e&&"function"!=typeof e)return ye(t,e,n)},[t,e,n])}const je={primary:{width:600,height:400,showAxes:!0,showGrid:!1,enableHover:!0,showLegend:void 0,showLabels:void 0,marginDefaults:{top:50,bottom:60,left:70,right:40}},context:{width:400,height:250,showAxes:!1,showGrid:!1,enableHover:!1,showLegend:!1,showLabels:!1,marginDefaults:{top:10,bottom:10,left:10,right:10}},sparkline:{width:120,height:24,showAxes:!1,showGrid:!1,enableHover:!1,showLegend:!1,showLabels:!1,marginDefaults:{top:2,bottom:2,left:0,right:0}}};function Re(t,e,r){var n,o,a,i,c,l;const s=je[t||"primary"],u="context"===t||"sparkline"===t;return{width:null!==(n=e.width)&&void 0!==n?n:t&&"primary"!==t||!(null==r?void 0:r.width)?s.width:r.width,height:null!==(o=e.height)&&void 0!==o?o:t&&"primary"!==t||!(null==r?void 0:r.height)?s.height:r.height,showAxes:s.showAxes,showGrid:null!==(a=e.showGrid)&&void 0!==a?a:s.showGrid,enableHover:null!==(i=e.enableHover)&&void 0!==i?i:!!e.linkedHover||s.enableHover,showLegend:null!==(c=e.showLegend)&&void 0!==c?c:s.showLegend,showLabels:null!==(l=e.showLabels)&&void 0!==l?l:s.showLabels,title:u?void 0:e.title,xLabel:u?void 0:e.xLabel,yLabel:u?void 0:e.yLabel,categoryLabel:u?void 0:e.categoryLabel,valueLabel:u?void 0:e.valueLabel,marginDefaults:s.marginDefaults}}function Ce({componentName:e,message:r,width:n,height:o}){return t.createElement("div",{role:"alert",style:{width:n,height:Math.max(o,120),display:"flex",alignItems:"center",justifyContent:"center",border:"1px dashed rgba(128, 128, 128, 0.4)",borderRadius:8,background:"rgba(128, 128, 128, 0.04)",padding:24,boxSizing:"border-box"}},t.createElement("div",{style:{textAlign:"center",maxWidth:400}},t.createElement("div",{style:{fontSize:13,fontWeight:600,color:"rgba(128, 128, 128, 0.7)",marginBottom:6,fontFamily:"monospace"}},e),t.createElement("div",{style:{fontSize:14,color:"rgba(128, 128, 128, 0.9)",lineHeight:1.5}},r)))}function Be({data:t,dataLabel:e="data"}){return null==t?`No ${e} provided. Pass a hierarchical data object to the ${e} prop.`:null}function ze({nodes:t,edges:e,nodesRequired:r=!1,edgesRequired:n=!0,accessors:o}){if(n&&(!e||!Array.isArray(e)||0===e.length))return"No edges provided. Pass a non-empty array to the edges prop.";if(r&&(!t||!Array.isArray(t)||0===t.length))return"No nodes provided. Pass a non-empty array to the nodes prop.";if(o&&t&&t.length>0)for(const e of(a=t).length>3?[a[0],a[Math.floor(a.length/2)],a[a.length-1]]:a)if(e&&"object"==typeof e)for(const[t,r]of Object.entries(o))if(r&&"string"==typeof r&&!(r in e))return`${t} "${r}" not found in node data. Available fields: ${Object.keys(e).join(", ")}.`;var a;return null}function Fe(e){var n;const o=Re(e.mode,{width:e.width,height:e.height,enableHover:e.enableHover,showLegend:e.showLegend,showLabels:e.showLabels,title:e.title},{width:600,height:600}),{nodes:i,edges:c,margin:l,className:s,nodeIDAccessor:u="id",sourceAccessor:d="source",targetAccessor:h="target",nodeLabel:f,colorBy:y,colorScheme:g="category10",nodeSize:p=8,nodeSizeRange:v=[5,20],edgeWidth:m=1,edgeColor:b="#999",edgeOpacity:x=.6,iterations:k=300,forceStrength:w=.1,tooltip:L,frameProps:E={},onObservation:D,chartId:A}=e,P=o.width,S=o.height,T=o.enableHover,O=o.showLegend,$=null!==(n=o.showLabels)&&void 0!==n&&n,_=o.title,I=i||[],N=c||[],W=Me(I,y,g),M=r(()=>t=>{const e={};return e.fill=y?fe(t.data||t,y,W):We,"number"==typeof p&&(e.r=p),e},[y,W,p]),j=r(()=>t=>({stroke:b,strokeWidth:"number"==typeof m?m:"function"==typeof m?m(t):t[m]||1,opacity:x}),[m,b,x]),R=r(()=>{if($&&f)return"function"==typeof f?f:t=>t[f]},[$,f]),{legend:C,margin:B}=function({data:t,colorBy:e,colorScale:n,showLegend:o,userMargin:a,defaults:i={top:50,bottom:60,left:70,right:40}}){const c=void 0!==o?o:!!e,l=r(()=>{if(c&&e)return function({data:t,colorBy:e,colorScale:r,getColor:n,strokeColor:o,strokeWidth:a}){const i=Array.from(new Set(t.map(t=>"function"==typeof e?e(t):t[e]))).map(o=>{const a=t.find("function"==typeof e?t=>e(t)===o:t=>t[e]===o),i=a?n(a,e,r):r?r(o):"#000000";return{label:o+"",color:i}});return{legendGroups:[{styleFn:t=>{const e={fill:t.color,stroke:t.color};return void 0!==o&&(e.stroke=o),void 0!==a&&(e.strokeWidth=a),e},type:"fill",items:i,label:""}]}}({data:t,colorBy:e,colorScale:n,getColor:fe})},[c,e,t,n]),s=r(()=>{const t=Object.assign(Object.assign({},i),a);return l&&120>t.right&&(t.right=120),t},[i,a,l]);return{legend:l,margin:s}}({data:I,colorBy:y,colorScale:W,showLegend:O,userMargin:l,defaults:o.marginDefaults}),z=a(t=>{if(!D)return;const e=Date.now();D(t?{type:"hover",datum:t.data||{},x:t.x,y:t.y,timestamp:e,chartType:"ForceDirectedGraph",chartId:A}:{type:"hover-end",timestamp:e,chartType:"ForceDirectedGraph",chartId:A})},[D,A]),F=ze({componentName:"ForceDirectedGraph",nodes:i,edges:c,nodesRequired:!0,edgesRequired:!0,accessors:{nodeIDAccessor:u}});return F?t.createElement(Ce,{componentName:"ForceDirectedGraph",message:F,width:P,height:S}):t.createElement(ke,Object.assign({chartType:"force",nodes:I,edges:N,size:[P,S],margin:B,nodeIDAccessor:u,sourceAccessor:d,targetAccessor:h,iterations:k,forceStrength:w,nodeStyle:M,edgeStyle:j,colorBy:y,colorScheme:g,nodeSize:p,nodeSizeRange:v,nodeLabel:R,showLabels:$,enableHover:T,tooltipContent:L?t=>De(L)(t.data):void 0,customHoverBehavior:D?z:void 0,legend:C,className:s,title:_},E))}function Ye(t,e){if(!t)return[];const r=[],n=t=>{r.push(t);const o="function"==typeof e?e(t):t[e];o&&Array.isArray(o)&&o.forEach(n)};return n(t),r}function Xe(t,e,r,n){if(t&&t.length>0)return t;const o=new Set;return e.forEach(t=>{const e="function"==typeof r?r(t):t[r],a="function"==typeof n?n(t):t[n];o.add(e),o.add(a)}),Array.from(o).map(t=>({id:t}))}function He(t){return"function"==typeof t?t:e=>e[t]||1}function Ge({edgeColorBy:t,colorBy:e,colorScale:r,nodeStyleFn:n,edgeOpacity:o,baseStyle:a={}}){return i=>{const c=Object.assign({fillOpacity:o},a);if("function"==typeof t)c.fill=t(i);else if("source"===t){const t="object"==typeof i.source?i.source:null;e&&t?c.fill=fe(t.data||t,e,r):t&&(c.fill=n(t,t.index).fill)}else if("target"===t){const t="object"==typeof i.target?i.target:null;e&&t?c.fill=fe(t.data||t,e,r):t&&(c.fill=n(t,t.index).fill)}else"gradient"===t&&(c.fill="#999",c.fillOpacity=.7*o);return c}}function qe(e){var n;const o=Re(e.mode,{width:e.width,height:e.height,enableHover:e.enableHover,showLabels:e.showLabels,title:e.title},{width:800,height:600}),{nodes:i,edges:c,margin:l,className:s,sourceAccessor:u="source",targetAccessor:d="target",valueAccessor:h="value",nodeIdAccessor:f="id",colorBy:y,colorScheme:g="category10",edgeColorBy:p="source",orientation:v="horizontal",nodeAlign:m="justify",nodePaddingRatio:b=.05,nodeWidth:x=15,nodeLabel:k,edgeOpacity:w=.5,edgeSort:L,tooltip:E,frameProps:D={},onObservation:A,chartId:P}=e,S=o.width,T=o.height,O=o.enableHover,$=null===(n=o.showLabels)||void 0===n||n,_=o.title,I=c||[],N=r(()=>Xe(i,I,u,d),[i,I,u,d]),W=Me(N,y,g),M=r(()=>t=>{const e={stroke:"black",strokeWidth:1};return e.fill=y?fe(t.data||t,y,W):"#4d430c",e},[y,W]),j=r(()=>Ge({edgeColorBy:p,colorBy:y,colorScale:W,nodeStyleFn:M,edgeOpacity:w,baseStyle:{stroke:"none",strokeWidth:0}}),[p,y,W,M,w]),R=r(()=>{if(!$)return;const t=k||f;return"function"==typeof t?t:e=>e[t]},[$,k,f]),C=Object.assign(Object.assign({},o.marginDefaults),l),B=Ne(t=>t.pushObservation),z=a(t=>{const e=Date.now();if(t){const r={type:"hover",datum:t.data||{},x:t.x,y:t.y,timestamp:e,chartType:"SankeyDiagram",chartId:P};A&&A(r),B&&B(r)}else{const t={type:"hover-end",timestamp:e,chartType:"SankeyDiagram",chartId:P};A&&A(t),B&&B(t)}},[A,P,B]),F=a(t=>{const e=Date.now();if(t){const r={type:"click",datum:t.data||{},x:t.x,y:t.y,timestamp:e,chartType:"SankeyDiagram",chartId:P};A&&A(r),B&&B(r)}else{const t={type:"click-end",timestamp:e,chartType:"SankeyDiagram",chartId:P};A&&A(t),B&&B(t)}},[A,P,B]),Y=ze({componentName:"SankeyDiagram",edges:c,edgesRequired:!0});return Y?t.createElement(Ce,{componentName:"SankeyDiagram",message:Y,width:S,height:T}):t.createElement(ke,Object.assign({chartType:"sankey",nodes:N,edges:I,size:[S,T],margin:C,nodeIDAccessor:f,sourceAccessor:u,targetAccessor:d,valueAccessor:h,orientation:v,nodeAlign:m,nodePaddingRatio:b,nodeWidth:x,nodeStyle:M,edgeStyle:j,colorBy:y,colorScheme:g,edgeColorBy:p,edgeOpacity:w,edgeSort:L,nodeLabel:R,showLabels:$,enableHover:O,tooltipContent:E?t=>De(E)(t.data):void 0,customHoverBehavior:A?z:void 0,customClickBehavior:A?F:void 0,className:s,title:_},D))}function Ve(e){var n;const o=Re(e.mode,{width:e.width,height:e.height,enableHover:e.enableHover,showLabels:e.showLabels,title:e.title},{width:600,height:600}),{nodes:i,edges:c,margin:l,className:s,sourceAccessor:u="source",targetAccessor:d="target",valueAccessor:h="value",nodeIdAccessor:f="id",colorBy:y,colorScheme:g="category10",edgeColorBy:p="source",padAngle:v=.01,groupWidth:m=20,sortGroups:b,nodeLabel:x,edgeOpacity:k=.5,tooltip:w,frameProps:L={},onObservation:E,chartId:D}=e,A=o.width,P=o.height,S=o.enableHover,T=null===(n=o.showLabels)||void 0===n||n,O=o.title,$=c||[],_=r(()=>Xe(i,$,u,d),[i,$,u,d]),I=Me(_,y,g),N=r(()=>(t,e)=>{var r,n;const o={stroke:"black",strokeWidth:1};if(y)o.fill=fe(t.data||t,y,I);else{const a=Array.isArray(g)?g:ue[g]||de,i=Array.isArray(a)?a:de,c=null!==(n=null!==(r=t.index)&&void 0!==r?r:e)&&void 0!==n?n:0;o.fill=i[c%i.length]}return o},[y,I,g]),W=r(()=>Ge({edgeColorBy:p,colorBy:y,colorScale:I,nodeStyleFn:N,edgeOpacity:k,baseStyle:{stroke:"black",strokeWidth:.5,strokeOpacity:k}}),[p,y,I,N,k]),M=r(()=>{if(!T)return;const t=x||f;return"function"==typeof t?t:e=>e[t]},[T,x,f]),j=Object.assign(Object.assign({},o.marginDefaults),l),R=a(t=>{if(!E)return;const e=Date.now();E(t?{type:"hover",datum:t.data||{},x:t.x,y:t.y,timestamp:e,chartType:"ChordDiagram",chartId:D}:{type:"hover-end",timestamp:e,chartType:"ChordDiagram",chartId:D})},[E,D]),C=ze({componentName:"ChordDiagram",edges:c,edgesRequired:!0});return C?t.createElement(Ce,{componentName:"ChordDiagram",message:C,width:A,height:P}):t.createElement(ke,Object.assign({chartType:"chord",nodes:_,edges:$,size:[A,P],margin:j,nodeIDAccessor:f,sourceAccessor:u,targetAccessor:d,valueAccessor:h,padAngle:v,groupWidth:m,sortGroups:b,nodeStyle:N,edgeStyle:W,colorBy:y,colorScheme:g,edgeColorBy:p,edgeOpacity:k,nodeLabel:M,showLabels:T,enableHover:S,tooltipContent:w?t=>De(w)(t.data):void 0,customHoverBehavior:E?R:void 0,className:s,title:O},L))}function Ze(e){var n;const o=Re(e.mode,{width:e.width,height:e.height,enableHover:e.enableHover,showLabels:e.showLabels,title:e.title},{width:600,height:600}),{data:i,margin:c,className:l,layout:s="tree",orientation:u="vertical",childrenAccessor:d="children",valueAccessor:h="value",nodeIdAccessor:f="name",colorBy:y,colorScheme:g="category10",colorByDepth:p=!1,edgeStyle:v="curve",nodeLabel:m,nodeSize:b=5,tooltip:x,frameProps:k={},onObservation:w,chartId:L}=e,E=o.width,D=o.height,A=o.enableHover,P=null===(n=o.showLabels)||void 0===n||n,S=o.title,T=r(()=>Ye(i,d),[i,d]),O=r(()=>{if(!p&&y&&"function"!=typeof y)return ye(T,y,g)},[T,y,p,g]),$=r(()=>t=>{const e={stroke:"black",strokeWidth:1};return e.fill=p?he[(t.depth||0)%he.length]:y?fe(t.data||t,y,O):We,e},[y,p,O]),_=r(()=>()=>({stroke:"#999",strokeWidth:1,fill:"none"}),[]),I=r(()=>{if("treemap"===s||"circlepack"===s||"partition"===s)return He(h)},[s,h]),N=Object.assign(Object.assign({},o.marginDefaults),c),W=a(t=>{if(!w)return;const e=Date.now();w(t?{type:"hover",datum:t.data||{},x:t.x,y:t.y,timestamp:e,chartType:"TreeDiagram",chartId:L}:{type:"hover-end",timestamp:e,chartType:"TreeDiagram",chartId:L})},[w,L]),M=Be({componentName:"TreeDiagram",data:i});return M?t.createElement(Ce,{componentName:"TreeDiagram",message:M,width:E,height:D}):t.createElement(ke,Object.assign({chartType:s,data:i,size:[E,D],margin:N,nodeIDAccessor:f,childrenAccessor:d,hierarchySum:I,treeOrientation:u,edgeType:v,nodeStyle:$,edgeStyle:_,colorBy:y,colorScheme:g,colorByDepth:p,nodeSize:b,nodeLabel:P?m||f:void 0,showLabels:P,enableHover:A,tooltipContent:x?t=>De(x)(t.data):void 0,customHoverBehavior:w?W:void 0,className:l,title:S},k))}function Ke(e){var n;const o=Re(e.mode,{width:e.width,height:e.height,enableHover:e.enableHover,showLabels:e.showLabels,title:e.title,linkedHover:e.linkedHover},{width:600,height:600}),{data:i,margin:c,className:l,childrenAccessor:s="children",valueAccessor:u="value",nodeIdAccessor:d="name",colorBy:h,colorScheme:f="category10",colorByDepth:y=!1,labelMode:g="leaf",nodeLabel:p,padding:v=4,paddingTop:m,tooltip:b,frameProps:x={},selection:k,linkedHover:w,onObservation:L,chartId:E}=e,D=o.width,A=o.height,P=o.enableHover,S=null===(n=o.showLabels)||void 0===n||n,T=o.title,{activeSelectionHook:O,customHoverBehavior:$}=function({selection:t,linkedHover:e,fallbackFields:r=[],unwrapData:n=!1,onObservation:o,chartType:i,chartId:c}){const l=function(t,e){return t?!0===t?{name:"hover",fields:e||[]}:"string"==typeof t?{name:t,fields:e||[]}:{name:t.name||"hover",fields:t.fields}:null}(e,r),s=_e({name:(null==t?void 0:t.name)||"__unused__"}),u=function(t){const e=t.name||"hover",{fields:r}=t,{predicate:n,isActive:o,selectPoints:i,clear:c}=_e({name:e});return{onHover:a(t=>{if(!t)return void c();const e={};for(const n of r){const r=t[n];void 0!==r&&(e[n]=[r])}Object.keys(e).length>0&&i(e)},[r,i,c]),predicate:n,isActive:o}}({name:(null==l?void 0:l.name)||"hover",fields:(null==l?void 0:l.fields)||[]}),d=Ne(t=>t.pushObservation);return{activeSelectionHook:t?{isActive:s.isActive,predicate:s.predicate}:null,customHoverBehavior:a(t=>{var r,n;if(e){let e=t&&(t.data||t.datum)||t;Array.isArray(e)&&(e=e[0]),u.onHover(e)}if(o||d){const e={timestamp:Date.now(),chartType:i,chartId:c};if(t){let a=t.data||t.datum||t;Array.isArray(a)&&(a=a[0]);const i=Object.assign(Object.assign({},e),{type:"hover",datum:a||{},x:null!==(r=t.x)&&void 0!==r?r:0,y:null!==(n=t.y)&&void 0!==n?n:0});o&&o(i),d&&d(i)}else{const t=Object.assign(Object.assign({},e),{type:"hover-end"});o&&o(t),d&&d(t)}}},[e,u,o,i,c,d]),customClickBehavior:a(t=>{var e,r;if(o||d){const n={timestamp:Date.now(),chartType:i,chartId:c};if(t){let a=t.data||t.datum||t;Array.isArray(a)&&(a=a[0]);const i=Object.assign(Object.assign({},n),{type:"click",datum:a||{},x:null!==(e=t.x)&&void 0!==e?e:0,y:null!==(r=t.y)&&void 0!==r?r:0});o&&o(i),d&&d(i)}else{const t=Object.assign(Object.assign({},n),{type:"click-end"});o&&o(t),d&&d(t)}}},[o,d,i,c])}}({selection:k,linkedHover:w,fallbackFields:h?["string"==typeof h?h:""]:[],onObservation:L,chartType:"Treemap",chartId:E}),_=a(t=>{if(!t)return $(null);const e=t.data||t;$({data:(null==e?void 0:e.data)||e})},[$]),I=r(()=>Ye(i,s),[i,s]),N=r(()=>{if(y)return;if(!h||"function"==typeof h)return;const t=h;return ye(I.filter(e=>null!=e[t]),t,f)},[I,h,y,f]),W=r(()=>t=>{const e={stroke:"#fff",strokeWidth:1,strokeOpacity:.8};return e.fill=y?he[(t.depth||0)%he.length]:h?fe(t.data||t,h,N):We,e},[h,y,N]),M=r(()=>O?t=>{var e,r;const n=Object.assign({},W(t));return O.isActive&&(O.predicate(t.data||t)?(null==k?void 0:k.selectedStyle)&&Object.assign(n,k.selectedStyle):(n.fillOpacity=null!==(e=null==k?void 0:k.unselectedOpacity)&&void 0!==e?e:.2,n.strokeOpacity=null!==(r=null==k?void 0:k.unselectedOpacity)&&void 0!==r?r:.2,(null==k?void 0:k.unselectedStyle)&&Object.assign(n,k.unselectedStyle))),n}:W,[W,O,k]),j=r(()=>He(u),[u]),R=void 0!==m?m:S&&"parent"===g?18:void 0,C=Object.assign(Object.assign({},o.marginDefaults),c),B=Be({componentName:"Treemap",data:i});return B?t.createElement(Ce,{componentName:"Treemap",message:B,width:D,height:A}):t.createElement(ke,Object.assign({chartType:"treemap",data:i,size:[D,A],margin:C,nodeIDAccessor:d,childrenAccessor:s,hierarchySum:j,padding:v,paddingTop:R,nodeStyle:M,colorBy:h,colorScheme:f,colorByDepth:y,nodeLabel:S?p||d:void 0,showLabels:S,enableHover:P,tooltipContent:b?t=>De(b)(t.data):void 0},(w||L)&&{customHoverBehavior:_},{className:l,title:T},x))}function Qe(e){var n;const o=Re(e.mode,{width:e.width,height:e.height,enableHover:e.enableHover,showLabels:e.showLabels,title:e.title},{width:600,height:600}),{data:i,margin:c,className:l,childrenAccessor:s="children",valueAccessor:u="value",nodeIdAccessor:d="name",colorBy:h,colorScheme:f="category10",colorByDepth:y=!1,nodeLabel:g,circleOpacity:p=.7,padding:v=4,tooltip:m,frameProps:b={},onObservation:x,chartId:k}=e,w=o.width,L=o.height,E=o.enableHover,D=null===(n=o.showLabels)||void 0===n||n,A=o.title,P=r(()=>Ye(i,s),[i,s]),S=r(()=>{if(!y&&h&&"function"!=typeof h)return ye(P,h,f)},[P,h,y,f]),T=r(()=>t=>{const e={stroke:"currentColor",strokeWidth:1,strokeOpacity:.3,fillOpacity:p};return e.fill=y?he[(t.depth||0)%he.length]:h?fe(t.data||t,h,S):We,e},[h,y,S,p]),O=r(()=>He(u),[u]),$=Object.assign(Object.assign({},o.marginDefaults),c),_=a(t=>{if(!x)return;const e=Date.now();x(t?{type:"hover",datum:t.data||{},x:t.x,y:t.y,timestamp:e,chartType:"CirclePack",chartId:k}:{type:"hover-end",timestamp:e,chartType:"CirclePack",chartId:k})},[x,k]),I=Be({componentName:"CirclePack",data:i});return I?t.createElement(Ce,{componentName:"CirclePack",message:I,width:w,height:L}):t.createElement(ke,Object.assign({chartType:"circlepack",data:i,size:[w,L],margin:$,nodeIDAccessor:d,childrenAccessor:s,hierarchySum:O,padding:v,nodeStyle:T,colorBy:h,colorScheme:f,colorByDepth:y,nodeLabel:D?g||d:void 0,showLabels:D,enableHover:E,tooltipContent:m?t=>De(m)(t.data):void 0,customHoverBehavior:x?_:void 0,className:l,title:A},b))}Fe.displayName="ForceDirectedGraph",qe.displayName="SankeyDiagram",Ve.displayName="ChordDiagram",Ze.displayName="TreeDiagram",Ke.displayName="Treemap",Qe.displayName="CirclePack";export{Ve as ChordDiagram,Qe as CirclePack,Fe as ForceDirectedGraph,qe as SankeyDiagram,ke as StreamNetworkFrame,Ze as TreeDiagram,Ke as Treemap};
1
+ import*as e from"react";import{useRef as t,useState as r,useEffect as n,forwardRef as o,useMemo as i,useCallback as a,useImperativeHandle as c,useContext as s,createContext as l,useLayoutEffect as u,useId as d}from"react";import{interpolateNumber as h}from"d3-interpolate";import{min as f,groups as y,max as g,sum as p,mean as v,group as m}from"d3-array";import{schemeCategory10 as b,interpolatePlasma as x,interpolateViridis as k,interpolatePurples as w,interpolateOranges as L,interpolateGreens as E,interpolateReds as A,interpolateBlues as D,schemeSet3 as P,schemeTableau10 as S}from"d3-scale-chromatic";import{forceLink as T,forceSimulation as O,forceManyBody as N,forceX as W,forceY as $}from"d3-force";import{scaleLinear as _,scaleOrdinal as I}from"d3-scale";import{ribbon as M,chord as j}from"d3-chord";import{arc as C}from"d3-shape";import{hierarchy as R,partition as B,pack as F,treemap as z,treemapBinary as H,cluster as Y,tree as X}from"d3-hierarchy";const G={weightChange:.1,newEdge:.5,newNode:1,threshold:3,transitionDuration:500},q={radius:3,opacity:.7,speedMultiplier:1,maxPerEdge:50,spawnRate:.1};class V{constructor(e){this.capacity=e,this.particles=Array(e);for(let t=0;e>t;t++)this.particles[t]={t:0,offset:0,edgeIndex:0,active:!1,x:0,y:0}}spawn(e){for(let t=0;this.capacity>t;t++){const r=this.particles[t];if(!r.active)return r.active=!0,r.t=0,r.offset=Math.random()-.5,r.edgeIndex=e,r.x=0,r.y=0,r}return null}step(e,t,r,n){var o;for(let i=0;this.capacity>i;i++){const a=this.particles[i];if(!a.active)continue;const c=r[a.edgeIndex];if(!c||!c.bezier){a.active=!1;continue}const s=n&&null!==(o=n[a.edgeIndex])&&void 0!==o?o:1;if(a.t+=e*t*s*(c.bezier.circular?.3:1),a.t>=1){a.active=!1;continue}const l=Z(c.bezier,a.t,a.offset);a.x=l.x,a.y=l.y}}countForEdge(e){let t=0;for(let r=0;this.capacity>r;r++)this.particles[r].active&&this.particles[r].edgeIndex===e&&t++;return t}clear(){for(let e=0;this.capacity>e;e++)this.particles[e].active=!1}resize(e){if(this.capacity>=e)return;const t=this.particles;this.particles=Array(e);for(let r=0;e>r;r++)this.particles[r]=t.length>r?t[r]:{t:0,offset:0,edgeIndex:0,active:!1,x:0,y:0};this.capacity=e}}function Z(e,t,r){if(e.circular&&e.segments)return function(e,t,r,n){const o=e.length,i=t*o,a=Math.min(Math.floor(i),o-1),c=i-a,[s,l,u,d]=e[a],h=K(s,l,u,d,c),f=d.x-s.x,y=d.y-s.y,g=Math.sqrt(f*f+y*y);if(g>.001){const e=f/g;h.x+=-y/g*r*n*2,h.y+=e*r*n*2}return h}(e.segments,t,r,e.halfWidth);if(!e.points)return{x:0,y:0};const[n,o,i,a]=e.points,c=K(n,o,i,a,t),s=a.x-n.x,l=a.y-n.y,u=Math.sqrt(s*s+l*l);if(u>.001){const t=s/u;c.x+=-l/u*r*e.halfWidth*2,c.y+=t*r*e.halfWidth*2}return c}function K(e,t,r,n,o){const i=1-o,a=i*i,c=a*i,s=o*o,l=s*o;return{x:c*e.x+3*a*o*t.x+3*i*s*r.x+l*n.x,y:c*e.y+3*a*o*t.y+3*i*s*r.y+l*n.y}}function Q(e,t){var r=e.get(t);if(!r)throw Error("missing: "+t);return r}function J(e,t){var r,n=[],o=[],i=[],a={},c=[];function s(e){i[e]=!1,a.hasOwnProperty(e)&&Object.keys(a[e]).forEach(function(t){delete a[e][t],i[t]&&s(t)})}function l(e){var t,n,d=!1;for(o.push(e),i[e]=!0,t=0;c[e].length>t;t++)(n=c[e][t])===r?(u(r,o),d=!0):i[n]||(d=l(n));if(d)s(e);else for(t=0;c[e].length>t;t++){var h=a[n=c[e][t]];h||(a[n]=h={}),h[n]=!0}return o.pop(),d}function u(e,t){var r=[].concat(t).concat(e);n.push(r)}function d(t){!function(t){for(var r=0;e.length>r;r++)r>=t&&e[r]||(e[r]=[]),e[r]=e[r].filter(function(e){return e>=t})}(t);for(var r,n=function(e){for(var t=e.length,r=Array(t),n=Array(t),o=Array(t),i=Array(t),a=Array(t),c=Array(t),s=0;t>s;++s)r[s]=-1,n[s]=0,o[s]=!1,i[s]=0,a[s]=-1,c[s]=[];var l,u=0,d=[],h=[];function f(t){var s=[t],l=[t];for(r[t]=n[t]=u,o[t]=!0,u+=1;l.length>0;){var f=e[t=l[l.length-1]];if(f.length>i[t]){for(var y=i[t];f.length>y;++y){var g=f[y];if(0>r[g]){r[g]=n[g]=u,o[g]=!0,u+=1,s.push(g),l.push(g);break}o[g]&&(n[t]=0|Math.min(n[t],n[g])),0>a[g]||c[t].push(a[g])}i[t]=y}else{if(n[t]===r[t]){var p=[],v=[],m=0;for(y=s.length-1;y>=0;--y){var b=s[y];if(o[b]=!1,p.push(b),v.push(c[b]),m+=c[b].length,a[b]=d.length,b===t){s.length=y;break}}d.push(p);var x=Array(m);for(y=0;v.length>y;y++)for(var k=0;v[y].length>k;k++)x[--m]=v[y][k];h.push(x)}l.pop()}}}for(s=0;t>s;++s)0>r[s]&&f(s);for(s=0;h.length>s;s++){var y=h[s];if(0!==y.length){y.sort(function(e,t){return e-t}),l=[y[0]];for(var g=1;y.length>g;g++)y[g]!==y[g-1]&&l.push(y[g]);h[s]=l}}return{components:d,adjacencyList:h}}(e),o=n.components.filter(function(e){return e.length>1}),i=1/0,a=0;o.length>a;a++)for(var c=0;o[a].length>c;c++)i>o[a][c]&&(i=o[a][c],r=a);var s=o[r];if(!s)return!1;var l=e.map(function(e,t){return-1===s.indexOf(t)?[]:e.filter(function(e){return-1!==s.indexOf(e)})});return{leastVertex:i,adjList:l}}r=0;for(var h=e.length;h>r;){var f=d(r);if(r=f.leastVertex,c=f.adjList){for(var y=0;c.length>y;y++)for(var g=0;c[y].length>g;g++){var p=c[y][g];i[+p]=!1,a[p]={}}l(r),r+=1}else r=h}return n}function U(e){return e.y0-e.y1>0?"up":"down"}function ee(e,t){return t(e.source)==t(e.target)}function te(e){var t=0;e.source.sourceLinks.forEach(function(e){t=e.circular?t+1:t});var r=0;return e.target.targetLinks.forEach(function(e){r=e.circular?r+1:r}),1>=t&&1>=r}function re(e){return e.target.x0-e.source.x1}function ne(e,t){var r=ie(e),n=re(t)/Math.tan(r);return"up"==U(e)?e.y1-n:e.y1+n}function oe(e,t){var r=ie(e),n=re(t)/Math.tan(r);return"up"==U(e)?e.y1+n:e.y1-n}function ie(e){var t=Math.abs(e.y1-e.y0);return Math.atan(Math.abs(e.target.x0-e.source.x1)/t)}function ae(e,t){return t(e)}function ce(e){return le(e.source)}function se(e){return le(e.target)}function le(e){return(e.y0+e.y1)/2}function ue(e){return e.virtual?0:e.value}function de(e,t){var r=0;e.sourceLinks.forEach(function(e){r=e.circular&&!ee(e,t)?r+1:r});var n=0;return e.targetLinks.forEach(function(e){n=e.circular&&!ee(e,t)?n+1:n}),r+n}function he(e){return e.target.depth}function fe(e,t){return e.sourceLinks.length?e.depth:t-1}function ye(e,t){return e.y0-t.y0}function ge(e,t){return t.y0-e.y0}function pe(e,t){return e.y1-t.y1}function ve(e,t){return t.y1-e.y1}function me(e,t){return xe(e.source,t.source)||e.index-t.index}function be(e,t){return xe(e.target,t.target)||e.index-t.index}function xe(e,t){return e.partOfCycle===t.partOfCycle?e.y0-t.y0:"top"===e.circularLinkType||"bottom"===t.circularLinkType?-1:1}function ke(e,t){return we(e)==we(t)?"bottom"==e.circularLinkType?ge(e,t):ye(e,t):we(t)-we(e)}function we(e){return e.target.column-e.source.column}function Le(e,t){return Ee(e)==Ee(t)}function Ee(e){return e.y0-e.y1>0?"up":"down"}function Ae(e,t,r,n,o){let i=e;var a=Math.max(8,.15*(i.y1-i.y0));i.links.forEach(function(e){e.circular&&(e._circularWidth=Math.min(e.width,a))});var c=f(i.links,function(e){return e.source.y0});i.links.forEach(function(e){e.circular&&(e.circularPathData={})});var s=i.links.filter(function(e){return e.circular});return s.sort(function(e,t){return t.value-e.value}),s.forEach(function(e,t){e._circularStub=t>=4}),De(i.links.filter(function(e){return"top"==e.circularLinkType}),t,r),De(i.links.filter(function(e){return"bottom"==e.circularLinkType}),t,r),i.links.forEach(function(e){if(e.circular){if(e.circularPathData.arcRadius=e._circularWidth+n,e.circularPathData.rightNodeBuffer=5,e.circularPathData.leftNodeBuffer=5,e.circularPathData.sourceWidth=e.source.x1-e.source.x0,e.circularPathData.sourceX=e.source.x0+e.circularPathData.sourceWidth,e.circularPathData.targetX=e.target.x0,e.circularPathData.sourceY=e.y0,e.circularPathData.targetY=e.y1,ee(e,t)&&te(e))e.circularPathData.rightSmallArcRadius=n+e._circularWidth/2,e.circularPathData.rightLargeArcRadius=n+e._circularWidth/2,e.circularPathData.leftSmallArcRadius=n+e._circularWidth/2,e.circularPathData.leftLargeArcRadius=n+e._circularWidth/2,"bottom"==e.circularLinkType?(e.circularPathData.verticalFullExtent=e.source.y1+o+e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.leftLargeArcRadius):(e.circularPathData.verticalFullExtent=e.source.y0-o-e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.leftLargeArcRadius);else{var a=e.source.column,s=e.circularLinkType,l=i.links.filter(function(e){return e.source.column==a&&e.circularLinkType==s});l.sort("bottom"==e.circularLinkType?ge:ye);var u=0;l.forEach(function(t,o){t.circularLinkID==e.circularLinkID&&(e.circularPathData.rightSmallArcRadius=n+e._circularWidth/2+u,e.circularPathData.rightLargeArcRadius=n+e._circularWidth/2+o*r+u),u+=t._circularWidth||t.width}),a=e.target.column,(l=i.links.filter(function(e){return e.target.column==a&&e.circularLinkType==s})).sort("bottom"==e.circularLinkType?ve:pe),u=0,l.forEach(function(t,o){t.circularLinkID==e.circularLinkID&&(e.circularPathData.leftSmallArcRadius=n+e._circularWidth/2+u,e.circularPathData.leftLargeArcRadius=n+e._circularWidth/2+o*r+u),u+=t._circularWidth||t.width}),"bottom"==e.circularLinkType?(e.circularPathData.verticalFullExtent=Math.max(i.y1,e.source.y1,e.target.y1)+o+e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.leftLargeArcRadius):(e.circularPathData.verticalFullExtent=c-o-e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.leftLargeArcRadius)}e.circularPathData.rightInnerExtent=e.circularPathData.sourceX+e.circularPathData.rightNodeBuffer,e.circularPathData.leftInnerExtent=e.circularPathData.targetX-e.circularPathData.leftNodeBuffer,e.circularPathData.rightFullExtent=e.circularPathData.sourceX+e.circularPathData.rightLargeArcRadius+e.circularPathData.rightNodeBuffer,e.circularPathData.leftFullExtent=e.circularPathData.targetX-e.circularPathData.leftLargeArcRadius-e.circularPathData.leftNodeBuffer}e.path=e.circular?function(e){return"top"==e.circularLinkType?"M"+e.circularPathData.sourceX+" "+e.circularPathData.sourceY+" L"+e.circularPathData.rightInnerExtent+" "+e.circularPathData.sourceY+" A"+e.circularPathData.rightLargeArcRadius+" "+e.circularPathData.rightSmallArcRadius+" 0 0 0 "+e.circularPathData.rightFullExtent+" "+(e.circularPathData.sourceY-e.circularPathData.rightSmallArcRadius)+" L"+e.circularPathData.rightFullExtent+" "+e.circularPathData.verticalRightInnerExtent+" A"+e.circularPathData.rightLargeArcRadius+" "+e.circularPathData.rightLargeArcRadius+" 0 0 0 "+e.circularPathData.rightInnerExtent+" "+e.circularPathData.verticalFullExtent+" L"+e.circularPathData.leftInnerExtent+" "+e.circularPathData.verticalFullExtent+" A"+e.circularPathData.leftLargeArcRadius+" "+e.circularPathData.leftLargeArcRadius+" 0 0 0 "+e.circularPathData.leftFullExtent+" "+e.circularPathData.verticalLeftInnerExtent+" L"+e.circularPathData.leftFullExtent+" "+(e.circularPathData.targetY-e.circularPathData.leftSmallArcRadius)+" A"+e.circularPathData.leftLargeArcRadius+" "+e.circularPathData.leftSmallArcRadius+" 0 0 0 "+e.circularPathData.leftInnerExtent+" "+e.circularPathData.targetY+" L"+e.circularPathData.targetX+" "+e.circularPathData.targetY:"M"+e.circularPathData.sourceX+" "+e.circularPathData.sourceY+" L"+e.circularPathData.rightInnerExtent+" "+e.circularPathData.sourceY+" A"+e.circularPathData.rightLargeArcRadius+" "+e.circularPathData.rightSmallArcRadius+" 0 0 1 "+e.circularPathData.rightFullExtent+" "+(e.circularPathData.sourceY+e.circularPathData.rightSmallArcRadius)+" L"+e.circularPathData.rightFullExtent+" "+e.circularPathData.verticalRightInnerExtent+" A"+e.circularPathData.rightLargeArcRadius+" "+e.circularPathData.rightLargeArcRadius+" 0 0 1 "+e.circularPathData.rightInnerExtent+" "+e.circularPathData.verticalFullExtent+" L"+e.circularPathData.leftInnerExtent+" "+e.circularPathData.verticalFullExtent+" A"+e.circularPathData.leftLargeArcRadius+" "+e.circularPathData.leftLargeArcRadius+" 0 0 1 "+e.circularPathData.leftFullExtent+" "+e.circularPathData.verticalLeftInnerExtent+" L"+e.circularPathData.leftFullExtent+" "+(e.circularPathData.targetY+e.circularPathData.leftSmallArcRadius)+" A"+e.circularPathData.leftLargeArcRadius+" "+e.circularPathData.leftSmallArcRadius+" 0 0 1 "+e.circularPathData.leftInnerExtent+" "+e.circularPathData.targetY+" L"+e.circularPathData.targetX+" "+e.circularPathData.targetY}(e):function(e){var t=e.source.x1,r=e.y0,n=e.target.x0,o=e.y1,i=(t+n)/2;return"M"+t+","+r+"C"+i+","+r+" "+i+","+o+" "+n+","+o}(e)}),i}function De(e,t,r){e.sort(ke);var n=e.filter(function(e){return!e._circularStub});return e.forEach(function(e,o){var i=0;if(e._circularStub)e.circularPathData.verticalBuffer=0;else if(ee(e,t)&&te(e))e.circularPathData.verticalBuffer=i+e._circularWidth/2;else{for(var a=0;n.length>a;a++){var c=n[a];if(c!==e&&c.circularPathData&&void 0!==c.circularPathData.verticalBuffer&&Pe(e,c)){var s=c.circularPathData.verticalBuffer+(c._circularWidth||c.width)/2+r;i=s>i?s:i}}e.circularPathData.verticalBuffer=i+e._circularWidth/2}}),e}function Pe(e,t){return e.source.column>=t.target.column&&t.source.column>=e.target.column}function Se(e){return function(){return e}}function Te(e){return e.index}function Oe(e){return e.nodes}function Ne(e){return e.links}function We(e,t,r){var n=y(e.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]});n.forEach(function(o){var i=o.length;o.sort(t||function(e,t){return e.circularLinkType==t.circularLinkType?de(t,r)-de(e,r):"top"==e.circularLinkType&&"bottom"==t.circularLinkType||"top"==e.circularLinkType&&0==t.partOfCycle||0==e.partOfCycle&&"bottom"==t.circularLinkType?-1:0}),o.forEach(function(t,o){t.depth==n.length-1&&1==i||0==t.depth&&1==i?(t.y0=e.y1/2-t.value*e.ky,t.y1=t.y0+t.value*e.ky):t.partOfCycle?0==de(t,r)?(t.y0=e.y1/2+o,t.y1=t.y0+t.value*e.ky):"top"==t.circularLinkType?(t.y0=e.y0+o,t.y1=t.y0+t.value*e.ky):(t.y0=e.y1-t.value*e.ky-o,t.y1=t.y0+t.value*e.ky):0==e.y0||0==e.y1?(t.y0=(e.y1-e.y0)/i*o,t.y1=t.y0+t.value*e.ky):(t.y0=(e.y1-e.y0)/2-i/2+o,t.y1=t.y0+t.value*e.ky)})})}function $e(e,t,r,n,o,i){var a=y(e.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]});u();for(var c=1,s=i;s>0;--s)l(c*=.99,r),u();function l(t,r){var n=a.length;a.forEach(function(o){var i=o.length,a=o[0].depth;o.forEach(function(o){var c;if(o.sourceLinks.length||o.targetLinks.length)if(o.partOfCycle&&de(o,r)>0){var s=v(o.sourceLinks,se),l=v(o.targetLinks,ce),u=s&&l?(s+l)/2:s||l;if(u){var d=(u-le(o))*t*.3;o.y0+=d,o.y1+=d}}else if(0==a&&1==i)o.y0=e.y1/2-(c=o.y1-o.y0)/2,o.y1=e.y1/2+c/2;else if(a==n-1&&1==i)o.y0=e.y1/2-(c=o.y1-o.y0)/2,o.y1=e.y1/2+c/2;else if(1==o.targetLinks.length&&1==o.targetLinks[0].source.sourceLinks.length)c=o.y1-o.y0,o.y0=o.targetLinks[0].source.y0,o.y1=o.y0+c;else{var h=v(o.sourceLinks,se),f=v(o.targetLinks,ce),y=((h&&f?(h+f)/2:h||f)-le(o))*t;o.y0+=y,o.y1+=y}})})}function u(){a.forEach(function(r){var i,a,c,s=e.y0,l=r.length;for(r.sort(t||xe),c=0;l>c;++c)(a=s-(i=r[c]).y0)>0&&(i.y0+=a,i.y1+=a),s=i.y1+n;if((a=s-n-e.y1)>0)for(s=i.y0-=a,i.y1-=a,c=l-2;c>=0;--c)(a=(i=r[c]).y1+o-s)>0&&(i.y0-=a,i.y1-=a),s=i.y0})}}function _e(e){e.nodes.forEach(function(e){e.sourceLinks.sort(be),e.targetLinks.sort(me)}),e.nodes.forEach(function(e){var t=e.y0,r=t,n=e.y1,o=n;e.sourceLinks.forEach(function(e){e.circular?(e.y0=n-e.width/2,n-=e.width):(e.y0=t+e.width/2,t+=e.width)}),e.targetLinks.forEach(function(e){e.circular?(e.y1=o-e.width/2,o-=e.width):(e.y1=r+e.width/2,r+=e.width)})})}function Ie(){var e=0,t=0,r=1,n=1,o=24,i=8,a=null,c=Te,s=fe,l=void 0,u=32,d=2,h=Oe,v=Ne;function b(){var b={nodes:h.apply(null,arguments),links:v.apply(null,arguments)};return function(h){h.x0=e,h.y0=t,h.x1=r,h.y1=n,h.py=0,function(e,t){e.nodes.forEach(function(e,t){e.index=t,e.sourceLinks=[],e.targetLinks=[]});var r=function(e,t){var r=new Map;return m(e,t).forEach(function(e,t){r.set(t,e[0])}),r}(e.nodes,t);e.links.forEach(function(e,t){e.index=t;var n=e.source,o=e.target;"object"!=typeof n&&(n=e.source=Q(r,n)),"object"!=typeof o&&(o=e.target=Q(r,o)),n.sourceLinks.push(e),o.targetLinks.push(e)})}(h,c),function(e,t){var r=0;if(null==t){for(var n=[],o=0;e.links.length>o;o++){var i=e.links[o],a=i.source.index,c=i.target.index;n[a]||(n[a]=[]),n[c]||(n[c]=[]),-1===n[a].indexOf(c)&&n[a].push(c)}var s=J(n);s.sort(function(e,t){return e.length-t.length});var l={};for(o=0;s.length>o;o++){var u=s[o].slice(-2);l[u[0]]||(l[u[0]]={}),l[u[0]][u[1]]=!0}e.links.forEach(function(e){var t=e.target.index,n=e.source.index;t===n||l[n]&&l[n][t]?(e.circular=!0,e.circularLinkID=r++):e.circular=!1})}else e.links.forEach(function(e){t(e.source)<t(e.target)?e.circular=!1:(e.circular=!0,e.circularLinkID=r++)})}(h,l),function(e,t){var r=0,n=0;e.links.forEach(function(o){o.circular&&(o.circularLinkType=o.source.circularLinkType||o.target.circularLinkType?o.source.circularLinkType?o.source.circularLinkType:o.target.circularLinkType:n>r?"top":"bottom","top"==o.circularLinkType?r++:n++,e.nodes.forEach(function(e){ae(e,t)!=ae(o.source,t)&&ae(e,t)!=ae(o.target,t)||(e.circularLinkType=o.circularLinkType)}))}),e.links.forEach(function(e){e.circular&&(e.source.circularLinkType==e.target.circularLinkType&&(e.circularLinkType=e.source.circularLinkType),ee(e,t)&&(e.circularLinkType=e.source.circularLinkType))})}(h,c),function(e){e.nodes.forEach(function(e){e.partOfCycle=!1,e.value=Math.max(p(e.sourceLinks,ue),p(e.targetLinks,ue)),e.sourceLinks.forEach(function(t){t.circular&&(e.partOfCycle=!0,e.circularLinkType=t.circularLinkType)}),e.targetLinks.forEach(function(t){t.circular&&(e.partOfCycle=!0,e.circularLinkType=t.circularLinkType)})})}(h),function(e,t,r){var n,o,i;if(null!=t){e.nodes.sort(function(e,r){return t(e)<t(r)?-1:1});var a=0,c=t(e.nodes[0]);e.nodes.forEach(function(e){a=t(e)==c?a:a+1,c=t(e)==c?c:t(e),e.column=a})}for(n=e.nodes,o=[],i=0;n.length;++i,n=o,o=[])n.forEach(function(e){e.depth=i,e.sourceLinks.forEach(function(e){0>o.indexOf(e.target)&&!e.circular&&o.push(e.target)})});for(n=e.nodes,o=[],i=0;n.length;++i,n=o,o=[])n.forEach(function(e){e.height=i,e.targetLinks.forEach(function(e){0>o.indexOf(e.source)&&!e.circular&&o.push(e.source)})});e.nodes.forEach(function(e){e.column=null==t?r(e,i):e.column})}(h,l,s);var v=i;if(null!==a){var b=y(h.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]}),x=g(b,function(e){return e.length});x>1&&(v=Math.max(1,(n-t)*a/(x-1)))}(function(e,t,r){var n=y(e.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]});e.py=t;var o=f(n,function(t){return(e.y1-e.y0-(t.length-1)*e.py)/p(t,function(e){return e.value})});e.ky=o,e.links.forEach(function(t){t.width=t.value*e.ky});var i=g(e.nodes,function(e){return e.column});e.nodes.forEach(i>0?function(t){t.x0=e.x0+t.column*((e.x1-e.x0-r)/i),t.x1=t.x0+r}:function(t){t.x0=e.x0,t.x1=t.x0+r})})(h,v,o),We(h,l,c),$e(h,l,c,v,v,u),_e(h),Ae(h,c,d,10,8),We(h,l,c),$e(h,l,c,v,v,u),_e(h),Ae(h,c,d,10,8),function(e,t){let r=e;r.nodes.forEach(function(e){e.y+(e.y1-e.y0)>r.y1&&(e.y=e.y-(e.y+(e.y1-e.y0)-r.y1));var n=r.links.filter(function(r){return ae(r.source,t)==ae(e,t)}),o=n.length;o>1&&n.sort(function(e,t){if(!e.circular&&!t.circular){if(e.target.column==t.target.column)return e.y1-t.y1;if(!Le(e,t))return e.y1-t.y1;if(e.target.column>t.target.column){var r=ne(t,e);return e.y1-r}if(t.target.column>e.target.column)return ne(e,t)-t.y1}return e.circular&&!t.circular?"top"==e.circularLinkType?-1:1:t.circular&&!e.circular?"top"==t.circularLinkType?1:-1:e.circular&&t.circular?e.circularLinkType===t.circularLinkType&&"top"==e.circularLinkType?e.target.column===t.target.column?e.target.y1-t.target.y1:t.target.column-e.target.column:e.circularLinkType===t.circularLinkType&&"bottom"==e.circularLinkType?e.target.column===t.target.column?t.target.y1-e.target.y1:e.target.column-t.target.column:"top"==e.circularLinkType?-1:1:void 0});var i=e.y0;n.forEach(function(e){e.y0=i+e.width/2,i+=e.width}),n.forEach(function(t,r){if("bottom"==t.circularLinkType){for(var i=r+1,a=0;o>i;i++)a+=n[i].width;t.y0=e.y1-a-t.width/2}})})}(h,c),function(e,t){let r=e;r.nodes.forEach(function(e){var n=r.links.filter(function(r){return ae(r.target,t)==ae(e,t)}),o=n.length;o>1&&n.sort(function(e,t){if(!e.circular&&!t.circular){if(e.source.column==t.source.column)return e.y0-t.y0;if(!Le(e,t))return e.y0-t.y0;if(e.source.column>t.source.column){var r=oe(t,e);return e.y0-r}if(t.source.column>e.source.column)return oe(e,t)-t.y0}return e.circular&&!t.circular?"top"==e.circularLinkType?-1:1:t.circular&&!e.circular?"top"==t.circularLinkType?1:-1:e.circular&&t.circular?e.circularLinkType===t.circularLinkType&&"top"==e.circularLinkType?e.source.column===t.source.column?e.source.y1-t.source.y1:e.source.column-t.source.column:e.circularLinkType===t.circularLinkType&&"bottom"==e.circularLinkType?e.source.column===t.source.column?e.source.y1-t.source.y1:t.source.column-e.source.column:"top"==e.circularLinkType?-1:1:void 0});var i=e.y0;n.forEach(function(e){e.y1=i+e.width/2,i+=e.width}),n.forEach(function(t,r){if("bottom"==t.circularLinkType){for(var i=r+1,a=0;o>i;i++)a+=n[i].width;t.y1=e.y1-a-t.width/2}})})}(h,c),function(e){var t=e.nodes,r=e.links,n=!1,o=!1;if(r.forEach(function(e){"top"==e.circularLinkType?n=!0:"bottom"==e.circularLinkType&&(o=!0)}),0==n||0==o){var i=f(t,function(e){return e.y0}),a=g(t,function(e){return e.y1}),c=(e.y1-e.y0)/(a-i);function s(t){return(t-i)/(a-i)*(e.y1-e.y0)+e.y0}1>c?(t.forEach(function(e){e.y0=s(e.y0),e.y1=s(e.y1)}),r.forEach(function(e){e.y0=s(e.y0),e.y1=s(e.y1),e.width=e.width*c})):t.forEach(function(e){var t=e.y1-e.y0,r=s(e.y0)-e.y0;e.y0=s(e.y0),e.y1=e.y0+t,e.sourceLinks.forEach(function(e){e.y0=e.y0+r}),e.targetLinks.forEach(function(e){e.y1=e.y1+r})})}}(h),Ae(h,c,d,10,8)}(b),b}return b.update=function(e){return _e(e),Ae(e,c,d,10,8),e},b.nodeWidth=function(e){return arguments.length?(o=+e,b):o},b.nodePadding=function(e){return arguments.length?(i=+e,b):i},b.nodePaddingRatio=function(e){return arguments.length?(a=+e,b):a},b.nodes=function(e){return arguments.length?(h="function"==typeof e?e:Se(e),b):h},b.links=function(e){return arguments.length?(v="function"==typeof e?e:Se(e),b):v},b.nodeId=function(e){return arguments.length?(c="function"==typeof e?e:Se(e),b):c},b.nodeAlign=function(e){return arguments.length?(s="function"==typeof e?e:Se(e),b):s},b.nodeSort=function(e){return arguments.length?(l=e,b):l},b.iterations=function(e){return arguments.length?(u=+e,b):u},b.circularLinkGap=function(e){return arguments.length?(d=+e,b):d},b.extent=function(o){return arguments.length?(e=+o[0][0],t=+o[0][1],r=+o[1][0],n=+o[1][1],b):[[e,t],[r,n]]},b.size=function(o){return arguments.length?(e=t=0,r=+o[0],n=+o[1],b):[r-e,n-t]},b}const Me=e=>{let t,r,n,o,i,a,c,s,l;return"down"===e.direction?(t=e.y0-e.sankeyWidth/2,r=e.y1-e.sankeyWidth/2,n=e.y1+e.sankeyWidth/2,o=e.y0+e.sankeyWidth/2,i=e.source.y1,a=e.target.y0,c=h(i,a),s=c(.5),l=c(.5),`M${t},${i}C${t},${s} ${r},${l} ${r},${a}L${n},${a}C${n},${l} ${o},${s} ${o},${i}Z`):(t=e.source.x1,r=e.target.x0,c=h(t,r),n=c(.5),o=c(.5),i=e.y0-e.sankeyWidth/2,a=e.y1-e.sankeyWidth/2,s=e.y1+e.sankeyWidth/2,l=e.y0+e.sankeyWidth/2,`M${t},${i}C${n},${i} ${o},${a} ${r},${a}L${r},${s}C${o},${s} ${n},${l} ${t},${l}Z`)};function je(e){var t;const r=e.sankeyWidth/2,n=(null!==(t=e._circularWidth)&&void 0!==t?t:e.sankeyWidth)/2,o=e.circularPathData;if(!o)return null;if("down"===e.direction)return null;if(e._circularStub){const t=o.sourceX,n=o.sourceY,i=o.targetX,a=o.targetY;if("object"!=typeof e.source||!e.source||"object"!=typeof e.target||!e.target)return null;const c=Math.max(15,Math.min(40,.33*(o.rightFullExtent-t))),s=Math.max(15,Math.min(40,.33*(i-o.leftFullExtent)));return`M${t},${n-r}L${t+c},${n-r}L${t+c},${n+r}L${t},${n+r}ZM${i},${a-r}L${i-s},${a-r}L${i-s},${a+r}L${i},${a+r}Z`}const i=o.sourceX,a=o.sourceY,c=o.targetX,s=o.targetY,l=o.rightFullExtent,u=o.leftFullExtent,d=o.verticalFullExtent,h="bottom"===e.circularLinkType?1:-1,f=Math.max(4,Math.min(n,15));return`M${i},${a-h*r}L${l},${a-h*r}L${l+n},${a-h*r+h*f}L${l+n},${d+h*n-h*f}L${l+n-f},${d+h*n}L${u-n+f},${d+h*n}L${u-n},${d+h*n-h*f}L${u-n},${s-h*r+h*f}L${u-n+f},${s-h*r}L${c},${s-h*r}L${c},${s+h*r}L${u+n},${s+h*r}L${u+n},${d-h*n}L${l-n},${d-h*n}L${l-n},${a+h*r}L${i},${a+h*r}Z`}const Ce={left:function(e){return e.depth},right:function(e,t){return t-1-e.height},center:function(e){return e.targetLinks.length?e.depth:e.sourceLinks.length?Math.min.apply(Math,e.sourceLinks.map(he))-1:0},justify:fe},Re={supportsStreaming:!0,hierarchical:!1,computeLayout(e,t,r,n){var o,i,a,c,s,l,u;if(0===e.length)return;const d="vertical"===r.orientation?"down":"right",h=r.nodeAlign||"justify",f=null!==(o=r.nodeWidth)&&void 0!==o?o:15,y=null!==(i=r.nodePaddingRatio)&&void 0!==i?i:.05,g=null!==(a=r.iterations)&&void 0!==a?a:100,p=e.map(e=>Object.assign({},e)),v=t.map(e=>Object.assign(Object.assign({},e),{source:"string"==typeof e.source?e.source:e.source.id,target:"string"==typeof e.target?e.target:e.target.id,value:Math.sqrt(Math.max(1,e.value||1))}));let m;m="down"===d?[[0,0],[n[1],n[0]]]:[[0,0],[n[0],n[1]]];const b=Ie().extent(m).links(v).nodes(p).nodeAlign(Ce[h]||fe).nodeId(e=>e.id).nodeWidth(f).iterations(g);b.nodePaddingRatio&&b.nodePaddingRatio(y),b();{let e=1/0,t=-1/0,r=1/0,o=-1/0;for(const n of p)e>n.x0&&(e=n.x0),n.x1>t&&(t=n.x1),r>n.y0&&(r=n.y0),n.y1>o&&(o=n.y1);for(const n of v){if(!n.circular||!n.circularPathData)continue;const i=n.circularPathData,a=(null!==(s=null!==(c=n._circularWidth)&&void 0!==c?c:n.width)&&void 0!==s?s:0)/2;e>i.leftFullExtent-a&&(e=i.leftFullExtent-a),i.rightFullExtent+a>t&&(t=i.rightFullExtent+a),r>i.verticalFullExtent-a&&(r=i.verticalFullExtent-a),i.verticalFullExtent+a>o&&(o=i.verticalFullExtent+a)}const i=t-e,a=o-r,u=n[0],d=n[1];if(i>0&&a>0&&(0>e||0>r||t>u||o>d)){const t=Math.min(u/i,d/a),n=-e*t+(u-i*t)/2,o=-r*t+(d-a*t)/2;for(const e of p)e.x0=e.x0*t+n,e.x1=e.x1*t+n,e.y0=e.y0*t+o,e.y1=e.y1*t+o;for(const e of v)if(e.y0=e.y0*t+o,e.y1=e.y1*t+o,e.width=(null!==(l=e.width)&&void 0!==l?l:0)*t,e._circularWidth&&(e._circularWidth*=t),e.circular&&e.circularPathData){const r=e.circularPathData;r.sourceX=r.sourceX*t+n,r.targetX=r.targetX*t+n,r.sourceY=r.sourceY*t+o,r.targetY=r.targetY*t+o,r.rightFullExtent=r.rightFullExtent*t+n,r.leftFullExtent=r.leftFullExtent*t+n,r.verticalFullExtent=r.verticalFullExtent*t+o,r.rightInnerExtent=r.rightInnerExtent*t+n,r.leftInnerExtent=r.leftInnerExtent*t+n,r.verticalRightInnerExtent=r.verticalRightInnerExtent*t+o,r.verticalLeftInnerExtent=r.verticalLeftInnerExtent*t+o,r.rightSmallArcRadius*=t,r.rightLargeArcRadius*=t,r.leftSmallArcRadius*=t,r.leftLargeArcRadius*=t,r.sourceWidth*=t,r.rightNodeBuffer*=t,r.leftNodeBuffer*=t,r.arcRadius*=t}}}const x=new Map;for(const t of e)x.set(t.id,t);for(const e of p){const t=x.get(e.id);t&&(t.x0=e.x0,t.x1=e.x1,t.y0=e.y0,t.y1=e.y1,t.value=e.value,t.depth=e.depth,t.sourceLinks=e.sourceLinks,t.targetLinks=e.targetLinks,t.width=e.x1-e.x0,t.height=e.y1-e.y0,t.x=e.x0+(e.x1-e.x0)/2,t.y=e.y0+(e.y1-e.y0)/2)}const k=new Map;for(const e of t)k.set(`${"string"==typeof e.source?e.source:e.source.id}\0${"string"==typeof e.target?e.target:e.target.id}`,e);for(const e of v){const t=e.source,r=e.target,n="object"==typeof t&&null!==t?t.id:t+"",o="object"==typeof r&&null!==r?r.id:r+"",i=k.get(`${n}\0${o}`);if(i){i.y0=e.y0,i.y1=e.y1,i.sankeyWidth=null!==(u=e.width)&&void 0!==u?u:0,i.circular=!!e.circular,i.circularPathData=e.circularPathData,i._circularWidth=e._circularWidth,i._circularStub=e._circularStub,i.path=e.path,i.circularLinkType=e.circularLinkType,i.direction=d;const t=x.get(n),r=x.get(o);t&&(i.source=t),r&&(i.target=r)}}},buildScene(e,t,r,n){var o,i,a,c;const s="vertical"===r.orientation?"down":"right",l=r.nodeStyle,u=r.edgeStyle,d=null!==(o=r.edgeOpacity)&&void 0!==o?o:.5,h=r.edgeColorBy||"source",f=Array.isArray(r.colorScheme)?r.colorScheme:b,y=new Map;e.forEach((e,t)=>{y.set(e.id,f[t%f.length])});const g=[],p=[],v=[];for(const t of e){const e=t.x1-t.x0,r=t.y1-t.y0;if(0>=e||0>=r)continue;const n=l?l(t):{},o={fill:n.fill||y.get(t.id)||"#4d430c",stroke:n.stroke,strokeWidth:n.strokeWidth,opacity:n.opacity};g.push({type:"rect",x:t.x0,y:t.y0,w:e,h:r,style:o,datum:t,id:t.id,label:t.id})}const m=[...t].sort((e,t)=>(t.sankeyWidth||0)-(e.sankeyWidth||0));for(const e of m){if(!e.sankeyWidth||0>=e.sankeyWidth)continue;const t="object"==typeof e.source?e.source:null,r="object"==typeof e.target?e.target:null;if(!t||!r)continue;let n="#999";u?n=u(e).fill||n:"target"===h&&r?n=y.get(r.id)||n:t&&(n=y.get(t.id)||n);const o=u?u(e):{};if(e._circularStub&&e.circular&&e.circularPathData){const t=e.circularPathData,r=e.sankeyWidth/2,c=Math.max(15,Math.min(40,.33*(t.rightFullExtent-t.sourceX))),s=Math.max(15,Math.min(40,.33*(t.targetX-t.leftFullExtent))),l=o.fill||n;p.push({type:"bezier",pathD:`M${t.sourceX},${t.sourceY-r}L${t.sourceX+c},${t.sourceY-r}L${t.sourceX+c},${t.sourceY+r}L${t.sourceX},${t.sourceY+r}Z`,style:{fill:l,fillOpacity:null!==(i=o.fillOpacity)&&void 0!==i?i:d,stroke:"none",opacity:o.opacity},datum:e,_gradient:{direction:"right",from:1,to:0,x0:t.sourceX,x1:t.sourceX+c}}),p.push({type:"bezier",pathD:`M${t.targetX},${t.targetY-r}L${t.targetX-s},${t.targetY-r}L${t.targetX-s},${t.targetY+r}L${t.targetX},${t.targetY+r}Z`,style:{fill:l,fillOpacity:null!==(a=o.fillOpacity)&&void 0!==a?a:d,stroke:"none",opacity:o.opacity},datum:e,_gradient:{direction:"left",from:0,to:1,x0:t.targetX-s,x1:t.targetX}});continue}let s;if(s=e.circular&&e.circularPathData?je(e):Me(e),!s)continue;const l={fill:o.fill||n,fillOpacity:null!==(c=o.fillOpacity)&&void 0!==c?c:d,stroke:o.stroke||"none",strokeWidth:o.strokeWidth,opacity:o.opacity};p.push({type:"bezier",pathD:s,bezierCache:e.bezier,style:l,datum:e})}if(!1!==r.showLabels){const t=(x=r.nodeLabel)?"function"==typeof x?x:e=>e[x]||e.id:null;for(const r of e){const e=r.x1-r.x0,o=r.y1-r.y0;if(0>=e||0>=o)continue;const i=t?t(r):r.id;if(!i)continue;let a,c,l;"down"===s?(a=r.x0+e/2,c=r.y1+14,l="middle"):(n[0]/2>r.x0+e/2?(a=r.x0-6,l="end"):(a=r.x1+6,l="start"),c=r.y0+o/2),v.push({x:a,y:c,text:i+"",anchor:l,baseline:"middle",fontSize:11})}}var x;return{sceneNodes:g,sceneEdges:p,labels:v}}},Be={supportsStreaming:!1,hierarchical:!1,computeLayout(e,t,r,n){var o,i;if(0===e.length)return;const a=null!==(o=r.iterations)&&void 0!==o?o:Math.max(50,Math.min(300,Math.floor(300-2*(e.length-30)))),c=null!==(i=r.forceStrength)&&void 0!==i?i:.1,s=n[0]/2,l=n[1]/2;for(let t=0;e.length>t;t++){const r=e[t];if(null==r.x||null==r.y||0===r.x&&0===r.y){const e=10*Math.sqrt(t+.5),n=2.399963229728653*t;r.x=s+e*Math.cos(n),r.y=l+e*Math.sin(n)}}const u=Fe(r.nodeSize,r.nodeSizeRange,e),d=T().strength(e=>Math.min(2.5,e.weight?e.weight*c:c)).id(e=>e.id),h=n[1]/n[0],f=O().force("charge",N().strength(e=>-25*(e=>u(e))(e))).force("x",W(n[0]/2).strength(.1*h)).force("y",$(n[1]/2).strength(.1));if(f.nodes(e),t.length>0){const e=t.map(e=>Object.assign(Object.assign({},e),{source:"string"==typeof e.source?e.source:e.source.id,target:"string"==typeof e.target?e.target:e.target.id}));f.force("link",d),f.force("link").links(e)}.1>f.alpha()&&f.alpha(1),f.stop();for(let e=0;a>e;++e)f.tick();const y=new Map;for(const t of e)y.set(t.id,t);for(const e of t){if("string"==typeof e.source){const t=y.get(e.source);t&&(e.source=t)}if("string"==typeof e.target){const t=y.get(e.target);t&&(e.target=t)}}},buildScene(e,t,r,n){var o,i,a;const c=r.nodeStyle,s=r.edgeStyle,l=Fe(r.nodeSize,r.nodeSizeRange,e),u=Array.isArray(r.colorScheme)?r.colorScheme:b,d=new Map;e.forEach((e,t)=>{d.set(e.id,u[t%u.length])});const h=[],f=[],y=[];for(const t of e){if(null==t.x||null==t.y)continue;const e=l(t),r=c?c(t):{},n={fill:r.fill||d.get(t.id)||"#007bff",stroke:r.stroke||"#fff",strokeWidth:null!==(o=r.strokeWidth)&&void 0!==o?o:2,opacity:r.opacity};h.push({type:"circle",cx:t.x,cy:t.y,r:e,style:n,datum:t,id:t.id,label:t.id})}const g=new Map;for(const t of e)g.set(t.id,t);for(const e of t){const t="object"==typeof e.source?e.source:g.get(e.source),r="object"==typeof e.target?e.target:g.get(e.target);if(!t||!r)continue;if(null==t.x||null==t.y)continue;if(null==r.x||null==r.y)continue;const n=s?s(e):{},o={stroke:n.stroke||"#999",strokeWidth:null!==(i=n.strokeWidth)&&void 0!==i?i:1,opacity:null!==(a=n.opacity)&&void 0!==a?a:.6};f.push({type:"line",x1:t.x,y1:t.y,x2:r.x,y2:r.y,style:o,datum:e})}if(!1!==r.showLabels){const t=(p=r.nodeLabel)?"function"==typeof p?p:e=>e[p]||e.id:null;for(const r of e){if(null==r.x||null==r.y)continue;const e=t?t(r):r.id;if(!e)continue;const n=l(r);y.push({x:r.x,y:r.y-n-4,text:e+"",anchor:"middle",baseline:"auto",fontSize:11})}}var p;return{sceneNodes:h,sceneEdges:f,labels:y}}};function Fe(e,t,r){var n,o;if(null==e)return()=>8;if("number"==typeof e)return()=>e;if("function"==typeof e)return t=>e(t)||8;const i=t||[5,20],a=r.map(t=>{var r;return null===(r=t.data)||void 0===r?void 0:r[e]}).filter(e=>null!=e&&"number"==typeof e);if(0===a.length)return()=>i[0];const c=null!==(n=f(a))&&void 0!==n?n:0,s=null!==(o=g(a))&&void 0!==o?o:1;if(c===s)return()=>(i[0]+i[1])/2;const l=_().domain([c,s]).range(i).clamp(!0);return t=>{var r;const n=null===(r=t.data)||void 0===r?void 0:r[e];return null==n||"number"!=typeof n?i[0]:l(n)}}const ze=b,He={supportsStreaming:!1,hierarchical:!1,computeLayout(e,t,r,n){if(0===e.length)return;const{padAngle:o=.01,groupWidth:i=20,sortGroups:a}=r,c=Math.min(n[0],n[1])/2,s=c-i,l=n[0]/2,u=n[1]/2,d=(h=r.valueAccessor)?"function"==typeof h?h:e=>{var t;return null!==(t=e[h])&&void 0!==t?t:1}:e=>{var t;return null!==(t=e.value)&&void 0!==t?t:1};var h;const f=new Map;for(let t=0;e.length>t;t++)f.set(e[t].id,t);const y=e.length,g=Array.from({length:y},()=>Array.from({length:y},()=>0));for(const e of t){const t="string"==typeof e.target?e.target:e.target.id,r=f.get("string"==typeof e.source?e.source:e.source.id),n=f.get(t);if(void 0===r||void 0===n)continue;const o=d(e);g[r][n]=o}const p=j().padAngle(o);a&&p.sortGroups(a);const v=p(g),m=v.groups,b=C().innerRadius(s).outerRadius(c);for(const t of m){const r=e[t.index],n=b.centroid(t);r.x=n[0]+l,r.y=n[1]+u,r.arcData={startAngle:t.startAngle,endAngle:t.endAngle}}const x=new Map;for(const t of e)x.set(t.id,t);for(const e of t){const t="string"==typeof e.target?e.target:e.target.id,r=x.get("string"==typeof e.source?e.source:e.source.id),n=x.get(t);r&&(e.source=r),n&&(e.target=n)}const k=new Map;for(const e of t)k.set(`${"string"==typeof e.source?e.source:e.source.id}\0${"string"==typeof e.target?e.target:e.target.id}`,e);for(const t of v){const r=e[t.source.index].id,n=e[t.target.index].id,o=k.get(`${r}\0${n}`)||k.get(`${n}\0${r}`);o&&(o.chordData=t)}},buildScene(e,t,r,n){var o,i;const{groupWidth:a=20,edgeOpacity:c=.5}=r,s=Math.min(n[0],n[1])/2,l=s-a,u=n[0]/2,d=n[1]/2,h=r.nodeStyle,f=r.edgeStyle,y=r.edgeColorBy||"source",g=Array.isArray(r.colorScheme)?r.colorScheme:ze,p=new Map;e.forEach((e,t)=>{p.set(e.id,g[t%g.length])});const v=M().radius(l),m=[],b=[],x=[];for(let t=0;e.length>t;t++){const r=e[t],n=r.arcData;if(!n)continue;let i;i=h?h(r).fill||p.get(r.id)||g[t%g.length]:p.get(r.id)||g[t%g.length];const a=h?h(r):{},c={fill:i,stroke:a.stroke||"black",strokeWidth:null!==(o=a.strokeWidth)&&void 0!==o?o:1,opacity:a.opacity};m.push({type:"arc",cx:u,cy:d,innerR:l,outerR:s,startAngle:n.startAngle-Math.PI/2,endAngle:n.endAngle-Math.PI/2,style:c,datum:r,id:r.id,label:r.id})}for(const e of t){const t=e.chordData;if(!t)continue;const r=v(t);if(!r)continue;const n=Ye(r,u,d);let o="#999";if(f)o=f(e).fill||o;else{const t="object"==typeof e.source?e.source:null,r="object"==typeof e.target?e.target:null;"target"===y&&r?o=p.get(r.id)||o:t&&(o=p.get(t.id)||o)}const a=f?f(e):{},s={fill:o,fillOpacity:null!==(i=a.fillOpacity)&&void 0!==i?i:c,stroke:a.stroke||"none",strokeWidth:a.strokeWidth,opacity:a.opacity};b.push({type:"ribbon",pathD:n,style:s,datum:e})}if(!1!==r.showLabels){const t=(k=r.nodeLabel)?"function"==typeof k?k:e=>e[k]||e.id:null,n=s+12;for(const r of e){const e=r.arcData;if(!e)continue;const o=t?t(r):r.id;if(!o)continue;const i=(e.startAngle+e.endAngle)/2,a=i-Math.PI/2;x.push({x:u+Math.cos(a)*n,y:d+Math.sin(a)*n,text:o+"",anchor:i>Math.PI?"end":"start",baseline:"middle",fontSize:11})}}var k;return{sceneNodes:m,sceneEdges:b,labels:x}}};function Ye(e,t,r){const n=e.match(/[a-zA-Z]|[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?/g);if(!n)return e;const o=[];let i=0;for(;n.length>i;){const e=n[i];if("M"===e||"L"===e)for(o.push(e),i++;n.length>i&&!isNaN(Number(n[i]));)o.push(Number(n[i])+t+""),i++,n.length>i&&!isNaN(Number(n[i]))&&(o.push(Number(n[i])+r+""),i++);else if("C"===e)for(o.push(e),i++;n.length>i&&!isNaN(Number(n[i]));)for(let e=0;3>e&&n.length>i&&!isNaN(Number(n[i]));e++)o.push(Number(n[i])+t+""),i++,n.length>i&&!isNaN(Number(n[i]))&&(o.push(Number(n[i])+r+""),i++);else if("Q"===e)for(o.push(e),i++;n.length>i&&!isNaN(Number(n[i]));)for(let e=0;2>e&&n.length>i&&!isNaN(Number(n[i]));e++)o.push(Number(n[i])+t+""),i++,n.length>i&&!isNaN(Number(n[i]))&&(o.push(Number(n[i])+r+""),i++);else if("A"===e)for(o.push(e),i++;n.length>i&&!isNaN(Number(n[i]));)o.push(n[i++]),n.length>i&&o.push(n[i++]),n.length>i&&o.push(n[i++]),n.length>i&&o.push(n[i++]),n.length>i&&o.push(n[i++]),n.length>i&&(o.push(Number(n[i])+t+""),i++),n.length>i&&(o.push(Number(n[i])+r+""),i++);else"Z"===e||"z"===e?(o.push(e),i++):(o.push(n[i]),i++)}return o.join(" ")}const Xe={supportsStreaming:!1,hierarchical:!0,computeLayout(e,t,r,n){var o;const i=r.__hierarchyRoot;if(!i)return;const a=r.chartType,c=(s=r.childrenAccessor)?"function"==typeof s?s:e=>e[s]:void 0;var s;const l=r.hierarchySum||(e=>{var t;return null!==(t=e.value)&&void 0!==t?t:0}),u=R(i,c);u.sum(l),u.sort((e,t)=>{var r,n;return(null!==(r=t.value)&&void 0!==r?r:0)-(null!==(n=e.value)&&void 0!==n?n:0)});const[d,h]=n;switch(a){case"tree":!function(e,t,r,n){const o=t.treeOrientation||"vertical",i=X();i.size("horizontal"===o?[n,r]:"radial"===o?[2*Math.PI,Math.min(r,n)/2*.8]:[r,n]),i(e)}(u,r,d,h);break;case"cluster":!function(e,t,r,n){const o=t.treeOrientation||"vertical",i=Y();i.size("horizontal"===o?[n,r]:"radial"===o?[2*Math.PI,Math.min(r,n)/2*.8]:[r,n]),i(e)}(u,r,d,h);break;case"treemap":!function(e,t,r,n){var o,i;const a=null!==(o=t.padding)&&void 0!==o?o:4,c=null!==(i=t.paddingTop)&&void 0!==i?i:0,s=z().size([r,n]).tile(H).padding(a);c>0&&s.paddingTop(c),s(e)}(u,r,d,h);break;case"circlepack":!function(e,t,r,n){var o;const i=null!==(o=t.padding)&&void 0!==o?o:4;F().size([r,n]).padding(i)(e)}(u,r,d,h);break;case"partition":!function(e,t,r,n){var o;B().size([r,n]).padding(null!==(o=t.padding)&&void 0!==o?o:1)(e)}(u,r,d,h)}const f=u.descendants();e.length=0,t.length=0;const y=new Map;for(let t=0;f.length>t;t++){const n=f[t],i={id:Ke(n,r,t),x:0,y:0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:null!==(o=n.value)&&void 0!==o?o:0,depth:n.depth,data:n.data,createdByFrame:!0};"tree"===a||"cluster"===a?Ge(i,n,r):"treemap"===a||"partition"===a?qe(i,n):"circlepack"===a&&Ve(i,n),i.__hierarchyNode=n,e.push(i),y.set(n,i)}if("tree"===a||"cluster"===a)for(const e of f)if(e.parent){const r=y.get(e.parent),n=y.get(e);r&&n&&t.push({source:r,target:n,value:1,y0:0,y1:0,sankeyWidth:0,data:{depth:e.depth}})}},buildScene(e,t,r,n){const o=r.nodeStyle||(()=>({})),i=r.edgeStyle||(()=>({}));switch(r.chartType){case"tree":case"cluster":return function(e,t,r,n,o,i){var a,c,s,l,u;const d=[],h=[],f=[],y=r.treeOrientation||"vertical",g="radial"===y,p=n[0]/2,v=n[1]/2,m="number"==typeof(x=r.nodeSize)?x:5,b=["#e8d5b7","#b8d4e3","#d4e3b8","#e3c4d4","#d4d4e3","#e3d4b8","#b8e3d4","#e3b8b8"];var x;for(const t of e){let e=t.x,n=t.y;g&&(e+=p,n+=v);const i=o(t);let c=i.fill||"#4d430c";r.colorByDepth&&void 0!==t.depth&&(c=b[t.depth%b.length]);const s={fill:c,stroke:i.stroke||"#fff",strokeWidth:null!==(a=i.strokeWidth)&&void 0!==a?a:1,opacity:i.opacity};d.push({type:"circle",cx:e,cy:n,r:m,style:s,datum:t,id:t.id,label:t.id,depth:t.depth})}const k=null!==(c=r.edgeOpacity)&&void 0!==c?c:.5;for(const e of t){const t="object"==typeof e.source?e.source:null,r="object"==typeof e.target?e.target:null;if(!t||!r)continue;let n=t.x,o=t.y,a=r.x,c=r.y;g&&(n+=p,o+=v,a+=p,c+=v);const u=Ze(n,o,a,c,y),d=i(e),f={fill:"none",stroke:d.stroke||"#999",strokeWidth:null!==(s=d.strokeWidth)&&void 0!==s?s:1.5,opacity:null!==(l=d.opacity)&&void 0!==l?l:k};h.push({type:"curved",pathD:u,style:f,datum:e})}if(!1!==r.showLabels){const t=Qe(r.nodeLabel);for(const r of e){const e=t?t(r):r.id;if(!e)continue;let n,o,i,a=r.x,c=r.y;if(g&&(a+=p,c+=v),g){const e=a-p,t=c-v,r=Math.sqrt(e*e+t*t);r>0?(n=a+e/r*10,o=c+t/r*10,i=0>e?"end":"start"):(n=a,o=c-12,i="middle")}else"horizontal"===y?((null===(u=r.data)||void 0===u?void 0:u.children)&&0!==r.data.children.length?(n=a-m-6,i="end"):(n=a+m+6,i="start"),o=c):(n=a,o=c+m+14,i="middle");f.push({x:n,y:o,text:e+"",anchor:i,baseline:"middle",fontSize:11})}}return{sceneNodes:d,sceneEdges:h,labels:f}}(e,t,r,n,o,i);case"treemap":case"partition":return function(e,t,r,n){var o,i;const a=[],c=[],s=["#e8d5b7","#b8d4e3","#d4e3b8","#e3c4d4","#d4d4e3","#e3d4b8","#b8e3d4","#e3b8b8"];for(const r of e){const e=r.x1-r.x0,i=r.y1-r.y0;if(0>=e||0>=i)continue;const c=n(r);let l=c.fill||"#4d430c";t.colorByDepth&&void 0!==r.depth&&(l=s[r.depth%s.length]);const u={fill:l,stroke:c.stroke||"#fff",strokeWidth:null!==(o=c.strokeWidth)&&void 0!==o?o:1,opacity:c.opacity};a.push({type:"rect",x:r.x0,y:r.y0,w:e,h:i,style:u,datum:r,id:r.id,label:r.id,depth:r.depth})}if(!1!==t.showLabels){const r=Qe(t.nodeLabel);for(const n of e){const e=n.x1-n.x0,o=n.y1-n.y0;if(0>=e||0>=o)continue;if((null===(i=n.data)||void 0===i?void 0:i.children)&&n.data.children.length>0&&"partition"!==t.chartType)continue;const a=r?r(n):n.id;a&&(30>e||16>o||c.push({x:n.x0+e/2,y:n.y0+o/2,text:a+"",anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,Math.min(e,o)/6))}))}}return{sceneNodes:a,sceneEdges:[],labels:c}}(e,r,0,o);case"circlepack":return function(e,t,r,n){var o,i,a,c,s;const l=[],u=[],d=["#e8d5b7","#b8d4e3","#d4e3b8","#e3c4d4","#d4d4e3","#e3d4b8","#b8e3d4","#e3b8b8"];for(const r of e){const e=null!==(o=r.__radius)&&void 0!==o?o:5;if(0>=e)continue;const c=n(r);let s=c.fill||"#4d430c";t.colorByDepth&&void 0!==r.depth&&(s=d[r.depth%d.length]);const u={fill:s,stroke:c.stroke||"#fff",strokeWidth:null!==(i=c.strokeWidth)&&void 0!==i?i:1,opacity:null!==(a=c.opacity)&&void 0!==a?a:.7};l.push({type:"circle",cx:r.x,cy:r.y,r:e,style:u,datum:r,id:r.id,label:r.id,depth:r.depth})}if(!1!==t.showLabels){const r=Qe(t.nodeLabel);for(const t of e){const e=null!==(c=t.__radius)&&void 0!==c?c:5,n=r?r(t):t.id;if(!n)continue;if(15>e)continue;const o=!((null===(s=t.data)||void 0===s?void 0:s.children)&&t.data.children.length>0);u.push({x:t.x,y:o?t.y:t.y-e+14,text:n+"",anchor:"middle",baseline:o?"middle":"hanging",fontSize:Math.min(11,Math.max(8,e/3)),fill:o?void 0:"#000",stroke:o?void 0:"#fff",strokeWidth:o?void 0:3,paintOrder:o?void 0:"stroke"})}}return{sceneNodes:l,sceneEdges:[],labels:u}}(e,r,0,o);default:return{sceneNodes:[],sceneEdges:[],labels:[]}}}};function Ge(e,t,r){const n=r.treeOrientation||"vertical";if("radial"===n){const r=t.x,n=t.y;e.x=n*Math.cos(r-Math.PI/2),e.y=n*Math.sin(r-Math.PI/2)}else"horizontal"===n?(e.x=t.y,e.y=t.x):(e.x=t.x,e.y=t.y);e.x0=e.x-5,e.x1=e.x+5,e.y0=e.y-5,e.y1=e.y+5,e.width=10,e.height=10}function qe(e,t){e.x0=t.x0,e.x1=t.x1,e.y0=t.y0,e.y1=t.y1,e.x=(t.x0+t.x1)/2,e.y=(t.y0+t.y1)/2,e.width=t.x1-t.x0,e.height=t.y1-t.y0}function Ve(e,t){var r;const n=null!==(r=t.r)&&void 0!==r?r:0;e.x=t.x,e.y=t.y,e.x0=t.x-n,e.x1=t.x+n,e.y0=t.y-n,e.y1=t.y+n,e.width=2*n,e.height=2*n,e.__radius=n}function Ze(e,t,r,n,o){if("horizontal"===o){const o=(e+r)/2;return`M ${e},${t} C ${o},${t} ${o},${n} ${r},${n}`}if("radial"===o){const o=(e+r)/2;return`M ${e},${t} Q ${o},${t} ${o},${(t+n)/2} T ${r},${n}`}{const o=(t+n)/2;return`M ${e},${t} C ${e},${o} ${r},${o} ${r},${n}`}}function Ke(e,t,r){const n=t.nodeIDAccessor;return"function"==typeof n?n(e.data)+"":"string"==typeof n&&void 0!==e.data[n]?e.data[n]+"":void 0!==e.data.name?e.data.name+"":void 0!==e.data.id?e.data.id+"":"node-"+r}function Qe(e){return e?"function"==typeof e?e:t=>{var r;return(null===(r=t.data)||void 0===r?void 0:r[e])||t[e]||t.id}:null}const Je={sankey:Re,force:Be,chord:He,tree:Xe,cluster:Xe,treemap:Xe,circlepack:Xe,partition:Xe};function Ue(e){return Je[e]}class et{constructor(e){this.nodes=new Map,this.edges=new Map,this.tension=0,this.layoutVersion=0,this.sceneNodes=[],this.sceneEdges=[],this.labels=[],this.particlePool=null,this.transition=null,this.lastIngestTime=0,this.nodeTimestamps=new Map,this.edgeTimestamps=new Map,this.addedNodes=new Set,this.removedNodes=new Set,this.addedEdges=new Set,this.removedEdges=new Set,this.lastTopologyChangeTime=0,this.previousNodeIds=new Set,this.previousEdgeKeys=new Set,this.config=e,this.tensionConfig=Object.assign(Object.assign({},G),e.tensionConfig),"sankey"===e.chartType&&e.showParticles&&(this.particlePool=new V(2e3))}updateConfig(e){this.config=e,this.tensionConfig=Object.assign(Object.assign({},G),e.tensionConfig),"sankey"===e.chartType&&e.showParticles&&!this.particlePool&&(this.particlePool=new V(2e3))}ingestHierarchy(e,t){this.nodes.clear(),this.edges.clear(),this.config.__hierarchyRoot=e,this.runLayout(t)}ingestBounded(e,t,r){const{nodeIDAccessor:n="id",sourceAccessor:o="source",targetAccessor:i="target",valueAccessor:a="value"}=this.config,c="function"==typeof n?n:e=>e[n],s="function"==typeof o?o:e=>e[o],l="function"==typeof i?i:e=>e[i],u="function"==typeof a?a:e=>{var t;return null!==(t=e[a])&&void 0!==t?t:1};this.nodes.clear(),this.edges.clear();for(const t of e){const e=c(t)+"";this.nodes.set(e,Object.assign(Object.assign({},tt(e)),{data:t}))}for(const e of t){const t=s(e)+"",r=l(e)+"",n=Number(u(e))||1;this.nodes.has(t)||this.nodes.set(t,Object.assign(Object.assign({},tt(t)),{data:e})),this.nodes.has(r)||this.nodes.set(r,Object.assign(Object.assign({},tt(r)),{data:e})),this.edges.set(`${t}\0${r}`,{source:t,target:r,value:n,y0:0,y1:0,sankeyWidth:0,data:e})}this.runLayout(r)}edgeKey(e,t){return`${e}\0${t}`}ingestEdge(e){const{source:t,target:r,value:n}=e,o=0===this.nodes.size;let i=!1;const a="undefined"!=typeof performance?performance.now():Date.now();this.lastIngestTime=a,this.nodes.has(t)||(this.nodes.set(t,tt(t)),this.nodeTimestamps.set(t,a),this.tension+=this.tensionConfig.newNode,i=!0),this.nodes.has(r)||(this.nodes.set(r,tt(r)),this.nodeTimestamps.set(r,a),this.tension+=this.tensionConfig.newNode,i=!0);const c=this.edgeKey(t,r),s=this.edges.get(c);return s?(s.value+=n,this.edgeTimestamps.set(c,a),this.tension+=this.tensionConfig.weightChange):(this.edges.set(c,{source:t,target:r,value:n,y0:0,y1:0,sankeyWidth:0}),this.edgeTimestamps.set(c,a),this.tension+=this.tensionConfig.newEdge,i=!0),o||i||this.tension>=this.tensionConfig.threshold}runLayout(e){const t=Ue(this.config.chartType);if(!t)return;let r=Array.from(this.nodes.values()),n=Array.from(this.edges.values());if(0===r.length&&!t.hierarchical)return;if(this.prepareForRelayout(),t.computeLayout(r,n,this.config,e),t.hierarchical&&r.length>0){this.nodes.clear(),this.edges.clear();for(const e of r)this.nodes.set(e.id,e);for(const e of n)this.edges.set(`${"string"==typeof e.source?e.source:e.source.id}\0${"string"==typeof e.target?e.target:e.target.id}`,e)}this.finalizeLayout(),this.saveTargetPositions(),r.some(e=>void 0!==e._prevX0&&(0!==e._prevX0||0!==e._prevX1||0!==e._prevY0||0!==e._prevY1))&&this.tensionConfig.transitionDuration>0&&(this.restorePreviousPositions(),this.transition={startTime:performance.now(),duration:this.tensionConfig.transitionDuration});const o=new Set(this.nodes.keys()),i=new Set(this.edges.keys());this.addedNodes=new Set,this.removedNodes=new Set,this.addedEdges=new Set,this.removedEdges=new Set;for(const e of o)this.previousNodeIds.has(e)||this.addedNodes.add(e);for(const e of this.previousNodeIds)o.has(e)||this.removedNodes.add(e);for(const e of i)this.previousEdgeKeys.has(e)||this.addedEdges.add(e);for(const e of this.previousEdgeKeys)i.has(e)||this.removedEdges.add(e);(this.addedNodes.size>0||this.removedNodes.size>0||this.addedEdges.size>0||this.removedEdges.size>0)&&(this.lastTopologyChangeTime="undefined"!=typeof performance?performance.now():Date.now()),this.previousNodeIds=o,this.previousEdgeKeys=i,this.layoutVersion++}buildScene(e){const t=Ue(this.config.chartType);if(!t)return;const r=Array.from(this.nodes.values()),n=Array.from(this.edges.values()),{sceneNodes:o,sceneEdges:i,labels:a}=t.buildScene(r,n,this.config,e);this.sceneNodes=o,this.sceneEdges=i,this.labels=a}advanceTransition(e){if(!this.transition)return!1;const t=Math.min((e-this.transition.startTime)/this.transition.duration,1),r=1-Math.pow(1-t,3);for(const e of this.nodes.values())void 0===e._targetX0||void 0===e._prevX0||0===e._prevX0&&0===e._prevX1||(e.x0=e._prevX0+(e._targetX0-e._prevX0)*r,e.x1=e._prevX1+(e._targetX1-e._prevX1)*r,e.y0=e._prevY0+(e._targetY0-e._prevY0)*r,e.y1=e._prevY1+(e._targetY1-e._prevY1)*r);for(const e of this.edges.values())void 0!==e._targetY0&&void 0!==e._prevY0&&void 0!==e._prevSankeyWidth&&e._prevSankeyWidth>0&&(e.y0=e._prevY0+(e._targetY0-e._prevY0)*r,e.y1=e._prevY1+(e._targetY1-e._prevY1)*r,e.sankeyWidth=e._prevSankeyWidth+(e._targetSankeyWidth-e._prevSankeyWidth)*r);return this.rebuildAllBeziers(),1>t||(this.snapToTargets(),this.transition=null,!1)}prepareForRelayout(){for(const e of this.nodes.values())e._prevX0=e.x0,e._prevX1=e.x1,e._prevY0=e.y0,e._prevY1=e.y1;for(const e of this.edges.values())e._prevY0=e.y0,e._prevY1=e.y1,e._prevSankeyWidth=e.sankeyWidth}finalizeLayout(){const e="vertical"===this.config.orientation?"down":"right";for(const e of this.nodes.values())if(0!==e.x0||0!==e.x1||0!==e.y0||0!==e.y1)e.width=e.x1-e.x0,e.height=e.y1-e.y0,e.x=e.x0+e.width/2,e.y=e.y0+e.height/2;else{const t=5;e.x0=e.x-t,e.x1=e.x+t,e.y0=e.y-t,e.y1=e.y+t,e.width=2*t,e.height=2*t}for(const t of this.edges.values())t.direction=e,this.updateEdgeBezier(t);this.tension=0}saveTargetPositions(){for(const e of this.nodes.values())e._targetX0=e.x0,e._targetX1=e.x1,e._targetY0=e.y0,e._targetY1=e.y1;for(const e of this.edges.values())e._targetY0=e.y0,e._targetY1=e.y1,e._targetSankeyWidth=e.sankeyWidth}restorePreviousPositions(){for(const e of this.nodes.values())void 0===e._prevX0||0===e._prevX0&&0===e._prevX1||(e.x0=e._prevX0,e.x1=e._prevX1,e.y0=e._prevY0,e.y1=e._prevY1);for(const e of this.edges.values())void 0!==e._prevY0&&void 0!==e._prevSankeyWidth&&e._prevSankeyWidth>0&&(e.y0=e._prevY0,e.y1=e._prevY1,e.sankeyWidth=e._prevSankeyWidth);this.rebuildAllBeziers()}snapToTargets(){for(const e of this.nodes.values())void 0!==e._targetX0&&(e.x0=e._targetX0,e.x1=e._targetX1,e.y0=e._targetY0,e.y1=e._targetY1);for(const e of this.edges.values())void 0!==e._targetY0&&(e.y0=e._targetY0,e.y1=e._targetY1,e.sankeyWidth=e._targetSankeyWidth);this.rebuildAllBeziers()}updateEdgeBezier(e){const t="string"==typeof e.source?this.nodes.get(e.source):e.source,r="string"==typeof e.target?this.nodes.get(e.target):e.target;t&&r&&(e.bezier=e.circular&&e.circularPathData?this.buildCircularBezier(e):this.buildStandardBezier(e,t,r))}buildStandardBezier(e,t,r){const n=(e.sankeyWidth||1)/2;if("down"===e.direction){const o=t.y1,i=r.y0,a=h(o,i);return{circular:!1,points:[{x:e.y0,y:o},{x:e.y0,y:a(.5)},{x:e.y1,y:a(.5)},{x:e.y1,y:i}],halfWidth:n}}const o=t.x1,i=r.x0,a=h(o,i);return{circular:!1,points:[{x:o,y:e.y0},{x:a(.5),y:e.y0},{x:a(.5),y:e.y1},{x:i,y:e.y1}],halfWidth:n}}buildCircularBezier(e){const t=(e._circularWidth||e.sankeyWidth||1)/2,r=e.circularPathData;if(e._circularStub){const e=Math.max(15,Math.min(40,.33*(r.rightFullExtent-r.sourceX))),n=Math.max(15,Math.min(40,.33*(r.targetX-r.leftFullExtent)));return{circular:!0,segments:[[{x:r.sourceX,y:r.sourceY},{x:r.sourceX+.33*e,y:r.sourceY},{x:r.sourceX+.66*e,y:r.sourceY},{x:r.sourceX+e,y:r.sourceY}],[{x:r.targetX-n,y:r.targetY},{x:r.targetX-.66*n,y:r.targetY},{x:r.targetX-.33*n,y:r.targetY},{x:r.targetX,y:r.targetY}]],halfWidth:t}}let n;n="down"===e.direction?[{x:r.sourceY,y:r.sourceX},{x:r.sourceY,y:r.rightFullExtent},{x:r.verticalFullExtent,y:r.rightFullExtent},{x:r.verticalFullExtent,y:r.leftFullExtent},{x:r.targetY,y:r.leftFullExtent},{x:r.targetY,y:r.targetX}]:[{x:r.sourceX,y:r.sourceY},{x:r.rightFullExtent,y:r.sourceY},{x:r.rightFullExtent,y:r.verticalFullExtent},{x:r.leftFullExtent,y:r.verticalFullExtent},{x:r.leftFullExtent,y:r.targetY},{x:r.targetX,y:r.targetY}];const o=[];for(let e=0;n.length-1>e;e++){const t=n[e],r=n[e+1],i=r.x-t.x,a=r.y-t.y;o.push([t,{x:t.x+i/3,y:t.y+a/3},{x:t.x+2*i/3,y:t.y+2*a/3},r])}return{circular:!0,segments:o,halfWidth:t}}rebuildAllBeziers(){for(const e of this.nodes.values())e.width=e.x1-e.x0,e.height=e.y1-e.y0,e.x=e.x0+e.width/2,e.y=e.y0+e.height/2;for(const e of this.edges.values())this.updateEdgeBezier(e)}applyPulse(e){var t,r,n,o,i;const a=this.config.pulse;if(!a)return;const c=null!==(t=a.duration)&&void 0!==t?t:500,s=null!==(r=a.color)&&void 0!==r?r:"rgba(255,255,255,0.6)",l=null!==(n=a.glowRadius)&&void 0!==n?n:4;for(const t of this.sceneNodes){const r=t.id;if(!r)continue;const n=this.nodeTimestamps.get(r);if(!n)continue;const o=e-n;c>o&&(t._pulseIntensity=1-o/c,t._pulseColor=s,t._pulseGlowRadius=l)}for(const t of this.sceneEdges){const r=t.datum;if(!r)continue;const n="object"==typeof r.source?null===(o=r.source)||void 0===o?void 0:o.id:r.source,a="object"==typeof r.target?null===(i=r.target)||void 0===i?void 0:i.id:r.target;if(!n||!a)continue;const l=this.edgeTimestamps.get(`${n}\0${a}`);if(!l)continue;const u=e-l;c>u&&(t._pulseIntensity=1-u/c,t._pulseColor=s)}}applyDecay(){var e,t,r,n,o;const i=this.config.decay;if(!i)return;const a=null!==(e=i.minOpacity)&&void 0!==e?e:.1,c=this.nodeTimestamps.size;if(1>=c)return;const s=Array.from(this.nodeTimestamps.entries()).sort((e,t)=>e[1]-t[1]),l=new Map;for(let e=0;s.length>e;e++)l.set(s[e][0],e);for(const e of this.sceneNodes){const s=e.id;if(!s)continue;const u=l.get(s);if(void 0===u)continue;const d=c-1-u;let h;switch(i.type){case"linear":h=a+(1-d/(c-1))*(1-a);break;case"exponential":{const e=null!==(t=i.halfLife)&&void 0!==t?t:c/2;h=a+Math.pow(.5,d/e)*(1-a);break}case"step":h=(null!==(r=i.stepThreshold)&&void 0!==r?r:.5*c)>d?1:a;break;default:h=1}const f=null!==(o=null===(n=e.style)||void 0===n?void 0:n.opacity)&&void 0!==o?o:1;e.style=Object.assign(Object.assign({},e.style),{opacity:f*h})}}applyTopologyDiff(e){var t;if(0===this.addedNodes.size)return;const r=e-this.lastTopologyChangeTime;if(r>=2e3)return;const n=1-r/2e3;for(const e of this.sceneNodes){const r=e.id;r&&this.addedNodes.has(r)&&(e._pulseIntensity=Math.max(null!==(t=e._pulseIntensity)&&void 0!==t?t:0,n),e._pulseColor="rgba(34, 197, 94, 0.7)",e._pulseGlowRadius=8)}}get hasActiveTopologyDiff(){return 0!==this.addedNodes.size&&2e3>("undefined"!=typeof performance?performance.now():Date.now())-this.lastTopologyChangeTime}applyThresholds(e){var t,r;const n=this.config.thresholds;if(!n)return;const o=null!==(t=n.warningColor)&&void 0!==t?t:"#f59e0b",i=null!==(r=n.criticalColor)&&void 0!==r?r:"#ef4444",a=!1!==n.pulse;for(const t of this.sceneNodes){const r=t.id;if(!r)continue;const c=this.nodes.get(r);if(!c)continue;const s=n.metric(c);let l=null;void 0===n.critical||n.critical>s?void 0===n.warning||n.warning>s||(l=o):l=i,l&&(t.style=Object.assign(Object.assign({},t.style),{fill:l}),a&&(t._pulseIntensity=.6+.4*Math.sin(e/300),t._pulseColor=l,t._pulseGlowRadius=6))}}get hasActiveThresholds(){const e=this.config.thresholds;if(!e)return!1;for(const t of this.nodes.values()){const r=e.metric(t);if(void 0!==e.warning&&r>=e.warning||void 0!==e.critical&&r>=e.critical)return!0}return!1}get hasActivePulses(){var e;const t=this.config.pulse;if(!t||0===this.lastIngestTime)return!1;const r="undefined"!=typeof performance?performance.now():Date.now();return(null!==(e=t.duration)&&void 0!==e?e:500)>r-this.lastIngestTime}getLayoutData(){return{nodes:Array.from(this.nodes.values()),edges:Array.from(this.edges.values())}}clear(){this.nodes.clear(),this.edges.clear(),this.tension=0,this.layoutVersion=0,this.sceneNodes=[],this.sceneEdges=[],this.labels=[],this.transition=null,this.lastIngestTime=0,this.nodeTimestamps.clear(),this.edgeTimestamps.clear(),this.particlePool&&this.particlePool.clear()}}function tt(e){return{id:e,x0:0,x1:0,y0:0,y1:0,x:0,y:0,width:0,height:0,value:0,createdByFrame:!0}}function rt(e,t,r,n,o=30){let i=null,a=o,c=1/0;for(const t of e){const e=nt(t,r,n);if(e)if("rect"===t.type){const r=t.w*t.h;c>r&&(i=e,c=r)}else a>e.distance&&(i=e,a=e.distance)}if(i)return i;for(const e of t){const t=ot(e,r,n);t&&a>t.distance&&(i=t,a=t.distance)}return i}function nt(e,t,r){switch(e.type){case"circle":return function(e,t,r){const n=t-e.cx,o=r-e.cy,i=Math.sqrt(n*n+o*o);return i>Math.max(e.r,5)+5?null:{type:"node",datum:e.datum,x:e.cx,y:e.cy,distance:i}}(e,t,r);case"rect":return function(e,t,r){return e.x>t||t>e.x+e.w||e.y>r||r>e.y+e.h?null:{type:"node",datum:e.datum,x:e.x+e.w/2,y:e.y+e.h/2,distance:0}}(e,t,r);case"arc":return function(e,t,r){const n=t-e.cx,o=r-e.cy,i=Math.sqrt(n*n+o*o);if(e.innerR-2>i||i>e.outerR+2)return null;let a=Math.atan2(o,n);0>a&&(a+=2*Math.PI);let c,s=e.startAngle,l=e.endAngle;if(0>s&&(s+=2*Math.PI),0>l&&(l+=2*Math.PI),c=s>l?a>=s||l>=a:a>=s&&l>=a,c){const t=(e.startAngle+e.endAngle)/2,r=(e.innerR+e.outerR)/2;return{type:"node",datum:e.datum,x:e.cx+r*Math.cos(t),y:e.cy+r*Math.sin(t),distance:0}}return null}(e,t,r);default:return null}}function ot(e,t,r){switch(e.type){case"bezier":return function(e,t,r){var n,o;if(!e.pathD)return null;try{const i=new Path2D(e.pathD),a=document.createElement("canvas").getContext("2d");if(!a)return null;if(a.isPointInPath(i,t,r)){const i="object"==typeof(null===(n=e.datum)||void 0===n?void 0:n.source)?e.datum.source:null,a="object"==typeof(null===(o=e.datum)||void 0===o?void 0:o.target)?e.datum.target:null;return{type:"edge",datum:e.datum,x:i&&a?(i.x1+a.x0)/2:t,y:e.datum?(e.datum.y0+e.datum.y1)/2:r,distance:0}}}catch(e){}return null}(e,t,r);case"line":return function(e,t,r){const n=e.x2-e.x1,o=e.y2-e.y1,i=n*n+o*o;if(0===i)return null;let a=((t-e.x1)*n+(r-e.y1)*o)/i;a=Math.max(0,Math.min(1,a));const c=e.x1+a*n,s=e.y1+a*o,l=Math.sqrt(Math.pow(t-c,2)+Math.pow(r-s,2));return l>5?null:{type:"edge",datum:e.datum,x:c,y:s,distance:l}}(e,t,r);case"ribbon":case"curved":return function(e,t,r){if(!e.pathD)return null;try{const n=new Path2D(e.pathD),o=document.createElement("canvas").getContext("2d");if(!o)return null;if(o.isPointInPath(n,t,r))return{type:"edge",datum:e.datum,x:t,y:r,distance:0}}catch(e){}return null}(e,t,r);default:return null}}function it(t){const{width:r,height:n,totalWidth:o,totalHeight:i,margin:a,labels:c,title:s,legend:l,foregroundGraphics:u,annotations:d,svgAnnotationRules:h}=t;return e.createElement("svg",{width:o,height:i,style:{position:"absolute",top:0,left:0,pointerEvents:"none"}},e.createElement("g",{transform:`translate(${a.left},${a.top})`},c.map((t,r)=>e.createElement("text",{key:"label-"+r,x:t.x,y:t.y,textAnchor:t.anchor||"start",dominantBaseline:t.baseline||"middle",fontSize:t.fontSize||11,fontWeight:t.fontWeight,fill:t.fill||"currentColor",stroke:t.stroke,strokeWidth:t.strokeWidth,paintOrder:t.paintOrder,style:{pointerEvents:"none"}},t.text)),d&&h&&d.map((t,o)=>{const i=h(t,o,{width:r,height:n});return i?e.createElement(e.Fragment,{key:"annotation-"+o},i):null}),u),s&&"string"==typeof s?e.createElement("text",{x:o/2,y:16,textAnchor:"middle",fontSize:14,fontWeight:600,fill:"currentColor"},s):s?e.createElement("foreignObject",{x:0,y:0,width:o,height:a.top},s):null,l&&"object"==typeof l&&"legendGroups"in l?e.createElement("g",{transform:`translate(${o-a.right+10},${a.top})`},l.legendGroups.map((t,r)=>{var n;return e.createElement("g",{key:"legend-group-"+r},null===(n=t.items)||void 0===n?void 0:n.map((t,r)=>e.createElement("g",{key:"legend-item-"+r,transform:`translate(0,${20*r})`},e.createElement("rect",{x:0,y:0,width:12,height:12,fill:t.color,rx:2}),e.createElement("text",{x:18,y:10,fontSize:11,fill:"currentColor"},t.label))))})):l?e.createElement("g",{transform:`translate(${o-a.right+10},${a.top})`},l):null)}function at(e,t){var r,n,o,i,a,c;if(!t.pathD)return;e.save();const s=new Path2D(t.pathD);if(t.style.fill&&"none"!==t.style.fill){const a=t._gradient;if(a){const o=e.createLinearGradient(a.x0,0,a.x1,0),i=null!==(n=null!==(r=t.style.fillOpacity)&&void 0!==r?r:t.style.opacity)&&void 0!==n?n:.5,c=t.style.fill;o.addColorStop(0,1===a.from?c:"transparent"),o.addColorStop(1,1===a.to?c:"transparent"),e.fillStyle=o,e.globalAlpha=i}else e.fillStyle=t.style.fill,e.globalAlpha=null!==(i=null!==(o=t.style.fillOpacity)&&void 0!==o?o:t.style.opacity)&&void 0!==i?i:.5;e.fill(s)}t.style.stroke&&"none"!==t.style.stroke&&(e.strokeStyle=t.style.stroke,e.lineWidth=null!==(a=t.style.strokeWidth)&&void 0!==a?a:.5,e.globalAlpha=.5*(null!==(c=t.style.opacity)&&void 0!==c?c:1),e.stroke(s)),t._pulseIntensity&&t._pulseIntensity>0&&(e.fillStyle=t._pulseColor||"rgba(255,255,255,0.6)",e.globalAlpha=.2*t._pulseIntensity,e.fill(s)),e.restore()}function ct(e,t){var r,n;e.save(),e.strokeStyle=t.style.stroke||"#999",e.lineWidth=null!==(r=t.style.strokeWidth)&&void 0!==r?r:1,void 0!==t.style.opacity&&(e.globalAlpha=t.style.opacity),t.style.strokeDasharray&&e.setLineDash(t.style.strokeDasharray.split(/[\s,]+/).map(Number)),e.beginPath(),e.moveTo(t.x1,t.y1),e.lineTo(t.x2,t.y2),e.stroke(),t._pulseIntensity&&t._pulseIntensity>0&&(e.setLineDash([]),e.strokeStyle=t._pulseColor||"rgba(255,255,255,0.6)",e.lineWidth=(null!==(n=t.style.strokeWidth)&&void 0!==n?n:1)+3*t._pulseIntensity,e.globalAlpha=.4*t._pulseIntensity,e.beginPath(),e.moveTo(t.x1,t.y1),e.lineTo(t.x2,t.y2),e.stroke()),e.restore()}function st(e,t){var r,n,o,i;if(!t.pathD)return;e.save();const a=new Path2D(t.pathD);t.style.fill&&"none"!==t.style.fill&&(e.fillStyle=t.style.fill,e.globalAlpha=null!==(n=null!==(r=t.style.fillOpacity)&&void 0!==r?r:t.style.opacity)&&void 0!==n?n:.5,e.fill(a)),t.style.stroke&&"none"!==t.style.stroke&&(e.strokeStyle=t.style.stroke,e.lineWidth=null!==(o=t.style.strokeWidth)&&void 0!==o?o:.5,e.globalAlpha=.3*(null!==(i=t.style.opacity)&&void 0!==i?i:1),e.stroke(a)),e.restore()}function lt(e,t){var r,n;if(!t.pathD)return;e.save();const o=new Path2D(t.pathD);e.strokeStyle=t.style.stroke||"#999",e.lineWidth=null!==(r=t.style.strokeWidth)&&void 0!==r?r:1,void 0!==t.style.opacity&&(e.globalAlpha=t.style.opacity),e.stroke(o),t.style.fill&&"none"!==t.style.fill&&(e.fillStyle=t.style.fill,e.globalAlpha=null!==(n=t.style.fillOpacity)&&void 0!==n?n:.1,e.fill(o)),e.restore()}it.displayName="NetworkSVGOverlay";const ut={category10:b,tableau10:S,set3:P,blues:D,reds:A,greens:E,oranges:L,purples:w,viridis:k,plasma:x},dt=b,ht=["#f0f0f0","#b5d4ea","#f4c2a1","#b8dab2","#d4b5e0","#f9e0a2","#a8d8d8"];function ft(e,t,r){if("function"==typeof t)return t(e);const n=e[t];return r?r(n):dt[Math.abs(function(e){let t=0;for(let r=0;e.length>r;r++)t=(t<<5)-t+e.charCodeAt(r),t&=t;return Math.abs(t)}(n+""))%dt.length]}function yt(e,t,r="category10"){const n=Array.from(new Set(e.map(e=>e[t]))),o=n.every(e=>"number"==typeof e||!isNaN(Number(e)));if(Array.isArray(r))return I().domain(n).range(r).unknown("#999");const i=ut[r]||ut.category10;if(o&&"function"==typeof i)return e=>i(Number(e)/Math.max(...n.map(Number)));{const e=Array.isArray(i)?i:dt;return I().domain(n).range(e).unknown("#999")}}const gt={top:20,right:80,bottom:20,left:80},pt={top:40,right:40,bottom:40,left:40},vt=new Set(["chord","force","circlepack"]),mt=[800,600],bt={background:"rgba(0, 0, 0, 0.85)",color:"white",padding:"6px 10px",borderRadius:4,fontSize:12,lineHeight:1.5,boxShadow:"0 2px 8px rgba(0, 0, 0, 0.15)",pointerEvents:"none",whiteSpace:"nowrap"};function xt({data:t}){var r,n,o,i,a,c;if("edge"===t.type){const r=t.data;return e.createElement("div",{className:"semiotic-tooltip",style:bt},e.createElement("div",{style:{fontWeight:600}},"object"==typeof r.source?r.source.id:r.source," → ","object"==typeof r.target?r.target.id:r.target),null!=r.value&&e.createElement("div",{style:{marginTop:4,opacity:.8}},"Value:"," ","number"==typeof r.value?r.value.toLocaleString():r.value+""))}const s=t.data,l=null==s?void 0:s.__hierarchyNode;if(l){const t=[];let a=l;for(;a;){const e=null!==(i=null!==(n=null===(r=a.data)||void 0===r?void 0:r.name)&&void 0!==n?n:null===(o=a.data)||void 0===o?void 0:o.id)&&void 0!==i?i:s.id;null!=e&&t.unshift(e+""),a=a.parent}t.length>1&&t.shift();const c=t.length-1;return e.createElement("div",{className:"semiotic-tooltip",style:bt},e.createElement("div",null,t.map((t,r)=>e.createElement("span",{key:r},r>0&&e.createElement("span",{style:{margin:"0 3px",opacity:.5}}," → "),r===c?e.createElement("strong",null,t):e.createElement("span",{style:{opacity:.7}},t)))),null!=s.value&&s.value>0&&e.createElement("div",{style:{marginTop:4,opacity:.8}},"number"==typeof s.value?s.value.toLocaleString():s.value+""))}const u=((null===(a=s.sourceLinks)||void 0===a?void 0:a.length)||0)+((null===(c=s.targetLinks)||void 0===c?void 0:c.length)||0),d=(s.sourceLinks||[]).reduce((e,t)=>e+(t.value||0),0)+(s.targetLinks||[]).reduce((e,t)=>e+(t.value||0),0);return e.createElement("div",{className:"semiotic-tooltip",style:bt},e.createElement("div",{style:{fontWeight:600}},s.id),null!=s.value&&s.value>0&&e.createElement("div",{style:{marginTop:4,opacity:.8}},"Total:"," ","number"==typeof s.value?s.value.toLocaleString():s.value+""),u>0&&e.createElement("div",{style:{marginTop:4,opacity:.8}},"Connections: ",u,d!==u&&` (weighted: ${d.toLocaleString()})`))}const kt=o(function(o,s){const{chartType:l,nodes:u,edges:d,data:h,initialEdges:f,nodeIDAccessor:y="id",sourceAccessor:g="source",targetAccessor:p="target",valueAccessor:v="value",childrenAccessor:m,hierarchySum:b,orientation:x="horizontal",nodeAlign:k="justify",nodePaddingRatio:w=.05,nodeWidth:L=15,iterations:E=300,forceStrength:A=.1,padAngle:D=.01,groupWidth:P=20,sortGroups:S,edgeSort:T,treeOrientation:O="vertical",edgeType:N="curve",padding:W,paddingTop:$,tensionConfig:_,showParticles:I=!1,particleStyle:M,nodeStyle:j,edgeStyle:C,colorBy:R,colorScheme:B="category10",edgeColorBy:F="source",edgeOpacity:z=.5,colorByDepth:H=!1,nodeSize:Y=8,nodeSizeRange:X=[5,20],nodeLabel:V,showLabels:Z=!0,size:K=mt,responsiveWidth:Q,responsiveHeight:J,margin:U,className:ee,background:te,enableHover:re=!0,tooltipContent:ne,customHoverBehavior:oe,customClickBehavior:ie,onObservation:ae,chartId:ce,onTopologyChange:se,annotations:le,svgAnnotationRules:ue,legend:de,title:he,foregroundGraphics:fe,backgroundGraphics:ye,decay:ge,pulse:pe,staleness:ve,thresholds:me}=o,be=vt.has(l)?pt:gt,[xe,ke]=function(e,o,i){const a=t(null),[c,s]=r(null);return n(()=>{if(!o&&!i)return;const e=a.current;if(!e)return;const t=new ResizeObserver(e=>{for(const t of e){const{width:e,height:r}=t.contentRect;s(t=>t&&t.w===e&&t.h===r?t:{w:e,h:r})}});return t.observe(e),()=>t.disconnect()},[o,i]),[a,[o&&c?c.w:e[0],i&&c?c.h:e[1]]]}(K,Q,J),we=Object.assign(Object.assign({},be),U),Le=ke[0]-we.left-we.right,Ee=ke[1]-we.top-we.bottom,Ae=i(()=>Object.assign(Object.assign({},G),_),[_]),De=i(()=>Object.assign(Object.assign({},q),M),[M]),Pe=i(()=>({chartType:l,nodeIDAccessor:y,sourceAccessor:g,targetAccessor:p,valueAccessor:v,childrenAccessor:m,hierarchySum:b,orientation:x,nodeAlign:k,nodePaddingRatio:w,nodeWidth:L,iterations:E,forceStrength:A,padAngle:D,groupWidth:P,sortGroups:S,edgeSort:T,treeOrientation:O,edgeType:N,padding:W,paddingTop:$,tensionConfig:Ae,showParticles:I,particleStyle:De,nodeStyle:j,edgeStyle:C,nodeLabel:V,showLabels:Z,colorBy:R,colorScheme:B,edgeColorBy:F,edgeOpacity:z,colorByDepth:H,nodeSize:Y,nodeSizeRange:X,decay:ge,pulse:pe,staleness:ve,thresholds:me}),[l,y,g,p,v,m,b,x,k,w,L,E,A,D,P,S,T,O,N,W,$,Ae,I,De,j,C,V,Z,R,B,F,z,H,Y,X,ge,pe,ve,me]),Se=t(null),Te=t(0),Oe=t(0),Ne=t(!0),We=t(()=>{}),$e=t(null);$e.current||($e.current=new et(Pe));const[_e,Ie]=r(null),[Me,je]=r(0),[Ce,Re]=r(0),[Be,Fe]=r(!1),ze=t(null),He=t(new Map),Ye=t(0),Xe=a(e=>{if("function"==typeof R)return R(e);if("string"==typeof R&&e.data){const t=e.data[R];if(void 0!==t){if(!He.current.has(t+"")){const e=Array.isArray(B)?B:dt;He.current.set(t+"",e[Ye.current++%e.length])}return He.current.get(t+"")}}if(!He.current.has(e.id)){const t=Array.isArray(B)?B:dt;He.current.set(e.id,t[Ye.current++%t.length])}return He.current.get(e.id)},[R,B]),Ge=a(e=>{if("function"==typeof F)return F(e);const t="object"==typeof e.source?e.source:null,r="object"==typeof e.target?e.target:null;return"target"===F&&r?Xe(r):t?Xe(t):"#999"},[F,Xe]),qe=a(e=>{if(!(null==M?void 0:M.colorBy))return Ge(e);const t="object"==typeof e.source?e.source:null,r="object"==typeof e.target?e.target:null;return"target"===De.colorBy&&r?Xe(r):t?Xe(t):"#999"},[null==M?void 0:M.colorBy,De.colorBy,Xe,Ge]),Ve="sankey"===l&&I||!!pe,Ze=a(()=>{Te.current&&!Ve||Te.current||(Te.current=requestAnimationFrame(()=>We.current()))},[Ve]);n(()=>{var e;null===(e=$e.current)||void 0===e||e.updateConfig(Pe),Ne.current=!0,Ze()},[Pe,Ze]);const Ke=a(()=>{const e=$e.current;if(!e)return;e.runLayout([Le,Ee]),e.buildScene([Le,Ee]),Ne.current=!0;const t=Array.isArray(B)?B:dt,r=Array.from(e.nodes.values());for(let e=0;r.length>e;e++){const n=r[e];He.current.has(n.id)||He.current.set(n.id,t[e%t.length])}if(Ye.current=r.length,je(e.layoutVersion),se){const{nodes:t,edges:r}=e.getLayoutData();se(t,r)}},[Le,Ee,se,B]),Qe=a(e=>{const t=$e.current;t&&(t.ingestEdge(e)&&Ke(),Ze())},[Ke,Ze]),Je=a(e=>{const t=$e.current;if(!t)return;let r=!1;for(const n of e)t.ingestEdge(n)&&(r=!0);r&&Ke(),Ze()},[Ke,Ze]),Ue=a(()=>{var e;null===(e=$e.current)||void 0===e||e.clear(),He.current.clear(),Ye.current=0,je(0),Ie(null),ze.current=null,Ne.current=!0,Ze()},[Ze]),tt=a(()=>{const e=$e.current;e&&(e.tension+=999,Ke(),Ze())},[Ke,Ze]);c(s,()=>({push:Qe,pushMany:Je,clear:Ue,getTopology:()=>{var e,t;return null!==(t=null===(e=$e.current)||void 0===e?void 0:e.getLayoutData())&&void 0!==t?t:{nodes:[],edges:[]}},getTopologyDiff:()=>{const e=$e.current;return e?{addedNodes:Array.from(e.addedNodes),removedNodes:Array.from(e.removedNodes),addedEdges:Array.from(e.addedEdges),removedEdges:Array.from(e.removedEdges)}:{addedNodes:[],removedNodes:[],addedEdges:[],removedEdges:[]}},relayout:tt,getTension:()=>{var e,t;return null!==(t=null===(e=$e.current)||void 0===e?void 0:e.tension)&&void 0!==t?t:0}}),[Qe,Je,Ue,tt]);const nt=["tree","cluster","treemap","circlepack","partition"].includes(l),ot=nt?h||(Array.isArray(d)?void 0:d):void 0;n(()=>{const e=$e.current;if(e)if(nt&&ot)e.ingestHierarchy(ot,[Le,Ee]),e.buildScene([Le,Ee]),Ne.current=!0,Ze();else{const t=u||[],r=Array.isArray(d)?d:[];if(0===t.length&&0===r.length)return;e.ingestBounded(t,r,[Le,Ee]),e.buildScene([Le,Ee]);const n=Array.isArray(B)?B:dt,o=Array.from(e.nodes.values());for(let e=0;o.length>e;e++){const t=o[e];He.current.has(t.id)||He.current.set(t.id,n[e%n.length])}Ye.current=o.length,Ne.current=!0,Ze()}},[u,d,h,ot,nt,Le,Ee,Pe,Ze,B]),n(()=>{f&&f.length>0&&Je(f)},[]);const ut=a(e=>{if(oe&&oe(e),ae){const t=Date.now();ae(e?{type:"hover",datum:e.data||{},x:e.x,y:e.y,timestamp:t,chartType:"StreamNetworkFrame",chartId:ce}:{type:"hover-end",timestamp:t,chartType:"StreamNetworkFrame",chartId:ce})}},[oe,ae,ce]),ht=a(e=>{if(ie&&ie(e),ae){const t=Date.now();ae(e?{type:"click",datum:e.data||{},x:e.x,y:e.y,timestamp:t,chartType:"StreamNetworkFrame",chartId:ce}:{type:"click-end",timestamp:t,chartType:"StreamNetworkFrame",chartId:ce})}},[ie,ae,ce]),ft=t(()=>{}),yt=t(()=>{});ft.current=e=>{if(!re)return;const t=Se.current;if(!t)return;const r=t.getBoundingClientRect(),n=e.clientX-r.left-we.left,o=e.clientY-r.top-we.top;if(0>n||n>Le||0>o||o>Ee)return void(ze.current&&(ze.current=null,Ie(null),ut&&(ut(null),Ne.current=!0),Ze()));const i=$e.current;if(!i)return;const a=rt(i.sceneNodes,i.sceneEdges,n,o);if(!a)return void(ze.current&&(ze.current=null,Ie(null),ut&&(ut(null),Ne.current=!0),Ze()));const c={type:a.type,data:a.datum,x:a.x,y:a.y};ze.current=c,Ie(c),ut&&(ut(c),Ne.current=!0),Ze()},yt.current=()=>{ze.current&&(ze.current=null,Ie(null),ut&&(ut(null),Ne.current=!0),Ze())};const bt=t(()=>{});bt.current=e=>{if(!ie&&!ae)return;const t=Se.current;if(!t)return;const r=t.getBoundingClientRect(),n=e.clientX-r.left-we.left,o=e.clientY-r.top-we.top;if(0>n||n>Le||0>o||o>Ee)return;const i=$e.current;if(!i)return;const a=rt(i.sceneNodes,i.sceneEdges,n,o);ht(a?{type:a.type,data:a.datum,x:a.x,y:a.y}:null)},a(e=>ft.current(e),[]);const kt=a(()=>yt.current(),[]),wt=a(e=>bt.current(e),[]),Lt=t(-1),Et=a(e=>{const t=$e.current;if(!t)return;const r=function(e){const t=[];for(const r of e)"circle"===r.type&&null!=r.cx?t.push({x:r.cx,y:r.cy,datum:r.datum}):"rect"===r.type&&null!=r.x?t.push({x:r.x+r.w/2,y:r.y+r.h/2,datum:r.datum}):"arc"===r.type&&null!=r.cx&&t.push({x:r.cx,y:r.cy,datum:r.datum});return t.sort((e,t)=>e.x-t.x||e.y-t.y),t}(t.sceneNodes);if(0===r.length)return;const n=Lt.current,o=function(e,t,r){switch(e){case"ArrowRight":case"ArrowDown":return r-1>t?t+1:t;case"ArrowLeft":case"ArrowUp":return t>0?t-1:t;case"Home":return 0;case"End":return r-1;case"Escape":return-1;default:return null}}(e.key,0>n?-1:n,r.length);if(null===o)return;if(e.preventDefault(),0>o)return Lt.current=-1,ze.current=null,Ie(null),ut&&(ut(null),Ne.current=!0),void Ze();const i=0>n?0:o;Lt.current=i;const a=r[i],c={type:"node",data:a.datum,x:a.x,y:a.y};ze.current=c,Ie(c),ut&&(ut(c),Ne.current=!0),Ze()},[ut,Ze]),At=a(e=>{Lt.current=-1,ft.current(e)},[]);We.current=()=>{var e,t,r;Te.current=0;const n=Se.current;if(!n)return;const o=n.getContext("2d");if(!o)return;const i=$e.current;if(!i)return;const a=performance.now(),c=Oe.current?Math.min((a-Oe.current)/1e3,.1):.016;Oe.current=a;const s=i.advanceTransition(a);(s||Ne.current)&&i.buildScene([Le,Ee]);const l="undefined"!=typeof window&&window.devicePixelRatio||1;n.width=ke[0]*l,n.height=ke[1]*l,n.style.width=ke[0]+"px",n.style.height=ke[1]+"px",o.scale(l,l),o.translate(we.left,we.top),o.clearRect(-we.left,-we.top,ke[0],ke[1]),te&&(o.fillStyle=te,o.fillRect(0,0,Le,Ee)),ge&&i.applyDecay(),pe&&i.applyPulse(a),me&&i.applyThresholds(a),i.applyTopologyDiff(a);const u=null!==(e=null==ve?void 0:ve.threshold)&&void 0!==e?e:5e3,d=ve&&i.lastIngestTime>0&&a-i.lastIngestTime>u;if(d&&(o.globalAlpha=null!==(t=null==ve?void 0:ve.dimOpacity)&&void 0!==t?t:.5),function(e,t){for(const r of t)switch(r.type){case"bezier":at(e,r);break;case"line":ct(e,r);break;case"ribbon":st(e,r);break;case"curved":lt(e,r)}}(o,i.sceneEdges),function(e,t){var r,n,o;for(const i of t){if("rect"!==i.type)continue;const t=i;t.w>0&&t.h>0&&(e.save(),void 0!==t.style.opacity&&(e.globalAlpha=t.style.opacity),t.style.fill&&(e.fillStyle=t.style.fill,void 0!==t.style.fillOpacity&&(e.globalAlpha=(null!==(r=t.style.opacity)&&void 0!==r?r:1)*t.style.fillOpacity),e.fillRect(t.x,t.y,t.w,t.h)),t.style.stroke&&"none"!==t.style.stroke&&(e.strokeStyle=t.style.stroke,e.lineWidth=null!==(n=t.style.strokeWidth)&&void 0!==n?n:1,e.globalAlpha=null!==(o=t.style.opacity)&&void 0!==o?o:1,e.strokeRect(t.x,t.y,t.w,t.h)),t._pulseIntensity&&t._pulseIntensity>0&&(e.globalAlpha=.3*t._pulseIntensity,e.fillStyle=t._pulseColor||"rgba(255,255,255,0.6)",e.fillRect(t.x,t.y,t.w,t.h)),e.restore())}}(o,i.sceneNodes),function(e,t){var r,n,o,i;for(const a of t){if("circle"!==a.type)continue;const t=a;if(t.r>0){if(e.save(),void 0!==t.style.opacity&&(e.globalAlpha=t.style.opacity),e.beginPath(),e.arc(t.cx,t.cy,t.r,0,2*Math.PI),t.style.fill&&(e.fillStyle=t.style.fill,void 0!==t.style.fillOpacity&&(e.globalAlpha=(null!==(r=t.style.opacity)&&void 0!==r?r:1)*t.style.fillOpacity),e.fill()),t.style.stroke&&"none"!==t.style.stroke&&(e.strokeStyle=t.style.stroke,e.lineWidth=null!==(n=t.style.strokeWidth)&&void 0!==n?n:1,e.globalAlpha=null!==(o=t.style.opacity)&&void 0!==o?o:1,e.stroke()),t._pulseIntensity&&t._pulseIntensity>0){const r=null!==(i=t._pulseGlowRadius)&&void 0!==i?i:4,n=t.r+r*t._pulseIntensity;e.beginPath(),e.arc(t.cx,t.cy,n,0,2*Math.PI),e.strokeStyle=t._pulseColor||"rgba(255,255,255,0.6)",e.lineWidth=2*t._pulseIntensity,e.globalAlpha=.6*t._pulseIntensity,e.stroke()}e.restore()}}}(o,i.sceneNodes),function(e,t){var r,n,o;for(const i of t){if("arc"!==i.type)continue;const t=i;e.save(),void 0!==t.style.opacity&&(e.globalAlpha=t.style.opacity),e.beginPath(),e.arc(t.cx,t.cy,t.outerR,t.startAngle,t.endAngle),e.arc(t.cx,t.cy,t.innerR,t.endAngle,t.startAngle,!0),e.closePath(),t.style.fill&&(e.fillStyle=t.style.fill,void 0!==t.style.fillOpacity&&(e.globalAlpha=(null!==(r=t.style.opacity)&&void 0!==r?r:1)*t.style.fillOpacity),e.fill()),t.style.stroke&&"none"!==t.style.stroke&&(e.strokeStyle=t.style.stroke,e.lineWidth=null!==(n=t.style.strokeWidth)&&void 0!==n?n:1,e.globalAlpha=null!==(o=t.style.opacity)&&void 0!==o?o:1,e.stroke()),e.restore()}}(o,i.sceneNodes),I&&i.particlePool&&!d){const e=Array.from(i.edges.values());if(e.length>0){!function(e,t,r,n){var o,i;const a=null!==(o=n.spawnRate)&&void 0!==o?o:q.spawnRate,c=null!==(i=n.maxPerEdge)&&void 0!==i?i:q.maxPerEdge;for(let n=0;t.length>n;n++){const o=t[n];if(!o.bezier)continue;if(e.countForEdge(n)>=c)continue;const i=o.value*a*r*(o.bezier.circular?.3:1),s=Math.floor(i),l=i-s;let u=s;Math.random()<l&&u++;for(let t=0;u>t&&e.countForEdge(n)<c;t++)e.spawn(n)}}(i.particlePool,e,c,De);const t=.5*(null!==(r=De.speedMultiplier)&&void 0!==r?r:1);let n;if(De.proportionalSpeed){const t=e.reduce((e,t)=>Math.max(e,t.value||1),1);n=e.map(e=>.3+(e.value||1)/t*1.7)}i.particlePool.step(c,t,e,n),function(e,t,r,n,o){var i,a;const c=null!==(i=n.radius)&&void 0!==i?i:q.radius,s=null!==(a=n.opacity)&&void 0!==a?a:q.opacity;e.globalAlpha=s;for(let i=0;t.particles.length>i;i++){const a=t.particles[i];if(!a.active)continue;const s=r[a.edgeIndex];if(s){if("function"==typeof n.color){const t="object"==typeof s.source?s.source:null;e.fillStyle=t?n.color(s,t):"#666"}else e.fillStyle=n.color&&"inherit"!==n.color?n.color:o(s);e.beginPath(),e.arc(a.x,a.y,c,0,2*Math.PI),e.fill()}}e.globalAlpha=1}(o,i.particlePool,e,De,qe)}}d&&(o.globalAlpha=1);const h=Ne.current;Ne.current=!1,(h||s)&&Re(e=>e+1),(Ve||s||i.hasActivePulses||i.hasActiveThresholds||i.hasActiveTopologyDiff)&&(Te.current=requestAnimationFrame(()=>We.current()))},n(()=>(Ze(),()=>{Te.current&&(cancelAnimationFrame(Te.current),Te.current=0)}),[Ze]),n(()=>{Ne.current=!0,Ze()},[l,Le,Ee,te,Ze]),n(()=>{if(!ve)return;const e=setInterval(()=>{var e;const t=$e.current;if(!t||0===t.lastIngestTime)return;const r="undefined"!=typeof performance?performance.now():Date.now(),n=null!==(e=ve.threshold)&&void 0!==e?e:5e3,o=r-t.lastIngestTime>n;o!==Be&&(Fe(o),Ne.current=!0,Ze())},1e3);return()=>clearInterval(e)},[ve,Be,Ze]);const Dt=re&&_e?e.createElement("div",{className:"stream-network-tooltip",style:{position:"absolute",left:we.left+_e.x,top:we.top+_e.y,transform:`translate(${_e.x>.6*Le?"calc(-100% - 12px)":"12px"}, ${.3*Ee>_e.y?"4px":"calc(-100% - 4px)"})`,pointerEvents:"none",zIndex:2}},ne?ne(_e):e.createElement(xt,{data:_e})):null,Pt=$e.current;return e.createElement("div",{ref:xe,className:"stream-network-frame"+(ee?" "+ee:""),role:"img","aria-label":"string"==typeof he?he:"Network chart",tabIndex:0,style:{position:"relative",width:Q?"100%":ke[0],height:J?"100%":ke[1]},onMouseMove:re?At:void 0,onMouseLeave:re?kt:void 0,onClick:ie||ae?wt:void 0,onKeyDown:Et},ye&&e.createElement("svg",{style:{position:"absolute",top:0,left:0,width:ke[0],height:ke[1],pointerEvents:"none"}},e.createElement("g",{transform:`translate(${we.left},${we.top})`},ye)),e.createElement("canvas",{ref:Se,style:{position:"absolute",top:0,left:0}}),e.createElement(it,{width:Le,height:Ee,totalWidth:ke[0],totalHeight:ke[1],margin:we,labels:(null==Pt?void 0:Pt.labels)||[],title:he,legend:de,foregroundGraphics:fe,annotations:le,svgAnnotationRules:ue,annotationFrame:Ce}),Dt,(null==ve?void 0:ve.showBadge)&&e.createElement("div",{className:"stream-staleness-badge",style:Object.assign(Object.assign({position:"absolute"},"top-left"===ve.badgePosition?{top:4,left:4}:"bottom-left"===ve.badgePosition?{bottom:4,left:4}:"bottom-right"===ve.badgePosition?{bottom:4,right:4}:{top:4,right:4}),{background:Be?"#dc3545":"#28a745",color:"white",fontSize:10,fontWeight:700,padding:"2px 6px",borderRadius:3,letterSpacing:"0.05em",zIndex:3,pointerEvents:"none"})},Be?"STALE":"LIVE"))});kt.displayName="StreamNetworkFrame";const wt={background:"rgba(0, 0, 0, 0.85)",color:"white",padding:"8px 12px",borderRadius:"4px",fontSize:"14px",lineHeight:"1.5",boxShadow:"0 2px 8px rgba(0, 0, 0, 0.15)",pointerEvents:"none",maxWidth:"300px",wordWrap:"break-word"};function Lt(e,t){return"function"==typeof t?t(e):e[t]}function Et(e,t){return t?t(e):null==e?"":"number"==typeof e?e.toLocaleString():e instanceof Date?e.toLocaleDateString():"object"==typeof e&&null!==e?void 0!==e.id?e.id+"":void 0!==e.name?e.name+"":JSON.stringify(e):e+""}function At(t){return!0===t||("function"==typeof t?t:!1!==t&&void 0!==t&&("object"!=typeof t||null===t||!("fields"in t)&&!("title"in t)||function(t={}){const{fields:r,title:n,format:o,style:i={},className:a=""}=t;return t=>{if(!t||"object"!=typeof t)return null;let c;const s=[];if(n){const e=Lt(t,n);c=Et(e,o)}if(r&&r.length>0)r.forEach(e=>{let r,n,i;"string"==typeof e?(r=e,n=e,i=o):(r=e.label,n=e.accessor||e.key||"",i=e.format||o);const a=Lt(t,n);s.push({label:r,value:Et(a,i)})});else if(!n){const e=["value","y","name","id","label"];for(const r of e)if(void 0!==t[r]){c=Et(t[r],o);break}if(!c){const e=Object.keys(t).filter(e=>!e.startsWith("_"));e.length>0&&(c=Et(t[e[0]],o))}}const l=Object.assign(Object.assign({},wt),i);return e.createElement("div",{className:("semiotic-tooltip "+a).trim(),style:l},c&&e.createElement("div",{style:{fontWeight:s.length>0?"bold":"normal"}},c),s.map((t,r)=>e.createElement("div",{key:r,style:{marginTop:0===r&&c?"4px":0}},t.label&&e.createElement("span",null,t.label,": "),t.value)))}}(t)))}const Dt=l(null);function Pt(t){const n=l(null),o=St(t);return[function({children:r}){const o=i(()=>St(t),[]);return e.createElement(n.Provider,{value:o,children:r})},e=>{var t;const i=null!==(t=s(n))&&void 0!==t?t:o;return function(e,t){const[n,o]=r(t);return u(()=>e(()=>o(t)),[e]),n}(i.subscribe,()=>e(i.getState()))}]}function St(e){const t=new EventTarget;let r=e(function(e){r=Object.assign(Object.assign({},r),e(r)),t.dispatchEvent(new CustomEvent("update"))});return{getState:()=>r,subscribe:function(e){return t.addEventListener("update",e),()=>t.removeEventListener("update",e)}}}function Tt(e){const t=[];for(const[r,n]of Object.entries(e.fields))if("point"===n.type)t.push(e=>n.values.has(e[r]));else{const[e,o]=n.range;t.push(t=>{const n=t[r];return n>=e&&o>=n})}return e=>t.every(t=>t(e))}function Ot(e,t){let r=e.get(t);return r||(r={name:t,resolution:"union",clauses:new Map},e.set(t,r)),r}const[Nt,Wt]=Pt(e=>({selections:new Map,setClause(t,r){e(e=>{const n=new Map(e.selections),o=Ot(n,t),i=new Map(o.clauses);return i.set(r.clientId,r),n.set(t,Object.assign(Object.assign({},o),{clauses:i})),{selections:n}})},clearClause(t,r){e(e=>{const n=e.selections.get(t);if(!n)return{};const o=new Map(e.selections),i=new Map(n.clauses);return i.delete(r),o.set(t,Object.assign(Object.assign({},n),{clauses:i})),{selections:o}})},setResolution(t,r){e(e=>{const n=new Map(e.selections),o=Ot(n,t);return n.set(t,Object.assign(Object.assign({},o),{resolution:r})),{selections:n}})},clearSelection(t){e(e=>{const r=new Map(e.selections),n=r.get(t);return n&&r.set(t,Object.assign(Object.assign({},n),{clauses:new Map})),{selections:r}})}}));function $t(e){const t=d(),r=e.clientId||t,{name:n}=e,o=Wt(e=>e.selections.get(n)),c=Wt(e=>e.setClause),s=Wt(e=>e.clearClause),l=i(()=>!!o&&o.clauses.size>0,[o]);return{predicate:i(()=>o&&0!==o.clauses.size?function(e,t){const r=[];for(const[n,o]of e.clauses)"crossfilter"===e.resolution&&n===t||r.push(Tt(o));return 0===r.length?()=>!0:"intersect"===e.resolution?e=>r.every(t=>t(e)):e=>r.some(t=>t(e))}(o,r):()=>!0,[o,r]),isActive:l,selectPoints:a(e=>{const t={};for(const[r,n]of Object.entries(e))t[r]={type:"point",values:new Set(n)};c(n,{clientId:r,type:"point",fields:t})},[r,n,c]),selectInterval:a(e=>{const t={};for(const[r,n]of Object.entries(e))t[r]={type:"interval",range:n};c(n,{clientId:r,type:"interval",fields:t})},[r,n,c]),clear:a(()=>{s(n,r)},[s,n,r]),clientId:r}}const[_t,It]=Pt(e=>({observations:[],maxObservations:100,version:0,pushObservation(t){e(e=>{const r=e.observations;return r.push(t),r.length>e.maxObservations&&r.shift(),{version:e.version+1}})},clearObservations(){e(()=>({observations:[],version:0}))}})),Mt="#007bff";function jt(e,t,r="category10"){const n=s(Dt);return i(()=>{if(t&&"function"!=typeof t)return n&&Object.keys(n).length>0?o=>n[o]||yt(e,t,r)(o):yt(e,t,r)},[e,t,r,n])}function Ct({selection:e,linkedHover:t,fallbackFields:r=[],unwrapData:n=!1,onObservation:o,chartType:i,chartId:c}){const s=function(e,t){return e?!0===e?{name:"hover",fields:t||[]}:"string"==typeof e?{name:e,fields:t||[]}:{name:e.name||"hover",fields:e.fields}:null}(t,r),l=$t({name:(null==e?void 0:e.name)||"__unused__"}),u=function(e){const t=e.name||"hover",{fields:r}=e,{predicate:n,isActive:o,selectPoints:i,clear:c}=$t({name:t});return{onHover:a(e=>{if(!e)return void c();const t={};for(const n of r){const r=e[n];void 0!==r&&(t[n]=[r])}Object.keys(t).length>0&&i(t)},[r,i,c,t]),predicate:n,isActive:o}}({name:(null==s?void 0:s.name)||"hover",fields:(null==s?void 0:s.fields)||r||[]}),d=It(e=>e.pushObservation);return{activeSelectionHook:e?{isActive:l.isActive,predicate:l.predicate}:null,customHoverBehavior:a(e=>{var r,n;if(t)if(e){let t=e.data||e.datum||e;Array.isArray(t)&&(t=t[0]),u.onHover(t)}else u.onHover(null);if(o||d){const t={timestamp:Date.now(),chartType:i||"unknown",chartId:c};if(e){let i=e.data||e.datum||e;Array.isArray(i)&&(i=i[0]);const a=Object.assign(Object.assign({},t),{type:"hover",datum:i||{},x:null!==(r=e.x)&&void 0!==r?r:0,y:null!==(n=e.y)&&void 0!==n?n:0});o&&o(a),d&&d(a)}else{const e=Object.assign(Object.assign({},t),{type:"hover-end"});o&&o(e),d&&d(e)}}},[t,u,o,i,c,d]),customClickBehavior:a(e=>{var t,r;if(o||d){const n={timestamp:Date.now(),chartType:i||"unknown",chartId:c};if(e){let i=e.data||e.datum||e;Array.isArray(i)&&(i=i[0]);const a=Object.assign(Object.assign({},n),{type:"click",datum:i||{},x:null!==(t=e.x)&&void 0!==t?t:0,y:null!==(r=e.y)&&void 0!==r?r:0});o&&o(a),d&&d(a)}else{const e=Object.assign(Object.assign({},n),{type:"click-end"});o&&o(e),d&&d(e)}}},[o,d,i,c])}}const Rt={primary:{width:600,height:400,showAxes:!0,showGrid:!1,enableHover:!0,showLegend:void 0,showLabels:void 0,marginDefaults:{top:50,bottom:60,left:70,right:40}},context:{width:400,height:250,showAxes:!1,showGrid:!1,enableHover:!1,showLegend:!1,showLabels:!1,marginDefaults:{top:10,bottom:10,left:10,right:10}},sparkline:{width:120,height:24,showAxes:!1,showGrid:!1,enableHover:!1,showLegend:!1,showLabels:!1,marginDefaults:{top:2,bottom:2,left:0,right:0}}};function Bt(e,t,r){var n,o,i,a,c,s;const l=Rt[e||"primary"],u="context"===e||"sparkline"===e;return{width:null!==(n=t.width)&&void 0!==n?n:e&&"primary"!==e||!(null==r?void 0:r.width)?l.width:r.width,height:null!==(o=t.height)&&void 0!==o?o:e&&"primary"!==e||!(null==r?void 0:r.height)?l.height:r.height,showAxes:l.showAxes,showGrid:null!==(i=t.showGrid)&&void 0!==i?i:l.showGrid,enableHover:null!==(a=t.enableHover)&&void 0!==a?a:!!t.linkedHover||l.enableHover,showLegend:null!==(c=t.showLegend)&&void 0!==c?c:l.showLegend,showLabels:null!==(s=t.showLabels)&&void 0!==s?s:l.showLabels,title:u?void 0:t.title,xLabel:u?void 0:t.xLabel,yLabel:u?void 0:t.yLabel,categoryLabel:u?void 0:t.categoryLabel,valueLabel:u?void 0:t.valueLabel,marginDefaults:l.marginDefaults}}function Ft({componentName:t,message:r,width:n,height:o}){return e.createElement("div",{role:"alert",style:{width:n,height:Math.max(o,120),display:"flex",alignItems:"center",justifyContent:"center",border:"1px dashed rgba(128, 128, 128, 0.4)",borderRadius:8,background:"rgba(128, 128, 128, 0.04)",padding:24,boxSizing:"border-box"}},e.createElement("div",{style:{textAlign:"center",maxWidth:400}},e.createElement("div",{style:{fontSize:13,fontWeight:600,color:"rgba(128, 128, 128, 0.7)",marginBottom:6,fontFamily:"monospace"}},t),e.createElement("div",{style:{fontSize:14,color:"rgba(128, 128, 128, 0.9)",lineHeight:1.5}},r)))}class zt extends e.Component{constructor(e){super(e),this.state={error:null}}static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){var r,n;null===(n=(r=this.props).onError)||void 0===n||n.call(r,e,t)}render(){if(this.state.error){const{fallback:t}=this.props,r=this.state.error;return"function"==typeof t?t(r):void 0!==t?t:e.createElement(Ft,{componentName:"ChartErrorBoundary",message:r.message||"An unexpected error occurred while rendering this chart.",width:600,height:400})}return this.props.children}}function Ht({componentName:t,width:r,height:n,children:o}){return e.createElement(zt,{fallback:o=>e.createElement(Ft,{componentName:t,message:o.message,width:r,height:n})},o)}function Yt(e,t){if(0===t.length)return null;const r=e.toLowerCase();return t.find(e=>e.toLowerCase().includes(r)||r.includes(e.toLowerCase()))||t[0]}function Xt({componentName:e,data:t,dataLabel:r="data"}){return null==t?`${e}: No ${r} provided. Pass a hierarchical object with children: { name: "root", children: [...] }.`:Array.isArray(t)?`${e}: ${r} should be a single root object, not an array. Expected: { name: "root", children: [...] }. If you have flat data, use LineChart, BarChart, or Scatterplot instead.`:null}function Gt({componentName:e,nodes:t,edges:r,nodesRequired:n=!1,edgesRequired:o=!0,accessors:i}){if(o&&(!r||!Array.isArray(r)||0===r.length))return e+': No edges provided. Pass a non-empty array: edges={[{ source: "A", target: "B", value: 10 }, ...]}.';if(n&&(!t||!Array.isArray(t)||0===t.length))return e+': No nodes provided. Pass a non-empty array: nodes={[{ id: "A" }, { id: "B" }, ...]}.';if(i&&t&&t.length>0){const r=(a=t,a.length>3?[a[0],a[Math.floor(a.length/2)],a[a.length-1]]:a).find(e=>e&&"object"==typeof e);if(r){const t=Object.keys(r);for(const[n,o]of Object.entries(i))if(o&&"string"==typeof o&&!(o in r)){const r=Yt(o,t),i=r?` Try ${n}="${r}".`:"";return`${e}: ${n} "${o}" not found in node data. Available fields: ${t.join(", ")}.${i}`}}}var a;return null}function qt(t){var r;const n=Bt(t.mode,{width:t.width,height:t.height,enableHover:t.enableHover,showLegend:t.showLegend,showLabels:t.showLabels,title:t.title},{width:600,height:600}),{nodes:o,edges:a,margin:c,className:s,nodeIDAccessor:l="id",sourceAccessor:u="source",targetAccessor:d="target",nodeLabel:h,colorBy:f,colorScheme:y="category10",nodeSize:g=8,nodeSizeRange:p=[5,20],edgeWidth:v=1,edgeColor:m="#999",edgeOpacity:b=.6,iterations:x=300,forceStrength:k=.1,tooltip:w,frameProps:L={},onObservation:E,chartId:A,selection:D,linkedHover:P}=t,S=n.width,T=n.height,O=n.enableHover,N=n.showLegend,W=null!==(r=n.showLabels)&&void 0!==r&&r,$=n.title,_=o||[],I=a||[],M=jt(_,f,y),j=i(()=>e=>{const t={};return t.fill=f?ft(e.data||e,f,M):Mt,"number"==typeof g&&(t.r=g),t},[f,M,g]),C=i(()=>e=>({stroke:m,strokeWidth:"number"==typeof v?v:"function"==typeof v?v(e):e[v]||1,opacity:b}),[v,m,b]),R=i(()=>{if(W&&h)return"function"==typeof h?h:e=>e[h]},[W,h]),{legend:B,margin:F}=function({data:e,colorBy:t,colorScale:r,showLegend:n,userMargin:o,defaults:a={top:50,bottom:60,left:70,right:40}}){const c=void 0!==n?n:!!t,s=i(()=>{if(c&&t)return function({data:e,colorBy:t,colorScale:r,getColor:n,strokeColor:o,strokeWidth:i}){const a=Array.from(new Set(e.map(e=>"function"==typeof t?t(e):e[t]))).map(o=>{const i=e.find("function"==typeof t?e=>t(e)===o:e=>e[t]===o),a=i?n(i,t,r):r?r(o):"#000000";return{label:o+"",color:a}});return{legendGroups:[{styleFn:e=>{const t={fill:e.color,stroke:e.color};return void 0!==o&&(t.stroke=o),void 0!==i&&(t.strokeWidth=i),t},type:"fill",items:a,label:""}]}}({data:e,colorBy:t,colorScale:r,getColor:ft})},[c,t,e,r]),l=i(()=>{const e=Object.assign(Object.assign({},a),o);return s&&120>e.right&&(e.right=120),e},[a,o,s]);return{legend:s,margin:l}}({data:_,colorBy:f,colorScale:M,showLegend:N,userMargin:c,defaults:n.marginDefaults}),{customHoverBehavior:z}=Ct({selection:D,linkedHover:P,fallbackFields:f?["string"==typeof f?f:""]:[],unwrapData:!0,onObservation:E,chartType:"ForceDirectedGraph",chartId:A}),H=Gt({componentName:"ForceDirectedGraph",nodes:o,edges:a,nodesRequired:!0,edgesRequired:!0,accessors:{nodeIDAccessor:l}});return H?e.createElement(Ft,{componentName:"ForceDirectedGraph",message:H,width:S,height:T}):e.createElement(Ht,{componentName:"ForceDirectedGraph",width:S,height:T},e.createElement(kt,Object.assign({chartType:"force",nodes:_,edges:I,size:[S,T],responsiveWidth:t.responsiveWidth,responsiveHeight:t.responsiveHeight,margin:F,nodeIDAccessor:l,sourceAccessor:u,targetAccessor:d,iterations:x,forceStrength:k,nodeStyle:j,edgeStyle:C,colorBy:f,colorScheme:y,nodeSize:g,nodeSizeRange:p,nodeLabel:R,showLabels:W,enableHover:O,tooltipContent:w?e=>At(w)(e.data):void 0,customHoverBehavior:P||E?z:void 0,legend:B,className:s,title:$},L)))}function Vt(e,t){if(!e)return[];const r=[],n=e=>{r.push(e);const o="function"==typeof t?t(e):e[t];o&&Array.isArray(o)&&o.forEach(n)};return n(e),r}function Zt(e,t,r,n){if(e&&e.length>0)return e;const o=new Set;return t.forEach(e=>{const t="function"==typeof r?r(e):e[r],i="function"==typeof n?n(e):e[n];o.add(t),o.add(i)}),Array.from(o).map(e=>({id:e}))}function Kt(e){return"function"==typeof e?e:t=>t[e]||1}function Qt({edgeColorBy:e,colorBy:t,colorScale:r,nodeStyleFn:n,edgeOpacity:o,baseStyle:i={}}){return a=>{const c=Object.assign({fillOpacity:o},i);if("function"==typeof e)c.fill=e(a);else if("source"===e){const e="object"==typeof a.source?a.source:null;t&&e?c.fill=ft(e.data||e,t,r):e&&(c.fill=n(e,e.index).fill)}else if("target"===e){const e="object"==typeof a.target?a.target:null;t&&e?c.fill=ft(e.data||e,t,r):e&&(c.fill=n(e,e.index).fill)}else"gradient"===e&&(c.fill="#999",c.fillOpacity=.7*o);return c}}function Jt(t){var r;const n=Bt(t.mode,{width:t.width,height:t.height,enableHover:t.enableHover,showLabels:t.showLabels,title:t.title},{width:800,height:600}),{nodes:o,edges:a,margin:c,className:s,sourceAccessor:l="source",targetAccessor:u="target",valueAccessor:d="value",nodeIdAccessor:h="id",colorBy:f,colorScheme:y="category10",edgeColorBy:g="source",orientation:p="horizontal",nodeAlign:v="justify",nodePaddingRatio:m=.05,nodeWidth:b=15,nodeLabel:x,edgeOpacity:k=.5,edgeSort:w,tooltip:L,frameProps:E={},onObservation:A,chartId:D,selection:P,linkedHover:S}=t,T=n.width,O=n.height,N=n.enableHover,W=null===(r=n.showLabels)||void 0===r||r,$=n.title,_=a||[],I=i(()=>Zt(o,_,l,u),[o,_,l,u]),M=jt(I,f,y),j=i(()=>e=>{const t={stroke:"black",strokeWidth:1};return t.fill=f?ft(e.data||e,f,M):"#4d430c",t},[f,M]),C=i(()=>Qt({edgeColorBy:g,colorBy:f,colorScale:M,nodeStyleFn:j,edgeOpacity:k,baseStyle:{stroke:"none",strokeWidth:0}}),[g,f,M,j,k]),R=i(()=>{if(!W)return;const e=x||h;return"function"==typeof e?e:t=>t[e]},[W,x,h]),B=Object.assign(Object.assign({},n.marginDefaults),c),{customHoverBehavior:F,customClickBehavior:z}=Ct({selection:P,linkedHover:S,fallbackFields:f?["string"==typeof f?f:""]:[],unwrapData:!0,onObservation:A,chartType:"SankeyDiagram",chartId:D}),H=Gt({componentName:"SankeyDiagram",edges:a,edgesRequired:!0});return H?e.createElement(Ft,{componentName:"SankeyDiagram",message:H,width:T,height:O}):e.createElement(Ht,{componentName:"SankeyDiagram",width:T,height:O},e.createElement(kt,Object.assign({chartType:"sankey",nodes:I,edges:_,size:[T,O],responsiveWidth:t.responsiveWidth,responsiveHeight:t.responsiveHeight,margin:B,nodeIDAccessor:h,sourceAccessor:l,targetAccessor:u,valueAccessor:d,orientation:p,nodeAlign:v,nodePaddingRatio:m,nodeWidth:b,nodeStyle:j,edgeStyle:C,colorBy:f,colorScheme:y,edgeColorBy:g,edgeOpacity:k,edgeSort:w,nodeLabel:R,showLabels:W,enableHover:N,tooltipContent:L?e=>At(L)(e.data):void 0,customHoverBehavior:S||A?F:void 0,customClickBehavior:A?z:void 0,className:s,title:$},E)))}function Ut(t){var r;const n=Bt(t.mode,{width:t.width,height:t.height,enableHover:t.enableHover,showLabels:t.showLabels,title:t.title},{width:600,height:600}),{nodes:o,edges:a,margin:c,className:s,sourceAccessor:l="source",targetAccessor:u="target",valueAccessor:d="value",nodeIdAccessor:h="id",colorBy:f,colorScheme:y="category10",edgeColorBy:g="source",padAngle:p=.01,groupWidth:v=20,sortGroups:m,nodeLabel:b,edgeOpacity:x=.5,tooltip:k,frameProps:w={},onObservation:L,chartId:E,selection:A,linkedHover:D}=t,P=n.width,S=n.height,T=n.enableHover,O=null===(r=n.showLabels)||void 0===r||r,N=n.title,W=a||[],$=i(()=>Zt(o,W,l,u),[o,W,l,u]),_=jt($,f,y),I=i(()=>(e,t)=>{var r,n;const o={stroke:"black",strokeWidth:1};if(f)o.fill=ft(e.data||e,f,_);else{const i=Array.isArray(y)?y:ut[y]||dt,a=Array.isArray(i)?i:dt,c=null!==(n=null!==(r=e.index)&&void 0!==r?r:t)&&void 0!==n?n:0;o.fill=a[c%a.length]}return o},[f,_,y]),M=i(()=>Qt({edgeColorBy:g,colorBy:f,colorScale:_,nodeStyleFn:I,edgeOpacity:x,baseStyle:{stroke:"black",strokeWidth:.5,strokeOpacity:x}}),[g,f,_,I,x]),j=i(()=>{if(!O)return;const e=b||h;return"function"==typeof e?e:t=>t[e]},[O,b,h]),C=Object.assign(Object.assign({},n.marginDefaults),c),{customHoverBehavior:R}=Ct({selection:A,linkedHover:D,fallbackFields:f?["string"==typeof f?f:""]:[],unwrapData:!0,onObservation:L,chartType:"ChordDiagram",chartId:E}),B=Gt({componentName:"ChordDiagram",edges:a,edgesRequired:!0});return B?e.createElement(Ft,{componentName:"ChordDiagram",message:B,width:P,height:S}):e.createElement(Ht,{componentName:"ChordDiagram",width:P,height:S},e.createElement(kt,Object.assign({chartType:"chord",nodes:$,edges:W,size:[P,S],responsiveWidth:t.responsiveWidth,responsiveHeight:t.responsiveHeight,margin:C,nodeIDAccessor:h,sourceAccessor:l,targetAccessor:u,valueAccessor:d,padAngle:p,groupWidth:v,sortGroups:m,nodeStyle:I,edgeStyle:M,colorBy:f,colorScheme:y,edgeColorBy:g,edgeOpacity:x,nodeLabel:j,showLabels:O,enableHover:T,tooltipContent:k?e=>At(k)(e.data):void 0,customHoverBehavior:D||L?R:void 0,className:s,title:N},w)))}function er(t){var r;const n=Bt(t.mode,{width:t.width,height:t.height,enableHover:t.enableHover,showLabels:t.showLabels,title:t.title},{width:600,height:600}),{data:o,margin:a,className:c,layout:s="tree",orientation:l="vertical",childrenAccessor:u="children",valueAccessor:d="value",nodeIdAccessor:h="name",colorBy:f,colorScheme:y="category10",colorByDepth:g=!1,edgeStyle:p="curve",nodeLabel:v,nodeSize:m=5,tooltip:b,frameProps:x={},onObservation:k,chartId:w,selection:L,linkedHover:E}=t,A=n.width,D=n.height,P=n.enableHover,S=null===(r=n.showLabels)||void 0===r||r,T=n.title,O=jt(i(()=>Vt(o,u),[o,u]),g?void 0:f,y),N=i(()=>e=>{const t={stroke:"black",strokeWidth:1};return t.fill=g?ht[(e.depth||0)%ht.length]:f?ft(e.data||e,f,O):Mt,t},[f,g,O]),W=i(()=>()=>({stroke:"#999",strokeWidth:1,fill:"none"}),[]),$=i(()=>{if("treemap"===s||"circlepack"===s||"partition"===s)return Kt(d)},[s,d]),_=Object.assign(Object.assign({},n.marginDefaults),a),{customHoverBehavior:I}=Ct({selection:L,linkedHover:E,fallbackFields:f?["string"==typeof f?f:""]:[],unwrapData:!0,onObservation:k,chartType:"TreeDiagram",chartId:w}),M=Xt({componentName:"TreeDiagram",data:o});return M?e.createElement(Ft,{componentName:"TreeDiagram",message:M,width:A,height:D}):e.createElement(Ht,{componentName:"TreeDiagram",width:A,height:D},e.createElement(kt,Object.assign({chartType:s,data:o,size:[A,D],responsiveWidth:t.responsiveWidth,responsiveHeight:t.responsiveHeight,margin:_,nodeIDAccessor:h,childrenAccessor:u,hierarchySum:$,treeOrientation:l,edgeType:p,nodeStyle:N,edgeStyle:W,colorBy:f,colorScheme:y,colorByDepth:g,nodeSize:m,nodeLabel:S?v||h:void 0,showLabels:S,enableHover:P,tooltipContent:b?e=>At(b)(e.data):void 0,customHoverBehavior:E||k?I:void 0,className:c,title:T},x)))}function tr(t){var r;const n=Bt(t.mode,{width:t.width,height:t.height,enableHover:t.enableHover,showLabels:t.showLabels,title:t.title,linkedHover:t.linkedHover},{width:600,height:600}),{data:o,margin:c,className:s,childrenAccessor:l="children",valueAccessor:u="value",nodeIdAccessor:d="name",colorBy:h,colorScheme:f="category10",colorByDepth:y=!1,labelMode:g="leaf",nodeLabel:p,padding:v=4,paddingTop:m,tooltip:b,frameProps:x={},selection:k,linkedHover:w,onObservation:L,chartId:E}=t,A=n.width,D=n.height,P=n.enableHover,S=null===(r=n.showLabels)||void 0===r||r,T=n.title,{activeSelectionHook:O,customHoverBehavior:N}=Ct({selection:k,linkedHover:w,fallbackFields:h?["string"==typeof h?h:""]:[],onObservation:L,chartType:"Treemap",chartId:E}),W=a(e=>{if(!e)return N(null);const t=e.data||e;N({data:(null==t?void 0:t.data)||t})},[N]),$=jt(i(()=>Vt(o,l),[o,l]),y?void 0:h,f),_=i(()=>e=>{const t={stroke:"#fff",strokeWidth:1,strokeOpacity:.8};return t.fill=y?ht[(e.depth||0)%ht.length]:h?ft(e.data||e,h,$):Mt,t},[h,y,$]),I=i(()=>O?e=>{var t;const r=Object.assign({},_(e));if(O.isActive)if(O.predicate(e.data||e))(null==k?void 0:k.selectedStyle)&&Object.assign(r,k.selectedStyle);else{const e=null!==(t=null==k?void 0:k.unselectedOpacity)&&void 0!==t?t:.2;r.opacity=e,r.fillOpacity=e,r.strokeOpacity=e,(null==k?void 0:k.unselectedStyle)&&Object.assign(r,k.unselectedStyle)}return r}:_,[_,O,k]),M=i(()=>Kt(u),[u]),j=void 0!==m?m:S&&"parent"===g?18:void 0,C=Object.assign(Object.assign({},n.marginDefaults),c),R=Xt({componentName:"Treemap",data:o});return R?e.createElement(Ft,{componentName:"Treemap",message:R,width:A,height:D}):e.createElement(Ht,{componentName:"Treemap",width:A,height:D},e.createElement(kt,Object.assign({chartType:"treemap",data:o,size:[A,D],responsiveWidth:t.responsiveWidth,responsiveHeight:t.responsiveHeight,margin:C,nodeIDAccessor:d,childrenAccessor:l,hierarchySum:M,padding:v,paddingTop:j,nodeStyle:I,colorBy:h,colorScheme:f,colorByDepth:y,nodeLabel:S?p||d:void 0,showLabels:S,enableHover:P,tooltipContent:b?e=>At(b)(e.data):void 0},(w||L)&&{customHoverBehavior:W},{className:s,title:T},x)))}function rr(t){var r;const n=Bt(t.mode,{width:t.width,height:t.height,enableHover:t.enableHover,showLabels:t.showLabels,title:t.title},{width:600,height:600}),{data:o,margin:a,className:c,childrenAccessor:s="children",valueAccessor:l="value",nodeIdAccessor:u="name",colorBy:d,colorScheme:h="category10",colorByDepth:f=!1,nodeLabel:y,circleOpacity:g=.7,padding:p=4,tooltip:v,frameProps:m={},onObservation:b,chartId:x,selection:k,linkedHover:w}=t,L=n.width,E=n.height,A=n.enableHover,D=null===(r=n.showLabels)||void 0===r||r,P=n.title,S=jt(i(()=>Vt(o,s),[o,s]),f?void 0:d,h),T=i(()=>e=>{const t={stroke:"currentColor",strokeWidth:1,strokeOpacity:.3,fillOpacity:g};return t.fill=f?ht[(e.depth||0)%ht.length]:d?ft(e.data||e,d,S):Mt,t},[d,f,S,g]),O=i(()=>Kt(l),[l]),N=Object.assign(Object.assign({},n.marginDefaults),a),{customHoverBehavior:W}=Ct({selection:k,linkedHover:w,fallbackFields:d?["string"==typeof d?d:""]:[],unwrapData:!0,onObservation:b,chartType:"CirclePack",chartId:x}),$=Xt({componentName:"CirclePack",data:o});return $?e.createElement(Ft,{componentName:"CirclePack",message:$,width:L,height:E}):e.createElement(Ht,{componentName:"CirclePack",width:L,height:E},e.createElement(kt,Object.assign({chartType:"circlepack",data:o,size:[L,E],responsiveWidth:t.responsiveWidth,responsiveHeight:t.responsiveHeight,margin:N,nodeIDAccessor:u,childrenAccessor:s,hierarchySum:O,padding:p,nodeStyle:T,colorBy:d,colorScheme:h,colorByDepth:f,nodeLabel:D?y||u:void 0,showLabels:D,enableHover:A,tooltipContent:v?e=>At(v)(e.data):void 0,customHoverBehavior:w||b?W:void 0,className:c,title:P},m)))}"undefined"!=typeof process&&process,qt.displayName="ForceDirectedGraph",Jt.displayName="SankeyDiagram",Ut.displayName="ChordDiagram",er.displayName="TreeDiagram",tr.displayName="Treemap",rr.displayName="CirclePack";export{Ut as ChordDiagram,rr as CirclePack,qt as ForceDirectedGraph,Jt as SankeyDiagram,kt as StreamNetworkFrame,er as TreeDiagram,tr as Treemap};