semiotic 3.10.0 → 3.10.1

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 (191) hide show
  1. package/README.md +55 -59
  2. package/ai/artifact-surface-inventory.json +1 -1
  3. package/ai/componentMetadata.cjs +3 -1
  4. package/ai/dist/mcp-server.js +45 -45
  5. package/ai/examples.md +67 -0
  6. package/ai/reference.md +75 -1
  7. package/ai/schema.json +5199 -1
  8. package/ai/surface-manifest.json +24 -3
  9. package/ai/task-packets/compare-category-totals.json +6 -6
  10. package/ai/task-packets/compare-category-totals.md +3 -3
  11. package/ai/task-packets/correct-published-chart.json +6 -6
  12. package/ai/task-packets/correct-published-chart.md +3 -3
  13. package/ai/task-packets/index.json +6 -6
  14. package/ai/task-packets/update-live-chart.json +6 -6
  15. package/ai/task-packets/update-live-chart.md +3 -3
  16. package/dist/c-2RL2QPZJ.min.js +1 -0
  17. package/dist/c-45CQWZZ6.min.js +1 -0
  18. package/dist/{c-PP6VY3QU.min.js → c-4BRHKVKV.min.js} +1 -1
  19. package/dist/c-7DVPSB5C.min.js +1 -0
  20. package/dist/{c-XDQKXPX4.min.js → c-A7OGOFSL.min.js} +1 -1
  21. package/dist/{c-AZKPVBOC.min.js → c-AH5HWZWS.min.js} +1 -1
  22. package/dist/c-B7GW7IHJ.min.js +1 -0
  23. package/dist/{c-ROEHCIGV.min.js → c-C3TZLTZK.min.js} +1 -1
  24. package/dist/c-CGQAQWBV.min.js +1 -0
  25. package/dist/c-DIPEYUOW.min.js +1 -0
  26. package/dist/{c-WNGH47HF.min.js → c-E72OTUZU.min.js} +1 -1
  27. package/dist/{c-DY2676CR.min.js → c-EUMPMDCS.min.js} +1 -1
  28. package/dist/c-EZZT2WAE.min.js +1 -0
  29. package/dist/c-FHBVFCQB.min.js +1 -0
  30. package/dist/{c-E32M6XW5.min.js → c-G4HCO2IQ.min.js} +1 -1
  31. package/dist/{c-ZYPXQF7B.min.js → c-G5VIJEOK.min.js} +1 -1
  32. package/dist/c-GHVOXAYH.min.js +1 -0
  33. package/dist/{c-EBOQ7ER7.min.js → c-HP4ZFM47.min.js} +1 -1
  34. package/dist/{c-IDJV3CZK.min.js → c-HYDTS5OP.min.js} +1 -1
  35. package/dist/c-IK33LNZ6.min.js +1 -0
  36. package/dist/c-IK3PZHRY.min.js +1 -0
  37. package/dist/{c-JO2UGTCP.min.js → c-J6DVC236.min.js} +1 -1
  38. package/dist/{c-MXCP7GNZ.min.js → c-JIMJF6F6.min.js} +1 -1
  39. package/dist/{c-4FN7Q6VQ.min.js → c-KKPMHAZC.min.js} +1 -1
  40. package/dist/c-L6WNDBHV.min.js +1 -0
  41. package/dist/c-LDEX5OFW.min.js +1 -0
  42. package/dist/{c-CPSPZH6A.min.js → c-LESEUVC5.min.js} +1 -1
  43. package/dist/c-MB6CV5NC.min.js +1 -0
  44. package/dist/{c-OO5QLMJC.min.js → c-MOKJOIPE.min.js} +1 -1
  45. package/dist/{c-BNG5ECK5.min.js → c-N3FXLRNT.min.js} +1 -1
  46. package/dist/c-N5NPTJVJ.min.js +1 -0
  47. package/dist/{c-DE5Q3U2X.min.js → c-NHBL4J67.min.js} +1 -1
  48. package/dist/{c-LMGSSD2E.min.js → c-ODG6TFSY.min.js} +1 -1
  49. package/dist/{c-HXDKPIKR.min.js → c-PSKKFZNP.min.js} +1 -1
  50. package/dist/{c-NYZ2QNAM.min.js → c-R2P4RR7Q.min.js} +1 -1
  51. package/dist/{c-KCRJGUHP.min.js → c-RFC7UAG7.min.js} +1 -1
  52. package/dist/c-SGAURYHG.min.js +1 -0
  53. package/dist/{c-DK662R77.min.js → c-SJMWU6UX.min.js} +1 -1
  54. package/dist/c-STIIGQOD.min.js +1 -0
  55. package/dist/c-T2ASIJVZ.min.js +1 -0
  56. package/dist/c-TX3THUTO.min.js +1 -0
  57. package/dist/{c-55BAJ333.min.js → c-TX7XJM3Z.min.js} +1 -1
  58. package/dist/c-UMXSJIOV.min.js +1 -0
  59. package/dist/{c-JLGRHXGZ.min.js → c-VRSXMLYF.min.js} +1 -1
  60. package/dist/c-VSLWSAN2.min.js +1 -0
  61. package/dist/{c-33QOXEUG.min.js → c-WCBRPILW.min.js} +1 -1
  62. package/dist/{c-WH2O53VI.min.js → c-WGHT7OCY.min.js} +1 -1
  63. package/dist/c-WWCW3APR.min.js +1 -0
  64. package/dist/c-Y6PYUMFU.min.js +1 -0
  65. package/dist/c-ZIVPFTOC.min.js +1 -0
  66. package/dist/components/charts/shared/chartDataProps.d.ts +3 -0
  67. package/dist/components/charts/shared/chartSpecAtlasSchemas.d.ts +5 -0
  68. package/dist/components/charts/shared/chartSpecCore.d.ts +4 -0
  69. package/dist/components/charts/shared/chartSpecsAtlas.d.ts +2 -0
  70. package/dist/components/charts/shared/hooks.d.ts +3 -1
  71. package/dist/components/charts/shared/knownChartComponents.d.ts +1 -1
  72. package/dist/components/recipes/atlas/DependencyForestChart.d.ts +20 -0
  73. package/dist/components/recipes/atlas/DependencyMatrix.d.ts +7 -0
  74. package/dist/components/recipes/atlas/FlowCircuitChart.d.ts +20 -0
  75. package/dist/components/recipes/atlas/MotifBraidChart.d.ts +17 -0
  76. package/dist/components/recipes/atlas/atlasChartOptions.d.ts +11 -0
  77. package/dist/components/recipes/atlas/braid.d.ts +62 -0
  78. package/dist/components/recipes/atlas/capsules.d.ts +18 -0
  79. package/dist/components/recipes/atlas/compare.d.ts +4 -0
  80. package/dist/components/recipes/atlas/completeness.d.ts +2 -0
  81. package/dist/components/recipes/atlas/dependencyForest.d.ts +32 -0
  82. package/dist/components/recipes/atlas/dependencyForestChartProps.d.ts +58 -0
  83. package/dist/components/recipes/atlas/dependencyForestLayout.d.ts +17 -0
  84. package/dist/components/recipes/atlas/dependencyQueries.d.ts +20 -0
  85. package/dist/components/recipes/atlas/dependencyTypes.d.ts +21 -0
  86. package/dist/components/recipes/atlas/directedGraph.d.ts +9 -0
  87. package/dist/components/recipes/atlas/entityCounts.d.ts +3 -0
  88. package/dist/components/recipes/atlas/flowCircuit.d.ts +32 -0
  89. package/dist/components/recipes/atlas/flowCircuitChartProps.d.ts +72 -0
  90. package/dist/components/recipes/atlas/flowCircuitChrome.d.ts +18 -0
  91. package/dist/components/recipes/atlas/flowCircuitGeometry.d.ts +11 -0
  92. package/dist/components/recipes/atlas/flowCircuitLayout.d.ts +20 -0
  93. package/dist/components/recipes/atlas/flowCircuitSemantics.d.ts +26 -0
  94. package/dist/components/recipes/atlas/flowCircuitTape.d.ts +22 -0
  95. package/dist/components/recipes/atlas/flowCircuitTypes.d.ts +144 -0
  96. package/dist/components/recipes/atlas/forests.d.ts +11 -0
  97. package/dist/components/recipes/atlas/ids.d.ts +6 -0
  98. package/dist/components/recipes/atlas/index.d.ts +26 -0
  99. package/dist/components/recipes/atlas/ledger.d.ts +7 -0
  100. package/dist/components/recipes/atlas/motifBraidChartProps.d.ts +51 -0
  101. package/dist/components/recipes/atlas/motifBraidGeometry.d.ts +5 -0
  102. package/dist/components/recipes/atlas/motifBraidLayout.d.ts +11 -0
  103. package/dist/components/recipes/atlas/motifs.d.ts +3 -0
  104. package/dist/components/recipes/atlas/prefixForest.d.ts +9 -0
  105. package/dist/components/recipes/atlas/prepare.d.ts +14 -0
  106. package/dist/components/recipes/atlas/prepareAsync.d.ts +7 -0
  107. package/dist/components/recipes/atlas/profile.d.ts +19 -0
  108. package/dist/components/recipes/atlas/publish.d.ts +10 -0
  109. package/dist/components/recipes/atlas/queries.d.ts +34 -0
  110. package/dist/components/recipes/atlas/requiredPaths.d.ts +9 -0
  111. package/dist/components/recipes/atlas/rootedForest.d.ts +4 -0
  112. package/dist/components/recipes/atlas/sections.d.ts +3 -0
  113. package/dist/components/recipes/atlas/support.d.ts +7 -0
  114. package/dist/components/recipes/atlas/types.d.ts +278 -0
  115. package/dist/components/recipes/atlas/validate.d.ts +12 -0
  116. package/dist/components/semiotic-atlas-core.d.ts +20 -0
  117. package/dist/components/semiotic-atlas.d.ts +8 -0
  118. package/dist/components/semiotic-recipes-core.d.ts +9 -0
  119. package/dist/components/server/serverChartConfigs.d.ts +3 -0
  120. package/dist/components/server/serverChartConfigsAtlas.d.ts +4 -0
  121. package/dist/components/stream/NetworkPipelineStore.d.ts +1 -0
  122. package/dist/components/stream/canvasSetup.d.ts +1 -2
  123. package/dist/components/stream/fontLoading.d.ts +4 -0
  124. package/dist/components/stream/networkCustomLayout.d.ts +8 -0
  125. package/dist/components/stream/networkCustomLayoutCache.d.ts +12 -0
  126. package/dist/components/stream/networkPipelineConfig.d.ts +0 -7
  127. package/dist/components/stream/physics/physicsSemanticUI.d.ts +2 -0
  128. package/dist/components/stream/physics/usePhysicsCanvasPointer.d.ts +3 -1
  129. package/dist/components/stream/physics/usePhysicsSemanticNavigation.d.ts +2 -0
  130. package/dist/components/stream/shallowEqual.d.ts +2 -0
  131. package/dist/components/stream/useEnsureCustomXYRenderers.d.ts +4 -2
  132. package/dist/geo.min.js +1 -1
  133. package/dist/geo.module.min.js +1 -1
  134. package/dist/network.module.min.js +1 -1
  135. package/dist/ordinal.module.min.js +1 -1
  136. package/dist/physics.module.min.js +1 -1
  137. package/dist/rough.module.min.js +1 -1
  138. package/dist/semiotic-access.module.min.js +1 -1
  139. package/dist/semiotic-ai-core.min.js +1 -1
  140. package/dist/semiotic-ai-core.module.min.js +1 -1
  141. package/dist/semiotic-ai.module.min.js +1 -1
  142. package/dist/semiotic-artifact.min.js +1 -1
  143. package/dist/semiotic-artifact.module.min.js +1 -1
  144. package/dist/semiotic-atlas-core.d.ts +20 -0
  145. package/dist/semiotic-atlas-core.min.js +1 -0
  146. package/dist/semiotic-atlas-core.module.min.js +1 -0
  147. package/dist/semiotic-atlas-selection.module.min.js +2 -0
  148. package/dist/semiotic-atlas.d.ts +8 -0
  149. package/dist/semiotic-atlas.min.js +2 -0
  150. package/dist/semiotic-atlas.module.min.js +2 -0
  151. package/dist/semiotic-client-cjs-shared.min.js +1 -1
  152. package/dist/semiotic-evidence.min.js +1 -1
  153. package/dist/semiotic-evidence.module.min.js +1 -1
  154. package/dist/semiotic-experimental-auxiliary.module.min.js +1 -1
  155. package/dist/semiotic-experimental-node-auxiliary.module.min.js +1 -1
  156. package/dist/semiotic-experimental-react-shared.module.min.js +1 -1
  157. package/dist/semiotic-experimental-vacp.min.js +1 -1
  158. package/dist/semiotic-experimental-vacp.module.min.js +1 -1
  159. package/dist/semiotic-line.module.min.js +1 -1
  160. package/dist/semiotic-realtime-core.module.min.js +1 -1
  161. package/dist/semiotic-recipes-core-cjs-base.min.js +1 -1
  162. package/dist/semiotic-recipes-core.d.ts +9 -0
  163. package/dist/semiotic-recipes-core.module.min.js +1 -1
  164. package/dist/semiotic-server-edge-node.module.min.js +1 -1
  165. package/dist/semiotic-server-edge.min.js +1 -1
  166. package/dist/semiotic-server-edge.module.min.js +1 -1
  167. package/dist/semiotic-server-node.min.js +1 -1
  168. package/dist/semiotic-server-node.module.min.js +1 -1
  169. package/dist/semiotic-text.min.js +1 -1
  170. package/dist/semiotic-text.module.min.js +1 -1
  171. package/dist/semiotic-utils-core.min.js +1 -1
  172. package/dist/semiotic-utils-core.module.min.js +1 -1
  173. package/dist/semiotic.module.min.js +1 -1
  174. package/dist/server.min.js +1 -1
  175. package/dist/server.module.min.js +1 -1
  176. package/dist/xy.module.min.js +1 -1
  177. package/package.json +16 -1
  178. package/dist/c-447VIMRO.min.js +0 -1
  179. package/dist/c-553QUDKA.min.js +0 -1
  180. package/dist/c-7HP7MB2I.min.js +0 -1
  181. package/dist/c-7NBU5ZKS.min.js +0 -1
  182. package/dist/c-CCTGN5CK.min.js +0 -1
  183. package/dist/c-GSZRZRD6.min.js +0 -1
  184. package/dist/c-GWX7JGMF.min.js +0 -1
  185. package/dist/c-ITKX3RC5.min.js +0 -1
  186. package/dist/c-JG2JCQLP.min.js +0 -1
  187. package/dist/c-LYVKDBQJ.min.js +0 -1
  188. package/dist/c-NG7BLZTR.min.js +0 -1
  189. package/dist/c-PYNW54D2.min.js +0 -1
  190. package/dist/c-TIXX5CAU.min.js +0 -1
  191. /package/dist/{c-OOVX2JPQ.min.js → c-UC7SIU2W.min.js} +0 -0
@@ -1 +1 @@
1
- function e(e,t){if("production"===process.env.NODE_ENV||!e||!e.data||"object"!=typeof e.data)return e;let r=Qr.get(e);if(r){let e=r.get(t);if(e)return e}else r=new Map,Qr.set(e,r);let i=new Proxy(e,{get(e,r,i){if("string"==typeof r&&!(r in e)&&e.data&&r in e.data){let e=`${t}:${r}`;Ur.has(e)||(Ur.add(e),console.warn(`[Semiotic] "${t}" callback accessed "${r}" on the wrapper object, but it only exists on ".data". Use d.data.${r} (or d.data?.${r}) instead. Frame callbacks receive RealtimeNode/RealtimeEdge wrappers, not your raw data.`))}return Reflect.get(e,r,i)}});return r.set(t,i),i}function t(e,t,r){let i=[];for(let a of t){let t=tr(a.source),n=tr(a.target),o=null;if(t===e?o=n:n===e&&(o=t),o){let e=r.get(o);e&&(0!==e.x||0!==e.y)&&i.push({x:e.x,y:e.y})}}return i}function r(e){let t=0;for(let r=0;e.length>r;r++)t=(t<<5)-t+e.charCodeAt(r)|0;return Math.abs(t)}function i(e){return e.data&&"object"==typeof e.data?e.data:e}function a(e,t,r){if(t)return r?.selectedStyle&&Object.assign(e,r.selectedStyle),e;let i=r?.unselectedOpacity??sr;return e.opacity=i,e.fillOpacity=i,e.strokeOpacity=i,r?.unselectedStyle&&Object.assign(e,r.unselectedStyle),e}function n(e,t,r){if(e)return t?n=>{let o={...e(n)};return t.isActive?a(o,t.predicate(i(n)),r):o}:e}function o(e,t,r){if(e)return t?n=>{let o={...e(n)};if(!t.isActive)return o;let l=i(n),s="object"==typeof n.source?i(n.source):null,c="object"==typeof n.target?i(n.target):null;return a(o,s||c?!!s&&t.predicate(s)||!!c&&t.predicate(c):t.predicate(l),r)}:e}function l(e,t){if(!e)return[];let r=[],i=e=>{r.push(e);let a="function"==typeof t?t(e):e[t];a&&Array.isArray(a)&&a.forEach(i)};return i(e),r}function s(e,t,r,i){if(e&&e.length>0)return e;let a=new Set;return t.forEach(e=>{let t="function"==typeof r?r(e):e[r],n="function"==typeof i?i(e):e[i];a.add(t),a.add(n)}),Array.from(a).map(e=>({id:e}))}function c(e){return"function"==typeof e?e:t=>t[e]||1}function u({edgeColorBy:e,colorBy:t,colorScale:r,nodeStyleFn:i,edgeOpacity:a,baseStyle:n={}}){return o=>{let l={fillOpacity:a,...n};if("function"==typeof e)l.fill=e(o);else if("source"===e){let e="object"==typeof o.source?o.source:null;t&&e?l.fill=Br(e.data||e,t,r):e&&(l.fill=i(e,e.index).fill)}else if("target"===e){let e="object"==typeof o.target?o.target:null;t&&e?l.fill=Br(e.data||e,t,r):e&&(l.fill=i(e,e.index).fill)}else"gradient"===e&&(l.fill="#999",l.fillOpacity=.7*a);return l}}function d(e){let{nodes:t,edges:r,inferNodes:i=!0,sourceAccessor:a="source",targetAccessor:n="target",colorBy:o,colorScheme:l,showLegend:c,legendPosition:u,legendInteraction:d,frameLegend:f,selection:h,linkedHover:g,onObservation:m,onClick:p,mobileInteraction:y,mobileSemantics:b,chartType:v,chartId:k,marginDefaults:x,userMargin:S,width:w,height:M,hasTitle:P,loading:L,loadingContent:T,emptyContent:A,emptyDataKey:D="edges"}=e,I=ei(()=>gr(r),[r]),E=ei(()=>gr(t),[t]),C=void 0===t&&void 0===r,[O,N]=ti([]),B=Jr(e=>{N(t=>t.length===e.length&&t.every((t,r)=>t===e[r])?t:e)},[]),$=br(L,w,M,T),H=$?null:yr("nodes"===D?void 0===t?void 0:E:void 0===r?void 0:I,w,M,A),R=ei(()=>i?s(E,I,a,n):E,[i,E,I,a,n]),F=Tr(R,o,l),W=Dr(),_=ei(()=>Array.isArray(l)&&l.length>0?l:[...$r(l,W,Cr)],[l,W]),z=ei(()=>hr(R,o),[R,o]),j=ei(()=>C&&O.length>0?O:z,[C,O,z]),X=ei(()=>{if(F)return F;if(!o||0===j.length)return;let e="__streamNetworkCategory";return Nr(j.map(t=>({[e]:t})),e,_)},[F,o,j,_]),Y=Ar(d,o,j),{legend:q,margin:G,legendPosition:V,legendMarginReserved:K}=Mr({data:R,colorBy:o,colorScale:X,showLegend:c,legendPosition:u,userMargin:S,defaults:x,categories:j,chartWidth:w,chartHeight:M,frameLegend:f,hasTitle:P}),U=ei(()=>{let e={};return q&&K&&(e.__legendMarginReservedFor=q),C&&o&&(e.legendCategoryAccessor=o,e.onCategoriesChange=B),e},[q,K,C,o,B]),Q=ei(()=>Sr(y,{width:w,mobileSemantics:b}),[y,w,b]),Z=Lr({selection:h,linkedHover:g,fallbackFields:o?["string"==typeof o?o:""]:[],unwrapData:!0,onObservation:m,onClick:p,mobileInteraction:Q,chartType:v,chartId:k}),{customHoverBehavior:J,customClickBehavior:ee,activeSelectionHook:te,hoverSelectionHook:re,crosshairSourceId:ie}=Z,ae=ei(()=>re||(Y.legendSelectionHook?Y.legendSelectionHook:te),[re,Y.legendSelectionHook,te]),ne=Ut(h);return{safeNodes:R,safeEdges:I,colorScale:X,effectivePalette:_,themeCategorical:W,allCategories:j,legendState:Y,legend:q,margin:G,legendPosition:V,legendBehaviorProps:U,mobileInteraction:Q,customHoverBehavior:J,customClickBehavior:ee,activeSelectionHook:te,hoverSelectionHook:re,effectiveSelectionHook:ae,resolvedSelection:ne,crosshairSourceId:ie,loadingEl:$,emptyEl:H}}function f(e,t,r){let i=e.match(/[a-zA-Z]|[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?/g);if(!i)return e;let a=[],n=0;for(;i.length>n;){let e=i[n];if("M"===e||"L"===e||"C"===e||"Q"===e)for(a.push(e),n++;i.length>n&&!isNaN(Number(i[n]));)a.push(Number(i[n])+t+""),n++,i.length>n&&!isNaN(Number(i[n]))&&(a.push(Number(i[n])+r+""),n++);else if("A"===e)for(a.push(e),n++;i.length>n&&!isNaN(Number(i[n]));)a.push(i[n++]),i.length>n&&a.push(i[n++]),i.length>n&&a.push(i[n++]),i.length>n&&a.push(i[n++]),i.length>n&&a.push(i[n++]),i.length>n&&(a.push(Number(i[n])+t+""),n++),i.length>n&&(a.push(Number(i[n])+r+""),n++);else"Z"===e||"z"===e?(a.push(e),n++):(a.push(i[n]),n++)}return a.join(" ")}function h(e,t){var r=e.get(t);if(!r)throw Error("missing: "+t);return r}function g(e,t){function r(e){c[e]=!1,u.hasOwnProperty(e)&&Object.keys(u[e]).forEach(function(t){delete u[e][t],c[t]&&r(t)})}function i(e){var t,n,l=!1;for(s.push(e),c[e]=!0,t=0;d[e].length>t;t++)(n=d[e][t])===o?(a(o,s),l=!0):c[n]||(l=i(n));if(l)r(e);else for(t=0;d[e].length>t;t++){var f=u[n=d[e][t]];f||(u[n]=f={}),f[n]=!0}return s.pop(),l}function a(e,r){var i=[].concat(r).concat(e);t?t(i):l.push(i)}function n(t){!function(t){for(var r=0;e.length>r;r++)(t>r||!e[r])&&(e[r]=[]),e[r]=e[r].filter(function(e){return e>=t})}(t);for(var r,i=function(e){function t(t){var r=[t],c=[t];for(i[t]=a[t]=d,n[t]=!0,d+=1;c.length>0;){var u=e[t=c[c.length-1]];if(u.length>o[t]){for(var g=o[t];u.length>g;++g){var m=u[g];if(0>i[m]){i[m]=a[m]=d,n[m]=!0,d+=1,r.push(m),c.push(m);break}n[m]&&(a[t]=0|Math.min(a[t],a[m])),l[m]>=0&&s[t].push(l[m])}o[t]=g}else{if(a[t]===i[t]){var p=[],y=[],b=0;for(g=r.length-1;g>=0;--g){var v=r[g];if(n[v]=!1,p.push(v),y.push(s[v]),b+=s[v].length,l[v]=f.length,v===t){r.length=g;break}}f.push(p);var k=Array(b);for(g=0;y.length>g;g++)for(var x=0;y[g].length>x;x++)k[--b]=y[g][x];h.push(k)}c.pop()}}}for(var r=e.length,i=Array(r),a=Array(r),n=Array(r),o=Array(r),l=Array(r),s=Array(r),c=0;r>c;++c)i[c]=-1,a[c]=0,n[c]=!1,o[c]=0,l[c]=-1,s[c]=[];var u,d=0,f=[],h=[];for(c=0;r>c;++c)0>i[c]&&t(c);for(c=0;h.length>c;c++){var g=h[c];if(0!==g.length){g.sort(function(e,t){return e-t}),u=[g[0]];for(var m=1;g.length>m;m++)g[m]!==g[m-1]&&u.push(g[m]);h[c]=u}}return{components:f,adjacencyList:h}}(e),a=i.components.filter(function(e){return e.length>1}),n=1/0,o=0;a.length>o;o++)for(var l=0;a[o].length>l;l++)n>a[o][l]&&(n=a[o][l],r=o);var s=a[r];return!!s&&{leastVertex:n,adjList:e.map(function(e,t){return-1===s.indexOf(t)?[]:e.filter(function(e){return-1!==s.indexOf(e)})})}}var o,l=[],s=[],c=[],u={},d=[];o=0;for(var f=e.length;f>o;){var h=n(o);if(o=h.leastVertex,d=h.adjList){for(var g=0;d.length>g;g++)for(var m=0;d[g].length>m;m++){var p=d[g][m];c[+p]=!1,u[p]={}}i(o),o+=1}else o=f}if(!t)return l}function m(e){return e.y0-e.y1>0?"up":"down"}function p(e,t){return t(e.source)==t(e.target)}function y(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}),!(t>1||r>1)}function b(e){return e.target.x0-e.source.x1}function v(e,t){var r=x(e),i=b(t)/Math.tan(r);return"up"==m(e)?e.y1-i:e.y1+i}function k(e,t){var r=x(e),i=b(t)/Math.tan(r);return"up"==m(e)?e.y1+i:e.y1-i}function x(e){var t=Math.abs(e.y1-e.y0);return Math.atan(Math.abs(e.target.x0-e.source.x1)/t)}function S(e,t){return t(e)}function w(e){return P(e.source)}function M(e){return P(e.target)}function P(e){return(e.y0+e.y1)/2}function L(e){return e.virtual?0:e.value}function T(e,t){var r=0;e.sourceLinks.forEach(function(e){r=e.circular&&!p(e,t)?r+1:r});var i=0;return e.targetLinks.forEach(function(e){i=e.circular&&!p(e,t)?i+1:i}),r+i}function A(e){return e.target.depth}function D(e,t){return e.sourceLinks.length?e.depth:t-1}function I(e,t){return e.y0-t.y0}function E(e,t){return t.y0-e.y0}function C(e,t){return e.y1-t.y1}function O(e,t){return t.y1-e.y1}function N(e,t){return $(e.source,t.source)||e.index-t.index}function B(e,t){return $(e.target,t.target)||e.index-t.index}function $(e,t){return e.partOfCycle===t.partOfCycle?e.y0-t.y0:"top"===e.circularLinkType||"bottom"===t.circularLinkType?-1:1}function H(e,t){return R(e)==R(t)?"bottom"==e.circularLinkType?E(e,t):I(e,t):R(t)-R(e)}function R(e){return e.target.column-e.source.column}function F(e,t){return W(e)==W(t)}function W(e){return e.y0-e.y1>0?"up":"down"}function _(e,t,r,i,a){let n=e;var o=Math.max(8,.15*(n.y1-n.y0));n.links.forEach(function(e){e.circular&&(e._circularWidth=Math.min(e.width,o))});var l=yi(n.links,function(e){return e.source.y0});n.links.forEach(function(e){e.circular&&(e.circularPathData={})});var s=n.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}),z(n.links.filter(function(e){return"top"==e.circularLinkType}),t,r),z(n.links.filter(function(e){return"bottom"==e.circularLinkType}),t,r),n.links.forEach(function(e){if(e.circular){if(e.circularPathData.arcRadius=e._circularWidth+i,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,p(e,t)&&y(e))e.circularPathData.rightSmallArcRadius=i+e._circularWidth/2,e.circularPathData.rightLargeArcRadius=i+e._circularWidth/2,e.circularPathData.leftSmallArcRadius=i+e._circularWidth/2,e.circularPathData.leftLargeArcRadius=i+e._circularWidth/2,"bottom"==e.circularLinkType?(e.circularPathData.verticalFullExtent=e.source.y1+a+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-a-e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.leftLargeArcRadius);else{var o=e.source.column,s=e.circularLinkType,c=n.links.filter(function(e){return e.source.column==o&&e.circularLinkType==s});c.sort("bottom"==e.circularLinkType?E:I);var u=0;c.forEach(function(t,a){t.circularLinkID==e.circularLinkID&&(e.circularPathData.rightSmallArcRadius=i+e._circularWidth/2+u,e.circularPathData.rightLargeArcRadius=i+e._circularWidth/2+a*r+u),u+=t._circularWidth||t.width}),o=e.target.column,(c=n.links.filter(function(e){return e.target.column==o&&e.circularLinkType==s})).sort("bottom"==e.circularLinkType?O:C),u=0,c.forEach(function(t,a){t.circularLinkID==e.circularLinkID&&(e.circularPathData.leftSmallArcRadius=i+e._circularWidth/2+u,e.circularPathData.leftLargeArcRadius=i+e._circularWidth/2+a*r+u),u+=t._circularWidth||t.width}),"bottom"==e.circularLinkType?(e.circularPathData.verticalFullExtent=Math.max(n.y1,e.source.y1,e.target.y1)+a+e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.leftLargeArcRadius):(e.circularPathData.verticalFullExtent=l-a-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,i=e.target.x0,a=e.y1,n=(t+i)/2;return"M"+t+","+r+"C"+n+","+r+" "+n+","+a+" "+i+","+a}(e)}),n}function z(e,t,r){e.sort(H);var i=e.filter(function(e){return!e._circularStub});return e.forEach(function(e,a){var n=0;if(e._circularStub)e.circularPathData.verticalBuffer=0;else if(p(e,t)&&y(e))e.circularPathData.verticalBuffer=n+e._circularWidth/2;else{for(var o=0;i.length>o;o++){var l=i[o];if(l!==e&&l.circularPathData&&void 0!==l.circularPathData.verticalBuffer&&j(e,l)){var s=l.circularPathData.verticalBuffer+(l._circularWidth||l.width)/2+r;n=s>n?s:n}}e.circularPathData.verticalBuffer=n+e._circularWidth/2}}),e}function j(e,t){return!(t.target.column>e.source.column||e.target.column>t.source.column)}function X(e){return function(){return e}}function Y(e){return e.index}function q(e){return e.nodes}function G(e){return e.links}function V(e,t,r){var i=wi(e.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]});i.forEach(function(a,n){var o=a.length;if(t)a.sort(t);else if(n>0){var l=new Map;a.forEach(function(e,t){var r,i,a,n=(i=0,a=0,(r=e).targetLinks.forEach(function(e){if(!e.circular){var t=e.value||1;a+=P(e.source)*t,i+=t}}),r.sourceLinks.forEach(function(e){if(!e.circular){var t=e.value||1;a+=P(e.target)*t,i+=t}}),i>0?a/i:NaN);l.set(e,{bc:n,idx:t})}),a.sort(function(e,t){var r=l.get(e),i=l.get(t),a=r.bc,n=i.bc;if(e.circularLinkType!==t.circularLinkType){if("top"==e.circularLinkType&&"bottom"==t.circularLinkType)return-1;if("bottom"==e.circularLinkType&&"top"==t.circularLinkType)return 1;if("top"==e.circularLinkType)return-1;if("top"==t.circularLinkType||"bottom"==e.circularLinkType)return 1;if("bottom"==t.circularLinkType)return-1}return isNaN(a)||isNaN(n)?isNaN(a)?isNaN(n)?r.idx-i.idx:1:-1:a-n})}else a.sort(function(e,t){return e.circularLinkType==t.circularLinkType?T(t,r)-T(e,r):"top"==e.circularLinkType&&"bottom"==t.circularLinkType||"top"==e.circularLinkType&&0==t.partOfCycle||0==e.partOfCycle&&"bottom"==t.circularLinkType?-1:0});a.forEach(function(t,a){t.depth==i.length-1&&1==o||0==t.depth&&1==o?(t.y0=e.y1/2-t.value*e.ky,t.y1=t.y0+t.value*e.ky):t.partOfCycle?0==T(t,r)?(t.y0=e.y1/2+a,t.y1=t.y0+t.value*e.ky):"top"==t.circularLinkType?(t.y0=e.y0+a,t.y1=t.y0+t.value*e.ky):(t.y0=e.y1-t.value*e.ky-a,t.y1=t.y0+t.value*e.ky):0==e.y0||0==e.y1?(t.y0=(e.y1-e.y0)/o*a,t.y1=t.y0+t.value*e.ky):(t.y0=(e.y1-e.y0)/2-o/2+a,t.y1=t.y0+t.value*e.ky)})})}function K(e,t,r,i,a,n){function o(t,r){var i=s.length;s.forEach(function(a){var n=a.length,o=a[0].depth;a.forEach(function(a){var l;if(a.sourceLinks.length||a.targetLinks.length)if(a.partOfCycle&&T(a,r)>0){var s=xi(a.sourceLinks,M),c=xi(a.targetLinks,w),u=s&&c?(s+c)/2:s||c;if(u){var d=(u-P(a))*t*.3;a.y0+=d,a.y1+=d}}else if(0==o&&1==n)a.y0=e.y1/2-(l=a.y1-a.y0)/2,a.y1=e.y1/2+l/2;else if(o==i-1&&1==n)a.y0=e.y1/2-(l=a.y1-a.y0)/2,a.y1=e.y1/2+l/2;else if(1==a.targetLinks.length&&1==a.targetLinks[0].source.sourceLinks.length)l=a.y1-a.y0,a.y0=a.targetLinks[0].source.y0,a.y1=a.y0+l;else{var f=xi(a.sourceLinks,M),h=xi(a.targetLinks,w),g=((f&&h?(f+h)/2:f||h)-P(a))*t;a.y0+=g,a.y1+=g}})})}function l(){s.forEach(function(r){var n,o,l,s=e.y0,c=r.length;for(r.sort(t||$),l=0;c>l;++l)(o=s-(n=r[l]).y0)>0&&(n.y0+=o,n.y1+=o),s=n.y1+i;if((o=s-i-e.y1)>0)for(s=n.y0-=o,n.y1-=o,l=c-2;l>=0;--l)(o=(n=r[l]).y1+a-s)>0&&(n.y0-=o,n.y1-=o),s=n.y0})}var s=wi(e.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]});l();for(var c=1,u=n;u>0;--u)o(c*=.99,r),l()}function U(e){e.nodes.forEach(function(e){e.sourceLinks.sort(B),e.targetLinks.sort(N)}),e.nodes.forEach(function(e){var t=e.y0,r=t,i=e.y1,a=i;e.sourceLinks.forEach(function(e){e.circular?(e.y0=i-e.width/2,i-=e.width):(e.y0=t+e.width/2,t+=e.width)}),e.targetLinks.forEach(function(e){e.circular?(e.y1=a-e.width/2,a-=e.width):(e.y1=r+e.width/2,r+=e.width)})})}function Q(){function e(){var e={nodes:y.apply(null,arguments),links:b.apply(null,arguments)};return function(e){e.x0=t,e.y0=r,e.x1=i,e.y1=a,e.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 Si(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 i=e.source,a=e.target;"object"!=typeof i&&(i=e.source=h(r,i)),"object"!=typeof a&&(a=e.target=h(r,a)),i.sourceLinks.push(e),a.targetLinks.push(e)})}(e,s),function(e,t){var r=0;if(null==t){for(var i=[],a=0;e.links.length>a;a++){var n=e.links[a],o=n.source.index,l=n.target.index;i[o]||(i[o]=[]),i[l]||(i[l]=[]),-1===i[o].indexOf(l)&&i[o].push(l)}var s=g(i);s.sort(function(e,t){return e.length-t.length});var c={};for(a=0;s.length>a;a++){var u=s[a].slice(-2);c[u[0]]||(c[u[0]]={}),c[u[0]][u[1]]=!0}e.links.forEach(function(e){var t=e.target.index,i=e.source.index;t===i||c[i]&&c[i][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++)})}(e,u),function(e,t){var r=0,i=0;e.links.forEach(function(a){a.circular&&(a.circularLinkType=a.source.circularLinkType||a.target.circularLinkType?a.source.circularLinkType?a.source.circularLinkType:a.target.circularLinkType:i>r?"top":"bottom","top"==a.circularLinkType?r++:i++,e.nodes.forEach(function(e){(S(e,t)==S(a.source,t)||S(e,t)==S(a.target,t))&&(e.circularLinkType=a.circularLinkType)}))}),e.links.forEach(function(e){e.circular&&(e.source.circularLinkType==e.target.circularLinkType&&(e.circularLinkType=e.source.circularLinkType),p(e,t)&&(e.circularLinkType=e.source.circularLinkType))})}(e,s),function(e){e.nodes.forEach(function(e){e.partOfCycle=!1,e.value=Math.max(ki(e.sourceLinks,L),ki(e.targetLinks,L)),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)})})}(e),function(e,t,r){var i,a,n;if(null!=t){e.nodes.sort(function(e,r){return t(e)<t(r)?-1:1});var o=0,l=t(e.nodes[0]);e.nodes.forEach(function(e){o=t(e)==l?o:o+1,l=t(e)==l?l:t(e),e.column=o})}for(i=e.nodes,a=[],n=0;i.length;++n,i=a,a=[])i.forEach(function(e){e.depth=n,e.sourceLinks.forEach(function(e){0>a.indexOf(e.target)&&!e.circular&&a.push(e.target)})});for(i=e.nodes,a=[],n=0;i.length;++n,i=a,a=[])i.forEach(function(e){e.height=n,e.targetLinks.forEach(function(e){0>a.indexOf(e.source)&&!e.circular&&a.push(e.source)})});e.nodes.forEach(function(e){e.column=null==t?r(e,n):e.column})}(e,u,c);var y=o;if(null!==l){var b=wi(e.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]}),x=vi(b,function(e){return e.length});x>1&&(y=Math.max(1,(a-r)*l/(x-1)))}(function(e,t,r){var i=wi(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 a=bi(i,function(t){return(e.y1-e.y0-(t.length-1)*e.py)/ki(t,function(e){return e.value})});e.ky=a,e.links.forEach(function(t){t.width=t.value*e.ky});var n=vi(e.nodes,function(e){return e.column});e.nodes.forEach(n>0?function(t){t.x0=e.x0+t.column*((e.x1-e.x0-r)/n),t.x1=t.x0+r}:function(t){t.x0=e.x0,t.x1=t.x0+r})})(e,y,n),V(e,u,s),K(e,u,s,y,y,d),U(e),_(e,s,f,m,8),V(e,u,s),K(e,u,s,y,y,d),U(e),_(e,s,f,m,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 i=r.links.filter(function(r){return S(r.source,t)==S(e,t)}),a=i.length;a>1&&i.sort(function(e,t){if(!e.circular&&!t.circular){if(e.target.column==t.target.column)return e.y1-t.y1;if(!F(e,t))return e.y1-t.y1;if(e.target.column>t.target.column){var r=v(t,e);return e.y1-r}if(t.target.column>e.target.column)return v(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 n=e.y0;i.forEach(function(e){e.y0=n+e.width/2,n+=e.width}),i.forEach(function(t,r){if("bottom"==t.circularLinkType){for(var n=r+1,o=0;a>n;n++)o+=i[n].width;t.y0=e.y1-o-t.width/2}})})}(e,s),function(e,t){let r=e;r.nodes.forEach(function(e){var i=r.links.filter(function(r){return S(r.target,t)==S(e,t)}),a=i.length;a>1&&i.sort(function(e,t){if(!e.circular&&!t.circular){if(e.source.column==t.source.column)return e.y0-t.y0;if(!F(e,t))return e.y0-t.y0;if(e.source.column>t.source.column){var r=k(t,e);return e.y0-r}if(t.source.column>e.source.column)return k(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 n=e.y0;i.forEach(function(e){e.y1=n+e.width/2,n+=e.width}),i.forEach(function(t,r){if("bottom"==t.circularLinkType){for(var n=r+1,o=0;a>n;n++)o+=i[n].width;t.y1=e.y1-o-t.width/2}})})}(e,s),function(e){var t=e.nodes,r=e.links,i=!1,a=!1;if(r.forEach(function(e){"top"==e.circularLinkType?i=!0:"bottom"==e.circularLinkType&&(a=!0)}),0==i||0==a){let i=function(t){return(t-n)/(o-n)*(e.y1-e.y0)+e.y0};var n=bi(t,function(e){return e.y0}),o=vi(t,function(e){return e.y1}),l=(e.y1-e.y0)/(o-n);1>l?(t.forEach(function(e){e.y0=i(e.y0),e.y1=i(e.y1)}),r.forEach(function(e){e.y0=i(e.y0),e.y1=i(e.y1),e.width=e.width*l})):t.forEach(function(e){var t=e.y1-e.y0,r=i(e.y0)-e.y0;e.y0=i(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})})}}(e),_(e,s,f,m,8)}(e),e}var t=0,r=0,i=1,a=1,n=24,o=8,l=null,s=Y,c=D,u=void 0,d=32,f=2,m=10,y=q,b=G;return e.update=function(e){return U(e),_(e,s,f,m,8),e},e.nodeWidth=function(t){return arguments.length?(n=+t,e):n},e.nodePadding=function(t){return arguments.length?(o=+t,e):o},e.nodePaddingRatio=function(t){return arguments.length?(l=+t,e):l},e.nodes=function(t){return arguments.length?(y="function"==typeof t?t:X(t),e):y},e.links=function(t){return arguments.length?(b="function"==typeof t?t:X(t),e):b},e.nodeId=function(t){return arguments.length?(s="function"==typeof t?t:X(t),e):s},e.nodeAlign=function(t){return arguments.length?(c="function"==typeof t?t:X(t),e):c},e.nodeSort=function(t){return arguments.length?(u=t,e):u},e.iterations=function(t){return arguments.length?(d=+t,e):d},e.circularLinkGap=function(t){return arguments.length?(f=+t,e):f},e.extent=function(n){return arguments.length?(t=+n[0][0],r=+n[0][1],i=+n[1][0],a=+n[1][1],e):[[t,r],[i,a]]},e.size=function(n){return arguments.length?(t=r=0,i=+n[0],a=+n[1],e):[i-t,a-r]},e}function Z(e){let{sx:t,sTop:r,sBot:i,tx:a,tTop:n,tBot:o,cp1X:l,cp2X:s}=e,c=(r+i)/2,u=(n+o)/2;return{pathD:[`M${t},${r}`,`C${l},${r} ${s},${n} ${a},${n}`,`L${a},${o}`,`C${s},${o} ${l},${i} ${t},${i}`,"Z"].join(" "),bezier:{circular:!1,points:[{x:t,y:c},{x:l,y:c},{x:s,y:u},{x:a,y:u}],halfWidth:(i-r)/2}}}function J(e){let t=e.sankeyWidth/2,r=(e._circularWidth??e.sankeyWidth)/2,i=e.circularPathData;if(!i||"down"===e.direction)return null;if(e._circularStub){let r=i.sourceX,a=i.sourceY,n=i.targetX,o=i.targetY;if("object"!=typeof e.source||!e.source||"object"!=typeof e.target||!e.target)return null;let l=Math.max(15,Math.min(40,.33*(i.rightFullExtent-r))),s=Math.max(15,Math.min(40,.33*(n-i.leftFullExtent)));return`M${r},${a-t}L${r+l},${a-t}L${r+l},${a+t}L${r},${a+t}ZM${n},${o-t}L${n-s},${o-t}L${n-s},${o+t}L${n},${o+t}Z`}let a=i.sourceX,n=i.sourceY,o=i.targetX,l=i.targetY,s=i.rightFullExtent,c=i.leftFullExtent,u=i.verticalFullExtent,d="bottom"===e.circularLinkType?1:-1,f=Math.max(4,Math.min(r,15));return`M${a},${n-d*t}L${s},${n-d*t}L${s+r},${n-d*t+d*f}L${s+r},${u+d*r-d*f}L${s+r-f},${u+d*r}L${c-r+f},${u+d*r}L${c-r},${u+d*r-d*f}L${c-r},${l-d*t+d*f}L${c-r+f},${l-d*t}L${o},${l-d*t}L${o},${l+d*t}L${c+r},${l+d*t}L${c+r},${u-d*r}L${s-r},${u-d*r}L${s-r},${n+d*t}L${a},${n+d*t}Z`}function ee(e="static"){return Ci[e]??Ci.static}function te(e){return"fatal"===e.severity||"warn"===e.severity?e.severity:Oi.has(e.kind)?"fatal":"warn"}function re(e,t,r,i={}){let a=ee(i.usageMode??"static"),n=[],o=new Set;for(let t of e)o.has(t.id)&&n.push({kind:"duplicate-node",id:t.id,severity:a.duplicateIds}),o.add(t.id);let l=new Set,s=Array.isArray(r)&&2===r.length,c=s&&Number.isFinite(r[0])&&Number.isFinite(r[1]);(!s||!c||!c||r[0]>r[1])&&n.push({kind:"invalid-domain"});for(let t of e)null!=t.xExtent&&(Array.isArray(t.xExtent)&&2===t.xExtent.length&&Number.isFinite(t.xExtent[0])&&Number.isFinite(t.xExtent[1])&&t.xExtent[1]>=t.xExtent[0]||n.push({kind:"invalid-node-time",id:t.id}));for(let e of t)l.has(e.id)&&n.push({kind:"duplicate-edge",id:e.id,severity:a.duplicateIds}),l.add(e.id),o.has(e.source)||n.push({kind:"missing-node",id:e.id,endpoint:"source",nodeId:e.source}),o.has(e.target)||n.push({kind:"missing-node",id:e.id,endpoint:"target",nodeId:e.target}),Number.isFinite(e.startTime)&&Number.isFinite(e.endTime)?((null!=e.systemInTime&&!Number.isFinite(e.systemInTime)||null!=e.systemOutTime&&!Number.isFinite(e.systemOutTime))&&n.push({kind:"invalid-system-time",id:e.id,severity:"warn"}),(!Number.isFinite(e.value)||0>=e.value)&&n.push({kind:"invalid-value",id:e.id}),e.startTime>e.endTime&&n.push({kind:"backward-edge",severity:"fatal",id:e.id,source:e.source,target:e.target})):n.push({kind:"invalid-edge-time",id:e.id});return n}function ie(e){return"invalid-node-time"===e.kind?`node ${e.id} has an invalid xExtent (must be [start, end] with start <= end)`:"invalid-edge-time"===e.kind?`edge ${e.id} has an invalid startTime or endTime`:"invalid-domain"===e.kind?"time domain must be a 2-tuple of finite times [start, end] with start <= end":"invalid-value"===e.kind?`edge ${e.id} must have a positive finite value`:"missing-node"===e.kind?`edge ${e.id} references missing ${e.endpoint} node "${e.nodeId}"`:"backward-edge"===e.kind?`edge ${e.id} (${e.source}->${e.target}) ends before it starts`:"duplicate-node"===e.kind?`node id "${e.id}" is duplicated`:"duplicate-edge"===e.kind?`edge id "${e.id}" is duplicated`:"invalid-system-time"===e.kind?`edge ${e.id} has an invalid systemInTime or systemOutTime`:e.kind}function ae(e){if(!e?.layoutQuality)return[];let t=[],r=e.layoutQuality,i=e.layoutQualityBefore;e.compressedPadding&&t.push({severity:"warning",code:"PROCESS_SANKEY_COMPRESSED_PADDING",message:"Lane gaps were compressed to fit peaks into the plot height.",fix:'Increase height, lower maxValueScale, use packing="reuse", or reduce concurrent peaks.'}),r.transitOcclusion>=Ni&&t.push({severity:"warning",code:"PROCESS_SANKEY_HIGH_TRANSIT",message:`High transit occlusion (${r.transitOcclusion.toFixed(1)}) — ribbons cross dense intermediate lanes.`,fix:'Try laneOrder="crossing-min+inside-out", packing="reuse", or lanePlacement="hug" with a modest maxValueScale.'}),r.verticalUtilization>=Bi&&t.push({severity:"warning",code:"PROCESS_SANKEY_HIGH_UTILIZATION",message:`Lane utilization is ${Math.round(100*r.verticalUtilization)}% of plot height.`,fix:"Increase chart height or cap band scale with maxValueScale."});let a=e.crossingsAfter??r.crossings;return null!=a&&a>=$i&&t.push({severity:"warning",code:"PROCESS_SANKEY_RESIDUAL_CROSSINGS",message:`Ordering left ${a} edge-pair crossings`+(i?` (from ${i.crossings})`:"")+".",fix:'Prefer laneOrder="crossing-min" or "crossing-min+inside-out"; check for unavoidable fan-outs.'}),t}function ne(e){if(!e?.layoutQuality)return null;let t=e.layoutQuality,r=e.layoutQualityBefore,i=e.crossingsAfter??t.crossings;return[`ProcessSankey layout uses ${e.slots?.length??"?"} packed lane(s).`,null!=i?`Edge-pair crossings ${r?r.crossings+" → ":""}${i}.`:null,`Pixel path length ${r?Math.round(r.pixelLength)+" → ":""}${Math.round(t.pixelLength)}.`,`Transit occlusion ${r?r.transitOcclusion.toFixed(1)+" → ":""}${t.transitOcclusion.toFixed(1)}.`,`Lane utilization ${Math.round(100*t.verticalUtilization)}%.`,e.compressedPadding?"Lane gaps were compressed to fit the plot.":null].filter(Boolean).join(" ")}function oe(e){let t=[],r=e.domain;null==r?t.push({severity:"error",code:"PROCESS_SANKEY_MISSING_DOMAIN",message:"ProcessSankey requires domain: [tStart, tEnd].",fix:"Pass domain={[start, end]} as numbers or Date-compatible values."}):(!Array.isArray(r)||2!==r.length||!Number.isFinite(Number(r[0]))||!Number.isFinite(Number(r[1])))&&t.push({severity:"error",code:"PROCESS_SANKEY_BAD_DOMAIN",message:"domain must be a 2-tuple of finite times.",fix:"Use domain={[t0, t1]} with t0 <= t1."});let i=e.edges;if(Array.isArray(i)&&i.length>0){let e=i[0];(null==e.startTime||null==e.endTime)&&t.push({severity:"warning",code:"PROCESS_SANKEY_EDGE_TIMES",message:"Edges should carry startTime and endTime for temporal layout.",fix:"Add startTime/endTime fields or set startTimeAccessor/endTimeAccessor."})}let a=e.nodes,n=Array.isArray(a)?a.length:0;return!0===e.showLabels&&n>=24&&t.push({severity:"warning",code:"PROCESS_SANKEY_LABEL_DENSITY",message:`showLabels={true} with ${n} nodes may overcrowd the plot.`,fix:'Use showLabels="auto" with optional labelPriorityAccessor / maxLabels.'}),(Array.isArray(i)?i.length:0)>=80&&null==e.layoutExecution&&"off"!==e.packing&&t.push({severity:"warning",code:"PROCESS_SANKEY_WORKER_HINT",message:"Dense ProcessSankey layouts benefit from worker packing/order.",fix:'layoutExecution defaults to "auto"; set layoutExecution="worker" or raise layoutWorkerThreshold deliberately.'}),t}function le(e,t,r,i={}){let a=!1!==i.inferOpeningStock,n=[];for(let t of r){let r=Number(t.value);if(!Number.isFinite(r))continue;let i=Number(t.endTime);t.target===e&&Number.isFinite(i)&&n.push({time:i,delta:r});let a=Number(t.startTime);if(t.source===e&&Number.isFinite(a)&&n.push({time:a,delta:-r}),t.target===e&&null!=t.systemOutTime){let e=Number(t.systemOutTime);Number.isFinite(e)&&n.push({time:e,delta:-r})}}n.sort((e,t)=>e.time-t.time||t.delta-e.delta);let o=0,l=0,s=0;for(let e of n)o+=e.delta,l=Math.min(l,o),t>=e.time&&(s+=e.delta);return a?s-l:s}function se(e){return null==e?NaN:e instanceof Date?e.getTime():"number"==typeof e?e:new Date(e).getTime()}function ce(e){let{desired:t,minGaps:r,weights:i}=e,a=t.length;if(0===a)return[];if(r.length!==Math.max(0,a-1))throw Error("placeWithMinGap: minGaps must have desired.length - 1 entries");let n=Array(a).fill(0);for(let e=1;a>e;e++)n[e]=n[e-1]+Math.max(0,Number.isFinite(r[e-1])?r[e-1]:0);let o=[];for(let e=0;a>e;e++){let r=Math.max(Number.EPSILON,Number.isFinite(i?.[e])?i[e]:1),a=(Number.isFinite(t[e])?t[e]:0)-n[e];for(o.push({start:e,end:e,weight:r,mean:a});o.length>1;){let e=o[o.length-1],t=o[o.length-2];if(e.mean>=t.mean)break;let r=t.weight+e.weight;o.splice(o.length-2,2,{start:t.start,end:e.end,weight:r,mean:(t.mean*t.weight+e.mean*e.weight)/r})}}let l=Number.isFinite(e.min)?e.min:-1/0,s=Number.isFinite(e.max)?e.max-n[a-1]:1/0,c=l>s?l:s,u=Array(a);for(let e of o){let t=Math.max(l,Math.min(c,e.mean));for(let r=e.start;e.end>=r;r++)u[r]=t+n[r]}return u}function ue(e,t){let r=0,i=e.length-1,a=-1;for(;i>=r;){let n=r+i>>>1;e[n].at>t?i=n-1:(a=n,r=n+1)}return 0>a?{at:t,before:0,after:0}:e[a]}function de(e,t=0){if(0===e.length)return{adjacentClearance:[],positions:[]};let r=[],i=[0];for(let a=0;e.length-1>a;a++){let n=e[a],o=e[a+1],l=[...new Set([...n.map(e=>e.at),...o.map(e=>e.at)])].sort((e,t)=>e-t),s=0;for(let e of l){let t=ue(n,e),r=ue(o,e);s=Math.max(s,t.after+r.before)}r.push(s),i.push(i[i.length-1]+s+t)}return{adjacentClearance:r,positions:i}}function fe(e,t,r,i={}){let a=[...e];if(1>=a.length)return a;let n=[...a],o=r(a),l=1,s=Math.max(0,i.passes??6),c=Math.max(1,i.maxEvaluations??1/0);for(let e=0;s>e&&c>l;e++){let e=new Map(a.map((e,t)=>[e,t])),s=new Map,c=new Map;for(let r of t){let t=e.get(r.source),i=e.get(r.target);if(null==t||null==i)continue;let a=Number.isFinite(r.weight)&&r.weight>0?r.weight:1;s.set(r.source,(s.get(r.source)??0)+i*a),c.set(r.source,(c.get(r.source)??0)+a),s.set(r.target,(s.get(r.target)??0)+t*a),c.set(r.target,(c.get(r.target)??0)+a)}a=a.map((e,t)=>({item:e,index:t,barycenter:(s.get(e)??t)/(c.get(e)??1)})).sort((e,t)=>e.barycenter-t.barycenter||(i.compare?.(e.item,t.item)??e.index-t.index)).map(e=>e.item);let u=r(a);if(l++,o>u)o=u,n=[...a];else if(u===o)break}return n}function he(e,t,r={}){let i=[...e],a=i.length;if(1>=a||a>(r.maxItems??8))return i;let n=Math.max(1,r.maxEvaluations??1/0),o=0,l=[...i],s=1/0,c=()=>{if(o>=n)return;let e=t(i);o++,s>e&&(s=e,l=[...i])};c();let u=Array(a).fill(0),d=0;for(;a>d&&n>o;)if(d>u[d]){let e=d%2==0?0:u[d];[i[e],i[d]]=[i[d],i[e]],c(),u[d]++,d=0}else u[d]=0,d++;return l}function ge(){return Object.create(null)}function me(e,t){return t>e?-1:e>t?1:0}function pe(e){return e.occupants.map(e=>e.id).sort(me).join("\0")}function ye(e,t,r=0){return e.slice(0,-1).map((i,a)=>null!=i.group&&i.group===e[a+1].group?r:t)}function be(e,t){return e.map(e=>{let r=new Map;for(let i of e.occupants){let e=t[i.id];if(e)for(let t of e.samples){let e=r.get(t.t)??{before:0,after:0},i=t.boundaryOffset??0;r.set(t.t,{before:Math.max(e.before,t.topMass-i),after:Math.max(e.after,t.botMass+i)})}}return[...r].sort((e,t)=>e[0]-t[0]).map(([e,t])=>({at:e,...t}))})}function ve(e,t,r){if(0===e.length)return[];let{padding:i,plotH:a,valueScale:n}=r,o=r.stackValueScale??n,l=ye(e,i,r.groupPadding??0),s=[i+e[0].peak.topPeak*o];for(let r=1;e.length>r;r++)s.push(s[r-1]+t[r-1]*o+l[r-1]);let c=s[s.length-1]+e[e.length-1].peak.botPeak*o+i;if(c>a&&c>0){let e=a/c;for(let t=0;s.length>t;t++)s[t]*=e}return s}function ke(e,t){let r=(e.boundaryOffset??0)*t,i=e.value*t;if("out"===e.kind){let a=e.sideMassBefore*t;return r+("top"===e.side?i/2-a:a-i/2)}let a=e.sideMassAfter*t;return r+("top"===e.side?i/2-a:a-i/2)}function xe(e,t,r,i,a,n){let o=n.adjacentClearance?[...n.adjacentClearance]:de(be(i,r)).adjacentClearance,l=ve(i,o,n),s="hug"===n.lanePlacement?function(e,t,r,i,a,n,o){let l=e.length;if(0===l)return[];let{padding:s,plotH:c,valueScale:u}=o,d=ye(e,s,o.groupPadding??0),f=a.map((e,t)=>e*u+d[t]),h=s+e[0].peak.topPeak*u,g=c-s-e[l-1].peak.botPeak*u;if(f.reduce((e,t)=>e+t,0)+1e-6>=g-h)return ve(e,a,o);let m=1===l?[(h+g)/2]:[...n];for(let e=0;12>e;e++){let e=Array(l).fill(0),a=Array(l).fill(0);for(let n of r){let r=t[n.source],o=t[n.target];if(null==r||null==o||r===o)continue;let l=i[n.source]?.localAttachments.get(n.id),s=i[n.target]?.localAttachments.get(n.id);if(!l||!s)continue;let c=n.value>0&&Number.isFinite(n.value)?n.value:1,d=ke(l,u),f=ke(s,u);e[r]+=(m[o]+f-d)*c,a[r]+=c,e[o]+=(m[r]+d-f)*c,a[o]+=c}let n=ce({desired:m.map((t,r)=>0===a[r]?t:.45*t+e[r]/a[r]*.55),minGaps:f,weights:a.map(e=>Math.max(1,e)),min:h,max:g}),o=0;for(let e=0;l>e;e++)o=Math.max(o,Math.abs(n[e]-m[e]));if(m=n,.01>o)break}return m}(i,a,t,r,o,l,n):[...l];if("hug"===n.lanePlacement){let r=t=>{let r=ge();for(let i of e)r[i.id]=t[a[i.id]];return r};Se(r(s),t)>Se(r(l),t)+1e-6&&(s=[...l])}let c=ge();for(let t of e)c[t.id]=s[a[t.id]];let u=1/0,d=-1/0;for(let t of e){let e=c[t.id],i=r[t.id];!Number.isFinite(e)||!i||(u=Math.min(u,e-i.topPeak*n.valueScale),d=Math.max(d,e+i.botPeak*n.valueScale))}return{adjacentClearance:o,centerlines:c,slotCenter:s,stackCenter:l,verticalUtilization:Number.isFinite(u)&&Number.isFinite(d)&&n.plotH>0?Math.max(0,Math.min(1,(d-u)/n.plotH)):0}}function Se(e,t){let r=0;for(let i of t){let t=e[i.source],a=e[i.target];Number.isFinite(t)&&Number.isFinite(a)&&(r+=Math.abs(t-a)*(i.value>0?i.value:1))}return r}function we(e,t){let r=e?.samples;if(!r||0===r.length||r[0].t>t)return{top:0,bot:0};let i=0,a=r.length-1,n=0;for(;a>=i;){let e=i+a>>>1;r[e].t>t?a=e-1:(n=e,i=e+1)}let o=r[n].boundaryOffset??0;return{top:r[n].topMass-o,bot:r[n].botMass+o}}function Me(e,t,r,i,a){let n=1-a;return n*n*n*e+3*n*n*a*t+3*n*a*a*r+a*a*a*i}function Pe(e,t){let r=0,i=1;for(let a=0;28>a;a++){let a=(r+i)/2;Me(0,t,t,1,a)<e?r=a:i=a}return(r+i)/2}function Le(e,t,r){let i=t+ke(e,r),a=e.value*r/2;return[i-a,i+a]}function Te(e,t,r,i){return Math.max(0,Math.min(t,i)-Math.max(e,r))/Math.max(1e-9,t-e)}function Ae(e,t,r,i,a,n,o){let{valueScale:l,domain:s,mode:c="quality"}=o,u="source"===o.ribbonLane?.85:"target"===o.ribbonLane?.15:.5,d=0;for(let o of e){let e=i[o.source],f=i[o.target];if(null==e||null==f||2>Math.abs(e-f))continue;let h=t[o.source]?.localAttachments.get(o.id),g=t[o.target]?.localAttachments.get(o.id);if(!h||!g)continue;let m=Math.max(o.startTime,s?.[0]??-1/0),p=Math.min(o.endTime,s?.[1]??1/0);if(m>=p)continue;let[y,b]=Le(h,a[o.source],l),[v,k]=Le(g,a[o.target],l),x=Math.min(e,f)+1,S=Math.max(e,f)-1;for(let e=x;S>=e;e++){let i=r[e];if(!i)continue;let s=[m,p];if("quality"===c)for(let e of i.occupants)for(let r of t[e.id]?.samples??[])r.t>m&&p>r.t&&s.push(r.t);let f=e=>{let r=Pe((e-m)/(p-m),u),s=Me(y,y,v,v,r),c=Me(b,b,k,k,r),d=0;for(let r of i.occupants){if(r.id===o.source||r.id===o.target)continue;let i=n[r.id];if(null!=i?.start&&i.start>e||null!=i?.end&&e>i.end)continue;let u=we(t[r.id],e),f=a[r.id];d=Math.max(d,Te(s,c,f-u.top*l,f+u.bot*l))}return d},h=[...new Set(s)].sort((e,t)=>e-t),g=0;for(let e=0;h.length-1>e;e++){let t=h[e],r=h[e+1]-t;g+=(f(t+.25*r)+f(t+.5*r)+f(t+.75*r))/3*r}d+=g/(p-m)*(o.value>0?o.value:1)}}return d}function De(e,t,r,i,a,n,o,l,s,c,u="both",d){return{crossings:e,weightedLength:t,pixelLength:Se(o,r),transitOcclusion:Ae(r,i,a,n,o,l,{valueScale:s,ribbonLane:u,domain:d,mode:"quality"}),verticalUtilization:c}}function Ie(e,t){return t?Math.max(t[0],Math.min(t[1],e)):e}function Ee(e,t){return e.map(e=>({t:Ie(e.t,t),topMass:e.topMass,botMass:e.botMass,...null!=e.boundaryOffset&&{boundaryOffset:e.boundaryOffset}}))}function Ce(e,t,r){let i=t+(e.boundaryOffset??0)*r,a=e.value*r;if("out"===e.kind){let t=e.sideMassBefore*r;if("top"===e.side){let e=i-t;return[e,e+a]}let n=i+t;return[n-a,n]}let n=e.sideMassAfter*r;if("top"===e.side){let e=i-n;return[e,e+a]}let o=i+n;return[o-a,o]}function Oe(e,t,r,i,a="temporal"){let n=t.incoming[e.id],o=t.outgoing[e.id],l=[];for(let e of n)l.push({time:e.endTime,delta:+e.value,edge:e,kind:"in",side:r.get(e.id).targetSide});for(let e of o)l.push({time:e.startTime,delta:-e.value,edge:e,kind:"out",side:r.get(e.id).sourceSide});let s={create:0,in:1,"transfer-out":2,"transfer-in":3,out:4},c=()=>{l.sort((e,t)=>e.time-t.time||(e.phase??0)-(t.phase??0)||(e.sequence??0)-(t.sequence??0)||(s[e.kind]??99)-(s[t.kind]??99)||((e,t)=>{if(!i||!e.edge||!t.edge||e.kind!==t.kind||e.side!==t.side)return 0;if("out"===e.kind){if(e.edge.target===t.edge.target&&e.edge.endTime===t.edge.endTime)return 0;let r=i.get(e.edge.id)?.target,a=i.get(t.edge.id)?.target;return"number"==typeof r&&Number.isFinite(r)&&"number"==typeof a&&Number.isFinite(a)&&r!==a?"top"===e.side?r-a:a-r:0}if("in"===e.kind){if(e.edge.source===t.edge.source&&e.edge.startTime===t.edge.startTime)return 0;let r=i.get(e.edge.id)?.source,a=i.get(t.edge.id)?.source;return"number"==typeof r&&Number.isFinite(r)&&"number"==typeof a&&Number.isFinite(a)&&r!==a?"top"===e.side?a-r:r-a:0}return 0})(e,t)||me(e.edge?.id??"",t.edge?.id??"")||me(e.side,t.side)||e.delta-t.delta)},u=l.length?Rr(l.map(e=>e.time)):null,d=Array.isArray(e.xExtent)&&Number.isFinite(e.xExtent[0])?e.xExtent[0]:null,f=null!=d?d-1:null!=u&&Number.isFinite(u)?u-1:null;c();let h=null,g=0;for(let e of l)e.time!==h&&(h=e.time,g=0),e.sequence=g++;let m=e=>({time:e.time,phase:0,sequence:e.sequence??0}),p=[],y=0,b=0;for(let e of l)if("out"===e.kind){let t=Math.abs(e.delta),r=t-("top"===e.side?y:b);if(r>0){let t="top"===e.side?"bot":"top",i=Math.min(r,"top"===t?y:b);if(i>0){let a=m(e);p.push({...a,delta:-i,kind:"transfer-out",side:t}),p.push({...a,delta:+i,kind:"transfer-in",side:e.side}),"top"===t?y-=i:b-=i,"top"===e.side?y+=i:b+=i,r-=i}r>0&&null!==f&&(p.push({time:f,delta:+r,kind:"create",side:e.side}),"top"===e.side?y+=r:b+=r)}"top"===e.side?y-=t:b-=t}else if("in"===e.kind){let t=Math.abs(e.delta);"top"===e.side?y+=t:b+=t}l.push(...p),c();let v=0,k=0,x=0,S=0,w=0,M=0,P=[],L=new Map,T=e=>{P.push({t:e,topMass:v,botMass:k,...Math.abs(x)>1e-12&&{boundaryOffset:x}})},A=()=>{S=Math.max(S,v+k),w=Math.max(w,v-x),M=Math.max(M,k+x)};for(let e of l){if("transfer-out"!==e.kind&&"transfer-in"!==e.kind&&T(e.time),("in"===e.kind||"out"===e.kind)&&e.edge){let t="top"===e.side?v:k;L.set(e.edge.id,{side:e.side,time:e.time,sideMassBefore:t,sideMassAfter:t+e.delta,kind:e.kind,value:Math.abs(e.delta),...Math.abs(x)>1e-12&&{boundaryOffset:x}})}"top"===e.side?v+=e.delta:k+=e.delta,"transfer-in"===e.kind?(x+="top"===e.side?e.delta:-e.delta,A(),T(e.time)):"transfer-out"!==e.kind&&(A(),"out"===e.kind&&1e-12>=v+k&&(x=0),T(e.time))}let D=[],I=0;for(;P.length>I;){let e=I;for(;P.length>e+1&&P[e+1].t===P[I].t;)e++;D.push(P[I]);for(let t=I+1;e>=t;t++){let e=D[D.length-1];(P[t].topMass!==e.topMass||P[t].botMass!==e.botMass||(P[t].boundaryOffset??0)!==(e.boundaryOffset??0))&&D.push(P[t])}I=e+1}let E=Array.isArray(e.xExtent)&&Number.isFinite(e.xExtent[1])?e.xExtent[1]:null,C=null;for(let e of o)null!=e.systemInTime&&Number.isFinite(e.systemInTime)&&e.startTime>e.systemInTime&&(null===C||C>e.systemInTime)&&(C=e.systemInTime);let O=null;for(let e of n)null!=e.systemOutTime&&Number.isFinite(e.systemOutTime)&&e.systemOutTime>e.endTime&&(null===O||e.systemOutTime>O)&&(O=e.systemOutTime);if(D.length>0){let e=D[D.length-1],t=Math.max(E??-1/0,O??-1/0);Number.isFinite(t)&&t>e.t&&e.topMass+e.botMass>0&&D.push({t:t,topMass:e.topMass,botMass:e.botMass,...null!=e.boundaryOffset&&{boundaryOffset:e.boundaryOffset}});let r,i=D[0],a=D.find(e=>e.topMass+e.botMass>0),n=1/0;null!=d&&Number.isFinite(d)&&i.t>d&&i.topMass+i.botMass>0&&(n=d,r=i),a&&null!=C&&Number.isFinite(C)&&a.t>C&&n>C&&(n=C,r=a),r&&Number.isFinite(n)&&D.unshift({t:n,topMass:r.topMass,botMass:r.botMass,...null!=r.boundaryOffset&&{boundaryOffset:r.boundaryOffset}})}let N=D;if("max"===a&&null!=d&&null!=E&&E>d){let e,t=0;for(let r of D){let i=r.topMass+r.botMass;i>t&&(t=i,e=r)}if(e){let t={topMass:e.topMass,botMass:e.botMass,...null!=e.boundaryOffset&&{boundaryOffset:e.boundaryOffset}};N=[...D.filter(e=>d>e.t),{t:d,...t},{t:E,...t},...D.filter(e=>e.t>E)]}}return{samples:N,peak:S,topPeak:w,botPeak:M,localAttachments:L}}function Ne(e){let t=ge();return e.forEach((e,r)=>{for(let i of e.occupants)t[i.id]=r}),t}function Be(e,t,r){e.splice(0,e.length,...r);let i=Ne(r);for(let e of Object.keys(t))delete t[e];Object.assign(t,i)}function $e(e){let t=new Map,r=[];e.forEach((e,i)=>{if(!e.group)return void r.push({anchor:i,stableId:pe(e),slots:[e]});let a=t.get(e.group)??{indexes:[],slots:[]};a.indexes.push(i),a.slots.push(e),t.set(e.group,a)});for(let[e,i]of t)r.push({anchor:i.indexes.reduce((e,t)=>e+t,0)/i.indexes.length,stableId:`${e}\0${i.slots.map(pe).join("\0")}`,slots:i.slots});return r.sort((e,t)=>e.anchor-t.anchor||me(e.stableId,t.stableId))}function He(e){return e.some(e=>e.group)?$e(e).flatMap(e=>e.slots):[...e]}function Re(e){return e.flatMap(e=>e.slots)}function Fe(e,t,r){let i=new Map;return e.forEach((e,t)=>{for(let r of e.slots)i.set(r,t)}),e.map((e,a)=>{if(1>=e.slots.length)return e;let n=new Map;for(let t of e.slots)n.set(t,0);for(let e of t){let t=i.get(e.source),r=i.get(e.target);if(null==t||null==r)continue;let o=Number.isFinite(e.weight)&&e.weight>0?e.weight:1;if(t===a&&r!==a){let t=r>a?1:-1;n.set(e.source,(n.get(e.source)??0)+o*t)}else if(r===a&&t!==a){let r=t>a?1:-1;n.set(e.target,(n.get(e.target)??0)+o*r)}}let o=[...e.slots].sort((e,t)=>(n.get(e)??0)-(n.get(t)??0)||r(e,t));return{...e,slots:o}})}function We(e,t){e.some(e=>e.group)&&Be(e,t,He(e))}function _e(e,t){return e.source!==t.source&&e.target!==t.target&&e.source!==t.target&&e.target!==t.source&&Math.min(e.endTime,t.endTime)>Math.max(e.startTime,t.startTime)}function ze(e,t){return function(e,t,r=()=>!0){let i=0;for(let a=0;e.length>a;a++){let[n,o]=t(e[a]);for(let l=a+1;e.length>l;l++){if(!r(e[a],e[l]))continue;let[s,c]=t(e[l]);0>(n-s)*(o-c)&&i++}}return i}(t,t=>[e[t.source],e[t.target]],_e)}function je(e,t){let r=0;for(let i of t){let t=e[i.source],a=e[i.target];null==t||null==a||(r+=Math.abs(t-a)*(i.value>0?i.value:1))}return r}function Xe(e,t,r){let[i,a]=r.get(e.first),[n,o]=r.get(e.second);return 0>(t.get(i)-t.get(n))*(t.get(a)-t.get(o))?1:0}function Ye(e,t,r,i,a,n,o){let l=[...a],s=new Map(a.map(e=>[e,pe(e)])),c=new Map;for(let e of a)for(let t of e.occupants)c.set(t.id,e);let u=new Map,d=[];for(let e of t){let t=c.get(e.source),r=c.get(e.target);!t||!r||(u.set(e,[t,r]),t!==r&&d.push({source:t,target:r,weight:e.value}))}let f=[];for(let e=0;t.length>e;e++)if(u.has(t[e]))for(let r=e+1;t.length>r;r++){if(!u.has(t[r])||!_e(t[e],t[r]))continue;let i=new Set([...u.get(t[e]),...u.get(t[r])]);f.push({index:f.length,first:t[e],second:t[r],involvedSlots:i})}let h=new Map;for(let e of a)h.set(e,[]);for(let e of f)for(let t of e.involvedSlots)h.get(t)?.push(e);let g=new Uint32Array(f.length),m=0,p=t.reduce((e,t)=>e+(t.value>0?t.value:1),0),y=o.plotH/Math.max(1,a.length),b=a.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),v=Math.max(1,p)*(Math.max(1,o.plotH)+y*Math.max(b,a.length)+1e-6*Math.max(1,a.length-1))+1,k=4*y,x={fullCrossing:0,localCrossing:0},S=new Map,w=(e,t)=>{let i=S.get(e);i||(i=new Map,S.set(e,i));let a=i.get(t);if(null!=a)return a;let n=function(e,t,r){return de(be([e,t],r)).adjacentClearance[0]??0}(e,t,r);return i.set(t,n),n},M=new Map(a.map((e,t)=>[e,t])),P=t.flatMap(e=>{let t=u.get(e);return t?[{source:M.get(t[0]),target:M.get(t[1]),weight:e.value>0?e.value:1}]:[]}),L=new Map;for(let e of t){let t=u.get(e);t&&L.set(e,{source:M.get(t[0]),target:M.get(t[1])})}let T=new Map,A=new Map,D=new Map,I=(e,t,r)=>{e.has(t)||e.set(t,new Set),e.get(t).add(r)};for(let e of t)I(T,e.source,e.target),I(A,e.target,e.source),I(D,e.source,e.target),I(D,e.target,e.source);let E=t.flatMap(e=>{if(!(e=>1===T.get(e.source)?.size&&T.get(e.source).has(e.target)||1===D.get(e.source)?.size||1===D.get(e.target)?.size)(e))return[];let t=L.get(e);return t&&t.source!==t.target?[{source:t.source,target:t.target,weight:e.value>0?e.value:1}]:[]}),C=e=>{let t=0;for(let r of E)t+=Math.max(0,Math.abs(e[r.source]-e[r.target])-1)*r.weight;return t*k},O=e=>{let t=new Int16Array(a.length);for(let r=0;e.length>r;r++)t[M.get(e[r])]=r;return C(t)},N=f.map(e=>{let t=L.get(e.first),r=L.get(e.second);return[t.source,t.target,r.source,r.target]}),B=new Int16Array(a.length),$=new Float64Array(a.length),H=new Float64Array(a.length+1),R=e=>{for(let t=0;e.length>t;t++)B[M.get(e[t])]=t;let t=0;for(let[e,r,i,a]of N)0>(B[e]-B[i])*(B[r]-B[a])&&t++;if(e.length>0){let t=M.get(e[0]);$[t]=o.padding+e[0].peak.topPeak*o.valueScale;for(let t=1;e.length>t;t++){let r=M.get(e[t-1]),i=M.get(e[t]);$[i]=$[r]+w(e[t-1],e[t])*o.valueScale+o.padding}let r=M.get(e[e.length-1]),i=$[r]+e[e.length-1].peak.botPeak*o.valueScale+o.padding;if(i>o.plotH&&i>0){let e=o.plotH/i;for(let t=0;$.length>t;t++)$[t]*=e}}H[0]=0;for(let t=0;e.length>t;t++)H[t+1]=H[t]+e[t].peak.topPeak+e[t].peak.botPeak;let r=0,i=0,a=0;for(let e of P){let t=B[e.source],n=B[e.target];if(r+=Math.abs(t-n)*e.weight,i+=Math.abs($[e.source]-$[e.target])*e.weight,Math.abs(t-n)>=2){let r=Math.min(t,n)+1;a+=(H[Math.max(t,n)]-H[r])*e.weight}}return t*v+i+a*y+C(B)+1e-6*r},F=(e,r)=>{let i=Array(e.length+1).fill(0);for(let t=0;e.length>t;t++)i[t+1]=i[t]+e[t].peak.topPeak+e[t].peak.botPeak;let a=0;for(let e of t){let t=r[e.source],n=r[e.target];if(null==t||null==n||2>Math.abs(t-n))continue;let o=Math.min(t,n)+1;a+=(i[Math.max(t,n)]-i[o])*(e.value>0?e.value:1)}return a},W=i=>{let a=Ne(i),n=i.slice(0,-1).map((e,t)=>w(e,i[t+1])),l=xe(e,t,r,i,a,{plotH:o.plotH,padding:o.padding,valueScale:o.valueScale,lanePlacement:o.lanePlacement??"stack",groupPadding:o.groupPadding,adjacentClearance:n});return{map:a,geometry:l,weightedLength:je(a,t),pixelLength:Se(l.centerlines,t),transitOcclusion:F(i,a)}},_=(e,t,r)=>({crossings:e,weightedLength:t.weightedLength,pixelLength:t.pixelLength,transitOcclusion:t.transitOcclusion,cost:e*v+t.pixelLength+t.transitOcclusion*y+O(r)+1e-6*t.weightedLength}),z=(e,t)=>{let r=t;if(null==r){let t=new Map(e.map((e,t)=>[e,t]));r=f.reduce((e,r)=>e+Xe(r,t,u),0),x.fullCrossing++}return _(r,W(e),e)},j=(e,a,n="quality")=>{let l=a;if(null==l){let t=new Map(e.map((e,t)=>[e,t]));l=f.reduce((e,r)=>e+Xe(r,t,u),0),x.fullCrossing++}let s=W(e);return _(l,{...s,transitOcclusion:Ae(t,r,e,s.map,s.geometry.centerlines,i,{valueScale:o.valueScale,ribbonLane:o.ribbonLane,domain:o.domain,mode:n})},e)},X=[...l],Y=(e,t)=>me(s.get(e),s.get(t)),q=function(e){let t=new Set;for(let r of e)if(r.group){if(t.has(r.group))return!0;t.add(r.group)}return!1}(X),G=e=>{let t=(e=>{let t=fe(e,d,e=>z(e).cost,{passes:6,compare:Y,maxEvaluations:Fi}),r=z(t),i=Fi;for(let e=0;6>e&&i>0;e++){let a=!1,n=Array.from({length:t.length-1},(e,t)=>t);e%2==1&&n.reverse();for(let e of n){if(0>=i--)break;let n=t[e],o=t[e+1],l=new Map(t.map((e,t)=>[e,t])),s=0,c=[];m++;for(let e of[...h.get(n)??[],...h.get(o)??[]])g[e.index]!==m&&(g[e.index]=m,c.push(e),s+=Xe(e,l,u));[t[e],t[e+1]]=[o,n];let d=new Map(l);d.set(n,e+1),d.set(o,e);let f=0;for(let e of c)f+=Xe(e,d,u);x.localCrossing+=c.length;let p=z(t,r.crossings-s+f);r.cost>p.cost?(r=p,a=!0):[t[e],t[e+1]]=[n,o]}if(!a)break}return t})(e);if((e.length>8?1/0:Hi(e.length)*(e.length+P.length+N.length))>Ri)return t;let r=he(e,R,{maxItems:8,maxEvaluations:5e4}),i=j(r),a=j(t);return i.crossings!==a.crossings&&a.crossings>i.crossings?r:t},V="geometry-refine"===o.mode;if(V||"crossing-min"!==o.laneOrder&&"crossing-min+inside-out"!==o.laneOrder){if(!V&&"inside-out"===o.laneOrder)if(q){let e=$e(X),t=e=>e.slots.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),r=[...e].sort((e,r)=>t(r)-t(e)||me(e.stableId,r.stableId)),i=Array(r.length),a=Math.floor((r.length-1)/2)-1,n=Math.floor((r.length-1)/2)+1;r.length>0&&(i[Math.floor((r.length-1)/2)]=r[0]);for(let e=1;r.length>e;e++)e%2==1&&r.length>n||0>a?i[n++]=r[e]:i[a--]=r[e];X=Re(i)}else{let e=[...X].sort((e,t)=>t.peak.topPeak+t.peak.botPeak-(e.peak.topPeak+e.peak.botPeak)||Y(e,t)),t=Array(e.length),r=Math.floor((e.length-1)/2)-1,i=Math.floor((e.length-1)/2)+1;e.length>0&&(t[Math.floor((e.length-1)/2)]=e[0]);for(let a=1;e.length>a;a++)a%2==1&&e.length>i||0>r?t[i++]=e[a]:t[r--]=e[a];X=t}}else X=q?(e=>{let t=$e(e);if(1>=t.length)return Re(t);let r=e=>z(Re(e)).cost;t=$e(G(e)),t=Fe(t,d,Y);let i=function(e,t){let r=new Map;for(let t of e)for(let e of t.slots)r.set(e,t);let i=new Map;for(let e of t){let t=r.get(e.source),a=r.get(e.target);if(!t||!a||t===a)continue;let n=Number.isFinite(e.weight)&&e.weight>0?e.weight:1,o=a.stableId>t.stableId?`${t.stableId}\0${a.stableId}`:`${a.stableId}\0${t.stableId}`,l=i.get(o);l?l.weight=(l.weight??0)+n:i.set(o,{source:t,target:a,weight:n})}return[...i.values()]}(t,d);if(t=fe(t,i,r,{passes:6,compare:(e,t)=>me(e.stableId,t.stableId),maxEvaluations:Fi}),t=function(e,t,r={}){let i=[...e];if(1>=i.length)return i;let a=t(i),n=1,o=Math.max(0,r.passes??6),l=Math.max(1,r.maxEvaluations??1/0);for(let e=0;o>e&&l>n;e++){let e=!1;for(let r=0;i.length-1>r&&l>n;r++){[i[r],i[r+1]]=[i[r+1],i[r]];let o=t(i);n++,a>o?(a=o,e=!0):[i[r],i[r+1]]=[i[r+1],i[r]]}if(!e)break}return i}(t,r,{passes:8,maxEvaluations:Fi}),(t.length>8?1/0:Hi(t.length)*(t.length+P.length+N.length))<=Ri){let e=he(t,e=>R(Re(e)),{maxItems:8,maxEvaluations:5e4}),r=Re(e),i=Re(t),a=j(r),n=j(i);a.crossings!==n.crossings?t=n.crossings>a.crossings?e:t:n.cost>a.cost&&(t=e)}return t=Fe(t,d,Y),Re(t)})(X):G(X);if(!V&&"crossing-min+inside-out"===o.laneOrder&&X.length>1)if(q){let e=$e(X),t=z(Re(e)),r=Re(e),i=t,a=Math.floor((e.length-1)/2),n=e=>e.slots.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),o=[...e].sort((e,t)=>n(t)-n(e)||me(e.stableId,t.stableId));for(let n of o){let o=e.indexOf(n);if(o===a)continue;e.splice(o,1),e.splice(a,0,n);let l=Re(e),s=z(l);s.cost>t.cost?(e.splice(a,1),e.splice(o,0,n)):(t=s,i.cost>s.cost&&(r=l,i=s))}X=r}else{let e=z(X),t=[...X],r=e,i=Math.floor((X.length-1)/2),a=[...X].sort((e,t)=>t.peak.topPeak+t.peak.botPeak-(e.peak.topPeak+e.peak.botPeak)||Y(e,t));for(let n of a){let a=X.indexOf(n);if(a===i)continue;X.splice(a,1),X.splice(i,0,n);let o=z(X);o.cost>e.cost?(X.splice(i,1),X.splice(a,0,n)):(e=o,r.cost>o.cost&&(t=[...X],r=o))}X=t}if((V||"crossing-min"===o.laneOrder||"crossing-min+inside-out"===o.laneOrder)&&X.length>1)if(q){let e=$e(X),t=j(Re(e),void 0,"score");for(let r=0;6>r&&e.length>1;r++){let r=!1;for(let i=0;e.length-1>i;i++){[e[i],e[i+1]]=[e[i+1],e[i]];let a=Re(e),n=j(a,void 0,"score");t.cost>n.cost?(X=a,t=n,r=!0):[e[i],e[i+1]]=[e[i+1],e[i]]}if(!r)break}e=Fe($e(X),d,Y),X=Re(e)}else{let e=j(X,void 0,"score");for(let t=0;X.length-1>t;t++){let r=X[t],i=X[t+1],a=new Map(X.map((e,t)=>[e,t])),n=0,o=[];m++;for(let e of[...h.get(r)??[],...h.get(i)??[]])g[e.index]!==m&&(g[e.index]=m,o.push(e),n+=Xe(e,a,u));[X[t],X[t+1]]=[i,r];let l=new Map(a);l.set(r,t+1),l.set(i,t);let s=0;for(let e of o)s+=Xe(e,l,u);x.localCrossing+=o.length;let c=j(X,e.crossings-n+s,"score");e.cost>c.cost?e=c:[X[t],X[t+1]]=[r,i]}}let K=He(l);X=He(X);let U=j(X),Q=j(K);if(V){let e=O(K),t=O(X);(U.crossings>Q.crossings||U.crossings===Q.crossings&&t>e+1e-9||U.cost>Q.cost)&&(X=K,U=Q)}else U.cost>Q.cost&&(X=K,U=Q);let Z=function({order:e,after:t,nodes:r,edges:i,outgoingPartners:a,incomingPartners:n,slotForNode:o,averageGap:l,evaluate:s}){let c=(r,a)=>{let n=[...new Set(a.map(t=>e.indexOf(t)))].sort((e,t)=>e-t),o=e.indexOf(r),c=n[0],u=n[n.length-1];if(3>n.length||!n.includes(o)||u-c+1!==n.length||1>=Math.abs(2*o-c-u))return;let d=[...e];d.splice(o,1),d.splice(c+u>>1,0,r);let f=He(d),h=s(f),g=new Set(r.occupants.map(e=>e.id)),m=new Set(a.flatMap(e=>e.occupants.map(e=>e.id))),p=i.reduce((e,t)=>g.has(t.source)&&m.has(t.target)||g.has(t.target)&&m.has(t.source)?e+(t.value>0?t.value:1):e,0);(function(e,t,r=0){return t.crossings>e.crossings||e.crossings===t.crossings&&t.cost+r>=e.cost})(h,t,Math.abs(2*o-c-u)*l*Math.max(1,p))&&(e=f,t=h)};for(let[e,t]of a)!n.has(e)&&t.size>=3&&c(o.get(e),[...t].map(e=>o.get(e)));for(let e of r){let t=o.get(e.id);!e.group&&t.group&&(n.get(e.id)?.size??0)>=3&&c(t,[...n.get(e.id)??[]].map(e=>o.get(e)).filter(e=>e===t||e.group===t.group).filter((e,t,r)=>r.indexOf(e)===t))}return{order:e,after:t}}({order:X,after:U,nodes:e,edges:t,outgoingPartners:T,incomingPartners:A,slotForNode:c,averageGap:y,evaluate:j});return X=Z.order,U=Z.after,Be(a,n,X),{before:Q,after:U,initialOrder:l.map(e=>s.get(e)),evaluations:x}}function qe(e,t,r){let i=e.map(e=>{let i=e.occupants.map(e=>({id:e.id,end:r[e.id]?.end??e.end})),a=0,n=0;for(let e of i){let r=t[e.id];a=Math.max(a,r?.topPeak||0),n=Math.max(n,r?.botPeak||0)}return{occupants:i,peak:{topPeak:a,botPeak:n},...null!=e.group?{group:e.group}:{}}}),a=ge();return i.forEach((e,t)=>{for(let r of e.occupants)a[r.id]=t}),{slots:i,slotByNode:a}}function Ge(e,t){return null!=e.start&&null!=e.end&&null!=t.start&&null!=t.end&&!(t.start>=e.end||e.start>=t.end)}function Ve(e,t){return me(e,t)>0?`${t}\0${e}`:`${e}\0${t}`}function Ke(e){let t=new Map,r=new Map;for(let i of e)r.has(i.source)||r.set(i.source,new Set),t.has(i.target)||t.set(i.target,new Set),r.get(i.source).add(i.target),t.get(i.target).add(i.source);return{incoming:new Map([...t].map(([e,t])=>[e,t.size])),outgoing:new Map([...r].map(([e,t])=>[e,t.size]))}}function Ue(e){let t=new Map,r=new Map,i=(e,t,r,i)=>{let a=e.get(t);a||(a=new Map,e.set(t,a)),a.set(r,(a.get(r)??0)+i)};for(let a of e){let e=a.value>0&&Number.isFinite(a.value)?a.value:1;i(t,a.source,a.target,e),i(r,a.target,a.source,e)}let a=new Map,n=e=>{if(a.has(e))return;let i=t.get(e),n=r.get(e),o=new Map;for(let[e,t]of i??[])o.set(e,(o.get(e)??0)+t);for(let[e,t]of n??[])o.set(e,(o.get(e)??0)+t);if(1===o.size){let[t,r]=[...o][0];a.set(e,{partner:t,weight:r})}};for(let t of e)n(t.source),n(t.target);return a}function Qe(e,t,r){let i=r.get(e),a=r.get(t);return!i||!a||i.partner===a.partner||i.partner===t||a.partner===e}function Ze(e,t,r){return!!r.has(e)&&t.some(t=>!Qe(e,t,r))}function Je(e,t){return(e.value>0&&Number.isFinite(e.value)?e.value:1)*(1+(1===t.outgoing.get(e.source)?1:0)+(1===t.incoming.get(e.target)?1:0))}function et(e,t,r,i){if(12>=e.length||1>=i.slotCount)return i.assignment;let a=new Map(e.map((e,t)=>[e,t])),n=Array.from({length:e.length},()=>new Map),o=Ke(r);for(let e of r){let t=a.get(e.source),r=a.get(e.target);if(null==t||null==r||t===r)continue;let i=Je(e,o);n[t].set(r,(n[t].get(r)??0)+i),n[r].set(t,(n[r].get(t)??0)+i)}let l=Ue(r),s=e.map(e=>l.get(e)?.weight??0),c=Array.from({length:e.length},()=>new Map),u=0;for(let r=0;e.length-1>r&&5e4>u;r++)if(l.has(e[r]))for(let i=r+1;e.length>i;i++){if(!l.has(e[i])||t.conflicts(e[r],e[i]))continue;u++;let a=Math.min(s[r],s[i])||Math.max(s[r],s[i]),n=Qe(e[r],e[i],l)?a:-a;if(Math.abs(n)>zi&&(c[r].set(i,n),c[i].set(r,n),u>=5e4))break}let d=[...i.assignment],f=Array.from({length:i.slotCount},()=>[]);d.forEach((e,t)=>f[e].push(t));let h=(e,t,r)=>{let i=d[t],a=d[r],n=0,o=new Set;for(let l of[t,r])for(let[s,c]of e[l]){let e=s>l?`${l}:${s}`:`${s}:${l}`;if(o.has(e))continue;o.add(e);let u=(l===t?a:i)===(s===t?a:s===r?i:d[s]);d[l]===d[s]!==u&&(n+=u?c:-c)}return n},g=(e,t,r)=>{let i=0;for(let[a,n]of e[t]){let e=r===d[a];d[t]===d[a]!==e&&(i+=e?n:-n)}return i},m=(e,t)=>e>zi||zi>=Math.abs(e)&&t>zi,p=(e,t,r,i)=>e>r+zi||zi>=Math.abs(e-r)&&t>i+zi,y=0;for(let r=0;32>r&&_i>y;r++){let r=null,i=-1,a=-1,o=-1,l=-1/0,s=-1/0;for(let u=0;e.length>u;u++){for(let h=0;f.length>h&&y++<_i;h++){if(h===d[u]||!f[h].every(r=>!t.conflicts(e[u],e[r])))continue;let y=g(n,u,h),b=g(c,u,h);m(y,b)&&p(y,b,l,s)&&(r="move",i=u,a=-1,o=h,l=y,s=b)}if(y>=_i)break}for(let u=0;e.length-1>u;u++){for(let g=u+1;e.length>g&&y++<_i;g++){let y=d[u],b=d[g];if(y===b||!f[b].every(r=>r===g||!t.conflicts(e[u],e[r]))||!f[y].every(r=>r===u||!t.conflicts(e[g],e[r])))continue;let v=h(n,u,g),k=h(c,u,g);m(v,k)&&p(v,k,l,s)&&(r="swap",i=u,a=g,o=-1,l=v,s=k)}if(y>=_i)break}if(null==r||-1===i)break;if("move"===r){let e=d[i];f[e].splice(f[e].indexOf(i),1),f[o].push(i),d[i]=o;continue}let u=d[i],b=d[a];f[u].splice(f[u].indexOf(i),1,a),f[b].splice(f[b].indexOf(a),1,i),d[i]=b,d[a]=u}return d}function tt(e,t){let r=1/0,i=-1/0;for(let t of e?.samples??[])1e-9>=t.topMass+t.botMass||(r=Math.min(r,t.t),i=Math.max(i,t.t));return Number.isFinite(r)&&Number.isFinite(i)?(null!=t.start&&(r=Math.max(r,t.start)),null!=t.end&&(i=Math.min(i,t.end)),r>i?{start:null,end:null}:{start:r,end:i}):{start:null,end:null}}function rt(e,t,r,i){let a=function(e,t,r,i){return`${e.map(e=>{let t=r[e.id],a=i[e.id];return[e.id,e.group??"",e.xExtent?.[0]??"",e.xExtent?.[1]??"",t?.topPeak??0,t?.botPeak??0,a?.start??"",a?.end??""].join(":")}).join("|")}#${t.map(e=>[e.id,e.source,e.target,e.value,e.startTime,e.endTime].join(":")).join("|")}`}(e,t,r,i),n=Wi.get(a);if(n)return qe(n.slots,r,i);let o=ge();for(let t of e)o[t.id]=tt(r[t.id],i[t.id]);let l=function(e,t){return e.filter(e=>null!=t[e.id].start).sort((e,r)=>t[e.id].start-t[r.id].start||t[e.id].end-t[r.id].end||me(e.id,r.id)).map(e=>e.id)}(e,o),s=new Map(e.map(e=>[e.id,e])),c=new Map(e.map(e=>[e.id,e.group||void 0])),u=Ue(t),d=function(e,t,r,i,a,n){let o=new Set,l=new Map(e.map(e=>[e,new Set])),s=new Map(e.map(e=>[e,new Set]));for(let e of i)o.add(Ve(e.source,e.target)),l.get(e.target)?.add(e.source),s.get(e.source)?.add(e.target);let c=new Map,u=new Set,d=(e,t)=>{for(let r=0;e.length>r;r++)for(let i=r+1;e.length>i;i++){let a=Ve(e[r],e[i]);t instanceof Map?t.set(a,[e[r],e[i]]):t.add(a)}};for(let e of s.values())d([...e],c);for(let e of l.values())d([...e],u);let f=new Set;for(let[e,[i,a]]of c)u.has(e)&&(Ge(t[i],t[a])||Ge(r[i],r[a])&&(f.add(i),f.add(a)));return{conflicts:(e,r)=>{let i=a.get(e),l=a.get(r);return!((null==i||null==l||i===l)&&(null!=i==(null!=l)||o.has(Ve(e,r))||n.has(e)&&n.has(r)&&Qe(e,r,n))&&!Ge(t[e],t[r])&&(!f.has(e)&&!f.has(r)||o.has(Ve(e,r))))}}}(l,o,i,t,c,u),f=function(e,t,r=new Map){let i=[],a=[];for(let n of e){let e=i.findIndex(e=>e.every(e=>!t.conflicts(n,e))&&!Ze(n,e,r));-1===e&&!r.has(n)&&(e=i.findIndex(e=>e.every(e=>!t.conflicts(n,e)))),-1===e&&(e=i.length,i.push([])),i[e].push(n),a.push(e)}return{assignment:a,slotCount:i.length}}(l,d,u),h=function(e,t,r,i){if(0===e.length||e.length>12||1>=i.slotCount)return i.assignment;let a=new Map(e.map((e,t)=>[e,t])),n=Array.from({length:e.length},()=>new Float64Array(e.length)),o=Array.from({length:e.length},()=>new Map),l=Array.from({length:e.length},()=>new Map),s=Ke(r);for(let e of r){let t=a.get(e.source),r=a.get(e.target);if(null==t||null==r||t===r)continue;let i=Je(e,s);n[t][r]+=i,n[r][t]+=i,l[t].set(r,(l[t].get(r)??0)+i),o[r].set(t,(o[r].get(t)??0)+i)}let c=Ue(r),u=e.map(e=>c.get(e)?.weight??0),d=Array.from({length:e.length},()=>new Float64Array(e.length));for(let t=0;e.length>t;t++)for(let r=t+1;e.length>r;r++){for(let[e,i]of o[t])d[t][r]+=Math.min(i,o[r].get(e)??0);for(let[e,i]of l[t])d[t][r]+=Math.min(i,l[r].get(e)??0);if(c.has(e[t])&&c.has(e[r])){let i=Math.min(u[t],u[r])||Math.max(u[t],u[r]);d[t][r]+=Qe(e[t],e[r],c)?i:-i}d[r][t]=d[t][r]}let f=[...i.assignment],h=(t=>{let r=0,i=0;for(let a=0;e.length>a;a++)for(let o=a+1;e.length>o;o++)t[a]===t[o]&&(r+=n[a][o],i+=d[a][o]);return{flow:r,affinity:i}})(f),g=0,m=Array(e.length).fill(-1),p=Array.from({length:i.slotCount},()=>[]),y=(r,a,o,l)=>{if(g>=75e3)return;if(r===e.length)return g++,void((o>h.flow||o===h.flow&&l>h.affinity||o===h.flow&&l===h.affinity&&function(e,t){for(let r=0;Math.min(e.length,t.length)>r;r++)if(e[r]!==t[r])return t[r]>e[r];return t.length>e.length}(m,f))&&(f=[...m],h={flow:o,affinity:l}));let s=Math.min(a+1,i.slotCount-1);for(let i=0;s>=i;i++){if(p[i].some(i=>t.conflicts(e[r],e[i])))continue;let s=0,c=0;for(let e of p[i])s+=n[r][e],c+=d[r][e];if(m[r]=i,p[i].push(r),y(r+1,Math.max(a,i),o+s,l+c),p[i].pop(),m[r]=-1,g>=75e3)return}};return m[0]=0,p[0].push(0),y(1,0,0,0),f}(l,d,t,{...f,assignment:et(l,d,t,f)}),g=new Map,m=h.map(e=>(g.has(e)||g.set(e,g.size),g.get(e))),p=Array.from({length:g.size||(e.length>0?1:0)},()=>({occupants:[],peak:{topPeak:0,botPeak:0}})),y=ge();l.forEach((e,t)=>{let r=m[t],i=p[r];i.occupants.push({id:e,end:o[e].end??-1/0});let a=s.get(e)?.group;a&&(i.group=a),y[e]=r});for(let t of[...e].sort((e,t)=>me(e.id,t.id)))null==y[t.id]&&(p[0].occupants.push({id:t.id,end:-1/0}),y[t.id]=0);for(let e of p){e.occupants.sort((e,t)=>(o[e.id].start??1/0)-(o[t.id].start??1/0)||me(e.id,t.id));for(let t of e.occupants){let i=r[t.id];e.peak.topPeak=Math.max(e.peak.topPeak,i?.topPeak||0),e.peak.botPeak=Math.max(e.peak.botPeak,i?.botPeak||0)}}let b={slots:p,slotByNode:y};return function(e,t){for(Wi.has(e)&&Wi.delete(e),Wi.set(e,{slots:t.slots.map(e=>({occupants:e.occupants.map(e=>({...e})),peak:{...e.peak},...null!=e.group?{group:e.group}:{}})),slotByNode:Object.assign(ge(),t.slotByNode)});Wi.size>12;){let e=Wi.keys().next().value;if(null==e)break;Wi.delete(e)}}(a,b),b}function it(e){return e.topMass+e.botMass}function at(e){let t=new Map;for(let r of e.samples){if(Number.isNaN(r.t))continue;let e=t.get(r.t);e||(e=[],t.set(r.t,e)),e.push(r)}let r=0,i=-1/0;return a=>{a>=i||(r=0),i=a;let n=t.get(a);if(n){let e=n.reduce((e,t)=>it(t)<it(e)?e:t,n[0]);return{exact:n,sample:e}}for(;e.samples.length>r&&a>=e.samples[r].t;)r++;return{exact:n,sample:e.samples[r-1]??null}}}function nt(e,t,r,i,a,n,o=0){let l=new Map;for(let r of e){if(!r.group||!t[r.id])continue;let e=l.get(r.group)??[];e.push(r),l.set(r.group,e)}if(0===l.size||0>=n)return t;let s=Object.fromEntries(Object.entries(t).map(([e,t])=>[e,{...t,samples:t.samples.map(e=>({...e})),localAttachments:new Map([...t.localAttachments].map(([e,t])=>[e,{...t}]))}]));for(let[e,c]of l){let l=r.map((e,t)=>({slot:e,index:t})).filter(({slot:t})=>t.group===e);if(0===l.length)continue;let u=l[0].slot,d=l.at(-1).slot,f=a[u.occupants[0]?.id],h=a[d.occupants[0]?.id];if(!Number.isFinite(f)||!Number.isFinite(h))continue;let g=(f-u.peak.topPeak*n+(h+d.peak.botPeak*n))/2,m=[...new Set(c.flatMap(e=>t[e.id].samples.map(e=>e.t)))].sort((e,t)=>e-t),p=new Map;for(let e of c)p.set(e.id,new Map);let y=new Map(c.map(e=>[e.id,at(t[e.id])]));for(let e of m){let t=new Map;for(let r of c){let{sample:a}=y.get(r.id)(e);if(!a||1e-9>=it(a))continue;let n=i[r.id];if(null==n)continue;let o=t.get(n)??[];o.push({node:r,sample:a}),t.set(n,o)}let r=[...t].sort((e,t)=>e[0]-t[0]).map(([e,t])=>({slot:e,active:t,mass:Math.max(...t.map(({sample:e})=>it(e)))}));if(0===r.length)continue;let l=g-(r.reduce((e,t)=>e+t.mass,0)*n+Math.max(0,o)*Math.max(0,r.length-1))/2;for(let t of r){for(let{node:r,sample:i}of t.active){let t=(l-a[r.id])/n+i.topMass-(i.boundaryOffset??0);p.get(r.id).set(e,t)}l+=t.mass*n+Math.max(0,o)}}for(let e of c){let r=t[e.id],i=s[e.id],a=p.get(e.id),n=y.get(e.id),o=[];for(let e of m){let t=a.get(e),{exact:r,sample:i}=n(e);r?o.push(...r.map(e=>({...e,...null!=t?{boundaryOffset:(e.boundaryOffset??0)+t}:{}}))):null==t||!i||1e-9>=it(i)||o.push({...i,t:e,boundaryOffset:(i.boundaryOffset??0)+t})}i.samples=o,i.localAttachments=new Map([...r.localAttachments].map(([e,t])=>{let r=a.get(t.time);return[e,{...t,...null!=r?{boundaryOffset:(t.boundaryOffset??0)+r}:{}}]}))}}return s}function ot(e,t,r,i,a){let{plotH:n,padding:o,valueScale:l,packing:s,laneOrder:c,lifetimeMode:u="half",lanePlacement:d="stack",groupPadding:f=0,ribbonLane:h="both",domain:g}=a,m=ge(),p=ge();for(let t of e)m[t.id]=r[t.id].topPeak||0,p[t.id]=r[t.id].botPeak||0;let y="half"===u,b=ge();for(let t of e){let e=Array.isArray(t.xExtent)?t.xExtent[0]:null,r=Array.isArray(t.xExtent)?t.xExtent[1]:null,a=null!=e&&Number.isFinite(e)?e:1/0,n=null!=r&&Number.isFinite(r)?r:-1/0;for(let e of i.outgoing[t.id]){a>e.startTime&&(a=e.startTime),null!=e.systemInTime&&Number.isFinite(e.systemInTime)&&a>e.systemInTime&&(a=e.systemInTime);let t=y?(e.startTime+e.endTime)/2:e.endTime;t>n&&(n=t)}for(let e of i.incoming[t.id]){let t=y?(e.startTime+e.endTime)/2:e.startTime;a>t&&(a=t),e.endTime>n&&(n=e.endTime),null!=e.systemOutTime&&Number.isFinite(e.systemOutTime)&&e.systemOutTime>n&&(n=e.systemOutTime)}b[t.id]={start:Number.isFinite(a)?a:null,end:Number.isFinite(n)?n:null}}let v=ge(),k=[],x=[];if(a.frozenSlots){let e=qe(a.frozenSlots,r,b);k=e.slots,v=e.slotByNode,x=k.map(pe)}else if("reuse"===s){let i=rt(e,t,r,b);k=i.slots,v=i.slotByNode}else e.forEach((e,t)=>{k.push({occupants:[{id:e.id,end:b[e.id]?.end??-1/0}],peak:{topPeak:m[e.id],botPeak:p[e.id]},...e.group?{group:e.group}:{}}),v[e.id]=t});We(k,v),0===x.length&&(x=k.map(pe));let S=null;a.frozenSlots||(a.fixedSlotOrder?function(e,t,r){let i=new Map(r.map((e,t)=>[e,t]));Be(e,t,[...e].sort((e,t)=>(i.get(pe(e))??1/0)-(i.get(pe(t))??1/0)||me(pe(e),pe(t))))}(k,v,a.fixedSlotOrder):a.runOrdering&&c&&"insertion"!==c&&(S=Ye(e,t,r,b,k,v,{plotH:n,padding:o,valueScale:l,groupPadding:f,laneOrder:c,ribbonLane:h,domain:g}))),We(k,v);let w=xe(e,t,r,k,v,{plotH:n,padding:o,valueScale:l,stackValueScale:a.stackValueScale,lanePlacement:d,groupPadding:f}),M=0===k.length?0:k[0].peak.topPeak+w.adjacentClearance.reduce((e,t)=>e+t,0)+k[k.length-1].peak.botPeak,P=S?.before.crossings??null,L=S?.after.crossings??null,T=S?.before.weightedLength??null,A=S?.after.weightedLength??null;return{effectiveSlotsHeight:M,centerlines:w.centerlines,laneLifetime:b,slots:k,slotByNode:v,slotCenter:w.slotCenter,stackCenter:w.stackCenter,verticalUtilization:w.verticalUtilization,selectedSlotOrder:k.map(pe),initialSlotOrder:x,ordering:S,crossingsBefore:P,crossingsAfter:L,lengthBefore:T,lengthAfter:A}}function lt(e,t,r,i="horizontal"){return"vertical"===i?{top:e?38:t?28:16,right:24,bottom:24,left:r?72:24}:{top:e?30:t?24:8,right:80,bottom:r?28:8,left:80}}function st(e,t,r,i,a,n,o,l,s={}){let c,u,d,f,h=a,g=e=>l?Math.max(l[0],Math.min(l[1],e)):e,m=n(g(e.time)),p=n(g(r.time)),y=e.value*h,b=r.value*h,v=t+(e.boundaryOffset??0)*h,k=i+(r.boundaryOffset??0)*h,x=e.sideMassBefore*h,S=r.sideMassAfter*h;"top"===e.side?(c=v-x,u=c+y):(u=v+x,c=u-y),"top"===r.side?(d=k-S,f=d+b):(f=k+S,d=f-b);let w=s.sourceRunwayStart,M=s.minRun,P=Math.abs((d+f)/2-(c+u)/2),L=p-m,T="number"==typeof w&&Number.isFinite(w),A="number"==typeof M&&Number.isFinite(M)&&M>0;if(T&&P>1e-9&&L>0&&("auto"===M||A)){let t="source"===o?.85:"target"===o?.15:.5,r="auto"===M?Math.min(144,Math.sqrt(8*P/(1.5*Math.min(t*t,(1-t)*(1-t))))):M;if(r>L){let t=n(g(Math.min(w,e.time)));Number.isFinite(t)&&(m=Math.min(m,Math.max(Math.min(m,t),p-r)))}}let D="source"===o?m+.85*(p-m):"target"===o?m+.15*(p-m):(m+p)/2;return{sx:m,sTop:c,sBot:u,tx:p,tTop:d,tBot:f,cp1X:D,cp2X:D}}function ct(e){return Math.max(18,11*e.length*.58)}function ut(e){let t=1.22*ct(e.labelText)+4;return"start"===e.labelAnchor?[e.labelX,e.labelX+t]:"middle"===e.labelAnchor?[e.labelX-t/2,e.labelX+t/2]:[e.labelX-t,e.labelX]}function dt(e,t){let r=e.labelX-ct(e.labelText),i=t.labelX-ct(t.labelText);return t.labelX+3>=r&&e.labelX+3>=i}function ft(e){return e.replace(oa,(e,t,r)=>`${r},${t}`)}function ht(e){if(!e)return;let t=e=>({x:e.y,y:e.x});return{...e,...e.points&&{points:e.points.map(t)},...e.segments&&{segments:e.segments.map(e=>e.map(t))}}}function gt(e){return{...e,pathD:ft(e.pathD),y0:e.x0,y1:e.x1,x0:0,x1:0}}function mt(e){let{nodes:t,edges:r,domain:i,plotW:a,plotH:n,ribbonLane:o,ribbonMinRun:l=0,edgeOpacity:s,colorOf:c,layoutOpts:u,orientation:d="horizontal",showLabels:f=!0,labelPriorityAccessor:h,maxLabels:g,selectionDatum:m="raw",styleRules:p,colorBy:y,valueAccessor:b,usageMode:v="static"}=e,k="vertical"===d?n:a,x="vertical"===d?a:n,S=re(t,r,i,{usageMode:v}),{fatal:w,warnings:M}=function(e){let t=[],r=[];for(let i of e)"fatal"===te(i)?t.push(i):r.push(i);return{fatal:t,warnings:r}}(S),P=function(e,t,r="static"){if("strip"!==ee(r).invalidSystemTime)return e;let i=new Set(t.filter(e=>"invalid-system-time"===e.kind).map(e=>e.id));return 0===i.size?e:e.map(e=>{if(!i.has(e.id))return e;let t={...e};return null!=t.systemInTime&&!Number.isFinite(t.systemInTime)&&delete t.systemInTime,null!=t.systemOutTime&&!Number.isFinite(t.systemOutTime)&&delete t.systemOutTime,t})}(r,S,v),L=na().domain(i).range([0,k]);if(w.length>0)return{layout:null,layoutConfig:{bands:[],ribbons:[],showLabels:!1!==f},issues:w,warnings:M,xScale:L};let T=function(e,t,r){let{plotH:i,pairing:a="temporal",packing:n="reuse",laneOrder:o="crossing-min",lifetimeMode:l="half",maxValueScale:s,lanePlacement:c="stack",nodeSizing:u="temporal",groupPadding:d=0,ribbonLane:f="both",domain:h}=r,g=Number.isFinite(d)?Math.max(0,d):0,m=function(e,t){let r=ge(),i=ge();for(let t of e)r[t.id]=[],i[t.id]=[];for(let e of t)i[e.source]&&i[e.source].push(e),r[e.target]&&r[e.target].push(e);return{incoming:r,outgoing:i}}(e,t),p=function(e,t,r,i="temporal"){let a="temporal"===i?(e,t)=>e.endTime-t.endTime||me(e.id,t.id):(e,t)=>t.value-e.value||me(e.id,t.id),n="temporal"===i?(e,t)=>e.startTime-t.startTime||me(e.id,t.id):(e,t)=>t.value-e.value||me(e.id,t.id),o=new Map;for(let e of t)o.set(e.id,{});let l=(e,t)=>{let r=new Map;for(let i of e){let e=i[t];r.has(e)||r.set(e,{partner:e,edges:[],total:0,earliestStart:1/0,latestEnd:-1/0});let a=r.get(e);a.edges.push(i),a.total+=i.value,a.earliestStart=Math.min(a.earliestStart,i.startTime),a.latestEnd=Math.max(a.latestEnd,i.endTime)}let o=[...r.values()];o.sort("temporal"===i?(e,r)=>"target"===t?e.earliestStart-r.earliestStart||me(e.partner,r.partner):e.latestEnd-r.latestEnd||me(e.partner,r.partner):(e,t)=>t.total-e.total||me(e.partner,t.partner));for(let e of o)e.edges.sort("target"===t?n:a);return o};for(let t of e){let e=r.outgoing[t.id],i=r.incoming[t.id];if(0===i.length)l(e,"target").forEach((e,t)=>{let r=t%2==0?"top":"bot";for(let t of e.edges)o.get(t.id).sourceSide=r});else if(0===e.length)l(i,"source").forEach((e,t)=>{let r=t%2==0?"top":"bot";for(let t of e.edges)o.get(t.id).targetSide=r});else{let t=l(i,"source"),r=l(e,"target"),a=Math.max(t.length,r.length);for(let e=0;a>e;e++){let i=e%2==0?"top":"bot";if(t[e])for(let r of t[e].edges)o.get(r.id).targetSide=i;if(r[e])for(let t of r[e].edges)o.get(t.id).sourceSide=i}}}return o}(e,t,m,a),y=ge();for(let t of e)y[t.id]=Oe(t,m,p,void 0,u);let b=ot(e,t,y,m,{plotH:i,padding:12,valueScale:1,packing:n,laneOrder:o,lifetimeMode:l,runOrdering:!0,lanePlacement:"stack",groupPadding:g,ribbonLane:f,domain:h}),v=b.slots.map(e=>({occupants:e.occupants.map(e=>({...e})),peak:{...e.peak},...null!=e.group?{group:e.group}:{}})),k=new Set;for(let e of t){let t=b.slotByNode[e.source],r=b.slotByNode[e.target];if(void 0===t||void 0===r)continue;let i=p.get(e.id);t!==r?t>r?(i.sourceSide="top",i.targetSide="bot"):(i.sourceSide="bot",i.targetSide="top"):(k.add(e.id),i.sourceSide="bot",i.targetSide="bot")}for(let t of e){let e=m.outgoing[t.id],r=m.incoming[t.id],i=new Set(e.map(e=>p.get(e.id).sourceSide)),a=new Set(r.map(e=>p.get(e.id).targetSide));if(1===i.size&&r.length>0){let e=[...i][0];for(let t of r)b.slotByNode[t.source]===b.slotByNode[t.target]&&(p.get(t.id).targetSide=e)}if(1===a.size&&e.length>0){let t=[...a][0];for(let r of e)b.slotByNode[r.source]===b.slotByNode[r.target]&&(p.get(r.id).sourceSide=t)}}(function(e,t,r){let i=new Map,a=[];for(let t of e)a.push({time:t.startTime,kind:"out",edge:t}),a.push({time:t.endTime,kind:"in",edge:t});a.sort((e,t)=>e.time-t.time||(e.kind===t.kind?0:"in"===e.kind?-1:1)||("out"===e.kind?t.edge.value-e.edge.value:0)||me(e.edge.id,t.edge.id));let n=e=>{let t=i.get(e);return t||(t={top:0,bot:0},i.set(e,t)),t},o=(e,t,r)=>{let i="top"===t?"bot":"top",a=Math.min(r,e[t]);e[t]-=a;let n=r-a;n>0&&(e[i]=Math.max(0,e[i]-n))};for(let e of a){let{edge:i}=e;if("in"===e.kind){let e=t.get(i.id)?.targetSide??"bot";n(i.target)[e]+=i.value;continue}let a=n(i.source),l=t.get(i.id),s=l.sourceSide??"bot";if(r[i.source]===r[i.target]){let e=a.top>=i.value,t=a.bot>=i.value;e!==t?s=e?"top":"bot":!e&&!t&&a.top!==a.bot&&(s=a.top>a.bot?"top":"bot"),l.sourceSide=s,l.targetSide=s}o(a,s,i.value)}})(t,p,b.slotByNode),function(e,t,r,i){for(let a of e){let e=t.incoming[a.id],n=t.outgoing[a.id];if(0===e.length||0===n.length)continue;let o=()=>{let t={inTop:0,inBot:0,outTop:0,outBot:0};for(let i of e)"top"===r.get(i.id).targetSide?t.inTop+=i.value:t.inBot+=i.value;for(let e of n)"top"===r.get(e.id).sourceSide?t.outTop+=e.value:t.outBot+=e.value;return t},l=(e,t)=>{let a=o(),l="top"===e?a.outTop-a.inTop:a.outBot-a.inBot,s="top"===t?a.inTop-a.outTop:a.inBot-a.outBot;if(0>=l||0>=s)return!1;let c=Math.min(l,s),u=n.filter(t=>!i.has(t.id)&&r.get(t.id).sourceSide===e&&c>=t.value).sort((e,t)=>t.value-e.value||me(e.id,t.id));return 0!==u.length&&(r.get(u[0].id).sourceSide=t,!0)},s=n.length+1;for(;s-- >0&&(l("top","bot")||l("bot","top")););}}(e,m,p,k),y=ge();for(let t of e)y[t.id]=Oe(t,m,p,void 0,u);let x=ot(e,t,y,m,{plotH:i,padding:12,valueScale:1,packing:n,laneOrder:o,lifetimeMode:l,frozenSlots:v,lanePlacement:"stack",groupPadding:g,ribbonLane:f,domain:h}),S=x.effectiveSlotsHeight??x.slots.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),w=x.slots.slice(0,-1).reduce((e,t,r)=>e+(null!=t.group&&t.group===x.slots[r+1].group?1:0),0),M=Math.max(1,x.slots.length+1-w),P=Math.min(12,Math.max(0,.35*i-w*g)/M),L=2*P+ye(x.slots,P,g).reduce((e,t)=>e+t,0),T=S>0?Math.max(0,(i-L)/S):1,A=Number.isFinite(s)&&s>0?Math.min(T,s):T,D=ot(e,t,y,m,{plotH:i,padding:P,valueScale:A,packing:n,laneOrder:o,lifetimeMode:l,frozenSlots:v,lanePlacement:c,groupPadding:g,ribbonLane:f,domain:h,stackValueScale:T}),I=Number.isFinite(s)&&s>0&&T>s+1e-12;if("insertion"!==o&&("hug"===c||I)&&D.slots.length>1&&(Ye(e,t,y,D.laneLifetime,D.slots,D.slotByNode,{plotH:i,padding:P,valueScale:A,groupPadding:g,laneOrder:o,ribbonLane:f,domain:h,lanePlacement:c,mode:"geometry-refine"}),D=ot(e,t,y,m,{plotH:i,padding:P,valueScale:A,packing:n,laneOrder:o,lifetimeMode:l,frozenSlots:D.slots,fixedSlotOrder:D.slots.map(pe),lanePlacement:c,groupPadding:g,ribbonLane:f,domain:h,stackValueScale:T})),function(e,t){let r=(e,r)=>{for(let i of e){let e=new Map;for(let a of i){let i=`${("out"===r?t.get(a.id)?.sourceSide:t.get(a.id)?.targetSide)??""}\0${"out"===r?a.startTime:a.endTime}`,n="out"===r?`${a.target}\0${a.endTime}`:`${a.source}\0${a.startTime}`,o=e.get(i);if(null!=o&&o!==n)return!0;e.set(i,n)}}return!1};return r(Object.values(e.outgoing),"out")||r(Object.values(e.incoming),"in")}(m,p)){let r=function(e,t,r,i){let a=new Map;for(let n of e){let e=t[n.source]?.localAttachments.get(n.id),o=t[n.target]?.localAttachments.get(n.id),l=r[n.source],s=r[n.target];if(!(e&&o&&Number.isFinite(l)&&Number.isFinite(s)))continue;let c=Ce(e,l,i),u=Ce(o,s,i);a.set(n.id,{source:(c[0]+c[1])/2,target:(u[0]+u[1])/2})}return a}(t,y,D.centerlines,A);y=ge();for(let t of e)y[t.id]=Oe(t,m,p,r,u);D=ot(e,t,y,m,{plotH:i,padding:P,valueScale:A,packing:n,laneOrder:o,lifetimeMode:l,frozenSlots:D.slots,fixedSlotOrder:D.slots.map(pe),lanePlacement:c,groupPadding:g,ribbonLane:f,domain:h,stackValueScale:T})}let E=new Map(b.initialSlotOrder.map((e,t)=>[e,t])),C=[...D.slots].sort((e,t)=>(E.get(pe(e))??1/0)-(E.get(pe(t))??1/0)||me(pe(e),pe(t))),O=ge();C.forEach((e,t)=>{for(let r of e.occupants)O[r.id]=t});let N=xe(e,t,y,C,O,{plotH:i,padding:P,valueScale:A,stackValueScale:T,lanePlacement:"stack",groupPadding:g}),B=nt(e,y,C,O,N.centerlines,A,g),$=De(ze(O,t),je(O,t),t,B,C,O,N.centerlines,D.laneLifetime,A,N.verticalUtilization,f,h);y=nt(e,y,D.slots,D.slotByNode,D.centerlines,A,g);let H=De(ze(D.slotByNode,t),je(D.slotByNode,t),t,y,D.slots,D.slotByNode,D.centerlines,D.laneLifetime,A,D.verticalUtilization,f,h);return{nodeData:y,sides:p,valueScale:A,padding:P,compressedPadding:12>P,centerlines:D.centerlines,laneLifetime:D.laneLifetime,slots:D.slots,slotByNode:D.slotByNode,crossingsBefore:"insertion"===o?null:$.crossings,crossingsAfter:"insertion"===o?null:H.crossings,lengthBefore:"insertion"===o?null:$.weightedLength,lengthAfter:"insertion"===o?null:H.weightedLength,layoutQualityBefore:$,layoutQuality:H}}(t,P,{plotH:x,...u,ribbonLane:o,domain:i}),{centerlines:A,nodeData:D,valueScale:I}=T,E=mr(y,b),C=[],O=[],N=0===l?new Map:function(e,t,r){let i=new Set(t.map(e=>e.target)),a=new Map(e.map(e=>[e.id,e])),n=new Map;for(let e of t){if(i.has(e.source))continue;let t=n.get(e.source)??[];t.push(e),n.set(e.source,t)}let o=new Map;for(let t of e){if(!t.group)continue;let e=o.get(t.group)??[];e.push(t),o.set(t.group,e)}let l=new Set;for(let[e,t]of o){let r=t.flatMap(e=>n.get(e.id)??[]),a=new Set(r.map(e=>e.startTime));r.length>0&&1===a.size&&t.every(e=>{let t=e.xExtent?.[0],a=r[0].startTime;return!i.has(e.id)&&(n.get(e.id)?.length??0)>0&&Number.isFinite(t)&&a>t})&&l.add(e)}let s=new Map;for(let[e,t]of n){let i=a.get(e);if(i?.group&&!l.has(i.group))continue;let n=i?.xExtent?.[0],o=[...t].sort((e,t)=>e.startTime-t.startTime||e.id.localeCompare(t.id)),c=o[0]?.startTime-1,u=null;for(let e=0;o.length>e;){let t=o[e].startTime,i=e+1;for(;o.length>i&&o[i].startTime===t;)i++;for(let t=e;i>t;t++){let e=o[t],i=Number.isFinite(n)&&e.startTime>n,a=Number.isFinite(e.systemInTime)&&e.startTime>e.systemInTime;if(!i&&!a)continue;let l=r[0];i&&(l=Math.max(l,n)),a&&(l=Math.max(l,e.systemInTime)),!i&&a&&Number.isFinite(c)&&(l=Math.max(l,c)),null!=u&&(l=Math.max(l,u)),e.startTime>l&&s.set(e.id,l)}u=t,e=i}}for(let[e,t]of o){if(!l.has(e))continue;let r=t.flatMap(e=>n.get(e.id)??[]);if(!r.every(e=>s.has(e.id))){for(let e of r)s.delete(e.id);continue}let i=Math.max(...r.map(e=>s.get(e.id)));for(let e of r)s.set(e.id,i)}return s}(t,P,i),B=new Map(t.filter(e=>e.group).map(e=>[e.id,e.group])),$=new Map;for(let e of P){let t=D[e.source]?.localAttachments.get(e.id),r=D[e.target]?.localAttachments.get(e.id);!t||!r||$.set(e.id,st(t,A[e.source],r,A[e.target],I,L,o,i,{minRun:l,sourceRunwayStart:N.get(e.id)}))}let H=function(e,t,r,i,a,n){let o=new Map(t),l=new Map;for(let t of e){let e=n?.get(t.source),r=null==e?"node:"+t.source:"group:"+e,i=l.get(r)??new Map,a=i.get(t.startTime)??[];a.push(t),i.set(t.startTime,a),l.set(r,i)}for(let e of l.values())for(let[n,l]of e){if(!l.some(e=>r.has(e.id)))continue;let e=l.map(e=>t.get(e.id));if(e.some(e=>null==e))continue;let s=i(n),c=Math.min(...e.map(e=>e.sx));if(c>=s-1e-9)continue;let u=Math.max(...l.map(e=>{let t=r.get(e.id);return null==t?s:Math.min(s,i(t))})),d=Math.min(s,Math.max(c,u));for(let e of l){let r=t.get(e.id),i=d+(r.tx-d)*("source"===a?.85:"target"===a?.15:.5);o.set(e.id,{...r,sx:d,cp1X:i,cp2X:i})}}return o}(P,$,N,L,o,B),R=function(e,t,r,i,a){let n=new Map;for(let o of e){if(!r.has(o.id))continue;let e=t.get(o.id);if(!e||e.sx>=i(o.startTime)-1e-9)continue;let l=a(e.sx);Number.isFinite(l)&&o.startTime>l&&n.set(o.id,l)}return n}(P,H,N,L,e=>i[0]+e/k*(i[1]-i[0])),F=function(e,t,r){let i=new Map,a=new Map;for(let[e,t]of r??[]){let r=a.get(t)??[];r.push(e),a.set(t,r)}for(let n of e){let e=t.get(n.id);if(null==e||!Number.isFinite(e)||e>=n.startTime)continue;let o=r?.get(n.source),l=null==o?[n.source]:a.get(o)??[n.source];for(let t of l){let r=i.get(t)??new Map,a=r.get(n.startTime);r.set(n.startTime,null==a?e:Math.min(a,e)),i.set(t,r)}}return i}(P,R,B);t.forEach((e,t)=>{let r=D[e.id];if(!r||0===r.samples.length)return;let a=(o=r.samples,(l=F.get(e.id))&&0!==l.size?o.map(e=>{let t=l.get(e.t);return null==t?e:{...e,t:t}}):o),n=function(e,t,r,i,a){if(0===e.length)return null;let n=Ee(e,a),o=e=>t+(n[e].boundaryOffset??0)*r,l=e=>o(e)-n[e].topMass*r,s=e=>o(e)+n[e].botMass*r,c=`M${i(n[0].t)},${l(0)}`;for(let e=1;n.length>e;e++)c+=` L${i(n[e].t)},${l(e)}`;c+=` L${i(n[n.length-1].t)},${s(n.length-1)}`;for(let e=n.length-2;e>=0;e--)c+=` L${i(n[e].t)},${s(e)}`;return c+" Z"}(a,A[e.id],I,L,i);var o,l;if(!n)return;let s,u,f=Ee(a,i),h=f.find(e=>e.topMass+e.botMass>0)||f[0],g=A[e.id]+(h.botMass-h.topMass+2*(h.boundaryOffset??0))*I/2,m=c(e.id,t),y=m,b=.5,v=e.__raw??e;if(p&&p.length>0){let e=wr(v,p,E(v));"string"==typeof e.fill?m=e.fill:null!=e.fill&&Fr(e.fill)&&(u=e.fill,m=e.fill.background&&"transparent"!==e.fill.background?e.fill.background:m),"string"==typeof e.stroke&&(y=e.stroke),"number"==typeof e.strokeWidth&&(b=e.strokeWidth),"number"==typeof e.fillOpacity&&(s=e.fillOpacity),"number"==typeof e.opacity&&null==s&&(s=e.opacity)}let k=function(e,t,r,i,a,n){let o=r.nodeData[e];if(!o||0===o.samples.length)return[];let l=r.valueScale,s=r.centerlines[e],c=Ee(o.samples,a),u=c.find(e=>e.topMass+e.botMass>0)||c[0],d=[...c].reverse().find(e=>e.topMass+e.botMass>0)||c[c.length-1],f=i(u.t),h=i(d.t),g=e=>i(Ie(e,a)),m=[],p=(e,t,r,i)=>`M${e},${t} L${r},${t} L${r},${i} L${e},${i} Z`;for(let r of t){if(r.source===e&&null!=r.systemInTime&&Number.isFinite(r.systemInTime)){let e=o.localAttachments.get(r.id),t=n?.get(r.id)??r.startTime;if(e&&"out"===e.kind&&t>r.systemInTime){let i=g(r.systemInTime),n=g(t),o=null!=a&&a[0]>r.systemInTime,c=o?i:i-20,u=o?Math.min(n,i+20):i,d=Math.max(f,c);if(n>d){let[t,r]=Ce(e,s,l);m.push({pathD:p(d,t,n,r),x0:c,x1:u,from:0,to:1})}}}if(r.target===e&&null!=r.systemOutTime&&Number.isFinite(r.systemOutTime)){let e=o.localAttachments.get(r.id);if(e&&"in"===e.kind&&r.systemOutTime>r.endTime){let t=g(r.systemOutTime),i=g(r.endTime),a=t+20,n=Math.min(h,a);if(n>i){let[r,o]=Ce(e,s,l);m.push({pathD:p(i,r,n,o),x0:t,x1:a,from:1,to:0})}}}}return m}(e.id,P,T,L,i,R);C.push({id:e.id,pathD:n,fill:m,stroke:y,strokeWidth:b,...null!=s&&{fillOpacity:s},...u&&{hatchFill:u},...k.length>0&&{gradientStubs:k},rawDatum:v,labelX:L("vertical"===d&&e.xExtent?e.xExtent[0]:h.t)-4,labelY:g,labelText:e.label??e.id})});let W=new Map;t.forEach((e,t)=>W.set(e.id,t)),P.forEach(e=>{let t=H.get(e.id);if(!t)return;let r=W.get(e.source)??0,i=c(e.source,r),{pathD:a,bezier:n}=Z(t),o=e.__raw??e,l="function"==typeof s?Number(s(o)):s,u=Number.isFinite(l)?Math.max(0,Math.min(1,l)):.35;O.push({id:e.id,pathD:a,fill:i,opacity:u,rawDatum:o,bezier:n})});let _=function(e,t,r){let i=e.map(e=>({...e})),a=new Map;for(let e of i){let r=t[e.id];if(null==r)continue;let i=a.get(r)??[];i.push(e),a.set(r,i)}let n=e=>{if(2>e.length)return;let t=e.reduce((e,t)=>e+t.labelY,0)/e.length,i=(e.length-1)/2;e.forEach((e,a)=>{e.labelY=Math.max(8,Math.min(r-8,t+16*(a-i)))})};for(let e of a.values()){e.sort((e,t)=>e.labelX-t.labelX||e.id.localeCompare(t.id));let t=[],r=-1/0;for(let i of e){let e=i.labelX-ct(i.labelText);t.length>0&&e>r+3&&(n(t),t=[],r=-1/0),t.push(i),r=Math.max(r,i.labelX)}n(t)}return function(e,t){let r=[...e].sort((e,t)=>e.labelY-t.labelY||e.labelX-t.labelX||e.id.localeCompare(t.id));for(let e=0;3>e;e+=1){for(let e=0;r.length>e;e+=1){let t=8;for(let i=0;e>i;i+=1)dt(r[e],r[i])&&(t=Math.max(t,r[i].labelY+16));r[e].labelY=Math.max(r[e].labelY,t)}for(let e=r.length-1;e>=0;e-=1){let i=t-8;for(let t=e+1;r.length>t;t+=1)dt(r[e],r[t])&&(i=Math.min(i,r[t].labelY-16));r[e].labelY=Math.min(r[e].labelY,i)}}}(i,r),i}(C,T.slotByNode,x).map(e=>function(e,t){return"horizontal"===t?e:{...e,pathD:ft(e.pathD),gradientStubs:e.gradientStubs?.map(gt),labelX:e.labelY,labelY:e.labelX,labelAnchor:"middle",labelBaseline:"auto"}}(e,d)),z="vertical"===d?function(e,t,r){let i=e.map(e=>({...e}));for(let e of i){let r=1.22*ct(e.labelText)+4;e.labelX=t-4>r?Math.max(r/2+2,Math.min(t-r/2-2,e.labelX)):t/2}let a=[],n=[...i].sort((e,t)=>e.labelY-t.labelY||e.labelX-t.labelX);for(let e of n){let t=a[a.length-1];!t||Math.abs(t[0].labelY-e.labelY)>14?a.push([e]):t.push(e)}for(let e of a){e.sort((e,t)=>e.labelX-t.labelX||e.id.localeCompare(t.id));let t=[],i=new Map;for(let r of e){let[e,a]=ut(r),n=t.findIndex(t=>e>t+8);-1===n&&(n=t.length),t[n]=a,i.set(r,n)}let a=e.reduce((e,t)=>e+t.labelY,0)/e.length,n=14*t.length+8>a;for(let t of e){let e=i.get(t)??0;t.labelY=n?Math.min(r-8,12+14*e):Math.max(8,a-14*e)}}return i}(_,a,n):_,j=new Map;if(null!=h)for(let e of t){let t=e.__raw??e,r="function"==typeof h?h(t):Number(t[h]);Number.isFinite(r)&&j.set(e.id,r)}let X=function(e,t,r,i,a={}){if(!1===i)return e.map(e=>({...e,labelText:"",labelDeferred:!1,labelFullText:void 0}));if(!0===i)return e.map(e=>({...e,labelDeferred:!1,labelFullText:void 0}));let n=Math.max(4,Math.min(e.length,Math.floor(Math.max(1,t*r)/14e3)));Number.isFinite(a.maxLabels)&&a.maxLabels>=0&&(n=Math.min(n,Math.floor(a.maxLabels)));let o=e.map((e,t)=>{let r=a.priorityById?.get(e.id),i=Math.abs(e.labelY);return{band:e,index:t,score:null!=r&&Number.isFinite(r)?1e6*r+ct(e.labelText):ct(e.labelText)+.01*i}}).filter(e=>e.band.labelText.trim().length>0).sort((e,t)=>t.score-e.score||e.index-t.index||e.band.id.localeCompare(t.band.id)),l=new Set(o.slice(0,n).map(e=>e.band.id));return e.map(e=>l.has(e.id)||0===e.labelText.trim().length?{...e,labelDeferred:!1,labelFullText:void 0}:{...e,labelFullText:e.labelText,labelText:"",labelDeferred:!0})}(z,a,n,f,{...j.size>0&&{priorityById:j},...null!=g&&{maxLabels:g}});return{layout:T,layoutConfig:{bands:X,ribbons:O.map(e=>function(e,t){return"horizontal"===t?e:{...e,pathD:ft(e.pathD),bezier:ht(e.bezier)}}(e,d)),showLabels:!1!==f,selectionDatum:m},issues:[],warnings:M,xScale:L}}function pt(e,t,r,i="reuse",a="crossing-min",n=5e4){return"sync"!==e&&("worker"===e||function(e,t,r="reuse",i="crossing-min"){return e*e*("reuse"===r?80:1)+t*t*(i&&"insertion"!==i?40:1)+10*(e+t)}(t,r,i,a)>=n)}function yt(){return"u">typeof window&&"u">typeof Worker}function bt(e){if(!e)return null;let t=e.sides,r=t instanceof Map?t:new Map(Array.isArray(t)?t:[]);return{...e,sides:r}}function vt(e){return!!(function(e){if(!e||0===e.length)return!1;for(let t of e)if("function"==typeof t.when||"function"==typeof t.style)return!0;return!1}(e.styleRules)||"function"==typeof e.edgeOpacity||"function"==typeof e.labelPriorityAccessor||e.styleRules&&e.styleRules.length>0&&("function"==typeof e.colorBy||"function"==typeof e.valueAccessor))}function kt(e){if(null!=e&&"object"==typeof e){try{if("function"==typeof structuredClone)return structuredClone(e)}catch{}try{return JSON.parse(JSON.stringify(e))}catch{return}}}function xt(e){let t=kt(e.__raw);return{id:e.id,...null!=e.label&&{label:e.label},...null!=e.group&&{group:e.group},...null!=e.xExtent&&{xExtent:e.xExtent},...null!=t&&{__raw:t}}}function St(e){let t=kt(e.__raw);return{id:e.id,source:e.source,target:e.target,value:e.value,startTime:e.startTime,endTime:e.endTime,...null!=e.systemInTime&&{systemInTime:e.systemInTime},...null!=e.systemOutTime&&{systemOutTime:e.systemOutTime},...null!=t&&{__raw:t}}}function wt(e,t){let r=Ir(),{execution:i="auto",workerThreshold:a,colorById:n,fallbackPalette:o,rawNodeById:l,rawEdgeById:s}=t,c=ta(()=>Object.keys(n).sort().map(e=>`${e}:${n[e]}`).join("|"),[n]),u=ta(()=>e?[e.nodes,e.edges,e.plotW,e.plotH,e.orientation??"horizontal",e.ribbonLane,(e.ribbonMinRun??0)+"",e.edgeOpacity,(e.showLabels??!0)+"",e.layoutOpts.pairing??"temporal",e.layoutOpts.packing??"reuse",e.layoutOpts.laneOrder??"crossing-min",e.layoutOpts.lifetimeMode??"half",e.layoutOpts.maxValueScale??"",e.layoutOpts.lanePlacement??"stack",e.layoutOpts.nodeSizing??"temporal",e.layoutOpts.groupPadding??0,e.domain[0],e.domain[1],e.styleRules,c]:"null",[e,c]),d=!!e&&!r&&function(e,t,r){return!(typeof window>"u"||!yt()||vt(e))&&pt(t,e.nodes.length,e.edges.length,e.layoutOpts.packing??"reuse",e.layoutOpts.laneOrder??"crossing-min",r)}(e,i,a),f=ta(()=>e?d?null:mt(e):ua([0,1],1),[u,d,e]),h=ra(r),[g,m]=ia(()=>e?r?{...mt(e),status:"ready",error:null}:d?{...ua(e.domain,"vertical"===e.orientation?e.plotH:e.plotW),status:"pending",error:null}:{...mt(e),status:"ready",error:null}:{...ua([0,1],1),status:"ready",error:null});return ea(()=>{if(h.current)return void(h.current=!1);if(!e||!d)return;let t=new AbortController;return m(e=>({...e,status:"pending",error:null})),async function(e,t){let{execution:r="auto",workerThreshold:i,signal:a,colorById:n,fallbackPalette:o=["#475569"],rawNodeById:l=new Map,rawEdgeById:s=new Map}=t,c=e.layoutOpts.packing??"reuse",u=e.layoutOpts.laneOrder??"crossing-min";if(!yt()||vt(e)||!pt(r,e.nodes.length,e.edges.length,c,u,i))return mt(e);try{let t=await function(e,t){return yt()?ca.get().request(e,t):Promise.reject(Error("Web Workers are unavailable"))}(function(e,t,r){return{input:{nodes:e.nodes.map(xt),edges:e.edges.map(St),domain:e.domain,plotW:e.plotW,plotH:e.plotH,orientation:e.orientation,ribbonLane:e.ribbonLane,ribbonMinRun:e.ribbonMinRun,edgeOpacity:"number"==typeof e.edgeOpacity?e.edgeOpacity:.35,layoutOpts:{...e.layoutOpts},showLabels:e.showLabels,..."string"==typeof e.labelPriorityAccessor&&{labelPriorityAccessor:e.labelPriorityAccessor},...null!=e.maxLabels&&{maxLabels:e.maxLabels},...null!=e.selectionDatum&&{selectionDatum:e.selectionDatum},...null!=e.usageMode&&{usageMode:e.usageMode},styleRules:e.styleRules,colorBy:"string"==typeof e.colorBy?e.colorBy:void 0,valueAccessor:"string"==typeof e.valueAccessor?e.valueAccessor:void 0},colorById:t,fallbackPalette:r}}(e,n,o),a);return function(e,t,r){let i=(e.layoutConfig.bands??[]).map(e=>({...e,rawDatum:t.get(e.id)??{id:e.id}})),a=(e.layoutConfig.ribbons??[]).map(e=>({...e,rawDatum:r.get(e.id)??{id:e.id}})),n=la().domain(e.domain).range([0,e.timelineExtent]);return{layout:e.layout,layoutConfig:{bands:i,ribbons:a,showLabels:e.layoutConfig.showLabels},issues:e.issues,warnings:e.warnings,xScale:n}}(t,l,s)}catch(t){if("AbortError"===t?.name)throw t;return mt(e)}}(e,{execution:i,workerThreshold:a,signal:t.signal,colorById:n,fallbackPalette:o,rawNodeById:l,rawEdgeById:s}).then(e=>{m({...e,status:"ready",error:null})}).catch(e=>{"AbortError"!==e.name&&m(t=>({...t,status:"error",error:e}))}),()=>t.abort()},[u,d,i,a,o,l,s]),f?{...f,status:"ready",error:null}:g}function Mt(e,t){return"function"==typeof e?e(t):t[e]}function Pt(e,t,r){return!t?.isActive||t.predicate(function(e,t){return"scene"===t?e:e.data}(e,r))}function Lt(e){return"object"==typeof e&&null!==e&&"__kind"in e&&("band"===e.__kind||"ribbon"===e.__kind)}function Tt(e){let[t,r,i]=function(e){if(e.startsWith("#")){let t=e.slice(1);if(3===t.length&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]),6===t.length)return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}let t=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return t?[+t[1],+t[2],+t[3]]:[128,128,128]}(e);return.299*t+.587*r+.114*i>150?"#222":"#fff"}function At(e,t,r){let i=t.nodeIDAccessor;return"function"==typeof i?i(e.data)+"":"string"==typeof i&&void 0!==e.data[i]?e.data[i]+"":void 0!==e.data.name?e.data.name+"":void 0!==e.data.id?e.data.id+"":"node-"+r}function Dt(e){if(!e)return null;if("function"==typeof e){let t=e;return e=>t(e.data??e)}return t=>t.data?.[e]||t[e]||t.id}function It(e){return Array.isArray(e.colorScheme)?e.colorScheme:e.themeCategorical&&e.themeCategorical.length>0?e.themeCategorical:Ca}function Et(e){return Array.isArray(e.colorScheme)&&e.colorScheme.length>0?e.colorScheme[0]:e.themeSemantic?.primary?e.themeSemantic.primary:e.themeCategorical&&e.themeCategorical.length>0?e.themeCategorical[0]:"#4d430c"}function Ct(e,t,r,i,a){if("horizontal"===a){let a=(e+r)/2;return`M ${e},${t} C ${a},${t} ${a},${i} ${r},${i}`}if("radial"===a){let a=(e+r)/2;return`M ${e},${t} Q ${a},${t} ${a},${(t+i)/2} T ${r},${i}`}{let a=(t+i)/2;return`M ${e},${t} C ${e},${a} ${r},${a} ${r},${i}`}}function Ot(e,t,r){let i=r.treeOrientation||"vertical";if("radial"===i){let r=t.x,i=t.y;e.x=i*Math.cos(r-Math.PI/2),e.y=i*Math.sin(r-Math.PI/2)}else"horizontal"===i?(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 Nt(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 Bt(e,t){let r=t.r??0;e.x=t.x,e.y=t.y,e.x0=t.x-r,e.x1=t.x+r,e.y0=t.y-r,e.y1=t.y+r,e.width=2*r,e.height=2*r,e.__radius=r}function $t(e){let t=Pr(e.mode,{width:e.width,height:e.height,enableHover:e.enableHover,showLegend:e.showLegend,showLabels:e.showLabels,title:e.title,description:e.description,accessibleTable:e.accessibleTable,summary:e.summary,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,responsiveRules:e.responsiveRules},{width:600,height:600}),{data:r,margin:i,className:a,layout:s="tree",orientation:u="vertical",childrenAccessor:f="children",valueAccessor:h="value",nodeIdAccessor:g="name",colorBy:m,colorScheme:p,colorByDepth:y=!1,styleRules:b,edgeStyle:v="curve",nodeLabel:k,nodeSize:x=5,tooltip:S,frameProps:w={},onObservation:M,onClick:P,chartId:L,selection:T,linkedHover:A,loading:D,loadingContent:I,legendInteraction:E,legendPosition:C,stroke:O,strokeWidth:N,opacity:B}=e,{width:$,height:H,enableHover:R,showLegend:F,showLabels:W=!0,title:_,description:z,summary:j,accessibleTable:X}=t,Y=d({nodes:Ma(()=>l(r??null,f),[r,f]),edges:void 0,inferNodes:!1,colorBy:y?void 0:m,colorScheme:p,showLegend:F,legendPosition:C,legendInteraction:E,frameLegend:w,selection:T,linkedHover:A,onObservation:M,onClick:P,mobileInteraction:t.mobileInteraction,mobileSemantics:t.mobileSemantics,chartType:"TreeDiagram",chartId:L,marginDefaults:t.marginDefaults,userMargin:i,width:$,height:H,hasTitle:!!_,loading:D,loadingContent:I}),q=Ma(()=>new Map,[]),G=Ma(()=>e=>{let t={stroke:"black",strokeWidth:1};return t.fill=y?Or[(e.depth||0)%Or.length]:m?Br(e.data||e,m,Y.colorScale):xr(void 0,Y.themeCategorical,p,void 0,q),t},[m,y,Y.colorScale,Y.themeCategorical,p,q]),V=Ma(()=>mr(m,h),[m,h]),K=Ma(()=>dr(G,b,V,e=>e.data||e),[G,b,V]),U=Ma(()=>ar(K,{stroke:O,strokeWidth:N,opacity:B}),[K,O,N,B]),Q=Ma(()=>n(U,Y.effectiveSelectionHook,Y.resolvedSelection),[U,Y.effectiveSelectionHook,Y.resolvedSelection]),Z=Ma(()=>()=>({stroke:"#999",strokeWidth:1,fill:"none"}),[]),J=Ma(()=>ar(Z,{stroke:O,strokeWidth:N,opacity:B}),[Z,O,N,B]),ee=Ma(()=>o(J,Y.effectiveSelectionHook,Y.resolvedSelection),[J,Y.effectiveSelectionHook,Y.resolvedSelection]),te=Ma(()=>{if("treemap"===s||"circlepack"===s||"partition"===s)return c(h)},[s,h]),re=Vt({componentName:"TreeDiagram",data:r});return re?Na(lr,{componentName:"TreeDiagram",message:re,width:$,height:H}):Y.loadingEl?Y.loadingEl:Na(cr,{componentName:"TreeDiagram",width:$,height:H,children:Na(Qt,{chartType:s,...null!=r&&{data:r},size:[$,H],responsiveWidth:e.responsiveWidth,responsiveHeight:e.responsiveHeight,maxDevicePixelRatio:e.maxDevicePixelRatio,margin:Y.margin,...Y.legendBehaviorProps,nodeIDAccessor:g,childrenAccessor:f,hierarchySum:te,treeOrientation:u,edgeType:v,nodeStyle:Q,edgeStyle:ee,colorBy:m,colorScheme:Y.effectivePalette,colorByDepth:y,nodeSize:x,nodeLabel:W?k||g:void 0,showLabels:W,enableHover:R,tooltipContent:!1===S?()=>null:pr(S)||void 0,...ir({linkedHover:A,selection:T,onObservation:M,onClick:P,mobileInteraction:Y.mobileInteraction,customHoverBehavior:Y.customHoverBehavior,customClickBehavior:Y.customClickBehavior,linkedHoverInClickPredicate:!1}),legend:Y.legend,legendPosition:Y.legendPosition,...E&&"none"!==E&&{legendHoverBehavior:Y.legendState.onLegendHover,legendClickBehavior:Y.legendState.onLegendClick,legendHighlightedCategory:Y.legendState.highlightedCategory,legendIsolatedCategories:Y.legendState.isolatedCategories},className:a,title:_,description:z,summary:j,accessibleTable:X,...null!=e.animate&&{animate:e.animate},...w})})}function Ht(e){let t=Pr(e.mode,{width:e.width,height:e.height,enableHover:e.enableHover,showLegend:e.showLegend,showLabels:e.showLabels,title:e.title,description:e.description,accessibleTable:e.accessibleTable,summary:e.summary,linkedHover:e.linkedHover,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,responsiveRules:e.responsiveRules},{width:600,height:600}),{data:r,margin:i,className:a,childrenAccessor:o="children",valueAccessor:s="value",nodeIdAccessor:u="name",colorBy:f,colorScheme:h,colorByDepth:g=!1,styleRules:m,labelMode:p="leaf",nodeLabel:y,padding:b=4,paddingTop:v,nodeStyle:k,tooltip:x,frameProps:S={},selection:w,linkedHover:M,onObservation:P,onClick:L,chartId:T,loading:A,loadingContent:D,legendInteraction:I,legendPosition:E,stroke:C,strokeWidth:O,opacity:N}=e,{nodeStyle:B,...$}=S,{width:H,height:R,enableHover:F,showLegend:W,showLabels:_=!0,title:z,description:j,summary:X,accessibleTable:Y}=t,q=d({nodes:Ba(()=>l(r??null,o),[r,o]),edges:void 0,inferNodes:!1,colorBy:g?void 0:f,colorScheme:h,showLegend:W,legendPosition:E,legendInteraction:I,frameLegend:$,selection:w,linkedHover:M,onObservation:P,onClick:L,mobileInteraction:t.mobileInteraction,mobileSemantics:t.mobileSemantics,chartType:"Treemap",chartId:T,marginDefaults:t.marginDefaults,userMargin:i,width:H,height:R,hasTitle:!!z,loading:A,loadingContent:D}),G=q.customHoverBehavior,V=$a(e=>{if(!e)return G(null);let t=e.data||e;G({data:t?.data||t})},[G]),K=Ba(()=>new Map,[]),U=Ba(()=>e=>{let t={stroke:"var(--semiotic-cell-border, var(--semiotic-border, #fff))",strokeWidth:1,strokeOpacity:.8};return t.fill=g?Or[(e.depth||0)%Or.length]:f?Br(e.data||e,f,q.colorScale):xr(void 0,q.themeCategorical,h,void 0,K),t},[f,g,q.colorScale,q.themeCategorical,h,K]),Q=Ba(()=>mr(f,s),[f,s]),Z=Ba(()=>dr(U,m,Q,e=>e.data||e),[U,m,Q]),J=Ba(()=>k||B?e=>({...Z(e),...B?B(e)??{}:{},...k?k(e)??{}:{}}):Z,[Z,k,B]),ee=Ba(()=>ar(J,{stroke:C,strokeWidth:O,opacity:N}),[J,C,O,N]),te=Ba(()=>n(ee,q.effectiveSelectionHook,q.resolvedSelection),[ee,q.effectiveSelectionHook,q.resolvedSelection]),re=Ba(()=>c(s),[s]),ie=void 0!==v?v:!_||"parent"!==p&&"all"!==p?void 0:18,ae=Vt({componentName:"Treemap",data:r});return ae?Ha(lr,{componentName:"Treemap",message:ae,width:H,height:R}):q.loadingEl?q.loadingEl:Ha(cr,{componentName:"Treemap",width:H,height:R,children:Ha(Qt,{chartType:"treemap",...null!=r&&{data:r},size:[H,R],responsiveWidth:e.responsiveWidth,responsiveHeight:e.responsiveHeight,maxDevicePixelRatio:e.maxDevicePixelRatio,margin:q.margin,...q.legendBehaviorProps,nodeIDAccessor:u,childrenAccessor:o,hierarchySum:re,padding:b,paddingTop:ie,nodeStyle:te,colorBy:f,colorScheme:q.effectivePalette,colorByDepth:g,nodeLabel:_?y||u:void 0,showLabels:_,labelMode:p,enableHover:F,tooltipContent:!1===x?()=>null:pr(x)||void 0,...ir({linkedHover:M,selection:w,onObservation:P,onClick:L,mobileInteraction:q.mobileInteraction,customHoverBehavior:V,customClickBehavior:q.customClickBehavior,linkedHoverInClickPredicate:!1}),legend:q.legend,legendPosition:q.legendPosition,...I&&"none"!==I&&{legendHoverBehavior:q.legendState.onLegendHover,legendClickBehavior:q.legendState.onLegendClick,legendHighlightedCategory:q.legendState.highlightedCategory,legendIsolatedCategories:q.legendState.isolatedCategories},className:a,title:z,description:j,summary:X,accessibleTable:Y,...null!=e.animate&&{animate:e.animate},...$})})}function Rt(e){let t=Pr(e.mode,{width:e.width,height:e.height,enableHover:e.enableHover,showLegend:e.showLegend,showLabels:e.showLabels,title:e.title,description:e.description,accessibleTable:e.accessibleTable,summary:e.summary,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,responsiveRules:e.responsiveRules},{width:600,height:600}),{data:r,margin:i,className:a,childrenAccessor:o="children",valueAccessor:s="value",nodeIdAccessor:u="name",colorBy:f,colorScheme:h,colorByDepth:g=!1,styleRules:m,nodeLabel:p,circleOpacity:y=.7,padding:b=4,tooltip:v,frameProps:k={},onObservation:x,onClick:S,chartId:w,selection:M,linkedHover:P,loading:L,loadingContent:T,legendInteraction:A,legendPosition:D,stroke:I,strokeWidth:E,opacity:C}=e,{width:O,height:N,enableHover:B,showLegend:$,showLabels:H=!0,title:R,description:F,summary:W,accessibleTable:_}=t,z=d({nodes:Ra(()=>l(r??null,o),[r,o]),edges:void 0,inferNodes:!1,colorBy:g?void 0:f,colorScheme:h,showLegend:$,legendPosition:D,legendInteraction:A,frameLegend:k,selection:M,linkedHover:P,onObservation:x,onClick:S,mobileInteraction:t.mobileInteraction,mobileSemantics:t.mobileSemantics,chartType:"CirclePack",chartId:w,marginDefaults:t.marginDefaults,userMargin:i,width:O,height:N,hasTitle:!!R,loading:L,loadingContent:T}),j=Ra(()=>new Map,[]),X=Ra(()=>e=>{let t={stroke:"currentColor",strokeWidth:1,strokeOpacity:.3,fillOpacity:y};return t.fill=g?Or[(e.depth||0)%Or.length]:f?Br(e.data||e,f,z.colorScale):xr(void 0,z.themeCategorical,h,void 0,j),t},[f,g,z.colorScale,y,z.themeCategorical,h,j]),Y=Ra(()=>mr(f,s),[f,s]),q=Ra(()=>dr(X,m,Y,e=>e.data||e),[X,m,Y]),G=Ra(()=>ar(q,{stroke:I,strokeWidth:E,opacity:C}),[q,I,E,C]),V=Ra(()=>n(G,z.effectiveSelectionHook,z.resolvedSelection),[G,z.effectiveSelectionHook,z.resolvedSelection]),K=Ra(()=>c(s),[s]),U=Vt({componentName:"CirclePack",data:r});return U?Fa(lr,{componentName:"CirclePack",message:U,width:O,height:N}):z.loadingEl?z.loadingEl:Fa(cr,{componentName:"CirclePack",width:O,height:N,children:Fa(Qt,{chartType:"circlepack",...null!=r&&{data:r},size:[O,N],responsiveWidth:e.responsiveWidth,responsiveHeight:e.responsiveHeight,maxDevicePixelRatio:e.maxDevicePixelRatio,margin:z.margin,...z.legendBehaviorProps,nodeIDAccessor:u,childrenAccessor:o,hierarchySum:K,padding:b,nodeStyle:V,colorBy:f,colorScheme:z.effectivePalette,colorByDepth:g,nodeLabel:H?p||u:void 0,showLabels:H,enableHover:B,tooltipContent:!1===v?()=>null:pr(v)||void 0,...ir({linkedHover:P,selection:M,onObservation:x,onClick:S,mobileInteraction:z.mobileInteraction,customHoverBehavior:z.customHoverBehavior,customClickBehavior:z.customClickBehavior,linkedHoverInClickPredicate:!1}),legend:z.legend,legendPosition:z.legendPosition,...A&&"none"!==A&&{legendHoverBehavior:z.legendState.onLegendHover,legendClickBehavior:z.legendState.onLegendClick,legendHighlightedCategory:z.legendState.highlightedCategory,legendIsolatedCategories:z.legendState.isolatedCategories},className:a,title:R,description:F,summary:W,accessibleTable:_,...null!=e.animate&&{animate:e.animate},...k})})}function Ft(e){let t=e.__orbitState;return t||(t={metaMap:new Map,startTime:"u">typeof performance?performance.now():Date.now()},e.__orbitState=t),t}function Wt(e){let t=Pr(e.mode,{width:e.width,height:e.height,enableHover:e.enableHover,showLegend:e.showLegend,showLabels:e.showLabels,title:e.title,description:e.description,accessibleTable:e.accessibleTable,summary:e.summary,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,responsiveRules:e.responsiveRules},{width:600,height:600}),{data:r,margin:i,className:a,childrenAccessor:o="children",nodeIdAccessor:s="name",colorBy:c,colorScheme:u,colorByDepth:f=!1,styleRules:h,orbitMode:g="flat",orbitSize:m=2.95,speed:p=.25,revolution:y,revolutionStyle:b,eccentricity:v=1,showRings:k=!0,nodeRadius:x=6,showLabels:S=!1,animated:w=!0,tooltip:M,foregroundGraphics:P,annotations:L,frameProps:T={},onObservation:A,onClick:D,chartId:I,selection:E,linkedHover:C,loading:O,loadingContent:N,legendPosition:B,legendInteraction:$,stroke:H,strokeWidth:R,opacity:F}=e,{width:W,height:_,enableHover:z,showLegend:j,title:X,description:Y,summary:q,accessibleTable:G}=t,V=d({nodes:Wa(()=>l(r,o),[r,o]),edges:void 0,inferNodes:!1,colorBy:f?void 0:c,colorScheme:u,showLegend:j,legendPosition:B,legendInteraction:$,frameLegend:T,selection:E,linkedHover:C,onObservation:A,onClick:D,mobileInteraction:t.mobileInteraction,mobileSemantics:t.mobileSemantics,chartType:"OrbitDiagram",chartId:I,marginDefaults:kr(t),userMargin:i,width:W,height:_,hasTitle:!!X,loading:O,loadingContent:N}),K=Wa(()=>new Map,[]),{colorScale:U,customClickBehavior:Q,customHoverBehavior:Z,themeCategorical:J}=V,ee=Wa(()=>{if(Array.isArray(u))return u;let e=Er[u];return Array.isArray(e)?e:Cr},[u]),te=Wa(()=>e=>{let t={stroke:"#fff",strokeWidth:1},r=0===(e.depth??0);return t.fill=f?r?ee[0]:Xa[(e.depth||0)%Xa.length]:c?Br(e.data||e,c,U):xr(void 0,J,u,void 0,K),t.opacity=r?1:.85,t},[c,f,U,ee,J,u,K]),re=Wa(()=>mr(c,"value"),[c]),ie=Wa(()=>dr(te,h,re,e=>e.data||e),[te,h,re]),ae=Wa(()=>ar(ie,{stroke:H,strokeWidth:R,opacity:F}),[ie,H,R,F]),ne=Wa(()=>n(ae,V.effectiveSelectionHook,V.resolvedSelection),[ae,V.effectiveSelectionHook,V.resolvedSelection]),oe=Wa(()=>()=>({stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1}),[]),le=Wa(()=>e=>{Z(e&&e.data&&void 0!==e.data.data?{...e,data:e.data.data}:e)},[Z]),se=Wa(()=>e=>{Q(e&&e.data&&void 0!==e.data.data?{...e,data:e.data.data}:e)},[Q]),ce=Vt({componentName:"OrbitDiagram",data:r});return ce?ja(lr,{componentName:"OrbitDiagram",message:ce,width:W,height:_}):V.loadingEl?V.loadingEl:ja(cr,{componentName:"OrbitDiagram",width:W,height:_,children:ja(Qt,{chartType:"orbit",...null!=r&&{data:r},size:[W,_],responsiveWidth:e.responsiveWidth,responsiveHeight:e.responsiveHeight,maxDevicePixelRatio:e.maxDevicePixelRatio,margin:V.margin,...V.legendBehaviorProps,nodeIDAccessor:s,childrenAccessor:o,nodeStyle:ne,edgeStyle:oe,colorBy:c,colorScheme:V.effectivePalette,colorByDepth:f,nodeSize:x,nodeLabel:S?s:void 0,showLabels:S,enableHover:!w&&z,tooltipContent:w?void 0:!1===M?()=>null:pr(M)||void 0,...ir({linkedHover:C,selection:E,onObservation:A,onClick:D,mobileInteraction:V.mobileInteraction,customHoverBehavior:le,customClickBehavior:se,linkedHoverInClickPredicate:!1}),legend:V.legend,legendPosition:V.legendPosition,...$&&"none"!==$&&{legendHoverBehavior:V.legendState.onLegendHover,legendClickBehavior:V.legendState.onLegendClick,legendHighlightedCategory:V.legendState.highlightedCategory,legendIsolatedCategories:V.legendState.isolatedCategories},foregroundGraphics:P,annotations:L,className:a,title:X,description:Y,summary:q,orbitMode:g,orbitSize:m,orbitSpeed:p,orbitRevolution:y,orbitRevolutionStyle:b,orbitEccentricity:v,orbitShowRings:k,orbitAnimated:w,accessibleTable:G,...null!=e.animate&&{animate:e.animate},...T})})}function _t(e,t,r={}){let i=r.iterations??260,a=r.repulsion??5200,n=r.linkDistance??165,o=r.linkStrength??.045,l=r.centerStrength??.018,s=r.damping??.84,c=r.nodeRadius??12,u=r.nodePadding??3,d=r.inset??.06,f=nr(r.seed??1),h=new Map;for(let t of e)h.set(t.id,0);for(let e of t)h.set(e.source,(h.get(e.source)??0)+1),h.set(e.target,(h.get(e.target)??0)+1);let g=500,m=e.map(e=>({id:e.id,data:e,x:200+600*f(),y:200+600*f()})),p=new Set(e.map(e=>e.id)),y=t.filter(e=>p.has(e.source)&&p.has(e.target)).map(e=>({source:e.source,target:e.target}));if(i>0){let e=Ja(m).randomSource(f).alphaDecay(1-Math.pow(.001,1/i)).velocityDecay(Math.max(0,Math.min(1,1-s))).force("charge",Za().strength(e=>{let t=h.get(e.id)??0;return 2.5*-Math.sqrt(a)*Math.sqrt(t+1)})).force("collide",Ua(e=>(e=>"function"==typeof c?c(e.data):c)(e)+u).strength(.9).iterations(2)).force("center",Ka(g,g).strength(.8)).force("x",en(g).strength(l)).force("y",tn(g).strength(l));y.length>0&&e.force("link",Qa(y).id(e=>e.id).distance(n).strength(e=>{let t="string"==typeof e.target?e.target:e.target.id,r=Math.max(1,Math.min(h.get("string"==typeof e.source?e.source:e.source.id)??1,h.get(t)??1));return o/.045/r})),e.stop();for(let t=0;i>t;t+=1)e.tick()}let b=1/0,v=1/0,k=-1/0,x=-1/0;for(let e of m){let t=e.x??g,r=e.y??g;b>t&&(b=t),v>r&&(v=r),t>k&&(k=t),r>x&&(x=r)}let S=k-b,w=x-v,M={};for(let e of m)Object.defineProperty(M,e.id,{value:{x:0===S?.5:d+((e.x??g)-b)/S*(1-2*d),y:0===w?.5:d+((e.y??g)-v)/w*(1-2*d)},enumerable:!0,configurable:!0,writable:!0});return M}import{ModuleWorkerSession as zt,createSharedWorkerSessionHolder as jt,errorFromPayload as Xt,parseModuleWorkerErrorField as Yt}from"./c-GXV3C3MO.min.js";import{useCustomChartScaffold as qt}from"./c-55BAJ333.min.js";import{validateNetworkData as Gt,validateObjectData as Vt}from"./c-D6HAAPTX.min.js";import{useFrameImperativeHandle as Kt,useResolvedSelection as Ut}from"./c-KCRJGUHP.min.js";import{StreamNetworkFrame_default as Qt,registerLayoutPlugin as Zt}from"./c-TIXX5CAU.min.js";import{resolveNodeSizeFn as Jt}from"./c-MVR3RWF3.min.js";import{resolveLabelFn as er,resolveNodeRefId as tr}from"./c-YLZIV3VS.min.js";import{buildBaseMetadataProps as rr,buildCustomBehaviorProps as ir,mergeShapeStyle as ar}from"./c-ITKX3RC5.min.js";import{mulberry32 as nr}from"./c-HYW2XA4Q.min.js";import{commonJsWorkerModuleUrl as or}from"./c-VJTDST2R.min.js";import{ChartError as lr,DEFAULT_SELECTION_OPACITY as sr,SafeRender as cr,clampLegendReservation as ur,composeStyleRules as dr,createSeededFrameRandom as fr,distinctCategories as hr,filterSparseArray as gr,makeNodeRuleContext as mr,normalizeTooltip as pr,renderEmptyState as yr,renderLoadingState as br,reserveLegendMargin as vr,resolveAxisFreeMarginDefaults as kr,resolveDefaultFill as xr,resolveMobileInteraction as Sr,resolveStyleRules as wr,useChartLegendAndMargin as Mr,useChartMode as Pr,useChartSelection as Lr,useColorScale as Tr,useLegendInteraction as Ar,useThemeCategorical as Dr,useWasHydratingFromSSR as Ir}from"./c-LMGSSD2E.min.js";import{COLOR_SCHEMES as Er,DEFAULT_COLORS as Cr,DEPTH_PALETTE_COLORS as Or,createColorScale as Nr,getColor as Br,resolveCategoricalPalette as $r,schemeCategory10 as Hr}from"./c-CPV4N35K.min.js";import{getMin as Rr}from"./c-QA3HMQJP.min.js";import{isHatchFill as Fr}from"./c-553QUDKA.min.js";import{useMemo as Wr,forwardRef as _r,useRef as zr}from"react";import{forceSimulation as jr,forceCenter as Xr,forceX as Yr,forceY as qr,forceLink as Gr,forceManyBody as Vr,forceCollide as Kr}from"d3-force";var Ur=new Set,Qr=new WeakMap,Zr={supportsStreaming:!0,hierarchical:!1,computeLayout(e,i,a,n){if(0===e.length)return;let o=a.forceStrength??.1,l=n[0]/2,s=n[1]/2,c=Math.max(.1,Math.min(1,Math.min(n[0],n[1])/200)),u=Math.min(.5,.06+1.8*(1-c)),d=a.__previousPositions,f=0,h=[];for(let t of e){let e=null!=t.x&&null!=t.y&&(0!==t.x||0!==t.y),r=d?.get(t.id);e?f++:r?(t.x=r.x,t.y=r.y,f++):h.push(t)}let g=f>0&&.3>=(e.length>0?h.length/e.length:1);if(g){let a=new Map;for(let t of e)a.set(t.id,t);for(let e of h){let n=t(e.id,i,a);if(n.length>0){let t=0,i=0;for(let e of n)t+=e.x,i+=e.y;let a=r(e.id),o=a%360*(Math.PI/180),l=(10+a%20)*c;e.x=t/n.length+l*Math.cos(o),e.y=i/n.length+l*Math.sin(o)}else{let t=r(e.id),i=t%360*(Math.PI/180),a=(15+t%30)*c;e.x=l+a*Math.cos(i),e.y=s+a*Math.sin(i)}}}else{let t=2.399963229728653;for(let r=0;e.length>r;r++){let i=e[r];if(null==i.x||null==i.y||0===i.x&&0===i.y){let e=10*Math.sqrt(r+.5)*c,a=r*t;i.x=l+e*Math.cos(a),i.y=s+e*Math.sin(a)}}}let m=a.__skipForceSimulation||0===a.iterations?0:g?40:a.iterations??Math.max(50,Math.min(300,Math.floor(300-2*(e.length-30)))),p=Jt(a.nodeSize,a.nodeSizeRange,e),y=e=>p(e);if(m>0){let t=new Map,r=new Map;for(let i of e)t.set(i.id,0),r.set(i.id,i);for(let e of i){let r=tr(e.source),i=tr(e.target);t.set(r,(t.get(r)??0)+1),t.set(i,(t.get(i)??0)+1)}let d=Gr().strength(e=>{let r=e.weight,i=tr(e.source),a=tr(e.target),n=Math.max(1,Math.min(t.get(i)??1,t.get(a)??1));return Math.min(2.5,(r&&r>0?Math.sqrt(r):1)*o/(.1*n))}).distance(e=>{let t="string"==typeof e.source?r.get(e.source):e.source,i="string"==typeof e.target?r.get(e.target):e.target,a=(t?y(t):0)+(i?y(i):0)+Math.max(6,12*c);return Math.max(16,40*c,a)}).id(e=>e.id),f=jr();if((void 0!==a.random||void 0!==a.seed)&&f.randomSource(a.random??fr(a.seed)),f.force("charge",Vr().strength(e=>{let r=t.get(e.id)??0;return-15*c*y(e)*Math.sqrt(r+1)})).force("collide",Kr(e=>y(e)+3*c).strength(.9).iterations(2)).force("center",Xr(l,s).strength(.8)).force("x",Yr(l).strength(u)).force("y",qr(s).strength(u)).force("bounds",function(e,t,r=2,i=.6){let a=[],n=n=>{let o=i*Math.max(n,.2);for(let i of a){let a=i.x??e[0]/2,n=i.y??e[1]/2,l=i.vx??0,s=i.vy??0,c=t(i)+r,u=Math.min(e[0]/2,c),d=Math.max(e[0]/2,e[0]-c),f=Math.min(e[1]/2,c),h=Math.max(e[1]/2,e[1]-c),g=a+l,m=n+s;u>g?i.vx=l+(u-g)*o:g>d&&(i.vx=l+(d-g)*o),f>m?i.vy=s+(f-m)*o:m>h&&(i.vy=s+(h-m)*o)}};return n.initialize=e=>{a=e},n}(n,y)),f.nodes(e),i.length>0){let e=i.map(e=>({...e,source:tr(e.source),target:tr(e.target)}));d.links(e),f.force("link",d)}g?f.alpha(.3):.1>f.alpha()&&f.alpha(1),f.stop();for(let e=0;m>e;++e)f.tick()}for(let t of e){if(null==t.x||null==t.y)continue;let e=y(t),r=m>0?2:0,i=Math.min(n[0]/2,e+r),a=Math.min(n[1]/2,e+r);t.x=Math.max(i,Math.min(n[0]-i,t.x)),t.y=Math.max(a,Math.min(n[1]-a,t.y)),t.x0=0,t.x1=0,t.y0=0,t.y1=0}let b=new Map;for(let t of e)b.set(t.id,t);for(let e of i){if("string"==typeof e.source){let t=b.get(e.source);t&&(e.source=t)}if("string"==typeof e.target){let t=b.get(e.target);t&&(e.target=t)}}},buildScene(t,r,i,a){let n=i.nodeStyle,o=i.edgeStyle,l=Jt(i.nodeSize,i.nodeSizeRange,t),s=Array.isArray(i.colorScheme)?i.colorScheme:i.themeCategorical&&i.themeCategorical.length>0?i.themeCategorical:Hr,c=new Map;t.forEach((e,t)=>{c.set(e.id,s[t%s.length])});let u=[],d=[],f=[];for(let r of t){if(null==r.x||null==r.y)continue;let t=l(e(r,"nodeSize")),a=n?n(e(r,"nodeStyle")):{},o={fill:a.fill||c.get(r.id)||i.themeSemantic?.primary||"#007bff",stroke:a.stroke||i.themeSemantic?.surface||"#fff",strokeWidth:a.strokeWidth??2,opacity:a.opacity,cursor:a.cursor};u.push({type:"circle",cx:r.x,cy:r.y,r:t,style:o,datum:r,id:r.id,label:r.id})}let h=new Map;for(let e of t)h.set(e.id,e);for(let t of r){let r="object"==typeof t.source?t.source:h.get(t.source),a="object"==typeof t.target?t.target:h.get(t.target);if(!r||!a||null==r.x||null==r.y||null==a.x||null==a.y)continue;let n=o?o(e(t,"edgeStyle")):{};d.push({type:"line",x1:r.x,y1:r.y,x2:a.x,y2:a.y,style:{stroke:n.stroke||i.themeSemantic?.border||i.themeSemantic?.secondary||"#999",strokeWidth:n.strokeWidth??1,opacity:n.opacity??.6,cursor:n.cursor},datum:t})}if(!1!==i.showLabels){let r=er(i.nodeLabel);for(let i of t){if(null==i.x||null==i.y)continue;let t=r?r(i):i.id;if(!t)continue;let a=l(e(i,"nodeSize"));f.push({x:i.x,y:i.y-a-4,text:t+"",anchor:"middle",baseline:"auto",fontSize:11})}}return{sceneNodes:u,sceneEdges:d,labels:f}}};Zt("force",Zr);import{useCallback as Jr,useMemo as ei,useState as ti}from"react";import{jsx as ri}from"react/jsx-runtime";Zt("force",Zr);var ii=_r(function(e,t){let r=zr(null);Kt(t,{variant:"network",frameRef:r});let i=Pr(e.mode,{width:e.width,height:e.height,enableHover:e.enableHover,showLegend:e.showLegend,showLabels:e.showLabels,title:e.title,description:e.description,accessibleTable:e.accessibleTable,summary:e.summary,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,responsiveRules:e.responsiveRules},{width:600,height:600}),{nodes:a,edges:l,margin:s,className:c,nodeIdAccessor:u,nodeIDAccessor:f,sourceAccessor:h="source",targetAccessor:g="target",nodeLabel:m,colorBy:p,colorScheme:y,styleRules:b,nodeSize:v=8,nodeSizeRange:k=[5,20],nodeStroke:x,nodeStrokeWidth:S,edgeWidth:w,edgeColor:M,edgeOpacity:P,iterations:L=300,forceStrength:T=.1,layoutExecution:A="auto",layoutLoadingContent:D,onLayoutStateChange:I,tooltip:E,frameProps:C={},onObservation:O,onClick:N,chartId:B,selection:$,linkedHover:H,loading:R,loadingContent:F,emptyContent:W,legendInteraction:_,legendPosition:z,stroke:j,strokeWidth:X,opacity:Y}=e,q=u??f??"id",{width:G,height:V,enableHover:K,showLegend:U,showLabels:Q=!1,title:Z,description:J,summary:ee,accessibleTable:te}=i,re=d({nodes:a,edges:l,inferNodes:!1,nodeIdAccessor:q,sourceAccessor:h,targetAccessor:g,colorBy:p,colorScheme:y,showLegend:U,legendPosition:z,legendInteraction:_,frameLegend:C,selection:$,linkedHover:H,onObservation:O,onClick:N,mobileInteraction:i.mobileInteraction,mobileSemantics:i.mobileSemantics,chartType:"ForceDirectedGraph",chartId:B,marginDefaults:i.marginDefaults,userMargin:s,width:G,height:V,hasTitle:!!Z,loading:R,loadingContent:F,emptyContent:W,emptyDataKey:"nodes"}),ie=Wr(()=>new Map,[]),ae=Wr(()=>e=>{let t={};return t.fill=p?Br(e.data||e,p,re.colorScale):xr(void 0,re.themeCategorical,y,void 0,ie),"number"==typeof v&&(t.r=v),t},[p,re.colorScale,v,re.themeCategorical,y,ie]),ne=Wr(()=>mr(p,"number"==typeof v?void 0:v),[p,v]),oe=Wr(()=>ar(dr(ae,b,ne,e=>e.data||e),{stroke:x??j,strokeWidth:S??X,opacity:Y}),[ae,b,ne,x,j,S,X,Y]),le=Wr(()=>n(oe,re.effectiveSelectionHook,re.resolvedSelection),[oe,re.effectiveSelectionHook,re.resolvedSelection]),se=M??j??"#999",ce=P??Y??.6,ue=X??1,de=Wr(()=>e=>{let t,r=e.data||e;if(void 0===w)t=ue;else if("number"==typeof w)t=w;else if("function"==typeof w)t=w(r);else{let e=r[w],i="number"==typeof e?e:Number(e);t=Number.isFinite(i)&&i>0?i:ue}return{stroke:se,strokeWidth:t,opacity:ce}},[w,se,ce,ue]),fe=Wr(()=>o(de,re.effectiveSelectionHook,re.resolvedSelection),[de,re.effectiveSelectionHook,re.resolvedSelection]),he=Wr(()=>{if(Q&&m)return"function"==typeof m?m:e=>e.data?.[m]??e[m]??e.id},[Q,m]),ge=Gt({componentName:"ForceDirectedGraph",nodes:a,edges:l,nodesRequired:!0,edgesRequired:!0,accessors:{nodeIDAccessor:q}});return ge?ri(lr,{componentName:"ForceDirectedGraph",message:ge,width:G,height:V}):re.loadingEl?re.loadingEl:re.emptyEl?re.emptyEl:ri(cr,{componentName:"ForceDirectedGraph",width:G,height:V,children:ri(Qt,{ref:r,chartType:"force",...null!=a&&{nodes:re.safeNodes},...null!=l&&{edges:re.safeEdges},size:[G,V],responsiveWidth:e.responsiveWidth,responsiveHeight:e.responsiveHeight,maxDevicePixelRatio:e.maxDevicePixelRatio,margin:re.margin,...re.legendBehaviorProps,nodeIDAccessor:q,sourceAccessor:h,targetAccessor:g,iterations:L,forceStrength:T,layoutExecution:A,layoutLoadingContent:D,onLayoutStateChange:I,nodeStyle:le,edgeStyle:fe,colorBy:p,colorScheme:re.effectivePalette,nodeSize:v,nodeSizeRange:k,nodeLabel:he,showLabels:Q,enableHover:K,tooltipContent:!1===E?()=>null:pr(E)||void 0,...ir({linkedHover:H,selection:$,onObservation:O,onClick:N,mobileInteraction:re.mobileInteraction,customHoverBehavior:re.customHoverBehavior,customClickBehavior:re.customClickBehavior,linkedHoverInClickPredicate:!1}),legend:re.legend,legendPosition:re.legendPosition,..._&&"none"!==_&&{legendHoverBehavior:re.legendState.onLegendHover,legendClickBehavior:re.legendState.onLegendClick,legendHighlightedCategory:re.legendState.highlightedCategory,legendIsolatedCategories:re.legendState.isolatedCategories},className:c,title:Z,description:J,summary:ee,accessibleTable:te,...null!=e.animate&&{animate:e.animate},...C})})});ii.displayName="ForceDirectedGraph";import{useMemo as ai,forwardRef as ni,useRef as oi}from"react";import{chord as li,ribbon as si}from"d3-chord";import{arc as ci}from"d3-shape";var ui=Hr,di={supportsStreaming:!1,hierarchical:!1,computeLayout(e,t,r,i){if(0===e.length)return;let{padAngle:a=.01,groupWidth:n=20,sortGroups:o}=r,l=Math.min(i[0],i[1])/2,s=l-n,c=i[0]/2,u=i[1]/2,d=(h=r.valueAccessor)?"function"==typeof h?h:e=>e[h]??1:e=>e.value??1,f=new Map;var h;for(let t=0;e.length>t;t++)f.set(e[t].id,t);let g=e.length,m=Array.from({length:g},()=>Array(g).fill(0));for(let e of t){let t=tr(e.source),r=tr(e.target),i=f.get(t),a=f.get(r);if(void 0===i||void 0===a)continue;let n=d(e);m[i][a]=n}let p=li().padAngle(a);o&&p.sortGroups(o);let y=p(m),b=y.groups,v=ci().innerRadius(s).outerRadius(l);for(let t of b){let r=e[t.index],i=v.centroid({innerRadius:s,outerRadius:l,startAngle:t.startAngle,endAngle:t.endAngle});r.x=i[0]+c,r.y=i[1]+u,r.__arcData={startAngle:t.startAngle,endAngle:t.endAngle}}let k=new Map;for(let t of e)k.set(t.id,t);for(let e of t){let t=tr(e.source),r=tr(e.target),i=k.get(t),a=k.get(r);i&&(e.source=i),a&&(e.target=a)}let x=new Map;for(let e of t){let t=tr(e.source),r=tr(e.target);x.set(`${t}\0${r}`,e)}for(let t of y){let r=e[t.source.index].id,i=e[t.target.index].id,a=x.get(`${r}\0${i}`)||x.get(`${i}\0${r}`);a&&(a.__chordData=t)}},buildScene(t,r,i,a){let{groupWidth:n=20,edgeOpacity:o=.5}=i,l=Math.min(a[0],a[1])/2,s=l-n,c=a[0]/2,u=a[1]/2,d=i.nodeStyle,h=i.edgeStyle,g=i.edgeColorBy||"source",m=Array.isArray(i.colorScheme)?i.colorScheme:i.themeCategorical&&i.themeCategorical.length>0?i.themeCategorical:ui,p=new Map;t.forEach((e,t)=>{p.set(e.id,m[t%m.length])});let y=si().radius(s),b=[],v=[],k=[];for(let r=0;t.length>r;r++){let i=t[r],a=i.__arcData;if(!a)continue;let n=d?d(e(i,"nodeStyle")):{},o={fill:("string"==typeof n.fill?n.fill:void 0)||p.get(i.id)||m[r%m.length],stroke:n.stroke||"black",strokeWidth:n.strokeWidth??1,opacity:n.opacity,cursor:n.cursor};b.push({type:"arc",cx:c,cy:u,innerR:s,outerR:l,startAngle:a.startAngle-Math.PI/2,endAngle:a.endAngle-Math.PI/2,style:o,datum:i,id:i.id,label:i.id})}for(let t of r){let r=t.__chordData;if(!r)continue;let a=y(r);if(!a)continue;let n=f(a,c,u),l=i.themeSemantic?.border||i.themeSemantic?.secondary||"#999",s=h?h(e(t,"edgeStyle")):{};if(h)l=("string"==typeof s.fill?s.fill:void 0)||l;else{let e="object"==typeof t.source?t.source:null,r="object"==typeof t.target?t.target:null;"target"===g&&r?l=p.get(r.id)||l:e&&(l=p.get(e.id)||l)}v.push({type:"ribbon",pathD:n,style:{fill:l,fillOpacity:s.fillOpacity??o,stroke:s.stroke||"none",strokeWidth:s.strokeWidth,opacity:s.opacity,cursor:s.cursor},datum:t})}if(!1!==i.showLabels){let e=er(i.nodeLabel),r=l+12;for(let i of t){let t=i.__arcData;if(!t)continue;let a=e?e(i):i.id;if(!a)continue;let n=(t.startAngle+t.endAngle)/2,o=n-Math.PI/2;k.push({x:c+Math.cos(o)*r,y:u+Math.sin(o)*r,text:a+"",anchor:n>Math.PI?"end":"start",baseline:"middle",fontSize:11})}}return{sceneNodes:b,sceneEdges:v,labels:k}}};Zt("chord",di);import{jsx as fi}from"react/jsx-runtime";Zt("chord",di);var hi=ni(function(e,t){let r=oi(null);Kt(t,{variant:"network",frameRef:r,overrides:{getData:()=>r.current?.getTopology()?.edges?.map(e=>e.data)??[]}});let i=Pr(e.mode,{width:e.width,height:e.height,enableHover:e.enableHover,showLegend:e.showLegend,showLabels:e.showLabels,title:e.title,description:e.description,accessibleTable:e.accessibleTable,summary:e.summary,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,responsiveRules:e.responsiveRules},{width:600,height:600}),{nodes:a,edges:l,margin:s,className:c,sourceAccessor:f="source",targetAccessor:h="target",valueAccessor:g="value",nodeIdAccessor:m="id",colorBy:p,colorScheme:y,styleRules:b,edgeColorBy:v="source",padAngle:k=.01,groupWidth:x=20,sortGroups:S,nodeLabel:w,edgeOpacity:M=.5,tooltip:P,frameProps:L={},onObservation:T,onClick:A,chartId:D,selection:I,linkedHover:E,loading:C,loadingContent:O,emptyContent:N,legendPosition:B,legendInteraction:$,stroke:H,strokeWidth:R,opacity:F}=e,{width:W,height:_,enableHover:z,showLegend:j,showLabels:X=!0,title:Y,description:q,summary:G,accessibleTable:V}=i,K=d({nodes:a,edges:l,inferNodes:!0,nodeIdAccessor:m,sourceAccessor:f,targetAccessor:h,colorBy:p,colorScheme:y,showLegend:j,legendPosition:B,legendInteraction:$,frameLegend:L,selection:I,linkedHover:E,onObservation:T,onClick:A,mobileInteraction:i.mobileInteraction,mobileSemantics:i.mobileSemantics,chartType:"ChordDiagram",chartId:D,marginDefaults:i.marginDefaults,userMargin:s,width:W,height:_,hasTitle:!!Y,loading:C,loadingContent:O,emptyContent:N}),U=ai(()=>new Map,[]),Q=ai(()=>new Map,[]),Z=K.safeNodes.length>0||K.allCategories.length>0,J=ai(()=>{if(Z)return(e,t)=>{let r={stroke:"black",strokeWidth:1};if(p)r.fill=Br(e.data||e,p,K.colorScale);else{let i=Array.isArray(y)?y:Er[y]||Cr,a=Array.isArray(i)?i:Cr,n=(e.id??e.data?.[m]??"")+"";Q.has(n)||Q.set(n,Q.size);let o=e.index??t??Q.get(n);r.fill=a[o%a.length]}return r}},[Z,p,K.colorScale,y,m,Q]),ee=ai(()=>mr(p),[p]),te=ai(()=>{if(J||b&&b.length>0)return ar(dr(J,b,ee,e=>e.data||e),{stroke:H,strokeWidth:R,opacity:F})},[J,b,ee,H,R,F]),re=ai(()=>n(te,K.effectiveSelectionHook,K.resolvedSelection),[te,K.effectiveSelectionHook,K.resolvedSelection]),ie=ai(()=>{if(Z)return u({edgeColorBy:v,colorBy:p,colorScale:K.colorScale,nodeStyleFn:re||(e=>({fill:xr(void 0,K.themeCategorical,y,void 0,U)})),edgeOpacity:M,baseStyle:{stroke:"black",strokeWidth:.5,strokeOpacity:M}})},[Z,v,p,K.colorScale,re,M,K.themeCategorical,y,U]),ae=ai(()=>ie?ar(ie,{stroke:H,strokeWidth:R,opacity:F}):void 0,[ie,H,R,F]),ne=ai(()=>o(ae,K.effectiveSelectionHook,K.resolvedSelection),[ae,K.effectiveSelectionHook,K.resolvedSelection]),oe=ai(()=>{if(!X)return;let e=w||m;return"function"==typeof e?e:t=>t.data?.[e]??t[e]??t.id},[X,w,m]),le=Gt({componentName:"ChordDiagram",edges:l,edgesRequired:!0});return le?fi(lr,{componentName:"ChordDiagram",message:le,width:W,height:_}):K.loadingEl?K.loadingEl:K.emptyEl?K.emptyEl:fi(cr,{componentName:"ChordDiagram",width:W,height:_,children:fi(Qt,{ref:r,chartType:"chord",...K.safeNodes.length>0&&{nodes:K.safeNodes},...null!=l&&{edges:K.safeEdges},size:[W,_],responsiveWidth:e.responsiveWidth,responsiveHeight:e.responsiveHeight,maxDevicePixelRatio:e.maxDevicePixelRatio,margin:K.margin,...K.legendBehaviorProps,nodeIDAccessor:m,sourceAccessor:f,targetAccessor:h,valueAccessor:g,padAngle:k,groupWidth:x,sortGroups:S,nodeStyle:re,edgeStyle:ne,colorBy:p,colorScheme:K.effectivePalette,edgeColorBy:v,edgeOpacity:M,nodeLabel:oe,showLabels:X,enableHover:z,tooltipContent:!1===P?()=>null:pr(P)||void 0,...ir({linkedHover:E,selection:I,onObservation:T,onClick:A,mobileInteraction:K.mobileInteraction,customHoverBehavior:K.customHoverBehavior,customClickBehavior:K.customClickBehavior,linkedHoverInClickPredicate:!1}),legend:K.legend,legendPosition:K.legendPosition,...$&&"none"!==$&&{legendHoverBehavior:K.legendState.onLegendHover,legendClickBehavior:K.legendState.onLegendClick,legendHighlightedCategory:K.legendState.highlightedCategory,legendIsolatedCategories:K.legendState.isolatedCategories},className:c,title:Y,description:q,summary:G,accessibleTable:V,...null!=e.animate&&{animate:e.animate},...L})})});hi.displayName="ChordDiagram";import{useMemo as gi,forwardRef as mi,useRef as pi}from"react";import{min as yi}from"d3-array";import{min as bi,max as vi,sum as ki,mean as xi,group as Si,groups as wi}from"d3-array";import{interpolateNumber as Mi}from"d3-interpolate";import{line as Pi,curveLinearClosed as Li}from"d3-shape";var Ti=e=>{let t,r,i,a,n,o,l,s,c;if("down"===e.direction)return t=e.y0-e.sankeyWidth/2,r=e.y1-e.sankeyWidth/2,i=e.y1+e.sankeyWidth/2,a=e.y0+e.sankeyWidth/2,n=e.source.x1,o=e.target.x0,l=Mi(n,o),s=l(.5),c=l(.5),`M${t},${n}C${t},${s} ${r},${c} ${r},${o}L${i},${o}C${i},${c} ${a},${s} ${a},${n}Z`;let u=e.sankeyWidth/2,d=Mi(e.source.x1,e.target.x0),{pathD:f}=Z({sx:e.source.x1,sTop:e.y0-u,sBot:e.y0+u,tx:e.target.x0,tTop:e.y1-u,tBot:e.y1+u,cp1X:d(.5),cp2X:d(.5)});return f},Ai={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(A))-1:0},justify:D},Di={supportsStreaming:!0,hierarchical:!1,computeLayout(e,t,r,i){if(0===e.length)return;let a,n="vertical"===r.orientation?"down":"right",o=r.nodeAlign||"justify",l=r.nodeWidth??15,s=r.nodePaddingRatio??.05,c=r.iterations??100,u=e.map(e=>({...e})),d=t.map(e=>({...e,source:tr(e.source),target:tr(e.target),value:Math.sqrt(Math.max(1,e.value||1))}));a="down"===n?[[0,0],[i[1],i[0]]]:[[0,0],[i[0],i[1]]];let f=Q().extent(a).links(d).nodes(u).nodeAlign(Ai[o]||D).nodeId(e=>e.id).nodeWidth(l).iterations(c);f.nodePaddingRatio&&f.nodePaddingRatio(s),f();{let e=1/0,t=-1/0,r=1/0,a=-1/0;for(let i of u)e>i.x0&&(e=i.x0),i.x1>t&&(t=i.x1),r>i.y0&&(r=i.y0),i.y1>a&&(a=i.y1);for(let i of d){if(!i.circular||!i.circularPathData)continue;let n=i.circularPathData,o=(i._circularWidth??i.width??0)/2;e>n.leftFullExtent-o&&(e=n.leftFullExtent-o),n.rightFullExtent+o>t&&(t=n.rightFullExtent+o),r>n.verticalFullExtent-o&&(r=n.verticalFullExtent-o),n.verticalFullExtent+o>a&&(a=n.verticalFullExtent+o)}let n=t-e,o=a-r,l=i[0],s=i[1];if(n>0&&o>0&&(0>e||0>r||t>l||a>s)){let t=Math.min(l/n,s/o),i=-e*t+(l-n*t)/2,a=-r*t+(s-o*t)/2;for(let e of u)e.x0=e.x0*t+i,e.x1=e.x1*t+i,e.y0=e.y0*t+a,e.y1=e.y1*t+a;for(let e of d)if(e.y0=e.y0*t+a,e.y1=e.y1*t+a,e.width=(e.width??0)*t,e._circularWidth&&(e._circularWidth*=t),e.circular&&e.circularPathData){let r=e.circularPathData;r.sourceX=r.sourceX*t+i,r.targetX=r.targetX*t+i,r.sourceY=r.sourceY*t+a,r.targetY=r.targetY*t+a,r.rightFullExtent=r.rightFullExtent*t+i,r.leftFullExtent=r.leftFullExtent*t+i,r.verticalFullExtent=r.verticalFullExtent*t+a,r.rightInnerExtent=r.rightInnerExtent*t+i,r.leftInnerExtent=r.leftInnerExtent*t+i,r.verticalRightInnerExtent=r.verticalRightInnerExtent*t+a,r.verticalLeftInnerExtent=r.verticalLeftInnerExtent*t+a,r.rightSmallArcRadius*=t,r.rightLargeArcRadius*=t,r.leftSmallArcRadius*=t,r.leftLargeArcRadius*=t,r.sourceWidth*=t,r.rightNodeBuffer*=t,r.leftNodeBuffer*=t,r.arcRadius*=t}}}let h=new Map;for(let t of e)h.set(t.id,t);for(let e of u){let t=h.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)}let g=new Map;for(let e of t)if(e._edgeKey)g.set(e._edgeKey,e);else{let t=tr(e.source),r=tr(e.target);g.set(`${t}\0${r}`,e)}for(let e of d){let t=tr(e.source),r=tr(e.target),i=g.get(e._edgeKey?e._edgeKey:`${t}\0${r}`);if(i){i.y0=e.y0,i.y1=e.y1,i.sankeyWidth=e.width??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=n;let a=h.get(t),o=h.get(r);a&&(i.source=a),o&&(i.target=o)}}},buildScene(t,r,i,a){let n="vertical"===i.orientation?"down":"right",o=i.nodeStyle,l=i.edgeStyle,s=i.edgeOpacity??.5,c=i.edgeColorBy||"source",u=Array.isArray(i.colorScheme)?i.colorScheme:i.themeCategorical&&i.themeCategorical.length>0?i.themeCategorical:Hr,d=new Map;t.forEach((e,t)=>{d.set(e.id,u[t%u.length])});let f=[],h=[],g=[],m=new Map;for(let r of t){let t=r.x1-r.x0,i=r.y1-r.y0;if(0>=t||0>=i)continue;let a=o?o(e(r,"nodeStyle")):{},l={fill:a.fill||d.get(r.id)||"#4d430c",stroke:a.stroke,strokeWidth:a.strokeWidth,opacity:a.opacity,cursor:a.cursor};m.set(r.id,("string"==typeof l.fill?l.fill:null)||d.get(r.id)||"#4d430c"),f.push("down"===n?{type:"rect",x:r.y0,y:r.x0,w:i,h:t,style:l,datum:r,id:r.id,label:r.id}:{type:"rect",x:r.x0,y:r.y0,w:t,h:i,style:l,datum:r,id:r.id,label:r.id})}let p=[...r].sort((e,t)=>(t.sankeyWidth||0)-(e.sankeyWidth||0));for(let t of p){if(!t.sankeyWidth||0>=t.sankeyWidth)continue;let r="object"==typeof t.source?t.source:null,a="object"==typeof t.target?t.target:null;if(!r||!a)continue;let n=i.themeSemantic?.border||i.themeSemantic?.secondary||"#999";n="function"==typeof c?c(t)||n:"target"===c?m.get(a.id)||d.get(a.id)||n:m.get(r.id)||d.get(r.id)||n;let o,u=l?l(e(t,"edgeStyle")):{};if(t._circularStub&&t.circular&&t.circularPathData){let e=t.circularPathData,r=t.sankeyWidth/2,i=Math.max(15,Math.min(40,.33*(e.rightFullExtent-e.sourceX))),a=Math.max(15,Math.min(40,.33*(e.targetX-e.leftFullExtent))),o=u.fill||n;h.push({type:"bezier",pathD:`M${e.sourceX},${e.sourceY-r}L${e.sourceX+i},${e.sourceY-r}L${e.sourceX+i},${e.sourceY+r}L${e.sourceX},${e.sourceY+r}Z`,style:{fill:o,fillOpacity:u.fillOpacity??s,stroke:"none",opacity:u.opacity,cursor:u.cursor},datum:t,_gradient:{direction:"right",from:1,to:0,x0:e.sourceX,x1:e.sourceX+i}}),h.push({type:"bezier",pathD:`M${e.targetX},${e.targetY-r}L${e.targetX-a},${e.targetY-r}L${e.targetX-a},${e.targetY+r}L${e.targetX},${e.targetY+r}Z`,style:{fill:o,fillOpacity:u.fillOpacity??s,stroke:"none",opacity:u.opacity,cursor:u.cursor},datum:t,_gradient:{direction:"left",from:0,to:1,x0:e.targetX-a,x1:e.targetX}});continue}o=t.circular&&t.circularPathData?J(t):Ti(t),o&&h.push({type:"bezier",pathD:o,bezierCache:t.bezier,style:{fill:u.fill||n,fillOpacity:u.fillOpacity??s,stroke:u.stroke||"none",strokeWidth:u.strokeWidth,opacity:u.opacity,cursor:u.cursor},datum:t})}if(!1!==i.showLabels){let e=er(i.nodeLabel);for(let r of t){let t=r.x1-r.x0,i=r.y1-r.y0;if(0>=t||0>=i)continue;let o,l,s,c=e?e(r):r.id;c&&("down"===n?(o=r.y0+(r.y1-r.y0)/2,l=r.x1+14,s="start"):(a[0]/2>r.x0+t/2?(o=r.x0-6,s="end"):(o=r.x1+6,s="start"),l=r.y0+i/2),g.push({x:o,y:l,text:c+"",anchor:"down"===n?"middle":s,baseline:"middle",fontSize:11}))}}return{sceneNodes:f,sceneEdges:h,labels:g}}};Zt("sankey",Di);import{jsx as Ii}from"react/jsx-runtime";Zt("sankey",Di);var Ei=mi(function(e,t){let r=pi(null);Kt(t,{variant:"network",frameRef:r,overrides:{getData:()=>r.current?.getTopology()?.edges?.map(e=>e.data)??[]}});let i=Pr(e.mode,{width:e.width,height:e.height,enableHover:e.enableHover,showLabels:e.showLabels,title:e.title,description:e.description,accessibleTable:e.accessibleTable,summary:e.summary,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,responsiveRules:e.responsiveRules},{width:800,height:600}),{nodes:a,edges:l,margin:s,className:c,sourceAccessor:f="source",targetAccessor:h="target",valueAccessor:g="value",nodeIdAccessor:m="id",colorBy:p,colorScheme:y,styleRules:b,edgeColorBy:v="source",orientation:k="horizontal",nodeAlign:x="justify",nodePaddingRatio:S=.05,nodeWidth:w=15,nodeLabel:M,edgeOpacity:P=.5,edgeSort:L,tooltip:T,frameProps:A={},onObservation:D,onClick:I,chartId:E,selection:C,linkedHover:O,loading:N,loadingContent:B,emptyContent:$,showLegend:H,legendPosition:R,legendInteraction:F,stroke:W,strokeWidth:_,opacity:z}=e,{width:j,height:X,enableHover:Y,showLabels:q=!0,title:G,description:V,summary:K,accessibleTable:U}=i,Q=d({nodes:a,edges:l,inferNodes:!0,nodeIdAccessor:m,sourceAccessor:f,targetAccessor:h,colorBy:p,colorScheme:y,showLegend:H,legendPosition:R,legendInteraction:F,frameLegend:A,selection:C,linkedHover:O,onObservation:D,onClick:I,mobileInteraction:i.mobileInteraction,mobileSemantics:i.mobileSemantics,chartType:"SankeyDiagram",chartId:E,marginDefaults:i.marginDefaults,userMargin:s,width:j,height:X,hasTitle:!!G,loading:N,loadingContent:B,emptyContent:$}),Z=gi(()=>new Map,[]),J=gi(()=>e=>{let t={stroke:"black",strokeWidth:1};return t.fill=p?Br(e.data||e,p,Q.colorScale):xr(void 0,Q.themeCategorical,y,void 0,Z),t},[p,Q.colorScale,Q.themeCategorical,y,Z]),ee=gi(()=>mr(p,g),[p,g]),te=gi(()=>ar(dr(J,b,ee,e=>e.data||e),{stroke:W,strokeWidth:_,opacity:z}),[J,b,ee,W,_,z]),re=gi(()=>n(te,Q.effectiveSelectionHook,Q.resolvedSelection),[te,Q.effectiveSelectionHook,Q.resolvedSelection]),ie=gi(()=>u({edgeColorBy:v,colorBy:p,colorScale:Q.colorScale,nodeStyleFn:re,edgeOpacity:P,baseStyle:{stroke:"none",strokeWidth:0}}),[v,p,Q.colorScale,re,P]),ae=gi(()=>ar(ie,{stroke:W,strokeWidth:_,opacity:z}),[ie,W,_,z]),ne=gi(()=>o(ae,Q.effectiveSelectionHook,Q.resolvedSelection),[ae,Q.effectiveSelectionHook,Q.resolvedSelection]),oe=gi(()=>{if(!q)return;let e=M||m;return"function"==typeof e?e:t=>t.data?.[e]??t[e]??t.id},[q,M,m]),le=Gt({componentName:"SankeyDiagram",edges:l,edgesRequired:!0});return le?Ii(lr,{componentName:"SankeyDiagram",message:le,width:j,height:X}):Q.loadingEl?Q.loadingEl:Q.emptyEl?Q.emptyEl:Ii(cr,{componentName:"SankeyDiagram",width:j,height:X,children:Ii(Qt,{ref:r,chartType:"sankey",...Q.safeNodes.length>0&&{nodes:Q.safeNodes},...null!=l&&{edges:Q.safeEdges},size:[j,X],responsiveWidth:e.responsiveWidth,responsiveHeight:e.responsiveHeight,maxDevicePixelRatio:e.maxDevicePixelRatio,margin:Q.margin,...Q.legendBehaviorProps,nodeIDAccessor:m,sourceAccessor:f,targetAccessor:h,valueAccessor:g,orientation:k,nodeAlign:x,nodePaddingRatio:S,nodeWidth:w,nodeStyle:re,edgeStyle:ne,colorBy:p,colorScheme:Q.effectivePalette,edgeColorBy:v,edgeOpacity:P,edgeSort:L,nodeLabel:oe,showLabels:q,enableHover:Y,tooltipContent:!1===T?()=>null:pr(T)||void 0,...ir({linkedHover:O,selection:C,onObservation:D,onClick:I,mobileInteraction:Q.mobileInteraction,customHoverBehavior:Q.customHoverBehavior,customClickBehavior:Q.customClickBehavior,linkedHoverInClickPredicate:!1}),legend:Q.legend,legendPosition:Q.legendPosition,...F&&"none"!==F&&{legendHoverBehavior:Q.legendState.onLegendHover,legendClickBehavior:Q.legendState.onLegendClick,legendHighlightedCategory:Q.legendState.highlightedCategory,legendIsolatedCategories:Q.legendState.isolatedCategories},className:c,title:G,description:V,summary:K,accessibleTable:U,...null!=e.animate&&{animate:e.animate},...A})})});Ei.displayName="SankeyDiagram";var Ci={static:{duplicateIds:"fatal",invalidSystemTime:"warn"},mcp:{duplicateIds:"fatal",invalidSystemTime:"warn"},push:{duplicateIds:"warn",invalidSystemTime:"strip"}},Oi=new Set(["invalid-domain","missing-node","backward-edge","invalid-edge-time","invalid-value","invalid-node-time"]),Ni=8,Bi=.92,$i=3,Hi=e=>{let t=1;for(let r=2;e>=r;r++)t*=r;return t},Ri=828*Hi(8),Fi=3e3,Wi=new Map,_i=1e5,zi=1e-9;import{forwardRef as ji,useMemo as Xi,useRef as Yi,useCallback as qi,useEffect as Gi}from"react";import{Fragment as Vi,jsx as Ki,jsxs as Ui}from"react/jsx-runtime";var Qi="var(--semiotic-grid, #94a3b8)",Zi="var(--semiotic-text-secondary, #475569)",Ji="var(--semiotic-text-secondary, #94a3b8)";import{useEffect as ea,useMemo as ta,useRef as ra,useState as ia}from"react";import{scaleTime as aa}from"d3-scale";import{scaleTime as na}from"d3-scale";var oa=/(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?),(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)/gi;import{scaleTime as la}from"d3-scale";var sa=class{constructor(e=function(){let e="string"==typeof import.meta.url&&import.meta.url?new URL("./processSankeyLayoutWorker.js",import.meta.url):or("processSankeyLayoutWorker.js");return new Worker(e,{type:"module",name:"semiotic-process-sankey-layout"})}()){this.session=new zt({name:"ProcessSankey layout",createWorker:()=>e,parseMessage:e=>{let t=e,{requestId:r,error:i}=Yt(t);return i?{requestId:r,ok:!1,error:Xt(i)}:{requestId:r,ok:!0,payload:{layout:bt(t.layout),layoutConfig:t.layoutConfig??{bands:[],ribbons:[],showLabels:!0},issues:t.issues??[],warnings:t.warnings??[],domain:t.domain??[0,1],timelineExtent:t.timelineExtent??0}}}})}get isDead(){return this.session.isDead}request(e,t){return this.session.request(e,t)}terminate(){this.session.terminate()}},ca=jt(()=>new sa),ua=(e,t)=>({layout:null,layoutConfig:{bands:[],ribbons:[],showLabels:!0},issues:[],warnings:[],xScale:aa().domain(e).range([0,t])});import{useCallback as da,useMemo as fa,useRef as ha,useState as ga}from"react";import{useCallback as ma,useMemo as pa}from"react";var ya=e=>{let{bands:t=[],ribbons:r=[],showLabels:i=!0,selectionDatum:a="raw"}=e.config,n=e.selection??null,o=[];for(let e of r){let t={__kind:"ribbon",data:e.rawDatum,id:e.id},r=!Pt(t,n,a);o.push({type:"bezier",pathD:e.pathD,...e.bezier&&{bezierCache:e.bezier},style:{fill:e.fill,opacity:r?Math.min(e.opacity,.22):e.opacity,stroke:"none"},datum:t})}for(let e of t){if(!e.gradientStubs)continue;let t=!Pt({__kind:"band",data:e.rawDatum,id:e.id},n,a);for(let r=0;e.gradientStubs.length>r;r++){let i=e.gradientStubs[r];o.push({type:"bezier",pathD:i.pathD,interactive:!1,style:{fill:e.fill,fillOpacity:t?.22:e.fillOpacity??.86,stroke:"none"},_gradient:{x0:i.x0,x1:i.x1,...null!=i.y0&&{y0:i.y0},...null!=i.y1&&{y1:i.y1},from:i.from,to:i.to},datum:{__kind:"band",data:e.rawDatum,id:`${e.id}__stub${r}`}})}}for(let e of t){let t=!(!e.gradientStubs||0>=e.gradientStubs.length),r={__kind:"band",data:e.rawDatum,id:e.id},i=!Pt(r,n,a);o.push({type:"bezier",pathD:e.pathD,style:{...t?{fill:"none"}:{fill:e.hatchFill??e.fill,fillOpacity:i?.22:e.fillOpacity??.86},stroke:e.stroke??("string"==typeof e.fill?e.fill:"#666"),strokeWidth:e.strokeWidth??.5,...i&&t?{opacity:.22}:{}},datum:r})}let l=i?t.flatMap(e=>{let t=e.labelDeferred&&e.labelFullText?.trim(),r=e.labelText.trim().length>0,i=t&&n?.isActive&&Pt({__kind:"band",data:e.rawDatum,id:e.id},n,a),o=r?e.labelText:i?e.labelFullText:"";return o.trim()?[{x:e.labelX,y:e.labelY,text:o,anchor:e.labelAnchor??"end",baseline:e.labelBaseline??"middle",fontSize:11,fontWeight:600}]:[]}):[];return{sceneNodes:t.map(e=>({type:"circle",id:e.id,cx:-1e4,cy:-1e4,r:0,style:{fill:e.fill},datum:{__kind:"band",data:e.rawDatum,id:e.id}})),sceneEdges:o,labels:l}};import{Fragment as ba,jsx as va,jsxs as ka}from"react/jsx-runtime";import{jsx as xa,jsxs as Sa}from"react/jsx-runtime";var wa=ji(function(e,t){let{nodes:r,edges:i,domain:a,axisTicks:n=[],nodeIdAccessor:o="id",nodeLabel:l,sourceAccessor:c="source",targetAccessor:u="target",valueAccessor:f="value",startTimeAccessor:h="startTime",endTimeAccessor:g="endTime",systemInTimeAccessor:m,systemOutTimeAccessor:p,xExtentAccessor:y="xExtent",groupBy:b,edgeIdAccessor:v="id",colorBy:k,colorScheme:x,showLegend:S,legendPosition:w="right",orientation:M="horizontal",pairing:P="temporal",packing:L="reuse",laneOrder:T="crossing-min",maxValueScale:A,lanePlacement:D="stack",nodeSizing:I="temporal",groupPadding:E=0,ribbonLane:C="both",ribbonMinRun:O=0,lifetimeMode:N="half",showLaneRails:B=!1,showQualityReadout:$=!1,showLabels:H=!0,labelPriorityAccessor:R,maxLabels:F,selectionDatum:W="raw",styleRules:_,layoutExecution:z="auto",layoutWorkerThreshold:j,layoutLoadingContent:X,onLayoutStateChange:Y,width:q=600,height:G=400,margin:V,title:K,description:U,summary:Q,accessibleTable:Z,responsiveWidth:J,responsiveHeight:ee,loading:te,loadingContent:re,emptyContent:ae,edgeOpacity:ne=.35,timeFormat:oe,valueFormat:le,tooltip:ce,enableHover:ue=!0,onObservation:de,onClick:fe,selection:he,linkedHover:ge,showParticles:me=!1,particleStyle:pe,chartId:ye,frameProps:be={}}=e,ve=Yi(null),ke=Yi(null),{rawNodes:xe,rawEdges:Se,frameRef:we,getNodeId:Me,getEdgeId:Pe}=function(e){let{ref:t,rawNodesProp:r,rawEdgesProp:i,nodeIdAccessor:a,edgeIdAccessor:n,sourceAccessor:o,targetAccessor:l,scalesRef:c,layoutSnapshotRef:u}=e,[d,f]=ga([]),[h,g]=ga([]),m=ha(d),p=ha(h);m.current=d,p.current=h;let y=da(e=>{m.current=e,f(e)},[]),b=da(e=>{p.current=e,g(e)},[]),v=void 0!==i,k=gr(v?i:d),x=fa(()=>{let e=gr(r??[]),t=h;if(0===e.length&&0===t.length)return s([],k,o,l);let i=new Set,n=[];for(let t of e){let e=Mt(a,t)+"";i.has(e)||(i.add(e),n.push(t))}for(let e of t){let t=Mt(a,e)+"";i.has(t)||(i.add(t),n.push(e))}let c=s([],k,o,l);for(let e of c)i.has(e.id)||(i.add(e.id),n.push(e));return n},[r,h,k,a,o,l]),S=ha(null),w=da((e,t)=>{let r=Mt(n,e);return null!=r?r+"":`${Mt(o,e)}-${Mt(l,e)}-${t}`},[n,o,l]),M=da(e=>{if(null==e)return!1;let t=e;return null!=Mt(o,t)&&null!=Mt(l,t)},[o,l]),P=da(e=>Mt(a,e)+"",[a]);return Kt(t,{variant:"network",frameRef:S,overrides:{push(e){if(M(e)){if(v)return void console.warn("ProcessSankey.push: edge ignored — `edges` prop is controlled.");y([...m.current,e])}else b([...p.current,e])},pushMany(e){let t=[],r=[];for(let i of e)M(i)?t.push(i):r.push(i);t.length>0&&(v?console.warn("ProcessSankey.pushMany: edges ignored — `edges` prop is controlled."):y([...m.current,...t])),r.length>0&&b([...p.current,...r])},remove(e){let t=new Set(Array.isArray(e)?e:[e]),r=[];if(!v){let e=m.current,i=[];for(let a=0;e.length>a;a++){let n=e[a];t.has(w(n,a))?r.push(n):i.push(n)}i.length!==e.length&&y(i)}let i=p.current,n=[];for(let e of i){let i=Mt(a,e)+"";t.has(i)?r.push(e):n.push(e)}return n.length!==i.length&&b(n),r},update(e,t){let r=new Set(Array.isArray(e)?e:[e]),i=[];if(!v){let e=!1,a=m.current.map((a,n)=>r.has(w(a,n))?(i.push(a),e=!0,t(a)):a);e&&y(a)}let n=!1,o=p.current.map(e=>{let o=Mt(a,e)+"";return r.has(o)?(i.push(e),n=!0,t(e)):e});return n&&b(o),i},clear(){v||y([]),b([]),S.current?.clear()},getData:()=>k??[],getScales:()=>c.current,getCustomLayout:()=>u.current}}),{rawNodes:x,rawEdges:k,frameRef:S,getNodeId:P,getEdgeId:w,isControlled:v}}({ref:t,rawNodesProp:r,rawEdgesProp:i,nodeIdAccessor:o,edgeIdAccessor:v,sourceAccessor:c,targetAccessor:u,scalesRef:ve,layoutSnapshotRef:ke}),{nodes:Le,edges:Te,domain:Ae,rawNodeById:De,rawEdgeById:Ie}=Xi(()=>{let e=(xe??[]).map(e=>{let t=Me(e),r=l?Mt(l,e):t,i={id:t,label:null==r?t:r+"",__raw:e},a=b?Mt(b,e):null;null!=a&&a+""!=""&&(i.group=a+"");let n=y?Mt(y,e):null;if(Array.isArray(n)&&2===n.length){let e=se(n[0]),t=se(n[1]);Number.isFinite(e)&&Number.isFinite(t)&&(i.xExtent=[e,t])}return i}),t=(Se??[]).map((e,t)=>{let r={id:Pe(e,t),source:Mt(c,e)+"",target:Mt(u,e)+"",value:Number(Mt(f,e)),startTime:se(Mt(h,e)),endTime:se(Mt(g,e)),__raw:e};if(m){let t=se(Mt(m,e));Number.isFinite(t)&&(r.systemInTime=t)}if(p){let t=se(Mt(p,e));Number.isFinite(t)&&(r.systemOutTime=t)}return r}),r=[se(a[0]),se(a[1])],i=new Map;for(let t of e)null!=t.__raw&&i.set(t.id,t.__raw);let n=new Map;for(let e of t)null!=e.__raw&&n.set(e.id,e.__raw);return{nodes:e,edges:t,domain:r,rawNodeById:i,rawEdgeById:n}},[xe,Se,a,Me,Pe,l,y,b,c,u,f,h,g,m,p]),Ee=d({nodes:xe,edges:Se,inferNodes:!1,nodeIdAccessor:o,sourceAccessor:c,targetAccessor:u,colorBy:k,colorScheme:x,showLegend:!1,legendPosition:w,frameLegend:be,selection:he,linkedHover:ge,onObservation:de,onClick:fe?(e,t)=>{Lt(e)?fe(e.data,t):fe(e,t)}:void 0,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,chartType:"ProcessSankey",chartId:ye,marginDefaults:lt(!!K,$,n.length>0,M),userMargin:V,width:q,height:G,hasTitle:!!K,loading:te,loadingContent:re,emptyContent:ae}),Ce=Object.hasOwn(be,"legend"),Oe=!Ce&&(S??!!k)&&!!k,Ne=qi((e,t)=>{if(k&&xe){let t=De.get(e);if(t)return Br(t,k,Ee.colorScale)}return Ee.effectivePalette[t%Ee.effectivePalette.length]||"#475569"},[k,xe,De,Ee.colorScale,Ee.effectivePalette]),Be=Xi(()=>{if(!Oe||!k)return;let e=new Map;(xe??[]).forEach((t,r)=>{let i=Mt(k,t),a=null==i?"":i+"";!a||e.has(a)||e.set(a,{label:a,color:Ne(Me(t),r)})});let t=Array.from(e.values());return 0===t.length?void 0:{legendGroups:[{type:"fill",label:"",items:t,styleFn:e=>{let t=e.color||"#333";return{fill:t,stroke:t}}}]}},[Oe,k,xe,Ne,Me]),$e=Ce?be.legend:Be,He=Xi(()=>{let e={...Ee.margin};if($e){let t={...e};vr(e,{legend:$e,position:Ee.legendPosition,size:[q,G],hasTitle:!!K,legendLayout:be.legendLayout,minimumMargin:"right"===Ee.legendPosition||"left"===Ee.legendPosition?140:"top"===Ee.legendPosition?50:80}),ur(e,t,[q,G],Ee.legendPosition)}return e},[Ee.margin,Ee.legendPosition,$e,q,G,K,be.legendLayout]),Re=q-He.left-He.right,Fe=G-He.top-He.bottom,We="vertical"===M?Fe:Re,_e=wt(Xi(()=>Re>0&&Fe>0?{nodes:Le,edges:Te,domain:Ae,plotW:Re,plotH:Fe,orientation:M,ribbonLane:C,ribbonMinRun:O,edgeOpacity:"function"==typeof ne?e=>ne(e):ne,colorOf:Ne,showLabels:H,labelPriorityAccessor:R,maxLabels:F,selectionDatum:W,styleRules:_,usageMode:"push",colorBy:k,valueAccessor:f,layoutOpts:{pairing:P,packing:L,laneOrder:T,lifetimeMode:N,maxValueScale:A,lanePlacement:D,nodeSizing:I,groupPadding:E}}:null,[Le,Te,Ae,Re,Fe,M,C,O,ne,Ne,H,R,F,W,_,k,f,P,L,T,N,A,D,I,E]),{execution:z,workerThreshold:j,colorById:Xi(()=>Object.fromEntries(Le.map((e,t)=>[e.id,Ne(e.id,t)])),[Le,Ne]),fallbackPalette:Ee.effectivePalette,rawNodeById:De,rawEdgeById:Ie}),{issues:ze,warnings:je,layout:Xe,xScale:Ye}=_e,qe=_e.layoutConfig,Ge=_e.status;ve.current=Xe?{time:Ye,centerlines:Xe.centerlines}:{time:Ye},ke.current=Xe?{layout:Xe,nodes:Le,edges:Te,bands:qe.bands,ribbons:qe.ribbons,warnings:je,status:Ge}:null;let Ve=Yi(Y);Ve.current=Y,Gi(()=>{Ve.current?.(Ge)},[Ge]),Gi(()=>{0!==je.length&&console.warn("ProcessSankey warnings:",je.map(ie).join("; "))},[je]);let Ke=void 0!==$e&&!Object.hasOwn(be,"margin"),Ue=function(e){let{tooltip:t,enableHover:r,layout:i,timeFormat:a,valueFormat:n,sourceAccessor:o,targetAccessor:l,valueAccessor:s,startTimeAccessor:c,endTimeAccessor:u}=e,d=pa(()=>!1!==t&&r&&void 0!==t&&!0!==t&&pr(t)||null,[t,r]),f=ma(e=>a?a(new Date(e)):Number.isFinite(e)?1e10>Math.abs(e)?Number.isInteger(e)?e+"":e.toFixed(2):new Date(e).toISOString().slice(0,10):"",[a]),h=ma(e=>n?n(e):e+"",[n]);return ma(e=>{if(!e||!e.data)return null;let t=e.data;if(!Lt(t))return null;let r=t.data;if(d)return d(r);if("band"===t.__kind){let e=t.id,r=i?function(e){if(!e)return[];let t=new Set,r=[];for(let i of e.samples){let e=i.topMass+i.botMass,a=`${i.t}:${e}`;t.has(a)||(t.add(a),r.push({t:i.t,total:e}))}return r}(i.nodeData[e]):[],a=5,n=r.length>a?r.length:null,o=function(e,t=5){if(t>=e.length)return e.slice();let r=[...e].sort((e,t)=>e.total-t.total),i=r.length-1,a=[{...r[0],mark:"min"},{...r[Math.floor(.25*i)],mark:"q25"},{...r[Math.floor(.5*i)],mark:"median"},{...r[Math.floor(.75*i)],mark:"q75"},{...r[i],mark:"max"}],n=new Set,o=[];for(let e of a)n.has(e.t)||(n.add(e.t),o.push(e));return o.sort((e,t)=>e.t-t.t)}(r,a);return ka("div",{style:{minWidth:160},children:[va("div",{style:{fontWeight:600,marginBottom:4},children:e}),o.length>0&&ka("table",{style:{borderCollapse:"collapse",fontSize:11,width:"100%"},children:[va("thead",{children:ka("tr",{style:{opacity:.6},children:[va("th",{style:{textAlign:"left",fontWeight:500,paddingRight:8},children:"Time"}),va("th",{style:{textAlign:"right",fontWeight:500},children:"Mass"}),null!=n&&va("th",{})]})}),va("tbody",{children:o.map((e,t)=>ka("tr",{children:[va("td",{style:{paddingRight:8},children:f(e.t)}),va("td",{style:{textAlign:"right"},children:h(e.total)}),null!=n&&va("td",{style:{textAlign:"right",paddingLeft:8,opacity:.55},children:e.mark})]},t))})]}),null!=n&&ka("div",{style:{marginTop:4,fontSize:10,opacity:.55},children:["showing ",o.length," of ",n," samples"]})]})}let a=r,n=Mt(o,a),g=Mt(l,a),m=Mt(s,a),p=Mt(c,a),y=Mt(u,a);return ka("div",{style:{minWidth:160},children:[ka("div",{style:{fontWeight:600,marginBottom:4},children:[n+""," → ",g+""]}),ka("div",{style:{display:"grid",gridTemplateColumns:"auto 1fr",columnGap:8,fontSize:11},children:[null!=m&&ka(ba,{children:[va("span",{style:{opacity:.6},children:"value"}),va("span",{style:{textAlign:"right"},children:h(Number(m))})]}),null!=p&&ka(ba,{children:[va("span",{style:{opacity:.6},children:"start"}),va("span",{style:{textAlign:"right"},children:f(se(p))})]}),null!=y&&ka(ba,{children:[va("span",{style:{opacity:.6},children:"end"}),va("span",{style:{textAlign:"right"},children:f(se(y))})]})]})]})},[i,d,f,h,o,l,s,c,u])}({tooltip:ce,enableHover:ue,layout:Xe,timeFormat:oe,valueFormat:le,sourceAccessor:c,targetAccessor:u,valueAccessor:f,startTimeAccessor:h,endTimeAccessor:g}),Qe=Xi(()=>{if(!Xe)return null;let e=je.map(e=>ie(e));return function(e){let t=e.layout,r=e.nodes,i=e.orientation,a=e.plotW,n=e.plotH,o=e.timelineExtent,l=e.axisTicks,s=e.showQualityReadout??!1,c=e.showLaneRails??!1,u=(e.warnings??[]).slice(0,3),d=e.timeFormat,f=e.colorOf,h=e.toTime,g=e.xScale,{centerlines:m,laneLifetime:p,nodeData:y,valueScale:b,compressedPadding:v,crossingsBefore:k,crossingsAfter:x,layoutQualityBefore:S,layoutQuality:w}=t,M=null,P=null;for(let e of r){let t=p[e.id];if(!t||null===t.start||null===t.end)continue;let r=g(t.start),i=g(t.end);(null===M||M>r)&&(M=r),(null===P||i>P)&&(P=i)}let L=e=>Math.max(0,Math.min(o,e)),T=L(M??0),A=Math.max(T,L(P??o)),D=l.map((e,t)=>({tick:e,index:t,coordinate:g(h(e.date))})).filter(({coordinate:e})=>e>=T-.5&&A+.5>=e),I=null!==(x??null)&&null!=S&&null!=w,E=s&&(I||u.length>0)?Ui("g",{fill:Ji,fontSize:10,textAnchor:"end",children:[I&&Ui(Vi,{children:[Ui("text",{x:a,y:-14,children:["crossings: ",k," → ",x," ","pixel length: ",Math.round(S.pixelLength)," → ",Math.round(w.pixelLength)]}),Ui("text",{x:a,y:-3,children:["transit: ",S.transitOcclusion.toFixed(1)," → ",w.transitOcclusion.toFixed(1)," ","lane use: ",Math.round(100*w.verticalUtilization),"%"]})]}),u.map((e,t)=>Ui("text",{x:a,y:I?10+11*t:11*t-3,fill:"var(--semiotic-warning, #b45309)",children:["warn: ",e]},"warn-"+t))]}):null,C=v?Ki("text",{x:a,y:"vertical"===i?-3:2,fontSize:10,fill:Ji,textAnchor:"end",children:"dense layout: lane gaps compressed"}):null,O=(e,t)=>f?f(e,t):Qi;return Ui("g","vertical"===i?{children:[E,C,D.map(({index:e,coordinate:t})=>Ki("line",{x1:0,y1:t,x2:a,y2:t,stroke:Qi,strokeOpacity:.15,strokeDasharray:"2 4"},"grid-"+e)),c&&r.map((e,t)=>{let r=p[e.id];if(!r||null===r.start)return null;let i=y[e.id],a=i?{topPeak:i.topPeak,botPeak:i.botPeak}:{topPeak:0,botPeak:0},n=m[e.id]+(a.botPeak-a.topPeak)*b/2,o=g(r.start),l=g(r.end),s=O(e.id,t);return Ui("g",{children:[Ki("line",{x1:n,y1:o,x2:n,y2:l,stroke:s,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),Ki("line",{x1:n-4,y1:o,x2:n+4,y2:o,stroke:s,strokeOpacity:.5}),Ki("line",{x1:n-4,y1:l,x2:n+4,y2:l,stroke:s,strokeOpacity:.5})]},"lane-"+e.id)}),Ki("line",{x1:-4,y1:T,x2:-4,y2:A,stroke:Qi}),D.map(({tick:e,index:t,coordinate:r})=>{let i=h(e.date),a=null!=e.label?e.label:d?d(new Date(i)):"";return Ui("g",{transform:`translate(-4,${r})`,children:[Ki("line",{x2:-6,stroke:Qi}),Ki("text",{x:-10,y:4,textAnchor:"end",fontSize:11,fill:Zi,children:a})]},t)})]}:{children:[E,C,D.map(({index:e,coordinate:t})=>Ki("line",{x1:t,y1:0,x2:t,y2:n,stroke:Qi,strokeOpacity:.15,strokeDasharray:"2 4"},"grid-"+e)),c&&r.map((e,t)=>{let r=p[e.id];if(!r||null===r.start)return null;let i=y[e.id],a=i?{topPeak:i.topPeak,botPeak:i.botPeak}:{topPeak:0,botPeak:0},n=m[e.id]+(a.botPeak-a.topPeak)*b/2,o=g(r.start),l=g(r.end),s=O(e.id,t);return Ui("g",{children:[Ki("line",{x1:o,y1:n,x2:l,y2:n,stroke:s,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),Ki("line",{x1:o,y1:n-4,x2:o,y2:n+4,stroke:s,strokeOpacity:.5}),Ki("line",{x1:l,y1:n-4,x2:l,y2:n+4,stroke:s,strokeOpacity:.5})]},"lane-"+e.id)}),Ki("line",{x1:T,y1:n+4,x2:A,y2:n+4,stroke:Qi}),D.map(({tick:e,index:t,coordinate:r})=>{let i=h(e.date),a=null!=e.label?e.label:d?d(new Date(i)):"";return Ui("g",{transform:`translate(${r},${n+4})`,children:[Ki("line",{y2:6,stroke:Qi}),Ki("text",{y:20,textAnchor:"middle",fontSize:11,fill:Zi,children:a})]},t)})]})}({layout:Xe,nodes:Le,orientation:M,plotW:Re,plotH:Fe,timelineExtent:We,axisTicks:n,showQualityReadout:$,showLaneRails:B,warnings:e,timeFormat:oe?e=>oe(e):void 0,colorOf:Ne,toTime:se,xScale:e=>Number(Ye(e))})},[Xe,Le,M,Re,Fe,We,n,$,B,je,oe,Ne,Ye]),Ze=Xi(()=>(xe??[]).map(e=>({id:Me(e),data:e})),[xe,Me]),Je=Xi(()=>{let e=new Map;for(let t of qe.ribbons)t.bezier&&e.set(t.id,t.bezier);return e},[qe]),et=Xi(()=>(Se??[]).map((e,t)=>{let r=Pe(e,t),i=Number(Mt(f,e));return{id:r,source:Mt(c,e)+"",target:Mt(u,e)+"",value:Number.isFinite(i)?i:0,bezier:Je.get(r),data:e}}),[Se,Pe,c,u,f,Je]);return ze.length>0?Sa("svg",{width:q,height:G,role:"img","aria-label":K??"Process Sankey validation failed",children:[xa("text",{x:20,y:30,fontSize:13,fontWeight:600,fill:"var(--semiotic-danger, #dc2626)",children:"ProcessSankey: data invalid"}),ze.map((e,t)=>xa("text",{x:20,y:56+18*t,fontSize:12,fill:"#64748b",children:"• "+ie(e)},t))]}):Ee.loadingEl?Ee.loadingEl:Ee.emptyEl?Ee.emptyEl:Sa("div",{style:{position:"relative",width:q,height:G},children:["pending"===Ge&&!1!==X&&!Xe&&xa("div",{style:{position:"absolute",inset:0,zIndex:3,background:"var(--semiotic-bg, #fff)"},children:br(!0,q,G,X)}),xa(Qt,{ref:we,chartType:"force",nodes:Ze,edges:et,customNetworkLayout:ya,layoutConfig:qe,size:[q,G],responsiveWidth:J,responsiveHeight:ee,maxDevicePixelRatio:e.maxDevicePixelRatio,margin:He,title:K,description:U??"Temporal process flow with lifetime-bounded node lanes, mass bands, and value-scaled ribbons.",summary:Q,accessibleTable:Z,enableHover:ue,tooltipContent:!1===ce?()=>null:Ue,backgroundGraphics:Qe,showParticles:me,particleStyle:pe,legend:$e,legendPosition:Ee.legendPosition,...Ke&&{__legendMarginReservedFor:$e},...ir({linkedHover:ge,selection:he,onObservation:de,onClick:fe,mobileInteraction:Ee.mobileInteraction,customHoverBehavior:Ee.customHoverBehavior,customClickBehavior:Ee.customClickBehavior,linkedHoverInClickPredicate:!1}),chartId:ye,colorScheme:Array.isArray(x)?x:void 0,layoutSelection:Ee.effectiveSelectionHook,...be})]})});wa.displayName="ProcessSankey";import{useMemo as Ma}from"react";import{hierarchy as Pa,tree as La,cluster as Ta,treemap as Aa,pack as Da,partition as Ia,treemapBinary as Ea}from"d3-hierarchy";var Ca=["#e8d5b7","#b8d4e3","#d4e3b8","#e3c4d4","#d4d4e3","#e3d4b8","#b8e3d4","#e3b8b8"],Oa={supportsStreaming:!1,hierarchical:!0,computeLayout(e,t,r,i){let a=r.__hierarchyRoot;if(!a)return;let n=r.chartType,o=function(e){if(e)return"function"==typeof e?e:t=>t[e]}(r.childrenAccessor),l=r.hierarchySum,s="function"==typeof l?l:"string"==typeof l?e=>Number(e[l])||0:e=>Number(e.value)||0,c=Pa(a,o);c.sum(s),c.sort((e,t)=>(t.value??0)-(e.value??0));let[u,d]=i;switch(n){case"tree":!function(e,t,r,i){let a=t.treeOrientation||"vertical",n=La();n.size("horizontal"===a?[i,r]:"radial"===a?[2*Math.PI,Math.min(r,i)/2*.8]:[r,i]),n(e)}(c,r,u,d);break;case"cluster":!function(e,t,r,i){let a=t.treeOrientation||"vertical",n=Ta();n.size("horizontal"===a?[i,r]:"radial"===a?[2*Math.PI,Math.min(r,i)/2*.8]:[r,i]),n(e)}(c,r,u,d);break;case"treemap":!function(e,t,r,i){let a=t.padding??4,n=t.paddingTop??0,o=Aa().size([r,i]).tile(Ea).padding(a);n>0&&o.paddingTop(n),o(e)}(c,r,u,d);break;case"circlepack":!function(e,t,r,i){let a=t.padding??4;Da().size([r,i]).padding(a)(e)}(c,r,u,d);break;case"partition":!function(e,t,r,i){Ia().size([r,i]).padding(t.padding??1)(e)}(c,r,u,d)}let f=c.descendants();e.length=0,t.length=0;let h=new Map;for(let t=0;f.length>t;t++){let i=f[t],a={id:At(i,r,t),x:0,y:0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:i.value??0,depth:i.depth,data:i.data,createdByFrame:!0};"tree"===n||"cluster"===n?Ot(a,i,r):"treemap"===n||"partition"===n?Nt(a,i):"circlepack"===n&&Bt(a,i),a.__hierarchyNode=i,e.push(a),h.set(i,a)}if("tree"===n||"cluster"===n)for(let e of f)if(e.parent){let r=h.get(e.parent),i=h.get(e);r&&i&&t.push({source:r,target:i,value:1,y0:0,y1:0,sankeyWidth:0,data:{depth:e.depth}})}},buildScene(t,r,i,a){let n=i.nodeStyle||(()=>({})),o=i.edgeStyle||(()=>({}));switch(i.chartType){case"tree":case"cluster":return function(t,r,i,a,n,o){let l=[],s=[],c=[],u=i.treeOrientation||"vertical",d="radial"===u,f=a[0]/2,h=a[1]/2,g="number"==typeof(m=i.nodeSize)?m:5;var m;for(let r of t){let t=r.x,a=r.y;d&&(t+=f,a+=h);let o=n(e(r,"nodeStyle")),s=o.fill||Et(i);if(i.colorByDepth&&void 0!==r.depth){let e=It(i);s=e[r.depth%e.length]}l.push({type:"circle",cx:t,cy:a,r:g,style:{fill:s,stroke:o.stroke||i.themeSemantic?.surface||"#fff",strokeWidth:o.strokeWidth??1,opacity:o.opacity,cursor:o.cursor},datum:r,id:r.id,label:r.id,depth:r.depth})}let p=i.edgeOpacity??.5;for(let t of r){let r="object"==typeof t.source?t.source:null,a="object"==typeof t.target?t.target:null;if(!r||!a)continue;let n=r.x,l=r.y,c=a.x,g=a.y;d&&(n+=f,l+=h,c+=f,g+=h);let m=Ct(n,l,c,g,u),y=o(e(t,"edgeStyle"));s.push({type:"curved",pathD:m,style:{fill:"none",stroke:y.stroke||i.themeSemantic?.border||i.themeSemantic?.secondary||"#999",strokeWidth:y.strokeWidth??1.5,opacity:y.opacity??p,cursor:y.cursor},datum:t})}if(!1!==i.showLabels){let e=Dt(i.nodeLabel);for(let r of t){let t=e?e(r):r.id;if(!t)continue;let i,a,n,o=r.x,l=r.y;if(d&&(o+=f,l+=h),d){let e=o-f,t=l-h,r=Math.sqrt(e*e+t*t);r>0?(i=o+e/r*10,a=l+t/r*10,n=0>e?"end":"start"):(i=o,a=l-12,n="middle")}else"horizontal"===u?(r.data?.children&&0!==r.data.children.length?(i=o-g-6,n="end"):(i=o+g+6,n="start"),a=l):(i=o,a=l+g+14,n="middle");c.push({x:i,y:a,text:t+"",anchor:n,baseline:"middle",fontSize:11})}}return{sceneNodes:l,sceneEdges:s,labels:c}}(t,r,i,a,n,o);case"treemap":case"partition":return function(t,r,i,a){let n=[],o=[];for(let i of t){let t=i.x1-i.x0,o=i.y1-i.y0;if(0>=t||0>=o)continue;let l=a(e(i,"nodeStyle")),s=l.fill||Et(r);if(r.colorByDepth&&void 0!==i.depth){let e=It(r);s=e[i.depth%e.length]}n.push({type:"rect",x:i.x0,y:i.y0,w:t,h:o,style:{fill:s,stroke:l.stroke||r.themeSemantic?.surface||"#fff",strokeWidth:l.strokeWidth??1,opacity:l.opacity,fillOpacity:l.fillOpacity,strokeOpacity:l.strokeOpacity,cursor:l.cursor},datum:i,id:i.id,label:i.id,depth:i.depth})}if(!1!==r.showLabels){let i=Dt(r.nodeLabel),n=r.labelMode||"leaf",l="partition"===r.chartType;for(let s of t){let t=s.x1-s.x0,c=s.y1-s.y0;if(0>=t||0>=c)continue;let u=!(s.data?.children&&s.data.children.length>0);if(!l&&("leaf"===n&&!u||"parent"===n&&u))continue;let d=i?i(s):s.id;if(!d)continue;if((u?30:40)>t||(u?16:14)>c)continue;let f=a(e(s,"nodeStyle")).fill||Et(r);if(r.colorByDepth&&void 0!==s.depth){let e=It(r);f=e[s.depth%e.length]}let h="string"==typeof f?Tt(f):r.themeSemantic?.text??"#000";o.push(u?{x:s.x0+t/2,y:s.y0+c/2,text:d+"",anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,Math.min(t,c)/6)),fill:h}:{x:s.x0+4,y:s.y0+12,text:d+"",anchor:"start",baseline:"auto",fontSize:11,fontWeight:600,fill:h})}}return{sceneNodes:n,sceneEdges:[],labels:o}}(t,i,0,n);case"circlepack":return function(t,r,i,a){let n=[],o=[];for(let i of t){let t=i.__radius??5;if(0>=t)continue;let o=a(e(i,"nodeStyle")),l=o.fill||Et(r);if(r.colorByDepth&&void 0!==i.depth){let e=It(r);l=e[i.depth%e.length]}n.push({type:"circle",cx:i.x,cy:i.y,r:t,style:{fill:l,stroke:o.stroke||r.themeSemantic?.surface||"#fff",strokeWidth:o.strokeWidth??1,opacity:o.opacity??.7,cursor:o.cursor},datum:i,id:i.id,label:i.id,depth:i.depth})}if(!1!==r.showLabels){let i=Dt(r.nodeLabel);for(let n of t){let t=n.__radius??5,l=i?i(n):n.id;if(!l||15>t)continue;let s=!(n.data?.children&&n.data.children.length>0),c=a(e(n,"nodeStyle")).fill||Et(r);if(r.colorByDepth&&void 0!==n.depth){let e=It(r);c=e[n.depth%e.length]}if(s){let e="string"==typeof c?Tt(c):r.themeSemantic?.text??"#000";o.push({x:n.x,y:n.y,text:l+"",anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,t/3)),fill:e})}else o.push({x:n.x,y:n.y-t+14,text:l+"",anchor:"middle",baseline:"hanging",fontSize:Math.min(11,Math.max(8,t/3)),fill:r.themeSemantic?.text||"#000",stroke:r.themeSemantic?.surface||"#fff",strokeWidth:3,paintOrder:"stroke"})}}return{sceneNodes:n,sceneEdges:[],labels:o}}(t,i,0,n);default:return{sceneNodes:[],sceneEdges:[],labels:[]}}}};Zt("tree",Oa),Zt("cluster",Oa),Zt("treemap",Oa),Zt("circlepack",Oa),Zt("partition",Oa);import{jsx as Na}from"react/jsx-runtime";Zt("tree",Oa),Zt("cluster",Oa),Zt("treemap",Oa),Zt("circlepack",Oa),Zt("partition",Oa),$t.displayName="TreeDiagram";import{useMemo as Ba,useCallback as $a}from"react";import{jsx as Ha}from"react/jsx-runtime";Zt("treemap",Oa),Ht.displayName="Treemap";import{useMemo as Ra}from"react";import{jsx as Fa}from"react/jsx-runtime";Zt("circlepack",Oa),Rt.displayName="CirclePack";import{useMemo as Wa}from"react";import{pie as _a}from"d3-shape";var za={supportsStreaming:!1,hierarchical:!0,supportsAnimation:!0,computeLayout(e,t,r,i){let a=r.__hierarchyRoot;a&&function(e,t,r,i,a){function n(e){let t=g.get(e)??0;return g.set(e,t+1),0===t?e:`${e}__${t}`}let o=function(e){if("function"==typeof e)return e;let t=e||"children";return e=>e[t]||null}(r.childrenAccessor),l=function(e){if("function"==typeof e)return e;let t=e||"name";return e=>(e[t]??"")+""}(r.nodeIDAccessor),s=function(e){if(Array.isArray(e))return e;switch(e){case"solar":return[1];case"atomic":return[2,8];default:return[9999]}}(r.orbitMode),c=r.orbitSize??2.95,u=r.orbitEccentricity??1,d="number"==typeof c?()=>c:c,f="number"==typeof u?()=>u:u,h=Ft(r);h.metaMap.clear(),i.length=0,a.length=0;let g=new Map,m=t[0]/2,p=t[1]/2,y=Math.min(t[0],t[1])/2*.85,b=n(l(e));i.push({id:b,x:m,y:p,x0:m,x1:m,y0:p,y1:p,width:0,height:0,value:0,depth:0,data:e}),h.metaMap.set(b,{ring:y,angle:0,depth:0,parentId:null,eccentricity:1}),function e(t,r,c,u,g,m,p){let y=o(t);if(!y?.length)return;let b=y.length,v=0,k=0,x=0;for(;b>k;)k+=s[Math.min(x,s.length-1)],x++,v++;let S=0;for(let b=0;v>b;b++){let k=s[Math.min(b,s.length-1)],x=y.slice(S,S+k);if(!x.length)break;let w=(b+1)/v,M={id:r,depth:m,data:t,parentId:r},P=p?g/d(M)*w:g*w,L=_a().value(e=>o(e)?.length?4:1).sort(null)(x),T=f(M);for(let t=0;x.length>t;t++){let o=(L[t].startAngle+L[t].endAngle)/2,s=x[t],d=n(l(s)),f=c+P*Math.sin(o),g=u+P*Math.cos(o)*T;i.push({id:d,x:f,y:g,x0:f,x1:f,y0:g,y1:g,width:0,height:0,value:0,depth:m,data:s}),h.metaMap.set(d,{ring:P,angle:o,depth:m,parentId:r,eccentricity:T}),a.push({source:r,target:d,value:1,y0:0,y1:0,sankeyWidth:0,data:{source:r,target:d}}),e(s,d,f,g,P,m+1,!0)}S+=k}}(e,b,m,p,y,1,!1)}(a,i,r,e,t)},buildScene(t,r,i,a){let n=i.nodeStyle,o=i.edgeStyle,l=i.nodeSize,s="number"==typeof l?()=>l:"function"==typeof l?l:()=>6,c=[],u=[],d=[];if(!1!==i.orbitShowRings){let e=Ft(i),r=new Map;for(let e of t)r.set(e.id,e);let a=new Map;for(let[,t]of e.metaMap){if(!t.parentId)continue;let e=r.get(t.parentId);if(!e)continue;let i=`${t.parentId}:${t.ring}`;a.has(i)||a.set(i,{parentX:e.x,parentY:e.y,ring:t.ring,ecc:t.eccentricity})}let n=48,o={stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1};for(let[,{parentX:e,parentY:t,ring:r,ecc:i}]of a)for(let a=0;n>a;a++){let l=a/n*Math.PI*2,s=(a+1)/n*Math.PI*2;u.push({type:"line",x1:e+r*Math.sin(l),y1:t+r*Math.cos(l)*i,x2:e+r*Math.sin(s),y2:t+r*Math.cos(s)*i,style:o,datum:null})}}for(let r of t){if(null==r.x||null==r.y)continue;let t=s(e(r,"nodeSize")),a=n?n(e(r,"nodeStyle")):{};c.push({type:"circle",cx:r.x,cy:r.y,r:t,style:{fill:a.fill||i.themeSemantic?.primary||"#6366f1",stroke:a.stroke||i.themeSemantic?.surface||"#fff",strokeWidth:a.strokeWidth??1,opacity:a.opacity??(0===(r.depth??0)?1:.85),cursor:a.cursor},datum:r,id:r.id,label:r.id,depth:r.depth})}let f=new Map;for(let e of t)f.set(e.id,e);for(let t of r){let r="object"==typeof t.source?t.source:f.get(t.source),i="object"==typeof t.target?t.target:f.get(t.target);if(!r||!i||null==r.x||null==i.x)continue;let a=o?o(e(t,"edgeStyle")):{};u.push({type:"line",x1:r.x,y1:r.y,x2:i.x,y2:i.y,style:{stroke:a.stroke||"rgba(128,128,128,0.35)",strokeWidth:a.strokeWidth??.5,opacity:a.opacity??1,cursor:a.cursor},datum:t})}if(i.showLabels){let r=i.nodeLabel;for(let i of t){let t=s(e(i,"nodeSize"));if(4>=t)continue;let a="function"==typeof r?r(i):r?i.data?.[r]??i.id:i.id;d.push({x:i.x,y:i.y+t+12,text:a+"",anchor:"middle",fontSize:10,fill:"currentColor"})}}return{sceneNodes:c,sceneEdges:u,labels:d}},tick:(e,t,r,i,a)=>!1!==r.orbitAnimated&&(function(e,t){let r=Ft(t),i=t.orbitSpeed??.25,a=t.orbitRevolution??function(e){switch(e){case"decay":return e=>Math.pow(.6,e.depth??0);case"alternate":return e=>{let t=e.depth??0;return(t%2==0?1:-1)/(t+1)};default:return e=>1/((e.depth??0)+1)}}(t.orbitRevolutionStyle),n=(("u">typeof performance?performance.now():Date.now())-r.startTime)/1e3,o=i*(Math.PI/6),l=new Map;for(let t of e)l.set(t.id,t);for(let t of e){let e=r.metaMap.get(t.id);if(!e||!e.parentId)continue;let i=l.get(e.parentId);if(!i)continue;let s=e.angle+n*o*a({id:t.id,depth:e.depth,data:t.data,parentId:e.parentId});t.x=i.x+e.ring*Math.sin(s),t.y=i.y+e.ring*Math.cos(s)*e.eccentricity,t.x0=t.x,t.x1=t.x,t.y0=t.y,t.y1=t.y}}(e,r),!0)};Zt("orbit",za);import{jsx as ja}from"react/jsx-runtime";Zt("orbit",za);var Xa=Or;Wt.displayName="OrbitDiagram";import{forwardRef as Ya,useMemo as qa}from"react";import{jsx as Ga}from"react/jsx-runtime";var Va=Ya(function(e,t){let{nodes:r,edges:i,layout:a,layoutConfig:n,onLayoutError:o,nodeIDAccessor:l="id",sourceAccessor:s="source",targetAccessor:c="target",margin:u,className:d,colorBy:f,colorScheme:h,tooltip:g,selection:m,linkedHover:p,onObservation:y,onClick:b,chartId:v,annotations:k,autoPlaceAnnotations:x,frameProps:S={}}=e,{frameRef:w,resolved:M,normalizedMargin:P}=qt({imperativeRef:t,imperativeVariant:"network",margin:u,width:e.width,height:e.height,enableHover:e.enableHover,title:e.title,description:e.description,summary:e.summary,accessibleTable:e.accessibleTable,mode:e.mode,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,responsiveRules:e.responsiveRules}),L=qa(()=>gr(r),[r]),T=qa(()=>gr(i),[i]),A=qa(()=>void 0===r&&void 0===i?void 0:[...L,...T],[i,r,T,L]),D=Sr(e.mobileInteraction,{mode:e.mode,width:M.width,mobileSemantics:e.mobileSemantics}),{customHoverBehavior:I,customClickBehavior:E,activeSelectionHook:C}=Lr({selection:m,linkedHover:p,fallbackFields:"string"==typeof f?[f]:[],onObservation:y,onClick:b,chartType:"NetworkCustomChart",chartId:v,colorByField:"string"==typeof f?f:void 0,mobileInteraction:D}),O=qa(()=>C?.isActive?{isActive:!0,predicate:C.predicate}:null,[C?.isActive,C?.predicate]),{width:N,height:B,enableHover:$,title:H,description:R,summary:F,accessibleTable:W}=M,_=qa(()=>pr(g),[g]),z=br(e.loading,N,B,e.loadingContent),j=z?null:yr(A,N,B,e.emptyContent);if(z||j)return z||j;let X={chartType:"force",...null!=r&&{nodes:L},...null!=i&&{edges:T},customNetworkLayout:a,layoutConfig:n,onLayoutError:o,nodeIDAccessor:l,sourceAccessor:s,targetAccessor:c,colorBy:f,colorScheme:h,size:[N,B],responsiveWidth:e.responsiveWidth,responsiveHeight:e.responsiveHeight,margin:P,enableHover:$,...rr({title:H,description:R,summary:F,accessibleTable:W,className:d,animate:e.animate,maxDevicePixelRatio:e.maxDevicePixelRatio,autoPlaceAnnotations:x}),...!1===g?{tooltipContent:()=>null}:_?{tooltipContent:_}:{},...ir({linkedHover:p,selection:m,onObservation:y,onClick:b,mobileInteraction:D,customHoverBehavior:I,customClickBehavior:E,linkedHoverInClickPredicate:!1}),layoutSelection:O,...null!=k&&{annotations:k},...S};return Ga(cr,{componentName:"NetworkCustomChart",width:N,height:B,children:Ga(Qt,{ref:w,...X})})});Va.displayName="NetworkCustomChart";import{forceCenter as Ka,forceCollide as Ua,forceLink as Qa,forceManyBody as Za,forceSimulation as Ja,forceX as en,forceY as tn}from"d3-force";export{Zr as forceLayoutPlugin,ii as ForceDirectedGraph,di as chordLayoutPlugin,hi as ChordDiagram,Di as sankeyLayoutPlugin,Ei as SankeyDiagram,re as validateProcessSankey,ie as formatProcessSankeyIssue,ae as diagnoseProcessSankeyLayout,ne as explainProcessSankeyLayout,oe as diagnoseProcessSankeyProps,le as inventoryAtTime,se as toProcessSankeyTime,wa as ProcessSankey,Oa as hierarchyLayoutPlugin,$t as TreeDiagram,Ht as Treemap,Rt as CirclePack,za as orbitLayoutPlugin,Wt as OrbitDiagram,Va as NetworkCustomChart,_t as forceLayout};
1
+ function e(e,t){if("production"===process.env.NODE_ENV||!e||!e.data||"object"!=typeof e.data)return e;let r=Kr.get(e);if(r){let e=r.get(t);if(e)return e}else r=new Map,Kr.set(e,r);let i=new Proxy(e,{get(e,r,i){if("string"==typeof r&&!(r in e)&&e.data&&r in e.data){let e=`${t}:${r}`;Qr.has(e)||(Qr.add(e),console.warn(`[Semiotic] "${t}" callback accessed "${r}" on the wrapper object, but it only exists on ".data". Use d.data.${r} (or d.data?.${r}) instead. Frame callbacks receive RealtimeNode/RealtimeEdge wrappers, not your raw data.`))}return Reflect.get(e,r,i)}});return r.set(t,i),i}function t(e,t,r){let i=[];for(let a of t){let t=tr(a.source),n=tr(a.target),o=null;if(t===e?o=n:n===e&&(o=t),o){let e=r.get(o);e&&(0!==e.x||0!==e.y)&&i.push({x:e.x,y:e.y})}}return i}function r(e){let t=0;for(let r=0;e.length>r;r++)t=(t<<5)-t+e.charCodeAt(r)|0;return Math.abs(t)}function i(e){return e.data&&"object"==typeof e.data?e.data:e}function a(e,t,r){if(t)return r?.selectedStyle&&Object.assign(e,r.selectedStyle),e;let i=r?.unselectedOpacity??sr;return e.opacity=i,e.fillOpacity=i,e.strokeOpacity=i,r?.unselectedStyle&&Object.assign(e,r.unselectedStyle),e}function n(e,t,r){if(e)return t?n=>{let o={...e(n)};return t.isActive?a(o,t.predicate(i(n)),r):o}:e}function o(e,t,r){if(e)return t?n=>{let o={...e(n)};if(!t.isActive)return o;let l=i(n),s="object"==typeof n.source?i(n.source):null,c="object"==typeof n.target?i(n.target):null;return a(o,s||c?!!s&&t.predicate(s)||!!c&&t.predicate(c):t.predicate(l),r)}:e}function l(e,t){if(!e)return[];let r=[],i=e=>{r.push(e);let a="function"==typeof t?t(e):e[t];a&&Array.isArray(a)&&a.forEach(i)};return i(e),r}function s(e,t,r,i){if(e&&e.length>0)return e;let a=new Set;return t.forEach(e=>{let t="function"==typeof r?r(e):e[r],n="function"==typeof i?i(e):e[i];a.add(t),a.add(n)}),Array.from(a).map(e=>({id:e}))}function c(e){return"function"==typeof e?e:t=>t[e]||1}function u({edgeColorBy:e,colorBy:t,colorScale:r,nodeStyleFn:i,edgeOpacity:a,baseStyle:n={}}){return o=>{let l={fillOpacity:a,...n};if("function"==typeof e)l.fill=e(o);else if("source"===e){let e="object"==typeof o.source?o.source:null;t&&e?l.fill=Br(e.data||e,t,r):e&&(l.fill=i(e,e.index).fill)}else if("target"===e){let e="object"==typeof o.target?o.target:null;t&&e?l.fill=Br(e.data||e,t,r):e&&(l.fill=i(e,e.index).fill)}else"gradient"===e&&(l.fill="#999",l.fillOpacity=.7*a);return l}}function d(e){let{nodes:t,edges:r,inferNodes:i=!0,sourceAccessor:a="source",targetAccessor:n="target",colorBy:o,colorScheme:l,showLegend:c,legendPosition:u,legendInteraction:d,frameLegend:f,selection:h,linkedHover:g,onObservation:m,onClick:p,mobileInteraction:y,mobileSemantics:b,chartType:v,chartId:k,marginDefaults:x,userMargin:S,width:w,height:M,hasTitle:P,loading:L,loadingContent:T,emptyContent:A,emptyDataKey:D="edges"}=e,I=ei(()=>gr(r),[r]),E=ei(()=>gr(t),[t]),C=void 0===t&&void 0===r,[O,N]=ti([]),B=Jr(e=>{N(t=>t.length===e.length&&t.every((t,r)=>t===e[r])?t:e)},[]),$=br(L,w,M,T),H=$?null:yr("nodes"===D?void 0===t?void 0:E:void 0===r?void 0:I,w,M,A),R=ei(()=>i?s(E,I,a,n):E,[i,E,I,a,n]),F=Tr(R,o,l),W=Dr(),_=ei(()=>Array.isArray(l)&&l.length>0?l:[...$r(l,W,Cr)],[l,W]),z=ei(()=>hr(R,o),[R,o]),j=ei(()=>C&&O.length>0?O:z,[C,O,z]),X=ei(()=>{if(F)return F;if(!o||0===j.length)return;let e="__streamNetworkCategory";return Nr(j.map(t=>({[e]:t})),e,_)},[F,o,j,_]),Y=Ar(d,o,j),{legend:G,margin:q,legendPosition:V,legendMarginReserved:U}=Mr({data:R,colorBy:o,colorScale:X,showLegend:c,legendPosition:u,userMargin:S,defaults:x,categories:j,chartWidth:w,chartHeight:M,frameLegend:f,hasTitle:P}),Q=ei(()=>{let e={};return G&&U&&(e.__legendMarginReservedFor=G),C&&o&&(e.legendCategoryAccessor=o,e.onCategoriesChange=B),e},[G,U,C,o,B]),K=ei(()=>Sr(y,{width:w,mobileSemantics:b}),[y,w,b]),Z=Lr({selection:h,linkedHover:g,fallbackFields:o?["string"==typeof o?o:""]:[],unwrapData:!0,onObservation:m,onClick:p,mobileInteraction:K,chartType:v,chartId:k}),{customHoverBehavior:J,customClickBehavior:ee,activeSelectionHook:te,hoverSelectionHook:re,crosshairSourceId:ie}=Z,ae=ei(()=>re||(Y.legendSelectionHook?Y.legendSelectionHook:te),[re,Y.legendSelectionHook,te]),ne=Qt(h);return{safeNodes:R,safeEdges:I,colorScale:X,effectivePalette:_,themeCategorical:W,allCategories:j,legendState:Y,legend:G,margin:q,legendPosition:V,legendBehaviorProps:Q,mobileInteraction:K,customHoverBehavior:J,customClickBehavior:ee,activeSelectionHook:te,hoverSelectionHook:re,effectiveSelectionHook:ae,resolvedSelection:ne,crosshairSourceId:ie,loadingEl:$,emptyEl:H}}function f(e,t,r){let i=e.match(/[a-zA-Z]|[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?/g);if(!i)return e;let a=[],n=0;for(;i.length>n;){let e=i[n];if("M"===e||"L"===e||"C"===e||"Q"===e)for(a.push(e),n++;i.length>n&&!isNaN(Number(i[n]));)a.push(Number(i[n])+t+""),n++,i.length>n&&!isNaN(Number(i[n]))&&(a.push(Number(i[n])+r+""),n++);else if("A"===e)for(a.push(e),n++;i.length>n&&!isNaN(Number(i[n]));)a.push(i[n++]),i.length>n&&a.push(i[n++]),i.length>n&&a.push(i[n++]),i.length>n&&a.push(i[n++]),i.length>n&&a.push(i[n++]),i.length>n&&(a.push(Number(i[n])+t+""),n++),i.length>n&&(a.push(Number(i[n])+r+""),n++);else"Z"===e||"z"===e?(a.push(e),n++):(a.push(i[n]),n++)}return a.join(" ")}function h(e,t){var r=e.get(t);if(!r)throw Error("missing: "+t);return r}function g(e,t){function r(e){c[e]=!1,u.hasOwnProperty(e)&&Object.keys(u[e]).forEach(function(t){delete u[e][t],c[t]&&r(t)})}function i(e){var t,n,l=!1;for(s.push(e),c[e]=!0,t=0;d[e].length>t;t++)(n=d[e][t])===o?(a(o,s),l=!0):c[n]||(l=i(n));if(l)r(e);else for(t=0;d[e].length>t;t++){var f=u[n=d[e][t]];f||(u[n]=f={}),f[n]=!0}return s.pop(),l}function a(e,r){var i=[].concat(r).concat(e);t?t(i):l.push(i)}function n(t){!function(t){for(var r=0;e.length>r;r++)(t>r||!e[r])&&(e[r]=[]),e[r]=e[r].filter(function(e){return e>=t})}(t);for(var r,i=function(e){function t(t){var r=[t],c=[t];for(i[t]=a[t]=d,n[t]=!0,d+=1;c.length>0;){var u=e[t=c[c.length-1]];if(u.length>o[t]){for(var g=o[t];u.length>g;++g){var m=u[g];if(0>i[m]){i[m]=a[m]=d,n[m]=!0,d+=1,r.push(m),c.push(m);break}n[m]&&(a[t]=0|Math.min(a[t],a[m])),l[m]>=0&&s[t].push(l[m])}o[t]=g}else{if(a[t]===i[t]){var p=[],y=[],b=0;for(g=r.length-1;g>=0;--g){var v=r[g];if(n[v]=!1,p.push(v),y.push(s[v]),b+=s[v].length,l[v]=f.length,v===t){r.length=g;break}}f.push(p);var k=Array(b);for(g=0;y.length>g;g++)for(var x=0;y[g].length>x;x++)k[--b]=y[g][x];h.push(k)}c.pop()}}}for(var r=e.length,i=Array(r),a=Array(r),n=Array(r),o=Array(r),l=Array(r),s=Array(r),c=0;r>c;++c)i[c]=-1,a[c]=0,n[c]=!1,o[c]=0,l[c]=-1,s[c]=[];var u,d=0,f=[],h=[];for(c=0;r>c;++c)0>i[c]&&t(c);for(c=0;h.length>c;c++){var g=h[c];if(0!==g.length){g.sort(function(e,t){return e-t}),u=[g[0]];for(var m=1;g.length>m;m++)g[m]!==g[m-1]&&u.push(g[m]);h[c]=u}}return{components:f,adjacencyList:h}}(e),a=i.components.filter(function(e){return e.length>1}),n=1/0,o=0;a.length>o;o++)for(var l=0;a[o].length>l;l++)n>a[o][l]&&(n=a[o][l],r=o);var s=a[r];return!!s&&{leastVertex:n,adjList:e.map(function(e,t){return-1===s.indexOf(t)?[]:e.filter(function(e){return-1!==s.indexOf(e)})})}}var o,l=[],s=[],c=[],u={},d=[];o=0;for(var f=e.length;f>o;){var h=n(o);if(o=h.leastVertex,d=h.adjList){for(var g=0;d.length>g;g++)for(var m=0;d[g].length>m;m++){var p=d[g][m];c[+p]=!1,u[p]={}}i(o),o+=1}else o=f}if(!t)return l}function m(e){return e.y0-e.y1>0?"up":"down"}function p(e,t){return t(e.source)==t(e.target)}function y(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}),!(t>1||r>1)}function b(e){return e.target.x0-e.source.x1}function v(e,t){var r=x(e),i=b(t)/Math.tan(r);return"up"==m(e)?e.y1-i:e.y1+i}function k(e,t){var r=x(e),i=b(t)/Math.tan(r);return"up"==m(e)?e.y1+i:e.y1-i}function x(e){var t=Math.abs(e.y1-e.y0);return Math.atan(Math.abs(e.target.x0-e.source.x1)/t)}function S(e,t){return t(e)}function w(e){return P(e.source)}function M(e){return P(e.target)}function P(e){return(e.y0+e.y1)/2}function L(e){return e.virtual?0:e.value}function T(e,t){var r=0;e.sourceLinks.forEach(function(e){r=e.circular&&!p(e,t)?r+1:r});var i=0;return e.targetLinks.forEach(function(e){i=e.circular&&!p(e,t)?i+1:i}),r+i}function A(e){return e.target.depth}function D(e,t){return e.sourceLinks.length?e.depth:t-1}function I(e,t){return e.y0-t.y0}function E(e,t){return t.y0-e.y0}function C(e,t){return e.y1-t.y1}function O(e,t){return t.y1-e.y1}function N(e,t){return $(e.source,t.source)||e.index-t.index}function B(e,t){return $(e.target,t.target)||e.index-t.index}function $(e,t){return e.partOfCycle===t.partOfCycle?e.y0-t.y0:"top"===e.circularLinkType||"bottom"===t.circularLinkType?-1:1}function H(e,t){return R(e)==R(t)?"bottom"==e.circularLinkType?E(e,t):I(e,t):R(t)-R(e)}function R(e){return e.target.column-e.source.column}function F(e,t){return W(e)==W(t)}function W(e){return e.y0-e.y1>0?"up":"down"}function _(e,t,r,i,a){let n=e;var o=Math.max(8,.15*(n.y1-n.y0));n.links.forEach(function(e){e.circular&&(e._circularWidth=Math.min(e.width,o))});var l=yi(n.links,function(e){return e.source.y0});n.links.forEach(function(e){e.circular&&(e.circularPathData={})});var s=n.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}),z(n.links.filter(function(e){return"top"==e.circularLinkType}),t,r),z(n.links.filter(function(e){return"bottom"==e.circularLinkType}),t,r),n.links.forEach(function(e){if(e.circular){if(e.circularPathData.arcRadius=e._circularWidth+i,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,p(e,t)&&y(e))e.circularPathData.rightSmallArcRadius=i+e._circularWidth/2,e.circularPathData.rightLargeArcRadius=i+e._circularWidth/2,e.circularPathData.leftSmallArcRadius=i+e._circularWidth/2,e.circularPathData.leftLargeArcRadius=i+e._circularWidth/2,"bottom"==e.circularLinkType?(e.circularPathData.verticalFullExtent=e.source.y1+a+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-a-e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.leftLargeArcRadius);else{var o=e.source.column,s=e.circularLinkType,c=n.links.filter(function(e){return e.source.column==o&&e.circularLinkType==s});c.sort("bottom"==e.circularLinkType?E:I);var u=0;c.forEach(function(t,a){t.circularLinkID==e.circularLinkID&&(e.circularPathData.rightSmallArcRadius=i+e._circularWidth/2+u,e.circularPathData.rightLargeArcRadius=i+e._circularWidth/2+a*r+u),u+=t._circularWidth||t.width}),o=e.target.column,(c=n.links.filter(function(e){return e.target.column==o&&e.circularLinkType==s})).sort("bottom"==e.circularLinkType?O:C),u=0,c.forEach(function(t,a){t.circularLinkID==e.circularLinkID&&(e.circularPathData.leftSmallArcRadius=i+e._circularWidth/2+u,e.circularPathData.leftLargeArcRadius=i+e._circularWidth/2+a*r+u),u+=t._circularWidth||t.width}),"bottom"==e.circularLinkType?(e.circularPathData.verticalFullExtent=Math.max(n.y1,e.source.y1,e.target.y1)+a+e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.leftLargeArcRadius):(e.circularPathData.verticalFullExtent=l-a-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,i=e.target.x0,a=e.y1,n=(t+i)/2;return"M"+t+","+r+"C"+n+","+r+" "+n+","+a+" "+i+","+a}(e)}),n}function z(e,t,r){e.sort(H);var i=e.filter(function(e){return!e._circularStub});return e.forEach(function(e,a){var n=0;if(e._circularStub)e.circularPathData.verticalBuffer=0;else if(p(e,t)&&y(e))e.circularPathData.verticalBuffer=n+e._circularWidth/2;else{for(var o=0;i.length>o;o++){var l=i[o];if(l!==e&&l.circularPathData&&void 0!==l.circularPathData.verticalBuffer&&j(e,l)){var s=l.circularPathData.verticalBuffer+(l._circularWidth||l.width)/2+r;n=s>n?s:n}}e.circularPathData.verticalBuffer=n+e._circularWidth/2}}),e}function j(e,t){return!(t.target.column>e.source.column||e.target.column>t.source.column)}function X(e){return function(){return e}}function Y(e){return e.index}function G(e){return e.nodes}function q(e){return e.links}function V(e,t,r){var i=wi(e.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]});i.forEach(function(a,n){var o=a.length;if(t)a.sort(t);else if(n>0){var l=new Map;a.forEach(function(e,t){var r,i,a,n=(i=0,a=0,(r=e).targetLinks.forEach(function(e){if(!e.circular){var t=e.value||1;a+=P(e.source)*t,i+=t}}),r.sourceLinks.forEach(function(e){if(!e.circular){var t=e.value||1;a+=P(e.target)*t,i+=t}}),i>0?a/i:NaN);l.set(e,{bc:n,idx:t})}),a.sort(function(e,t){var r=l.get(e),i=l.get(t),a=r.bc,n=i.bc;if(e.circularLinkType!==t.circularLinkType){if("top"==e.circularLinkType&&"bottom"==t.circularLinkType)return-1;if("bottom"==e.circularLinkType&&"top"==t.circularLinkType)return 1;if("top"==e.circularLinkType)return-1;if("top"==t.circularLinkType||"bottom"==e.circularLinkType)return 1;if("bottom"==t.circularLinkType)return-1}return isNaN(a)||isNaN(n)?isNaN(a)?isNaN(n)?r.idx-i.idx:1:-1:a-n})}else a.sort(function(e,t){return e.circularLinkType==t.circularLinkType?T(t,r)-T(e,r):"top"==e.circularLinkType&&"bottom"==t.circularLinkType||"top"==e.circularLinkType&&0==t.partOfCycle||0==e.partOfCycle&&"bottom"==t.circularLinkType?-1:0});a.forEach(function(t,a){t.depth==i.length-1&&1==o||0==t.depth&&1==o?(t.y0=e.y1/2-t.value*e.ky,t.y1=t.y0+t.value*e.ky):t.partOfCycle?0==T(t,r)?(t.y0=e.y1/2+a,t.y1=t.y0+t.value*e.ky):"top"==t.circularLinkType?(t.y0=e.y0+a,t.y1=t.y0+t.value*e.ky):(t.y0=e.y1-t.value*e.ky-a,t.y1=t.y0+t.value*e.ky):0==e.y0||0==e.y1?(t.y0=(e.y1-e.y0)/o*a,t.y1=t.y0+t.value*e.ky):(t.y0=(e.y1-e.y0)/2-o/2+a,t.y1=t.y0+t.value*e.ky)})})}function U(e,t,r,i,a,n){function o(t,r){var i=s.length;s.forEach(function(a){var n=a.length,o=a[0].depth;a.forEach(function(a){var l;if(a.sourceLinks.length||a.targetLinks.length)if(a.partOfCycle&&T(a,r)>0){var s=xi(a.sourceLinks,M),c=xi(a.targetLinks,w),u=s&&c?(s+c)/2:s||c;if(u){var d=(u-P(a))*t*.3;a.y0+=d,a.y1+=d}}else if(0==o&&1==n)a.y0=e.y1/2-(l=a.y1-a.y0)/2,a.y1=e.y1/2+l/2;else if(o==i-1&&1==n)a.y0=e.y1/2-(l=a.y1-a.y0)/2,a.y1=e.y1/2+l/2;else if(1==a.targetLinks.length&&1==a.targetLinks[0].source.sourceLinks.length)l=a.y1-a.y0,a.y0=a.targetLinks[0].source.y0,a.y1=a.y0+l;else{var f=xi(a.sourceLinks,M),h=xi(a.targetLinks,w),g=((f&&h?(f+h)/2:f||h)-P(a))*t;a.y0+=g,a.y1+=g}})})}function l(){s.forEach(function(r){var n,o,l,s=e.y0,c=r.length;for(r.sort(t||$),l=0;c>l;++l)(o=s-(n=r[l]).y0)>0&&(n.y0+=o,n.y1+=o),s=n.y1+i;if((o=s-i-e.y1)>0)for(s=n.y0-=o,n.y1-=o,l=c-2;l>=0;--l)(o=(n=r[l]).y1+a-s)>0&&(n.y0-=o,n.y1-=o),s=n.y0})}var s=wi(e.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]});l();for(var c=1,u=n;u>0;--u)o(c*=.99,r),l()}function Q(e){e.nodes.forEach(function(e){e.sourceLinks.sort(B),e.targetLinks.sort(N)}),e.nodes.forEach(function(e){var t=e.y0,r=t,i=e.y1,a=i;e.sourceLinks.forEach(function(e){e.circular?(e.y0=i-e.width/2,i-=e.width):(e.y0=t+e.width/2,t+=e.width)}),e.targetLinks.forEach(function(e){e.circular?(e.y1=a-e.width/2,a-=e.width):(e.y1=r+e.width/2,r+=e.width)})})}function K(){function e(){var e={nodes:y.apply(null,arguments),links:b.apply(null,arguments)};return function(e){e.x0=t,e.y0=r,e.x1=i,e.y1=a,e.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 Si(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 i=e.source,a=e.target;"object"!=typeof i&&(i=e.source=h(r,i)),"object"!=typeof a&&(a=e.target=h(r,a)),i.sourceLinks.push(e),a.targetLinks.push(e)})}(e,s),function(e,t){var r=0;if(null==t){for(var i=[],a=0;e.links.length>a;a++){var n=e.links[a],o=n.source.index,l=n.target.index;i[o]||(i[o]=[]),i[l]||(i[l]=[]),-1===i[o].indexOf(l)&&i[o].push(l)}var s=g(i);s.sort(function(e,t){return e.length-t.length});var c={};for(a=0;s.length>a;a++){var u=s[a].slice(-2);c[u[0]]||(c[u[0]]={}),c[u[0]][u[1]]=!0}e.links.forEach(function(e){var t=e.target.index,i=e.source.index;t===i||c[i]&&c[i][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++)})}(e,u),function(e,t){var r=0,i=0;e.links.forEach(function(a){a.circular&&(a.circularLinkType=a.source.circularLinkType||a.target.circularLinkType?a.source.circularLinkType?a.source.circularLinkType:a.target.circularLinkType:i>r?"top":"bottom","top"==a.circularLinkType?r++:i++,e.nodes.forEach(function(e){(S(e,t)==S(a.source,t)||S(e,t)==S(a.target,t))&&(e.circularLinkType=a.circularLinkType)}))}),e.links.forEach(function(e){e.circular&&(e.source.circularLinkType==e.target.circularLinkType&&(e.circularLinkType=e.source.circularLinkType),p(e,t)&&(e.circularLinkType=e.source.circularLinkType))})}(e,s),function(e){e.nodes.forEach(function(e){e.partOfCycle=!1,e.value=Math.max(ki(e.sourceLinks,L),ki(e.targetLinks,L)),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)})})}(e),function(e,t,r){var i,a,n;if(null!=t){e.nodes.sort(function(e,r){return t(e)<t(r)?-1:1});var o=0,l=t(e.nodes[0]);e.nodes.forEach(function(e){o=t(e)==l?o:o+1,l=t(e)==l?l:t(e),e.column=o})}for(i=e.nodes,a=[],n=0;i.length;++n,i=a,a=[])i.forEach(function(e){e.depth=n,e.sourceLinks.forEach(function(e){0>a.indexOf(e.target)&&!e.circular&&a.push(e.target)})});for(i=e.nodes,a=[],n=0;i.length;++n,i=a,a=[])i.forEach(function(e){e.height=n,e.targetLinks.forEach(function(e){0>a.indexOf(e.source)&&!e.circular&&a.push(e.source)})});e.nodes.forEach(function(e){e.column=null==t?r(e,n):e.column})}(e,u,c);var y=o;if(null!==l){var b=wi(e.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]}),x=vi(b,function(e){return e.length});x>1&&(y=Math.max(1,(a-r)*l/(x-1)))}(function(e,t,r){var i=wi(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 a=bi(i,function(t){return(e.y1-e.y0-(t.length-1)*e.py)/ki(t,function(e){return e.value})});e.ky=a,e.links.forEach(function(t){t.width=t.value*e.ky});var n=vi(e.nodes,function(e){return e.column});e.nodes.forEach(n>0?function(t){t.x0=e.x0+t.column*((e.x1-e.x0-r)/n),t.x1=t.x0+r}:function(t){t.x0=e.x0,t.x1=t.x0+r})})(e,y,n),V(e,u,s),U(e,u,s,y,y,d),Q(e),_(e,s,f,m,8),V(e,u,s),U(e,u,s,y,y,d),Q(e),_(e,s,f,m,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 i=r.links.filter(function(r){return S(r.source,t)==S(e,t)}),a=i.length;a>1&&i.sort(function(e,t){if(!e.circular&&!t.circular){if(e.target.column==t.target.column)return e.y1-t.y1;if(!F(e,t))return e.y1-t.y1;if(e.target.column>t.target.column){var r=v(t,e);return e.y1-r}if(t.target.column>e.target.column)return v(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 n=e.y0;i.forEach(function(e){e.y0=n+e.width/2,n+=e.width}),i.forEach(function(t,r){if("bottom"==t.circularLinkType){for(var n=r+1,o=0;a>n;n++)o+=i[n].width;t.y0=e.y1-o-t.width/2}})})}(e,s),function(e,t){let r=e;r.nodes.forEach(function(e){var i=r.links.filter(function(r){return S(r.target,t)==S(e,t)}),a=i.length;a>1&&i.sort(function(e,t){if(!e.circular&&!t.circular){if(e.source.column==t.source.column)return e.y0-t.y0;if(!F(e,t))return e.y0-t.y0;if(e.source.column>t.source.column){var r=k(t,e);return e.y0-r}if(t.source.column>e.source.column)return k(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 n=e.y0;i.forEach(function(e){e.y1=n+e.width/2,n+=e.width}),i.forEach(function(t,r){if("bottom"==t.circularLinkType){for(var n=r+1,o=0;a>n;n++)o+=i[n].width;t.y1=e.y1-o-t.width/2}})})}(e,s),function(e){var t=e.nodes,r=e.links,i=!1,a=!1;if(r.forEach(function(e){"top"==e.circularLinkType?i=!0:"bottom"==e.circularLinkType&&(a=!0)}),0==i||0==a){let i=function(t){return(t-n)/(o-n)*(e.y1-e.y0)+e.y0};var n=bi(t,function(e){return e.y0}),o=vi(t,function(e){return e.y1}),l=(e.y1-e.y0)/(o-n);1>l?(t.forEach(function(e){e.y0=i(e.y0),e.y1=i(e.y1)}),r.forEach(function(e){e.y0=i(e.y0),e.y1=i(e.y1),e.width=e.width*l})):t.forEach(function(e){var t=e.y1-e.y0,r=i(e.y0)-e.y0;e.y0=i(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})})}}(e),_(e,s,f,m,8)}(e),e}var t=0,r=0,i=1,a=1,n=24,o=8,l=null,s=Y,c=D,u=void 0,d=32,f=2,m=10,y=G,b=q;return e.update=function(e){return Q(e),_(e,s,f,m,8),e},e.nodeWidth=function(t){return arguments.length?(n=+t,e):n},e.nodePadding=function(t){return arguments.length?(o=+t,e):o},e.nodePaddingRatio=function(t){return arguments.length?(l=+t,e):l},e.nodes=function(t){return arguments.length?(y="function"==typeof t?t:X(t),e):y},e.links=function(t){return arguments.length?(b="function"==typeof t?t:X(t),e):b},e.nodeId=function(t){return arguments.length?(s="function"==typeof t?t:X(t),e):s},e.nodeAlign=function(t){return arguments.length?(c="function"==typeof t?t:X(t),e):c},e.nodeSort=function(t){return arguments.length?(u=t,e):u},e.iterations=function(t){return arguments.length?(d=+t,e):d},e.circularLinkGap=function(t){return arguments.length?(f=+t,e):f},e.extent=function(n){return arguments.length?(t=+n[0][0],r=+n[0][1],i=+n[1][0],a=+n[1][1],e):[[t,r],[i,a]]},e.size=function(n){return arguments.length?(t=r=0,i=+n[0],a=+n[1],e):[i-t,a-r]},e}function Z(e){let{sx:t,sTop:r,sBot:i,tx:a,tTop:n,tBot:o,cp1X:l,cp2X:s}=e,c=(r+i)/2,u=(n+o)/2;return{pathD:[`M${t},${r}`,`C${l},${r} ${s},${n} ${a},${n}`,`L${a},${o}`,`C${s},${o} ${l},${i} ${t},${i}`,"Z"].join(" "),bezier:{circular:!1,points:[{x:t,y:c},{x:l,y:c},{x:s,y:u},{x:a,y:u}],halfWidth:(i-r)/2}}}function J(e){let t=e.sankeyWidth/2,r=(e._circularWidth??e.sankeyWidth)/2,i=e.circularPathData;if(!i||"down"===e.direction)return null;if(e._circularStub){let r=i.sourceX,a=i.sourceY,n=i.targetX,o=i.targetY;if("object"!=typeof e.source||!e.source||"object"!=typeof e.target||!e.target)return null;let l=Math.max(15,Math.min(40,.33*(i.rightFullExtent-r))),s=Math.max(15,Math.min(40,.33*(n-i.leftFullExtent)));return`M${r},${a-t}L${r+l},${a-t}L${r+l},${a+t}L${r},${a+t}ZM${n},${o-t}L${n-s},${o-t}L${n-s},${o+t}L${n},${o+t}Z`}let a=i.sourceX,n=i.sourceY,o=i.targetX,l=i.targetY,s=i.rightFullExtent,c=i.leftFullExtent,u=i.verticalFullExtent,d="bottom"===e.circularLinkType?1:-1,f=Math.max(4,Math.min(r,15));return`M${a},${n-d*t}L${s},${n-d*t}L${s+r},${n-d*t+d*f}L${s+r},${u+d*r-d*f}L${s+r-f},${u+d*r}L${c-r+f},${u+d*r}L${c-r},${u+d*r-d*f}L${c-r},${l-d*t+d*f}L${c-r+f},${l-d*t}L${o},${l-d*t}L${o},${l+d*t}L${c+r},${l+d*t}L${c+r},${u-d*r}L${s-r},${u-d*r}L${s-r},${n+d*t}L${a},${n+d*t}Z`}function ee(e="static"){return Ci[e]??Ci.static}function te(e){return"fatal"===e.severity||"warn"===e.severity?e.severity:Oi.has(e.kind)?"fatal":"warn"}function re(e,t,r,i={}){let a=ee(i.usageMode??"static"),n=[],o=new Set;for(let t of e)o.has(t.id)&&n.push({kind:"duplicate-node",id:t.id,severity:a.duplicateIds}),o.add(t.id);let l=new Set,s=Array.isArray(r)&&2===r.length,c=s&&Number.isFinite(r[0])&&Number.isFinite(r[1]);(!s||!c||!c||r[0]>r[1])&&n.push({kind:"invalid-domain"});for(let t of e)null!=t.xExtent&&(Array.isArray(t.xExtent)&&2===t.xExtent.length&&Number.isFinite(t.xExtent[0])&&Number.isFinite(t.xExtent[1])&&t.xExtent[1]>=t.xExtent[0]||n.push({kind:"invalid-node-time",id:t.id}));for(let e of t)l.has(e.id)&&n.push({kind:"duplicate-edge",id:e.id,severity:a.duplicateIds}),l.add(e.id),o.has(e.source)||n.push({kind:"missing-node",id:e.id,endpoint:"source",nodeId:e.source}),o.has(e.target)||n.push({kind:"missing-node",id:e.id,endpoint:"target",nodeId:e.target}),Number.isFinite(e.startTime)&&Number.isFinite(e.endTime)?((null!=e.systemInTime&&!Number.isFinite(e.systemInTime)||null!=e.systemOutTime&&!Number.isFinite(e.systemOutTime))&&n.push({kind:"invalid-system-time",id:e.id,severity:"warn"}),(!Number.isFinite(e.value)||0>=e.value)&&n.push({kind:"invalid-value",id:e.id}),e.startTime>e.endTime&&n.push({kind:"backward-edge",severity:"fatal",id:e.id,source:e.source,target:e.target})):n.push({kind:"invalid-edge-time",id:e.id});return n}function ie(e){return"invalid-node-time"===e.kind?`node ${e.id} has an invalid xExtent (must be [start, end] with start <= end)`:"invalid-edge-time"===e.kind?`edge ${e.id} has an invalid startTime or endTime`:"invalid-domain"===e.kind?"time domain must be a 2-tuple of finite times [start, end] with start <= end":"invalid-value"===e.kind?`edge ${e.id} must have a positive finite value`:"missing-node"===e.kind?`edge ${e.id} references missing ${e.endpoint} node "${e.nodeId}"`:"backward-edge"===e.kind?`edge ${e.id} (${e.source}->${e.target}) ends before it starts`:"duplicate-node"===e.kind?`node id "${e.id}" is duplicated`:"duplicate-edge"===e.kind?`edge id "${e.id}" is duplicated`:"invalid-system-time"===e.kind?`edge ${e.id} has an invalid systemInTime or systemOutTime`:e.kind}function ae(e){if(!e?.layoutQuality)return[];let t=[],r=e.layoutQuality,i=e.layoutQualityBefore;e.compressedPadding&&t.push({severity:"warning",code:"PROCESS_SANKEY_COMPRESSED_PADDING",message:"Lane gaps were compressed to fit peaks into the plot height.",fix:'Increase height, lower maxValueScale, use packing="reuse", or reduce concurrent peaks.'}),r.transitOcclusion>=Ni&&t.push({severity:"warning",code:"PROCESS_SANKEY_HIGH_TRANSIT",message:`High transit occlusion (${r.transitOcclusion.toFixed(1)}) — ribbons cross dense intermediate lanes.`,fix:'Try laneOrder="crossing-min+inside-out", packing="reuse", or lanePlacement="hug" with a modest maxValueScale.'}),r.verticalUtilization>=Bi&&t.push({severity:"warning",code:"PROCESS_SANKEY_HIGH_UTILIZATION",message:`Lane utilization is ${Math.round(100*r.verticalUtilization)}% of plot height.`,fix:"Increase chart height or cap band scale with maxValueScale."});let a=e.crossingsAfter??r.crossings;return null!=a&&a>=$i&&t.push({severity:"warning",code:"PROCESS_SANKEY_RESIDUAL_CROSSINGS",message:`Ordering left ${a} edge-pair crossings`+(i?` (from ${i.crossings})`:"")+".",fix:'Prefer laneOrder="crossing-min" or "crossing-min+inside-out"; check for unavoidable fan-outs.'}),t}function ne(e){if(!e?.layoutQuality)return null;let t=e.layoutQuality,r=e.layoutQualityBefore,i=e.crossingsAfter??t.crossings;return[`ProcessSankey layout uses ${e.slots?.length??"?"} packed lane(s).`,null!=i?`Edge-pair crossings ${r?r.crossings+" → ":""}${i}.`:null,`Pixel path length ${r?Math.round(r.pixelLength)+" → ":""}${Math.round(t.pixelLength)}.`,`Transit occlusion ${r?r.transitOcclusion.toFixed(1)+" → ":""}${t.transitOcclusion.toFixed(1)}.`,`Lane utilization ${Math.round(100*t.verticalUtilization)}%.`,e.compressedPadding?"Lane gaps were compressed to fit the plot.":null].filter(Boolean).join(" ")}function oe(e){let t=[],r=e.domain;null==r?t.push({severity:"error",code:"PROCESS_SANKEY_MISSING_DOMAIN",message:"ProcessSankey requires domain: [tStart, tEnd].",fix:"Pass domain={[start, end]} as numbers or Date-compatible values."}):(!Array.isArray(r)||2!==r.length||!Number.isFinite(Number(r[0]))||!Number.isFinite(Number(r[1])))&&t.push({severity:"error",code:"PROCESS_SANKEY_BAD_DOMAIN",message:"domain must be a 2-tuple of finite times.",fix:"Use domain={[t0, t1]} with t0 <= t1."});let i=e.edges;if(Array.isArray(i)&&i.length>0){let e=i[0];(null==e.startTime||null==e.endTime)&&t.push({severity:"warning",code:"PROCESS_SANKEY_EDGE_TIMES",message:"Edges should carry startTime and endTime for temporal layout.",fix:"Add startTime/endTime fields or set startTimeAccessor/endTimeAccessor."})}let a=e.nodes,n=Array.isArray(a)?a.length:0;return!0===e.showLabels&&n>=24&&t.push({severity:"warning",code:"PROCESS_SANKEY_LABEL_DENSITY",message:`showLabels={true} with ${n} nodes may overcrowd the plot.`,fix:'Use showLabels="auto" with optional labelPriorityAccessor / maxLabels.'}),(Array.isArray(i)?i.length:0)>=80&&null==e.layoutExecution&&"off"!==e.packing&&t.push({severity:"warning",code:"PROCESS_SANKEY_WORKER_HINT",message:"Dense ProcessSankey layouts benefit from worker packing/order.",fix:'layoutExecution defaults to "auto"; set layoutExecution="worker" or raise layoutWorkerThreshold deliberately.'}),t}function le(e,t,r,i={}){let a=!1!==i.inferOpeningStock,n=[];for(let t of r){let r=Number(t.value);if(!Number.isFinite(r))continue;let i=Number(t.endTime);t.target===e&&Number.isFinite(i)&&n.push({time:i,delta:r});let a=Number(t.startTime);if(t.source===e&&Number.isFinite(a)&&n.push({time:a,delta:-r}),t.target===e&&null!=t.systemOutTime){let e=Number(t.systemOutTime);Number.isFinite(e)&&n.push({time:e,delta:-r})}}n.sort((e,t)=>e.time-t.time||t.delta-e.delta);let o=0,l=0,s=0;for(let e of n)o+=e.delta,l=Math.min(l,o),t>=e.time&&(s+=e.delta);return a?s-l:s}function se(e){return null==e?NaN:e instanceof Date?e.getTime():"number"==typeof e?e:new Date(e).getTime()}function ce(e){let{desired:t,minGaps:r,weights:i}=e,a=t.length;if(0===a)return[];if(r.length!==Math.max(0,a-1))throw Error("placeWithMinGap: minGaps must have desired.length - 1 entries");let n=Array(a).fill(0);for(let e=1;a>e;e++)n[e]=n[e-1]+Math.max(0,Number.isFinite(r[e-1])?r[e-1]:0);let o=[];for(let e=0;a>e;e++){let r=Math.max(Number.EPSILON,Number.isFinite(i?.[e])?i[e]:1),a=(Number.isFinite(t[e])?t[e]:0)-n[e];for(o.push({start:e,end:e,weight:r,mean:a});o.length>1;){let e=o[o.length-1],t=o[o.length-2];if(e.mean>=t.mean)break;let r=t.weight+e.weight;o.splice(o.length-2,2,{start:t.start,end:e.end,weight:r,mean:(t.mean*t.weight+e.mean*e.weight)/r})}}let l=Number.isFinite(e.min)?e.min:-1/0,s=Number.isFinite(e.max)?e.max-n[a-1]:1/0,c=l>s?l:s,u=Array(a);for(let e of o){let t=Math.max(l,Math.min(c,e.mean));for(let r=e.start;e.end>=r;r++)u[r]=t+n[r]}return u}function ue(e,t){let r=0,i=e.length-1,a=-1;for(;i>=r;){let n=r+i>>>1;e[n].at>t?i=n-1:(a=n,r=n+1)}return 0>a?{at:t,before:0,after:0}:e[a]}function de(e,t=0){if(0===e.length)return{adjacentClearance:[],positions:[]};let r=[],i=[0];for(let a=0;e.length-1>a;a++){let n=e[a],o=e[a+1],l=[...new Set([...n.map(e=>e.at),...o.map(e=>e.at)])].sort((e,t)=>e-t),s=0;for(let e of l){let t=ue(n,e),r=ue(o,e);s=Math.max(s,t.after+r.before)}r.push(s),i.push(i[i.length-1]+s+t)}return{adjacentClearance:r,positions:i}}function fe(e,t,r,i={}){let a=[...e];if(1>=a.length)return a;let n=[...a],o=r(a),l=1,s=Math.max(0,i.passes??6),c=Math.max(1,i.maxEvaluations??1/0);for(let e=0;s>e&&c>l;e++){let e=new Map(a.map((e,t)=>[e,t])),s=new Map,c=new Map;for(let r of t){let t=e.get(r.source),i=e.get(r.target);if(null==t||null==i)continue;let a=Number.isFinite(r.weight)&&r.weight>0?r.weight:1;s.set(r.source,(s.get(r.source)??0)+i*a),c.set(r.source,(c.get(r.source)??0)+a),s.set(r.target,(s.get(r.target)??0)+t*a),c.set(r.target,(c.get(r.target)??0)+a)}a=a.map((e,t)=>({item:e,index:t,barycenter:(s.get(e)??t)/(c.get(e)??1)})).sort((e,t)=>e.barycenter-t.barycenter||(i.compare?.(e.item,t.item)??e.index-t.index)).map(e=>e.item);let u=r(a);if(l++,o>u)o=u,n=[...a];else if(u===o)break}return n}function he(e,t,r={}){let i=[...e],a=i.length;if(1>=a||a>(r.maxItems??8))return i;let n=Math.max(1,r.maxEvaluations??1/0),o=0,l=[...i],s=1/0,c=()=>{if(o>=n)return;let e=t(i);o++,s>e&&(s=e,l=[...i])};c();let u=Array(a).fill(0),d=0;for(;a>d&&n>o;)if(d>u[d]){let e=d%2==0?0:u[d];[i[e],i[d]]=[i[d],i[e]],c(),u[d]++,d=0}else u[d]=0,d++;return l}function ge(){return Object.create(null)}function me(e,t){return t>e?-1:e>t?1:0}function pe(e){return e.occupants.map(e=>e.id).sort(me).join("\0")}function ye(e,t,r=0){return e.slice(0,-1).map((i,a)=>null!=i.group&&i.group===e[a+1].group?r:t)}function be(e,t){return e.map(e=>{let r=new Map;for(let i of e.occupants){let e=t[i.id];if(e)for(let t of e.samples){let e=r.get(t.t)??{before:0,after:0},i=t.boundaryOffset??0;r.set(t.t,{before:Math.max(e.before,t.topMass-i),after:Math.max(e.after,t.botMass+i)})}}return[...r].sort((e,t)=>e[0]-t[0]).map(([e,t])=>({at:e,...t}))})}function ve(e,t,r){if(0===e.length)return[];let{padding:i,plotH:a,valueScale:n}=r,o=r.stackValueScale??n,l=ye(e,i,r.groupPadding??0),s=[i+e[0].peak.topPeak*o];for(let r=1;e.length>r;r++)s.push(s[r-1]+t[r-1]*o+l[r-1]);let c=s[s.length-1]+e[e.length-1].peak.botPeak*o+i;if(c>a&&c>0){let e=a/c;for(let t=0;s.length>t;t++)s[t]*=e}return s}function ke(e,t){let r=(e.boundaryOffset??0)*t,i=e.value*t;if("out"===e.kind){let a=e.sideMassBefore*t;return r+("top"===e.side?i/2-a:a-i/2)}let a=e.sideMassAfter*t;return r+("top"===e.side?i/2-a:a-i/2)}function xe(e,t,r,i,a,n){let o=n.adjacentClearance?[...n.adjacentClearance]:de(be(i,r)).adjacentClearance,l=ve(i,o,n),s="hug"===n.lanePlacement?function(e,t,r,i,a,n,o){let l=e.length;if(0===l)return[];let{padding:s,plotH:c,valueScale:u}=o,d=ye(e,s,o.groupPadding??0),f=a.map((e,t)=>e*u+d[t]),h=s+e[0].peak.topPeak*u,g=c-s-e[l-1].peak.botPeak*u;if(f.reduce((e,t)=>e+t,0)+1e-6>=g-h)return ve(e,a,o);let m=1===l?[(h+g)/2]:[...n];for(let e=0;12>e;e++){let e=Array(l).fill(0),a=Array(l).fill(0);for(let n of r){let r=t[n.source],o=t[n.target];if(null==r||null==o||r===o)continue;let l=i[n.source]?.localAttachments.get(n.id),s=i[n.target]?.localAttachments.get(n.id);if(!l||!s)continue;let c=n.value>0&&Number.isFinite(n.value)?n.value:1,d=ke(l,u),f=ke(s,u);e[r]+=(m[o]+f-d)*c,a[r]+=c,e[o]+=(m[r]+d-f)*c,a[o]+=c}let n=ce({desired:m.map((t,r)=>0===a[r]?t:.45*t+e[r]/a[r]*.55),minGaps:f,weights:a.map(e=>Math.max(1,e)),min:h,max:g}),o=0;for(let e=0;l>e;e++)o=Math.max(o,Math.abs(n[e]-m[e]));if(m=n,.01>o)break}return m}(i,a,t,r,o,l,n):[...l];if("hug"===n.lanePlacement){let r=t=>{let r=ge();for(let i of e)r[i.id]=t[a[i.id]];return r};Se(r(s),t)>Se(r(l),t)+1e-6&&(s=[...l])}let c=ge();for(let t of e)c[t.id]=s[a[t.id]];let u=1/0,d=-1/0;for(let t of e){let e=c[t.id],i=r[t.id];!Number.isFinite(e)||!i||(u=Math.min(u,e-i.topPeak*n.valueScale),d=Math.max(d,e+i.botPeak*n.valueScale))}return{adjacentClearance:o,centerlines:c,slotCenter:s,stackCenter:l,verticalUtilization:Number.isFinite(u)&&Number.isFinite(d)&&n.plotH>0?Math.max(0,Math.min(1,(d-u)/n.plotH)):0}}function Se(e,t){let r=0;for(let i of t){let t=e[i.source],a=e[i.target];Number.isFinite(t)&&Number.isFinite(a)&&(r+=Math.abs(t-a)*(i.value>0?i.value:1))}return r}function we(e,t){let r=e?.samples;if(!r||0===r.length||r[0].t>t)return{top:0,bot:0};let i=0,a=r.length-1,n=0;for(;a>=i;){let e=i+a>>>1;r[e].t>t?a=e-1:(n=e,i=e+1)}let o=r[n].boundaryOffset??0;return{top:r[n].topMass-o,bot:r[n].botMass+o}}function Me(e,t,r,i,a){let n=1-a;return n*n*n*e+3*n*n*a*t+3*n*a*a*r+a*a*a*i}function Pe(e,t){let r=0,i=1;for(let a=0;28>a;a++){let a=(r+i)/2;Me(0,t,t,1,a)<e?r=a:i=a}return(r+i)/2}function Le(e,t,r){let i=t+ke(e,r),a=e.value*r/2;return[i-a,i+a]}function Te(e,t,r,i){return Math.max(0,Math.min(t,i)-Math.max(e,r))/Math.max(1e-9,t-e)}function Ae(e,t,r,i,a,n,o){let{valueScale:l,domain:s,mode:c="quality"}=o,u="source"===o.ribbonLane?.85:"target"===o.ribbonLane?.15:.5,d=0;for(let o of e){let e=i[o.source],f=i[o.target];if(null==e||null==f||2>Math.abs(e-f))continue;let h=t[o.source]?.localAttachments.get(o.id),g=t[o.target]?.localAttachments.get(o.id);if(!h||!g)continue;let m=Math.max(o.startTime,s?.[0]??-1/0),p=Math.min(o.endTime,s?.[1]??1/0);if(m>=p)continue;let[y,b]=Le(h,a[o.source],l),[v,k]=Le(g,a[o.target],l),x=Math.min(e,f)+1,S=Math.max(e,f)-1;for(let e=x;S>=e;e++){let i=r[e];if(!i)continue;let s=[m,p];if("quality"===c)for(let e of i.occupants)for(let r of t[e.id]?.samples??[])r.t>m&&p>r.t&&s.push(r.t);let f=e=>{let r=Pe((e-m)/(p-m),u),s=Me(y,y,v,v,r),c=Me(b,b,k,k,r),d=0;for(let r of i.occupants){if(r.id===o.source||r.id===o.target)continue;let i=n[r.id];if(null!=i?.start&&i.start>e||null!=i?.end&&e>i.end)continue;let u=we(t[r.id],e),f=a[r.id];d=Math.max(d,Te(s,c,f-u.top*l,f+u.bot*l))}return d},h=[...new Set(s)].sort((e,t)=>e-t),g=0;for(let e=0;h.length-1>e;e++){let t=h[e],r=h[e+1]-t;g+=(f(t+.25*r)+f(t+.5*r)+f(t+.75*r))/3*r}d+=g/(p-m)*(o.value>0?o.value:1)}}return d}function De(e,t,r,i,a,n,o,l,s,c,u="both",d){return{crossings:e,weightedLength:t,pixelLength:Se(o,r),transitOcclusion:Ae(r,i,a,n,o,l,{valueScale:s,ribbonLane:u,domain:d,mode:"quality"}),verticalUtilization:c}}function Ie(e,t){return t?Math.max(t[0],Math.min(t[1],e)):e}function Ee(e,t){return e.map(e=>({t:Ie(e.t,t),topMass:e.topMass,botMass:e.botMass,...null!=e.boundaryOffset&&{boundaryOffset:e.boundaryOffset}}))}function Ce(e,t,r){let i=t+(e.boundaryOffset??0)*r,a=e.value*r;if("out"===e.kind){let t=e.sideMassBefore*r;if("top"===e.side){let e=i-t;return[e,e+a]}let n=i+t;return[n-a,n]}let n=e.sideMassAfter*r;if("top"===e.side){let e=i-n;return[e,e+a]}let o=i+n;return[o-a,o]}function Oe(e,t,r,i,a="temporal"){let n=t.incoming[e.id],o=t.outgoing[e.id],l=[];for(let e of n)l.push({time:e.endTime,delta:+e.value,edge:e,kind:"in",side:r.get(e.id).targetSide});for(let e of o)l.push({time:e.startTime,delta:-e.value,edge:e,kind:"out",side:r.get(e.id).sourceSide});let s={create:0,in:1,"transfer-out":2,"transfer-in":3,out:4},c=()=>{l.sort((e,t)=>e.time-t.time||(e.phase??0)-(t.phase??0)||(e.sequence??0)-(t.sequence??0)||(s[e.kind]??99)-(s[t.kind]??99)||((e,t)=>{if(!i||!e.edge||!t.edge||e.kind!==t.kind||e.side!==t.side)return 0;if("out"===e.kind){if(e.edge.target===t.edge.target&&e.edge.endTime===t.edge.endTime)return 0;let r=i.get(e.edge.id)?.target,a=i.get(t.edge.id)?.target;return"number"==typeof r&&Number.isFinite(r)&&"number"==typeof a&&Number.isFinite(a)&&r!==a?"top"===e.side?r-a:a-r:0}if("in"===e.kind){if(e.edge.source===t.edge.source&&e.edge.startTime===t.edge.startTime)return 0;let r=i.get(e.edge.id)?.source,a=i.get(t.edge.id)?.source;return"number"==typeof r&&Number.isFinite(r)&&"number"==typeof a&&Number.isFinite(a)&&r!==a?"top"===e.side?a-r:r-a:0}return 0})(e,t)||me(e.edge?.id??"",t.edge?.id??"")||me(e.side,t.side)||e.delta-t.delta)},u=l.length?Rr(l.map(e=>e.time)):null,d=Array.isArray(e.xExtent)&&Number.isFinite(e.xExtent[0])?e.xExtent[0]:null,f=null!=d?d-1:null!=u&&Number.isFinite(u)?u-1:null;c();let h=null,g=0;for(let e of l)e.time!==h&&(h=e.time,g=0),e.sequence=g++;let m=e=>({time:e.time,phase:0,sequence:e.sequence??0}),p=[],y=0,b=0;for(let e of l)if("out"===e.kind){let t=Math.abs(e.delta),r=t-("top"===e.side?y:b);if(r>0){let t="top"===e.side?"bot":"top",i=Math.min(r,"top"===t?y:b);if(i>0){let a=m(e);p.push({...a,delta:-i,kind:"transfer-out",side:t}),p.push({...a,delta:+i,kind:"transfer-in",side:e.side}),"top"===t?y-=i:b-=i,"top"===e.side?y+=i:b+=i,r-=i}r>0&&null!==f&&(p.push({time:f,delta:+r,kind:"create",side:e.side}),"top"===e.side?y+=r:b+=r)}"top"===e.side?y-=t:b-=t}else if("in"===e.kind){let t=Math.abs(e.delta);"top"===e.side?y+=t:b+=t}l.push(...p),c();let v=0,k=0,x=0,S=0,w=0,M=0,P=[],L=new Map,T=e=>{P.push({t:e,topMass:v,botMass:k,...Math.abs(x)>1e-12&&{boundaryOffset:x}})},A=()=>{S=Math.max(S,v+k),w=Math.max(w,v-x),M=Math.max(M,k+x)};for(let e of l){if("transfer-out"!==e.kind&&"transfer-in"!==e.kind&&T(e.time),("in"===e.kind||"out"===e.kind)&&e.edge){let t="top"===e.side?v:k;L.set(e.edge.id,{side:e.side,time:e.time,sideMassBefore:t,sideMassAfter:t+e.delta,kind:e.kind,value:Math.abs(e.delta),...Math.abs(x)>1e-12&&{boundaryOffset:x}})}"top"===e.side?v+=e.delta:k+=e.delta,"transfer-in"===e.kind?(x+="top"===e.side?e.delta:-e.delta,A(),T(e.time)):"transfer-out"!==e.kind&&(A(),"out"===e.kind&&1e-12>=v+k&&(x=0),T(e.time))}let D=[],I=0;for(;P.length>I;){let e=I;for(;P.length>e+1&&P[e+1].t===P[I].t;)e++;D.push(P[I]);for(let t=I+1;e>=t;t++){let e=D[D.length-1];(P[t].topMass!==e.topMass||P[t].botMass!==e.botMass||(P[t].boundaryOffset??0)!==(e.boundaryOffset??0))&&D.push(P[t])}I=e+1}let E=Array.isArray(e.xExtent)&&Number.isFinite(e.xExtent[1])?e.xExtent[1]:null,C=null;for(let e of o)null!=e.systemInTime&&Number.isFinite(e.systemInTime)&&e.startTime>e.systemInTime&&(null===C||C>e.systemInTime)&&(C=e.systemInTime);let O=null;for(let e of n)null!=e.systemOutTime&&Number.isFinite(e.systemOutTime)&&e.systemOutTime>e.endTime&&(null===O||e.systemOutTime>O)&&(O=e.systemOutTime);if(D.length>0){let e=D[D.length-1],t=Math.max(E??-1/0,O??-1/0);Number.isFinite(t)&&t>e.t&&e.topMass+e.botMass>0&&D.push({t:t,topMass:e.topMass,botMass:e.botMass,...null!=e.boundaryOffset&&{boundaryOffset:e.boundaryOffset}});let r,i=D[0],a=D.find(e=>e.topMass+e.botMass>0),n=1/0;null!=d&&Number.isFinite(d)&&i.t>d&&i.topMass+i.botMass>0&&(n=d,r=i),a&&null!=C&&Number.isFinite(C)&&a.t>C&&n>C&&(n=C,r=a),r&&Number.isFinite(n)&&D.unshift({t:n,topMass:r.topMass,botMass:r.botMass,...null!=r.boundaryOffset&&{boundaryOffset:r.boundaryOffset}})}let N=D;if("max"===a&&null!=d&&null!=E&&E>d){let e,t=0;for(let r of D){let i=r.topMass+r.botMass;i>t&&(t=i,e=r)}if(e){let t={topMass:e.topMass,botMass:e.botMass,...null!=e.boundaryOffset&&{boundaryOffset:e.boundaryOffset}};N=[...D.filter(e=>d>e.t),{t:d,...t},{t:E,...t},...D.filter(e=>e.t>E)]}}return{samples:N,peak:S,topPeak:w,botPeak:M,localAttachments:L}}function Ne(e){let t=ge();return e.forEach((e,r)=>{for(let i of e.occupants)t[i.id]=r}),t}function Be(e,t,r){e.splice(0,e.length,...r);let i=Ne(r);for(let e of Object.keys(t))delete t[e];Object.assign(t,i)}function $e(e){let t=new Map,r=[];e.forEach((e,i)=>{if(!e.group)return void r.push({anchor:i,stableId:pe(e),slots:[e]});let a=t.get(e.group)??{indexes:[],slots:[]};a.indexes.push(i),a.slots.push(e),t.set(e.group,a)});for(let[e,i]of t)r.push({anchor:i.indexes.reduce((e,t)=>e+t,0)/i.indexes.length,stableId:`${e}\0${i.slots.map(pe).join("\0")}`,slots:i.slots});return r.sort((e,t)=>e.anchor-t.anchor||me(e.stableId,t.stableId))}function He(e){return e.some(e=>e.group)?$e(e).flatMap(e=>e.slots):[...e]}function Re(e){return e.flatMap(e=>e.slots)}function Fe(e,t,r){let i=new Map;return e.forEach((e,t)=>{for(let r of e.slots)i.set(r,t)}),e.map((e,a)=>{if(1>=e.slots.length)return e;let n=new Map;for(let t of e.slots)n.set(t,0);for(let e of t){let t=i.get(e.source),r=i.get(e.target);if(null==t||null==r)continue;let o=Number.isFinite(e.weight)&&e.weight>0?e.weight:1;if(t===a&&r!==a){let t=r>a?1:-1;n.set(e.source,(n.get(e.source)??0)+o*t)}else if(r===a&&t!==a){let r=t>a?1:-1;n.set(e.target,(n.get(e.target)??0)+o*r)}}let o=[...e.slots].sort((e,t)=>(n.get(e)??0)-(n.get(t)??0)||r(e,t));return{...e,slots:o}})}function We(e,t){e.some(e=>e.group)&&Be(e,t,He(e))}function _e(e,t){return e.source!==t.source&&e.target!==t.target&&e.source!==t.target&&e.target!==t.source&&Math.min(e.endTime,t.endTime)>Math.max(e.startTime,t.startTime)}function ze(e,t){return function(e,t,r=()=>!0){let i=0;for(let a=0;e.length>a;a++){let[n,o]=t(e[a]);for(let l=a+1;e.length>l;l++){if(!r(e[a],e[l]))continue;let[s,c]=t(e[l]);0>(n-s)*(o-c)&&i++}}return i}(t,t=>[e[t.source],e[t.target]],_e)}function je(e,t){let r=0;for(let i of t){let t=e[i.source],a=e[i.target];null==t||null==a||(r+=Math.abs(t-a)*(i.value>0?i.value:1))}return r}function Xe(e,t,r){let[i,a]=r.get(e.first),[n,o]=r.get(e.second);return 0>(t.get(i)-t.get(n))*(t.get(a)-t.get(o))?1:0}function Ye(e,t,r,i,a,n,o){let l=[...a],s=new Map(a.map(e=>[e,pe(e)])),c=new Map;for(let e of a)for(let t of e.occupants)c.set(t.id,e);let u=new Map,d=[];for(let e of t){let t=c.get(e.source),r=c.get(e.target);!t||!r||(u.set(e,[t,r]),t!==r&&d.push({source:t,target:r,weight:e.value}))}let f=[];for(let e=0;t.length>e;e++)if(u.has(t[e]))for(let r=e+1;t.length>r;r++){if(!u.has(t[r])||!_e(t[e],t[r]))continue;let i=new Set([...u.get(t[e]),...u.get(t[r])]);f.push({index:f.length,first:t[e],second:t[r],involvedSlots:i})}let h=new Map;for(let e of a)h.set(e,[]);for(let e of f)for(let t of e.involvedSlots)h.get(t)?.push(e);let g=new Uint32Array(f.length),m=0,p=t.reduce((e,t)=>e+(t.value>0?t.value:1),0),y=o.plotH/Math.max(1,a.length),b=a.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),v=Math.max(1,p)*(Math.max(1,o.plotH)+y*Math.max(b,a.length)+1e-6*Math.max(1,a.length-1))+1,k=4*y,x={fullCrossing:0,localCrossing:0},S=new Map,w=(e,t)=>{let i=S.get(e);i||(i=new Map,S.set(e,i));let a=i.get(t);if(null!=a)return a;let n=function(e,t,r){return de(be([e,t],r)).adjacentClearance[0]??0}(e,t,r);return i.set(t,n),n},M=new Map(a.map((e,t)=>[e,t])),P=t.flatMap(e=>{let t=u.get(e);return t?[{source:M.get(t[0]),target:M.get(t[1]),weight:e.value>0?e.value:1}]:[]}),L=new Map;for(let e of t){let t=u.get(e);t&&L.set(e,{source:M.get(t[0]),target:M.get(t[1])})}let T=new Map,A=new Map,D=new Map,I=(e,t,r)=>{e.has(t)||e.set(t,new Set),e.get(t).add(r)};for(let e of t)I(T,e.source,e.target),I(A,e.target,e.source),I(D,e.source,e.target),I(D,e.target,e.source);let E=t.flatMap(e=>{if(!(e=>1===T.get(e.source)?.size&&T.get(e.source).has(e.target)||1===D.get(e.source)?.size||1===D.get(e.target)?.size)(e))return[];let t=L.get(e);return t&&t.source!==t.target?[{source:t.source,target:t.target,weight:e.value>0?e.value:1}]:[]}),C=e=>{let t=0;for(let r of E)t+=Math.max(0,Math.abs(e[r.source]-e[r.target])-1)*r.weight;return t*k},O=e=>{let t=new Int16Array(a.length);for(let r=0;e.length>r;r++)t[M.get(e[r])]=r;return C(t)},N=f.map(e=>{let t=L.get(e.first),r=L.get(e.second);return[t.source,t.target,r.source,r.target]}),B=new Int16Array(a.length),$=new Float64Array(a.length),H=new Float64Array(a.length+1),R=e=>{for(let t=0;e.length>t;t++)B[M.get(e[t])]=t;let t=0;for(let[e,r,i,a]of N)0>(B[e]-B[i])*(B[r]-B[a])&&t++;if(e.length>0){let t=M.get(e[0]);$[t]=o.padding+e[0].peak.topPeak*o.valueScale;for(let t=1;e.length>t;t++){let r=M.get(e[t-1]),i=M.get(e[t]);$[i]=$[r]+w(e[t-1],e[t])*o.valueScale+o.padding}let r=M.get(e[e.length-1]),i=$[r]+e[e.length-1].peak.botPeak*o.valueScale+o.padding;if(i>o.plotH&&i>0){let e=o.plotH/i;for(let t=0;$.length>t;t++)$[t]*=e}}H[0]=0;for(let t=0;e.length>t;t++)H[t+1]=H[t]+e[t].peak.topPeak+e[t].peak.botPeak;let r=0,i=0,a=0;for(let e of P){let t=B[e.source],n=B[e.target];if(r+=Math.abs(t-n)*e.weight,i+=Math.abs($[e.source]-$[e.target])*e.weight,Math.abs(t-n)>=2){let r=Math.min(t,n)+1;a+=(H[Math.max(t,n)]-H[r])*e.weight}}return t*v+i+a*y+C(B)+1e-6*r},F=(e,r)=>{let i=Array(e.length+1).fill(0);for(let t=0;e.length>t;t++)i[t+1]=i[t]+e[t].peak.topPeak+e[t].peak.botPeak;let a=0;for(let e of t){let t=r[e.source],n=r[e.target];if(null==t||null==n||2>Math.abs(t-n))continue;let o=Math.min(t,n)+1;a+=(i[Math.max(t,n)]-i[o])*(e.value>0?e.value:1)}return a},W=i=>{let a=Ne(i),n=i.slice(0,-1).map((e,t)=>w(e,i[t+1])),l=xe(e,t,r,i,a,{plotH:o.plotH,padding:o.padding,valueScale:o.valueScale,lanePlacement:o.lanePlacement??"stack",groupPadding:o.groupPadding,adjacentClearance:n});return{map:a,geometry:l,weightedLength:je(a,t),pixelLength:Se(l.centerlines,t),transitOcclusion:F(i,a)}},_=(e,t,r)=>({crossings:e,weightedLength:t.weightedLength,pixelLength:t.pixelLength,transitOcclusion:t.transitOcclusion,cost:e*v+t.pixelLength+t.transitOcclusion*y+O(r)+1e-6*t.weightedLength}),z=(e,t)=>{let r=t;if(null==r){let t=new Map(e.map((e,t)=>[e,t]));r=f.reduce((e,r)=>e+Xe(r,t,u),0),x.fullCrossing++}return _(r,W(e),e)},j=(e,a,n="quality")=>{let l=a;if(null==l){let t=new Map(e.map((e,t)=>[e,t]));l=f.reduce((e,r)=>e+Xe(r,t,u),0),x.fullCrossing++}let s=W(e);return _(l,{...s,transitOcclusion:Ae(t,r,e,s.map,s.geometry.centerlines,i,{valueScale:o.valueScale,ribbonLane:o.ribbonLane,domain:o.domain,mode:n})},e)},X=[...l],Y=(e,t)=>me(s.get(e),s.get(t)),G=function(e){let t=new Set;for(let r of e)if(r.group){if(t.has(r.group))return!0;t.add(r.group)}return!1}(X),q=e=>{let t=(e=>{let t=fe(e,d,e=>z(e).cost,{passes:6,compare:Y,maxEvaluations:Fi}),r=z(t),i=Fi;for(let e=0;6>e&&i>0;e++){let a=!1,n=Array.from({length:t.length-1},(e,t)=>t);e%2==1&&n.reverse();for(let e of n){if(0>=i--)break;let n=t[e],o=t[e+1],l=new Map(t.map((e,t)=>[e,t])),s=0,c=[];m++;for(let e of[...h.get(n)??[],...h.get(o)??[]])g[e.index]!==m&&(g[e.index]=m,c.push(e),s+=Xe(e,l,u));[t[e],t[e+1]]=[o,n];let d=new Map(l);d.set(n,e+1),d.set(o,e);let f=0;for(let e of c)f+=Xe(e,d,u);x.localCrossing+=c.length;let p=z(t,r.crossings-s+f);r.cost>p.cost?(r=p,a=!0):[t[e],t[e+1]]=[n,o]}if(!a)break}return t})(e);if((e.length>8?1/0:Hi(e.length)*(e.length+P.length+N.length))>Ri)return t;let r=he(e,R,{maxItems:8,maxEvaluations:5e4}),i=j(r),a=j(t);return i.crossings!==a.crossings&&a.crossings>i.crossings?r:t},V="geometry-refine"===o.mode;if(V||"crossing-min"!==o.laneOrder&&"crossing-min+inside-out"!==o.laneOrder){if(!V&&"inside-out"===o.laneOrder)if(G){let e=$e(X),t=e=>e.slots.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),r=[...e].sort((e,r)=>t(r)-t(e)||me(e.stableId,r.stableId)),i=Array(r.length),a=Math.floor((r.length-1)/2)-1,n=Math.floor((r.length-1)/2)+1;r.length>0&&(i[Math.floor((r.length-1)/2)]=r[0]);for(let e=1;r.length>e;e++)e%2==1&&r.length>n||0>a?i[n++]=r[e]:i[a--]=r[e];X=Re(i)}else{let e=[...X].sort((e,t)=>t.peak.topPeak+t.peak.botPeak-(e.peak.topPeak+e.peak.botPeak)||Y(e,t)),t=Array(e.length),r=Math.floor((e.length-1)/2)-1,i=Math.floor((e.length-1)/2)+1;e.length>0&&(t[Math.floor((e.length-1)/2)]=e[0]);for(let a=1;e.length>a;a++)a%2==1&&e.length>i||0>r?t[i++]=e[a]:t[r--]=e[a];X=t}}else X=G?(e=>{let t=$e(e);if(1>=t.length)return Re(t);let r=e=>z(Re(e)).cost;t=$e(q(e)),t=Fe(t,d,Y);let i=function(e,t){let r=new Map;for(let t of e)for(let e of t.slots)r.set(e,t);let i=new Map;for(let e of t){let t=r.get(e.source),a=r.get(e.target);if(!t||!a||t===a)continue;let n=Number.isFinite(e.weight)&&e.weight>0?e.weight:1,o=a.stableId>t.stableId?`${t.stableId}\0${a.stableId}`:`${a.stableId}\0${t.stableId}`,l=i.get(o);l?l.weight=(l.weight??0)+n:i.set(o,{source:t,target:a,weight:n})}return[...i.values()]}(t,d);if(t=fe(t,i,r,{passes:6,compare:(e,t)=>me(e.stableId,t.stableId),maxEvaluations:Fi}),t=function(e,t,r={}){let i=[...e];if(1>=i.length)return i;let a=t(i),n=1,o=Math.max(0,r.passes??6),l=Math.max(1,r.maxEvaluations??1/0);for(let e=0;o>e&&l>n;e++){let e=!1;for(let r=0;i.length-1>r&&l>n;r++){[i[r],i[r+1]]=[i[r+1],i[r]];let o=t(i);n++,a>o?(a=o,e=!0):[i[r],i[r+1]]=[i[r+1],i[r]]}if(!e)break}return i}(t,r,{passes:8,maxEvaluations:Fi}),(t.length>8?1/0:Hi(t.length)*(t.length+P.length+N.length))<=Ri){let e=he(t,e=>R(Re(e)),{maxItems:8,maxEvaluations:5e4}),r=Re(e),i=Re(t),a=j(r),n=j(i);a.crossings!==n.crossings?t=n.crossings>a.crossings?e:t:n.cost>a.cost&&(t=e)}return t=Fe(t,d,Y),Re(t)})(X):q(X);if(!V&&"crossing-min+inside-out"===o.laneOrder&&X.length>1)if(G){let e=$e(X),t=z(Re(e)),r=Re(e),i=t,a=Math.floor((e.length-1)/2),n=e=>e.slots.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),o=[...e].sort((e,t)=>n(t)-n(e)||me(e.stableId,t.stableId));for(let n of o){let o=e.indexOf(n);if(o===a)continue;e.splice(o,1),e.splice(a,0,n);let l=Re(e),s=z(l);s.cost>t.cost?(e.splice(a,1),e.splice(o,0,n)):(t=s,i.cost>s.cost&&(r=l,i=s))}X=r}else{let e=z(X),t=[...X],r=e,i=Math.floor((X.length-1)/2),a=[...X].sort((e,t)=>t.peak.topPeak+t.peak.botPeak-(e.peak.topPeak+e.peak.botPeak)||Y(e,t));for(let n of a){let a=X.indexOf(n);if(a===i)continue;X.splice(a,1),X.splice(i,0,n);let o=z(X);o.cost>e.cost?(X.splice(i,1),X.splice(a,0,n)):(e=o,r.cost>o.cost&&(t=[...X],r=o))}X=t}if((V||"crossing-min"===o.laneOrder||"crossing-min+inside-out"===o.laneOrder)&&X.length>1)if(G){let e=$e(X),t=j(Re(e),void 0,"score");for(let r=0;6>r&&e.length>1;r++){let r=!1;for(let i=0;e.length-1>i;i++){[e[i],e[i+1]]=[e[i+1],e[i]];let a=Re(e),n=j(a,void 0,"score");t.cost>n.cost?(X=a,t=n,r=!0):[e[i],e[i+1]]=[e[i+1],e[i]]}if(!r)break}e=Fe($e(X),d,Y),X=Re(e)}else{let e=j(X,void 0,"score");for(let t=0;X.length-1>t;t++){let r=X[t],i=X[t+1],a=new Map(X.map((e,t)=>[e,t])),n=0,o=[];m++;for(let e of[...h.get(r)??[],...h.get(i)??[]])g[e.index]!==m&&(g[e.index]=m,o.push(e),n+=Xe(e,a,u));[X[t],X[t+1]]=[i,r];let l=new Map(a);l.set(r,t+1),l.set(i,t);let s=0;for(let e of o)s+=Xe(e,l,u);x.localCrossing+=o.length;let c=j(X,e.crossings-n+s,"score");e.cost>c.cost?e=c:[X[t],X[t+1]]=[r,i]}}let U=He(l);X=He(X);let Q=j(X),K=j(U);if(V){let e=O(U),t=O(X);(Q.crossings>K.crossings||Q.crossings===K.crossings&&t>e+1e-9||Q.cost>K.cost)&&(X=U,Q=K)}else Q.cost>K.cost&&(X=U,Q=K);let Z=function({order:e,after:t,nodes:r,edges:i,outgoingPartners:a,incomingPartners:n,slotForNode:o,averageGap:l,evaluate:s}){let c=(r,a)=>{let n=[...new Set(a.map(t=>e.indexOf(t)))].sort((e,t)=>e-t),o=e.indexOf(r),c=n[0],u=n[n.length-1];if(3>n.length||!n.includes(o)||u-c+1!==n.length||1>=Math.abs(2*o-c-u))return;let d=[...e];d.splice(o,1),d.splice(c+u>>1,0,r);let f=He(d),h=s(f),g=new Set(r.occupants.map(e=>e.id)),m=new Set(a.flatMap(e=>e.occupants.map(e=>e.id))),p=i.reduce((e,t)=>g.has(t.source)&&m.has(t.target)||g.has(t.target)&&m.has(t.source)?e+(t.value>0?t.value:1):e,0);(function(e,t,r=0){return t.crossings>e.crossings||e.crossings===t.crossings&&t.cost+r>=e.cost})(h,t,Math.abs(2*o-c-u)*l*Math.max(1,p))&&(e=f,t=h)};for(let[e,t]of a)!n.has(e)&&t.size>=3&&c(o.get(e),[...t].map(e=>o.get(e)));for(let e of r){let t=o.get(e.id);!e.group&&t.group&&(n.get(e.id)?.size??0)>=3&&c(t,[...n.get(e.id)??[]].map(e=>o.get(e)).filter(e=>e===t||e.group===t.group).filter((e,t,r)=>r.indexOf(e)===t))}return{order:e,after:t}}({order:X,after:Q,nodes:e,edges:t,outgoingPartners:T,incomingPartners:A,slotForNode:c,averageGap:y,evaluate:j});return X=Z.order,Q=Z.after,Be(a,n,X),{before:K,after:Q,initialOrder:l.map(e=>s.get(e)),evaluations:x}}function Ge(e,t,r){let i=e.map(e=>{let i=e.occupants.map(e=>({id:e.id,end:r[e.id]?.end??e.end})),a=0,n=0;for(let e of i){let r=t[e.id];a=Math.max(a,r?.topPeak||0),n=Math.max(n,r?.botPeak||0)}return{occupants:i,peak:{topPeak:a,botPeak:n},...null!=e.group?{group:e.group}:{}}}),a=ge();return i.forEach((e,t)=>{for(let r of e.occupants)a[r.id]=t}),{slots:i,slotByNode:a}}function qe(e,t){return null!=e.start&&null!=e.end&&null!=t.start&&null!=t.end&&!(t.start>=e.end||e.start>=t.end)}function Ve(e,t){return me(e,t)>0?`${t}\0${e}`:`${e}\0${t}`}function Ue(e){let t=new Map,r=new Map;for(let i of e)r.has(i.source)||r.set(i.source,new Set),t.has(i.target)||t.set(i.target,new Set),r.get(i.source).add(i.target),t.get(i.target).add(i.source);return{incoming:new Map([...t].map(([e,t])=>[e,t.size])),outgoing:new Map([...r].map(([e,t])=>[e,t.size]))}}function Qe(e){let t=new Map,r=new Map,i=(e,t,r,i)=>{let a=e.get(t);a||(a=new Map,e.set(t,a)),a.set(r,(a.get(r)??0)+i)};for(let a of e){let e=a.value>0&&Number.isFinite(a.value)?a.value:1;i(t,a.source,a.target,e),i(r,a.target,a.source,e)}let a=new Map,n=e=>{if(a.has(e))return;let i=t.get(e),n=r.get(e),o=new Map;for(let[e,t]of i??[])o.set(e,(o.get(e)??0)+t);for(let[e,t]of n??[])o.set(e,(o.get(e)??0)+t);if(1===o.size){let[t,r]=[...o][0];a.set(e,{partner:t,weight:r})}};for(let t of e)n(t.source),n(t.target);return a}function Ke(e,t,r){let i=r.get(e),a=r.get(t);return!i||!a||i.partner===a.partner||i.partner===t||a.partner===e}function Ze(e,t,r){return!!r.has(e)&&t.some(t=>!Ke(e,t,r))}function Je(e,t){return(e.value>0&&Number.isFinite(e.value)?e.value:1)*(1+(1===t.outgoing.get(e.source)?1:0)+(1===t.incoming.get(e.target)?1:0))}function et(e,t,r,i){if(12>=e.length||1>=i.slotCount)return i.assignment;let a=new Map(e.map((e,t)=>[e,t])),n=Array.from({length:e.length},()=>new Map),o=Ue(r);for(let e of r){let t=a.get(e.source),r=a.get(e.target);if(null==t||null==r||t===r)continue;let i=Je(e,o);n[t].set(r,(n[t].get(r)??0)+i),n[r].set(t,(n[r].get(t)??0)+i)}let l=Qe(r),s=e.map(e=>l.get(e)?.weight??0),c=Array.from({length:e.length},()=>new Map),u=0;for(let r=0;e.length-1>r&&5e4>u;r++)if(l.has(e[r]))for(let i=r+1;e.length>i;i++){if(!l.has(e[i])||t.conflicts(e[r],e[i]))continue;u++;let a=Math.min(s[r],s[i])||Math.max(s[r],s[i]),n=Ke(e[r],e[i],l)?a:-a;if(Math.abs(n)>zi&&(c[r].set(i,n),c[i].set(r,n),u>=5e4))break}let d=[...i.assignment],f=Array.from({length:i.slotCount},()=>[]);d.forEach((e,t)=>f[e].push(t));let h=(e,t,r)=>{let i=d[t],a=d[r],n=0,o=new Set;for(let l of[t,r])for(let[s,c]of e[l]){let e=s>l?`${l}:${s}`:`${s}:${l}`;if(o.has(e))continue;o.add(e);let u=(l===t?a:i)===(s===t?a:s===r?i:d[s]);d[l]===d[s]!==u&&(n+=u?c:-c)}return n},g=(e,t,r)=>{let i=0;for(let[a,n]of e[t]){let e=r===d[a];d[t]===d[a]!==e&&(i+=e?n:-n)}return i},m=(e,t)=>e>zi||zi>=Math.abs(e)&&t>zi,p=(e,t,r,i)=>e>r+zi||zi>=Math.abs(e-r)&&t>i+zi,y=0;for(let r=0;32>r&&_i>y;r++){let r=null,i=-1,a=-1,o=-1,l=-1/0,s=-1/0;for(let u=0;e.length>u;u++){for(let h=0;f.length>h&&y++<_i;h++){if(h===d[u]||!f[h].every(r=>!t.conflicts(e[u],e[r])))continue;let y=g(n,u,h),b=g(c,u,h);m(y,b)&&p(y,b,l,s)&&(r="move",i=u,a=-1,o=h,l=y,s=b)}if(y>=_i)break}for(let u=0;e.length-1>u;u++){for(let g=u+1;e.length>g&&y++<_i;g++){let y=d[u],b=d[g];if(y===b||!f[b].every(r=>r===g||!t.conflicts(e[u],e[r]))||!f[y].every(r=>r===u||!t.conflicts(e[g],e[r])))continue;let v=h(n,u,g),k=h(c,u,g);m(v,k)&&p(v,k,l,s)&&(r="swap",i=u,a=g,o=-1,l=v,s=k)}if(y>=_i)break}if(null==r||-1===i)break;if("move"===r){let e=d[i];f[e].splice(f[e].indexOf(i),1),f[o].push(i),d[i]=o;continue}let u=d[i],b=d[a];f[u].splice(f[u].indexOf(i),1,a),f[b].splice(f[b].indexOf(a),1,i),d[i]=b,d[a]=u}return d}function tt(e,t){let r=1/0,i=-1/0;for(let t of e?.samples??[])1e-9>=t.topMass+t.botMass||(r=Math.min(r,t.t),i=Math.max(i,t.t));return Number.isFinite(r)&&Number.isFinite(i)?(null!=t.start&&(r=Math.max(r,t.start)),null!=t.end&&(i=Math.min(i,t.end)),r>i?{start:null,end:null}:{start:r,end:i}):{start:null,end:null}}function rt(e,t,r,i){let a=function(e,t,r,i){return`${e.map(e=>{let t=r[e.id],a=i[e.id];return[e.id,e.group??"",e.xExtent?.[0]??"",e.xExtent?.[1]??"",t?.topPeak??0,t?.botPeak??0,a?.start??"",a?.end??""].join(":")}).join("|")}#${t.map(e=>[e.id,e.source,e.target,e.value,e.startTime,e.endTime].join(":")).join("|")}`}(e,t,r,i),n=Wi.get(a);if(n)return Ge(n.slots,r,i);let o=ge();for(let t of e)o[t.id]=tt(r[t.id],i[t.id]);let l=function(e,t){return e.filter(e=>null!=t[e.id].start).sort((e,r)=>t[e.id].start-t[r.id].start||t[e.id].end-t[r.id].end||me(e.id,r.id)).map(e=>e.id)}(e,o),s=new Map(e.map(e=>[e.id,e])),c=new Map(e.map(e=>[e.id,e.group||void 0])),u=Qe(t),d=function(e,t,r,i,a,n){let o=new Set,l=new Map(e.map(e=>[e,new Set])),s=new Map(e.map(e=>[e,new Set]));for(let e of i)o.add(Ve(e.source,e.target)),l.get(e.target)?.add(e.source),s.get(e.source)?.add(e.target);let c=new Map,u=new Set,d=(e,t)=>{for(let r=0;e.length>r;r++)for(let i=r+1;e.length>i;i++){let a=Ve(e[r],e[i]);t instanceof Map?t.set(a,[e[r],e[i]]):t.add(a)}};for(let e of s.values())d([...e],c);for(let e of l.values())d([...e],u);let f=new Set;for(let[e,[i,a]]of c)u.has(e)&&(qe(t[i],t[a])||qe(r[i],r[a])&&(f.add(i),f.add(a)));return{conflicts:(e,r)=>{let i=a.get(e),l=a.get(r);return!((null==i||null==l||i===l)&&(null!=i==(null!=l)||o.has(Ve(e,r))||n.has(e)&&n.has(r)&&Ke(e,r,n))&&!qe(t[e],t[r])&&(!f.has(e)&&!f.has(r)||o.has(Ve(e,r))))}}}(l,o,i,t,c,u),f=function(e,t,r=new Map){let i=[],a=[];for(let n of e){let e=i.findIndex(e=>e.every(e=>!t.conflicts(n,e))&&!Ze(n,e,r));-1===e&&!r.has(n)&&(e=i.findIndex(e=>e.every(e=>!t.conflicts(n,e)))),-1===e&&(e=i.length,i.push([])),i[e].push(n),a.push(e)}return{assignment:a,slotCount:i.length}}(l,d,u),h=function(e,t,r,i){if(0===e.length||e.length>12||1>=i.slotCount)return i.assignment;let a=new Map(e.map((e,t)=>[e,t])),n=Array.from({length:e.length},()=>new Float64Array(e.length)),o=Array.from({length:e.length},()=>new Map),l=Array.from({length:e.length},()=>new Map),s=Ue(r);for(let e of r){let t=a.get(e.source),r=a.get(e.target);if(null==t||null==r||t===r)continue;let i=Je(e,s);n[t][r]+=i,n[r][t]+=i,l[t].set(r,(l[t].get(r)??0)+i),o[r].set(t,(o[r].get(t)??0)+i)}let c=Qe(r),u=e.map(e=>c.get(e)?.weight??0),d=Array.from({length:e.length},()=>new Float64Array(e.length));for(let t=0;e.length>t;t++)for(let r=t+1;e.length>r;r++){for(let[e,i]of o[t])d[t][r]+=Math.min(i,o[r].get(e)??0);for(let[e,i]of l[t])d[t][r]+=Math.min(i,l[r].get(e)??0);if(c.has(e[t])&&c.has(e[r])){let i=Math.min(u[t],u[r])||Math.max(u[t],u[r]);d[t][r]+=Ke(e[t],e[r],c)?i:-i}d[r][t]=d[t][r]}let f=[...i.assignment],h=(t=>{let r=0,i=0;for(let a=0;e.length>a;a++)for(let o=a+1;e.length>o;o++)t[a]===t[o]&&(r+=n[a][o],i+=d[a][o]);return{flow:r,affinity:i}})(f),g=0,m=Array(e.length).fill(-1),p=Array.from({length:i.slotCount},()=>[]),y=(r,a,o,l)=>{if(g>=75e3)return;if(r===e.length)return g++,void((o>h.flow||o===h.flow&&l>h.affinity||o===h.flow&&l===h.affinity&&function(e,t){for(let r=0;Math.min(e.length,t.length)>r;r++)if(e[r]!==t[r])return t[r]>e[r];return t.length>e.length}(m,f))&&(f=[...m],h={flow:o,affinity:l}));let s=Math.min(a+1,i.slotCount-1);for(let i=0;s>=i;i++){if(p[i].some(i=>t.conflicts(e[r],e[i])))continue;let s=0,c=0;for(let e of p[i])s+=n[r][e],c+=d[r][e];if(m[r]=i,p[i].push(r),y(r+1,Math.max(a,i),o+s,l+c),p[i].pop(),m[r]=-1,g>=75e3)return}};return m[0]=0,p[0].push(0),y(1,0,0,0),f}(l,d,t,{...f,assignment:et(l,d,t,f)}),g=new Map,m=h.map(e=>(g.has(e)||g.set(e,g.size),g.get(e))),p=Array.from({length:g.size||(e.length>0?1:0)},()=>({occupants:[],peak:{topPeak:0,botPeak:0}})),y=ge();l.forEach((e,t)=>{let r=m[t],i=p[r];i.occupants.push({id:e,end:o[e].end??-1/0});let a=s.get(e)?.group;a&&(i.group=a),y[e]=r});for(let t of[...e].sort((e,t)=>me(e.id,t.id)))null==y[t.id]&&(p[0].occupants.push({id:t.id,end:-1/0}),y[t.id]=0);for(let e of p){e.occupants.sort((e,t)=>(o[e.id].start??1/0)-(o[t.id].start??1/0)||me(e.id,t.id));for(let t of e.occupants){let i=r[t.id];e.peak.topPeak=Math.max(e.peak.topPeak,i?.topPeak||0),e.peak.botPeak=Math.max(e.peak.botPeak,i?.botPeak||0)}}let b={slots:p,slotByNode:y};return function(e,t){for(Wi.has(e)&&Wi.delete(e),Wi.set(e,{slots:t.slots.map(e=>({occupants:e.occupants.map(e=>({...e})),peak:{...e.peak},...null!=e.group?{group:e.group}:{}})),slotByNode:Object.assign(ge(),t.slotByNode)});Wi.size>12;){let e=Wi.keys().next().value;if(null==e)break;Wi.delete(e)}}(a,b),b}function it(e){return e.topMass+e.botMass}function at(e){let t=new Map;for(let r of e.samples){if(Number.isNaN(r.t))continue;let e=t.get(r.t);e||(e=[],t.set(r.t,e)),e.push(r)}let r=0,i=-1/0;return a=>{a>=i||(r=0),i=a;let n=t.get(a);if(n){let e=n.reduce((e,t)=>it(t)<it(e)?e:t,n[0]);return{exact:n,sample:e}}for(;e.samples.length>r&&a>=e.samples[r].t;)r++;return{exact:n,sample:e.samples[r-1]??null}}}function nt(e,t,r,i,a,n,o=0){let l=new Map;for(let r of e){if(!r.group||!t[r.id])continue;let e=l.get(r.group)??[];e.push(r),l.set(r.group,e)}if(0===l.size||0>=n)return t;let s=Object.fromEntries(Object.entries(t).map(([e,t])=>[e,{...t,samples:t.samples.map(e=>({...e})),localAttachments:new Map([...t.localAttachments].map(([e,t])=>[e,{...t}]))}]));for(let[e,c]of l){let l=r.map((e,t)=>({slot:e,index:t})).filter(({slot:t})=>t.group===e);if(0===l.length)continue;let u=l[0].slot,d=l.at(-1).slot,f=a[u.occupants[0]?.id],h=a[d.occupants[0]?.id];if(!Number.isFinite(f)||!Number.isFinite(h))continue;let g=(f-u.peak.topPeak*n+(h+d.peak.botPeak*n))/2,m=[...new Set(c.flatMap(e=>t[e.id].samples.map(e=>e.t)))].sort((e,t)=>e-t),p=new Map;for(let e of c)p.set(e.id,new Map);let y=new Map(c.map(e=>[e.id,at(t[e.id])]));for(let e of m){let t=new Map;for(let r of c){let{sample:a}=y.get(r.id)(e);if(!a||1e-9>=it(a))continue;let n=i[r.id];if(null==n)continue;let o=t.get(n)??[];o.push({node:r,sample:a}),t.set(n,o)}let r=[...t].sort((e,t)=>e[0]-t[0]).map(([e,t])=>({slot:e,active:t,mass:Math.max(...t.map(({sample:e})=>it(e)))}));if(0===r.length)continue;let l=g-(r.reduce((e,t)=>e+t.mass,0)*n+Math.max(0,o)*Math.max(0,r.length-1))/2;for(let t of r){for(let{node:r,sample:i}of t.active){let t=(l-a[r.id])/n+i.topMass-(i.boundaryOffset??0);p.get(r.id).set(e,t)}l+=t.mass*n+Math.max(0,o)}}for(let e of c){let r=t[e.id],i=s[e.id],a=p.get(e.id),n=y.get(e.id),o=[];for(let e of m){let t=a.get(e),{exact:r,sample:i}=n(e);r?o.push(...r.map(e=>({...e,...null!=t?{boundaryOffset:(e.boundaryOffset??0)+t}:{}}))):null==t||!i||1e-9>=it(i)||o.push({...i,t:e,boundaryOffset:(i.boundaryOffset??0)+t})}i.samples=o,i.localAttachments=new Map([...r.localAttachments].map(([e,t])=>{let r=a.get(t.time);return[e,{...t,...null!=r?{boundaryOffset:(t.boundaryOffset??0)+r}:{}}]}))}}return s}function ot(e,t,r,i,a){let{plotH:n,padding:o,valueScale:l,packing:s,laneOrder:c,lifetimeMode:u="half",lanePlacement:d="stack",groupPadding:f=0,ribbonLane:h="both",domain:g}=a,m=ge(),p=ge();for(let t of e)m[t.id]=r[t.id].topPeak||0,p[t.id]=r[t.id].botPeak||0;let y="half"===u,b=ge();for(let t of e){let e=Array.isArray(t.xExtent)?t.xExtent[0]:null,r=Array.isArray(t.xExtent)?t.xExtent[1]:null,a=null!=e&&Number.isFinite(e)?e:1/0,n=null!=r&&Number.isFinite(r)?r:-1/0;for(let e of i.outgoing[t.id]){a>e.startTime&&(a=e.startTime),null!=e.systemInTime&&Number.isFinite(e.systemInTime)&&a>e.systemInTime&&(a=e.systemInTime);let t=y?(e.startTime+e.endTime)/2:e.endTime;t>n&&(n=t)}for(let e of i.incoming[t.id]){let t=y?(e.startTime+e.endTime)/2:e.startTime;a>t&&(a=t),e.endTime>n&&(n=e.endTime),null!=e.systemOutTime&&Number.isFinite(e.systemOutTime)&&e.systemOutTime>n&&(n=e.systemOutTime)}b[t.id]={start:Number.isFinite(a)?a:null,end:Number.isFinite(n)?n:null}}let v=ge(),k=[],x=[];if(a.frozenSlots){let e=Ge(a.frozenSlots,r,b);k=e.slots,v=e.slotByNode,x=k.map(pe)}else if("reuse"===s){let i=rt(e,t,r,b);k=i.slots,v=i.slotByNode}else e.forEach((e,t)=>{k.push({occupants:[{id:e.id,end:b[e.id]?.end??-1/0}],peak:{topPeak:m[e.id],botPeak:p[e.id]},...e.group?{group:e.group}:{}}),v[e.id]=t});We(k,v),0===x.length&&(x=k.map(pe));let S=null;a.frozenSlots||(a.fixedSlotOrder?function(e,t,r){let i=new Map(r.map((e,t)=>[e,t]));Be(e,t,[...e].sort((e,t)=>(i.get(pe(e))??1/0)-(i.get(pe(t))??1/0)||me(pe(e),pe(t))))}(k,v,a.fixedSlotOrder):a.runOrdering&&c&&"insertion"!==c&&(S=Ye(e,t,r,b,k,v,{plotH:n,padding:o,valueScale:l,groupPadding:f,laneOrder:c,ribbonLane:h,domain:g}))),We(k,v);let w=xe(e,t,r,k,v,{plotH:n,padding:o,valueScale:l,stackValueScale:a.stackValueScale,lanePlacement:d,groupPadding:f}),M=0===k.length?0:k[0].peak.topPeak+w.adjacentClearance.reduce((e,t)=>e+t,0)+k[k.length-1].peak.botPeak,P=S?.before.crossings??null,L=S?.after.crossings??null,T=S?.before.weightedLength??null,A=S?.after.weightedLength??null;return{effectiveSlotsHeight:M,centerlines:w.centerlines,laneLifetime:b,slots:k,slotByNode:v,slotCenter:w.slotCenter,stackCenter:w.stackCenter,verticalUtilization:w.verticalUtilization,selectedSlotOrder:k.map(pe),initialSlotOrder:x,ordering:S,crossingsBefore:P,crossingsAfter:L,lengthBefore:T,lengthAfter:A}}function lt(e,t,r,i="horizontal"){return"vertical"===i?{top:e?38:t?28:16,right:24,bottom:24,left:r?72:24}:{top:e?30:t?24:8,right:80,bottom:r?28:8,left:80}}function st(e,t,r,i,a,n,o,l,s={}){let c,u,d,f,h=a,g=e=>l?Math.max(l[0],Math.min(l[1],e)):e,m=n(g(e.time)),p=n(g(r.time)),y=e.value*h,b=r.value*h,v=t+(e.boundaryOffset??0)*h,k=i+(r.boundaryOffset??0)*h,x=e.sideMassBefore*h,S=r.sideMassAfter*h;"top"===e.side?(c=v-x,u=c+y):(u=v+x,c=u-y),"top"===r.side?(d=k-S,f=d+b):(f=k+S,d=f-b);let w=s.sourceRunwayStart,M=s.minRun,P=Math.abs((d+f)/2-(c+u)/2),L=p-m,T="number"==typeof w&&Number.isFinite(w),A="number"==typeof M&&Number.isFinite(M)&&M>0;if(T&&P>1e-9&&L>0&&("auto"===M||A)){let t="source"===o?.85:"target"===o?.15:.5,r="auto"===M?Math.min(144,Math.sqrt(8*P/(1.5*Math.min(t*t,(1-t)*(1-t))))):M;if(r>L){let t=n(g(Math.min(w,e.time)));Number.isFinite(t)&&(m=Math.min(m,Math.max(Math.min(m,t),p-r)))}}let D="source"===o?m+.85*(p-m):"target"===o?m+.15*(p-m):(m+p)/2;return{sx:m,sTop:c,sBot:u,tx:p,tTop:d,tBot:f,cp1X:D,cp2X:D}}function ct(e){return Math.max(18,11*e.length*.58)}function ut(e){let t=1.22*ct(e.labelText)+4;return"start"===e.labelAnchor?[e.labelX,e.labelX+t]:"middle"===e.labelAnchor?[e.labelX-t/2,e.labelX+t/2]:[e.labelX-t,e.labelX]}function dt(e,t){let r=e.labelX-ct(e.labelText),i=t.labelX-ct(t.labelText);return t.labelX+3>=r&&e.labelX+3>=i}function ft(e){return e.replace(oa,(e,t,r)=>`${r},${t}`)}function ht(e){if(!e)return;let t=e=>({x:e.y,y:e.x});return{...e,...e.points&&{points:e.points.map(t)},...e.segments&&{segments:e.segments.map(e=>e.map(t))}}}function gt(e){return{...e,pathD:ft(e.pathD),y0:e.x0,y1:e.x1,x0:0,x1:0}}function mt(e){let{nodes:t,edges:r,domain:i,plotW:a,plotH:n,ribbonLane:o,ribbonMinRun:l=0,edgeOpacity:s,colorOf:c,layoutOpts:u,orientation:d="horizontal",showLabels:f=!0,labelPriorityAccessor:h,maxLabels:g,selectionDatum:m="raw",styleRules:p,colorBy:y,valueAccessor:b,usageMode:v="static"}=e,k="vertical"===d?n:a,x="vertical"===d?a:n,S=re(t,r,i,{usageMode:v}),{fatal:w,warnings:M}=function(e){let t=[],r=[];for(let i of e)"fatal"===te(i)?t.push(i):r.push(i);return{fatal:t,warnings:r}}(S),P=function(e,t,r="static"){if("strip"!==ee(r).invalidSystemTime)return e;let i=new Set(t.filter(e=>"invalid-system-time"===e.kind).map(e=>e.id));return 0===i.size?e:e.map(e=>{if(!i.has(e.id))return e;let t={...e};return null!=t.systemInTime&&!Number.isFinite(t.systemInTime)&&delete t.systemInTime,null!=t.systemOutTime&&!Number.isFinite(t.systemOutTime)&&delete t.systemOutTime,t})}(r,S,v),L=na().domain(i).range([0,k]);if(w.length>0)return{layout:null,layoutConfig:{bands:[],ribbons:[],showLabels:!1!==f},issues:w,warnings:M,xScale:L};let T=function(e,t,r){let{plotH:i,pairing:a="temporal",packing:n="reuse",laneOrder:o="crossing-min",lifetimeMode:l="half",maxValueScale:s,lanePlacement:c="stack",nodeSizing:u="temporal",groupPadding:d=0,ribbonLane:f="both",domain:h}=r,g=Number.isFinite(d)?Math.max(0,d):0,m=function(e,t){let r=ge(),i=ge();for(let t of e)r[t.id]=[],i[t.id]=[];for(let e of t)i[e.source]&&i[e.source].push(e),r[e.target]&&r[e.target].push(e);return{incoming:r,outgoing:i}}(e,t),p=function(e,t,r,i="temporal"){let a="temporal"===i?(e,t)=>e.endTime-t.endTime||me(e.id,t.id):(e,t)=>t.value-e.value||me(e.id,t.id),n="temporal"===i?(e,t)=>e.startTime-t.startTime||me(e.id,t.id):(e,t)=>t.value-e.value||me(e.id,t.id),o=new Map;for(let e of t)o.set(e.id,{});let l=(e,t)=>{let r=new Map;for(let i of e){let e=i[t];r.has(e)||r.set(e,{partner:e,edges:[],total:0,earliestStart:1/0,latestEnd:-1/0});let a=r.get(e);a.edges.push(i),a.total+=i.value,a.earliestStart=Math.min(a.earliestStart,i.startTime),a.latestEnd=Math.max(a.latestEnd,i.endTime)}let o=[...r.values()];o.sort("temporal"===i?(e,r)=>"target"===t?e.earliestStart-r.earliestStart||me(e.partner,r.partner):e.latestEnd-r.latestEnd||me(e.partner,r.partner):(e,t)=>t.total-e.total||me(e.partner,t.partner));for(let e of o)e.edges.sort("target"===t?n:a);return o};for(let t of e){let e=r.outgoing[t.id],i=r.incoming[t.id];if(0===i.length)l(e,"target").forEach((e,t)=>{let r=t%2==0?"top":"bot";for(let t of e.edges)o.get(t.id).sourceSide=r});else if(0===e.length)l(i,"source").forEach((e,t)=>{let r=t%2==0?"top":"bot";for(let t of e.edges)o.get(t.id).targetSide=r});else{let t=l(i,"source"),r=l(e,"target"),a=Math.max(t.length,r.length);for(let e=0;a>e;e++){let i=e%2==0?"top":"bot";if(t[e])for(let r of t[e].edges)o.get(r.id).targetSide=i;if(r[e])for(let t of r[e].edges)o.get(t.id).sourceSide=i}}}return o}(e,t,m,a),y=ge();for(let t of e)y[t.id]=Oe(t,m,p,void 0,u);let b=ot(e,t,y,m,{plotH:i,padding:12,valueScale:1,packing:n,laneOrder:o,lifetimeMode:l,runOrdering:!0,lanePlacement:"stack",groupPadding:g,ribbonLane:f,domain:h}),v=b.slots.map(e=>({occupants:e.occupants.map(e=>({...e})),peak:{...e.peak},...null!=e.group?{group:e.group}:{}})),k=new Set;for(let e of t){let t=b.slotByNode[e.source],r=b.slotByNode[e.target];if(void 0===t||void 0===r)continue;let i=p.get(e.id);t!==r?t>r?(i.sourceSide="top",i.targetSide="bot"):(i.sourceSide="bot",i.targetSide="top"):(k.add(e.id),i.sourceSide="bot",i.targetSide="bot")}for(let t of e){let e=m.outgoing[t.id],r=m.incoming[t.id],i=new Set(e.map(e=>p.get(e.id).sourceSide)),a=new Set(r.map(e=>p.get(e.id).targetSide));if(1===i.size&&r.length>0){let e=[...i][0];for(let t of r)b.slotByNode[t.source]===b.slotByNode[t.target]&&(p.get(t.id).targetSide=e)}if(1===a.size&&e.length>0){let t=[...a][0];for(let r of e)b.slotByNode[r.source]===b.slotByNode[r.target]&&(p.get(r.id).sourceSide=t)}}(function(e,t,r){let i=new Map,a=[];for(let t of e)a.push({time:t.startTime,kind:"out",edge:t}),a.push({time:t.endTime,kind:"in",edge:t});a.sort((e,t)=>e.time-t.time||(e.kind===t.kind?0:"in"===e.kind?-1:1)||("out"===e.kind?t.edge.value-e.edge.value:0)||me(e.edge.id,t.edge.id));let n=e=>{let t=i.get(e);return t||(t={top:0,bot:0},i.set(e,t)),t},o=(e,t,r)=>{let i="top"===t?"bot":"top",a=Math.min(r,e[t]);e[t]-=a;let n=r-a;n>0&&(e[i]=Math.max(0,e[i]-n))};for(let e of a){let{edge:i}=e;if("in"===e.kind){let e=t.get(i.id)?.targetSide??"bot";n(i.target)[e]+=i.value;continue}let a=n(i.source),l=t.get(i.id),s=l.sourceSide??"bot";if(r[i.source]===r[i.target]){let e=a.top>=i.value,t=a.bot>=i.value;e!==t?s=e?"top":"bot":!e&&!t&&a.top!==a.bot&&(s=a.top>a.bot?"top":"bot"),l.sourceSide=s,l.targetSide=s}o(a,s,i.value)}})(t,p,b.slotByNode),function(e,t,r,i){for(let a of e){let e=t.incoming[a.id],n=t.outgoing[a.id];if(0===e.length||0===n.length)continue;let o=()=>{let t={inTop:0,inBot:0,outTop:0,outBot:0};for(let i of e)"top"===r.get(i.id).targetSide?t.inTop+=i.value:t.inBot+=i.value;for(let e of n)"top"===r.get(e.id).sourceSide?t.outTop+=e.value:t.outBot+=e.value;return t},l=(e,t)=>{let a=o(),l="top"===e?a.outTop-a.inTop:a.outBot-a.inBot,s="top"===t?a.inTop-a.outTop:a.inBot-a.outBot;if(0>=l||0>=s)return!1;let c=Math.min(l,s),u=n.filter(t=>!i.has(t.id)&&r.get(t.id).sourceSide===e&&c>=t.value).sort((e,t)=>t.value-e.value||me(e.id,t.id));return 0!==u.length&&(r.get(u[0].id).sourceSide=t,!0)},s=n.length+1;for(;s-- >0&&(l("top","bot")||l("bot","top")););}}(e,m,p,k),y=ge();for(let t of e)y[t.id]=Oe(t,m,p,void 0,u);let x=ot(e,t,y,m,{plotH:i,padding:12,valueScale:1,packing:n,laneOrder:o,lifetimeMode:l,frozenSlots:v,lanePlacement:"stack",groupPadding:g,ribbonLane:f,domain:h}),S=x.effectiveSlotsHeight??x.slots.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),w=x.slots.slice(0,-1).reduce((e,t,r)=>e+(null!=t.group&&t.group===x.slots[r+1].group?1:0),0),M=Math.max(1,x.slots.length+1-w),P=Math.min(12,Math.max(0,.35*i-w*g)/M),L=2*P+ye(x.slots,P,g).reduce((e,t)=>e+t,0),T=S>0?Math.max(0,(i-L)/S):1,A=Number.isFinite(s)&&s>0?Math.min(T,s):T,D=ot(e,t,y,m,{plotH:i,padding:P,valueScale:A,packing:n,laneOrder:o,lifetimeMode:l,frozenSlots:v,lanePlacement:c,groupPadding:g,ribbonLane:f,domain:h,stackValueScale:T}),I=Number.isFinite(s)&&s>0&&T>s+1e-12;if("insertion"!==o&&("hug"===c||I)&&D.slots.length>1&&(Ye(e,t,y,D.laneLifetime,D.slots,D.slotByNode,{plotH:i,padding:P,valueScale:A,groupPadding:g,laneOrder:o,ribbonLane:f,domain:h,lanePlacement:c,mode:"geometry-refine"}),D=ot(e,t,y,m,{plotH:i,padding:P,valueScale:A,packing:n,laneOrder:o,lifetimeMode:l,frozenSlots:D.slots,fixedSlotOrder:D.slots.map(pe),lanePlacement:c,groupPadding:g,ribbonLane:f,domain:h,stackValueScale:T})),function(e,t){let r=(e,r)=>{for(let i of e){let e=new Map;for(let a of i){let i=`${("out"===r?t.get(a.id)?.sourceSide:t.get(a.id)?.targetSide)??""}\0${"out"===r?a.startTime:a.endTime}`,n="out"===r?`${a.target}\0${a.endTime}`:`${a.source}\0${a.startTime}`,o=e.get(i);if(null!=o&&o!==n)return!0;e.set(i,n)}}return!1};return r(Object.values(e.outgoing),"out")||r(Object.values(e.incoming),"in")}(m,p)){let r=function(e,t,r,i){let a=new Map;for(let n of e){let e=t[n.source]?.localAttachments.get(n.id),o=t[n.target]?.localAttachments.get(n.id),l=r[n.source],s=r[n.target];if(!(e&&o&&Number.isFinite(l)&&Number.isFinite(s)))continue;let c=Ce(e,l,i),u=Ce(o,s,i);a.set(n.id,{source:(c[0]+c[1])/2,target:(u[0]+u[1])/2})}return a}(t,y,D.centerlines,A);y=ge();for(let t of e)y[t.id]=Oe(t,m,p,r,u);D=ot(e,t,y,m,{plotH:i,padding:P,valueScale:A,packing:n,laneOrder:o,lifetimeMode:l,frozenSlots:D.slots,fixedSlotOrder:D.slots.map(pe),lanePlacement:c,groupPadding:g,ribbonLane:f,domain:h,stackValueScale:T})}let E=new Map(b.initialSlotOrder.map((e,t)=>[e,t])),C=[...D.slots].sort((e,t)=>(E.get(pe(e))??1/0)-(E.get(pe(t))??1/0)||me(pe(e),pe(t))),O=ge();C.forEach((e,t)=>{for(let r of e.occupants)O[r.id]=t});let N=xe(e,t,y,C,O,{plotH:i,padding:P,valueScale:A,stackValueScale:T,lanePlacement:"stack",groupPadding:g}),B=nt(e,y,C,O,N.centerlines,A,g),$=De(ze(O,t),je(O,t),t,B,C,O,N.centerlines,D.laneLifetime,A,N.verticalUtilization,f,h);y=nt(e,y,D.slots,D.slotByNode,D.centerlines,A,g);let H=De(ze(D.slotByNode,t),je(D.slotByNode,t),t,y,D.slots,D.slotByNode,D.centerlines,D.laneLifetime,A,D.verticalUtilization,f,h);return{nodeData:y,sides:p,valueScale:A,padding:P,compressedPadding:12>P,centerlines:D.centerlines,laneLifetime:D.laneLifetime,slots:D.slots,slotByNode:D.slotByNode,crossingsBefore:"insertion"===o?null:$.crossings,crossingsAfter:"insertion"===o?null:H.crossings,lengthBefore:"insertion"===o?null:$.weightedLength,lengthAfter:"insertion"===o?null:H.weightedLength,layoutQualityBefore:$,layoutQuality:H}}(t,P,{plotH:x,...u,ribbonLane:o,domain:i}),{centerlines:A,nodeData:D,valueScale:I}=T,E=mr(y,b),C=[],O=[],N=0===l?new Map:function(e,t,r){let i=new Set(t.map(e=>e.target)),a=new Map(e.map(e=>[e.id,e])),n=new Map;for(let e of t){if(i.has(e.source))continue;let t=n.get(e.source)??[];t.push(e),n.set(e.source,t)}let o=new Map;for(let t of e){if(!t.group)continue;let e=o.get(t.group)??[];e.push(t),o.set(t.group,e)}let l=new Set;for(let[e,t]of o){let r=t.flatMap(e=>n.get(e.id)??[]),a=new Set(r.map(e=>e.startTime));r.length>0&&1===a.size&&t.every(e=>{let t=e.xExtent?.[0],a=r[0].startTime;return!i.has(e.id)&&(n.get(e.id)?.length??0)>0&&Number.isFinite(t)&&a>t})&&l.add(e)}let s=new Map;for(let[e,t]of n){let i=a.get(e);if(i?.group&&!l.has(i.group))continue;let n=i?.xExtent?.[0],o=[...t].sort((e,t)=>e.startTime-t.startTime||e.id.localeCompare(t.id)),c=o[0]?.startTime-1,u=null;for(let e=0;o.length>e;){let t=o[e].startTime,i=e+1;for(;o.length>i&&o[i].startTime===t;)i++;for(let t=e;i>t;t++){let e=o[t],i=Number.isFinite(n)&&e.startTime>n,a=Number.isFinite(e.systemInTime)&&e.startTime>e.systemInTime;if(!i&&!a)continue;let l=r[0];i&&(l=Math.max(l,n)),a&&(l=Math.max(l,e.systemInTime)),!i&&a&&Number.isFinite(c)&&(l=Math.max(l,c)),null!=u&&(l=Math.max(l,u)),e.startTime>l&&s.set(e.id,l)}u=t,e=i}}for(let[e,t]of o){if(!l.has(e))continue;let r=t.flatMap(e=>n.get(e.id)??[]);if(!r.every(e=>s.has(e.id))){for(let e of r)s.delete(e.id);continue}let i=Math.max(...r.map(e=>s.get(e.id)));for(let e of r)s.set(e.id,i)}return s}(t,P,i),B=new Map(t.filter(e=>e.group).map(e=>[e.id,e.group])),$=new Map;for(let e of P){let t=D[e.source]?.localAttachments.get(e.id),r=D[e.target]?.localAttachments.get(e.id);!t||!r||$.set(e.id,st(t,A[e.source],r,A[e.target],I,L,o,i,{minRun:l,sourceRunwayStart:N.get(e.id)}))}let H=function(e,t,r,i,a,n){let o=new Map(t),l=new Map;for(let t of e){let e=n?.get(t.source),r=null==e?"node:"+t.source:"group:"+e,i=l.get(r)??new Map,a=i.get(t.startTime)??[];a.push(t),i.set(t.startTime,a),l.set(r,i)}for(let e of l.values())for(let[n,l]of e){if(!l.some(e=>r.has(e.id)))continue;let e=l.map(e=>t.get(e.id));if(e.some(e=>null==e))continue;let s=i(n),c=Math.min(...e.map(e=>e.sx));if(c>=s-1e-9)continue;let u=Math.max(...l.map(e=>{let t=r.get(e.id);return null==t?s:Math.min(s,i(t))})),d=Math.min(s,Math.max(c,u));for(let e of l){let r=t.get(e.id),i=d+(r.tx-d)*("source"===a?.85:"target"===a?.15:.5);o.set(e.id,{...r,sx:d,cp1X:i,cp2X:i})}}return o}(P,$,N,L,o,B),R=function(e,t,r,i,a){let n=new Map;for(let o of e){if(!r.has(o.id))continue;let e=t.get(o.id);if(!e||e.sx>=i(o.startTime)-1e-9)continue;let l=a(e.sx);Number.isFinite(l)&&o.startTime>l&&n.set(o.id,l)}return n}(P,H,N,L,e=>i[0]+e/k*(i[1]-i[0])),F=function(e,t,r){let i=new Map,a=new Map;for(let[e,t]of r??[]){let r=a.get(t)??[];r.push(e),a.set(t,r)}for(let n of e){let e=t.get(n.id);if(null==e||!Number.isFinite(e)||e>=n.startTime)continue;let o=r?.get(n.source),l=null==o?[n.source]:a.get(o)??[n.source];for(let t of l){let r=i.get(t)??new Map,a=r.get(n.startTime);r.set(n.startTime,null==a?e:Math.min(a,e)),i.set(t,r)}}return i}(P,R,B);t.forEach((e,t)=>{let r=D[e.id];if(!r||0===r.samples.length)return;let a=(o=r.samples,(l=F.get(e.id))&&0!==l.size?o.map(e=>{let t=l.get(e.t);return null==t?e:{...e,t:t}}):o),n=function(e,t,r,i,a){if(0===e.length)return null;let n=Ee(e,a),o=e=>t+(n[e].boundaryOffset??0)*r,l=e=>o(e)-n[e].topMass*r,s=e=>o(e)+n[e].botMass*r,c=`M${i(n[0].t)},${l(0)}`;for(let e=1;n.length>e;e++)c+=` L${i(n[e].t)},${l(e)}`;c+=` L${i(n[n.length-1].t)},${s(n.length-1)}`;for(let e=n.length-2;e>=0;e--)c+=` L${i(n[e].t)},${s(e)}`;return c+" Z"}(a,A[e.id],I,L,i);var o,l;if(!n)return;let s,u,f=Ee(a,i),h=f.find(e=>e.topMass+e.botMass>0)||f[0],g=A[e.id]+(h.botMass-h.topMass+2*(h.boundaryOffset??0))*I/2,m=c(e.id,t),y=m,b=.5,v=e.__raw??e;if(p&&p.length>0){let e=wr(v,p,E(v));"string"==typeof e.fill?m=e.fill:null!=e.fill&&Fr(e.fill)&&(u=e.fill,m=e.fill.background&&"transparent"!==e.fill.background?e.fill.background:m),"string"==typeof e.stroke&&(y=e.stroke),"number"==typeof e.strokeWidth&&(b=e.strokeWidth),"number"==typeof e.fillOpacity&&(s=e.fillOpacity),"number"==typeof e.opacity&&null==s&&(s=e.opacity)}let k=function(e,t,r,i,a,n){let o=r.nodeData[e];if(!o||0===o.samples.length)return[];let l=r.valueScale,s=r.centerlines[e],c=Ee(o.samples,a),u=c.find(e=>e.topMass+e.botMass>0)||c[0],d=[...c].reverse().find(e=>e.topMass+e.botMass>0)||c[c.length-1],f=i(u.t),h=i(d.t),g=e=>i(Ie(e,a)),m=[],p=(e,t,r,i)=>`M${e},${t} L${r},${t} L${r},${i} L${e},${i} Z`;for(let r of t){if(r.source===e&&null!=r.systemInTime&&Number.isFinite(r.systemInTime)){let e=o.localAttachments.get(r.id),t=n?.get(r.id)??r.startTime;if(e&&"out"===e.kind&&t>r.systemInTime){let i=g(r.systemInTime),n=g(t),o=null!=a&&a[0]>r.systemInTime,c=o?i:i-20,u=o?Math.min(n,i+20):i,d=Math.max(f,c);if(n>d){let[t,r]=Ce(e,s,l);m.push({pathD:p(d,t,n,r),x0:c,x1:u,from:0,to:1})}}}if(r.target===e&&null!=r.systemOutTime&&Number.isFinite(r.systemOutTime)){let e=o.localAttachments.get(r.id);if(e&&"in"===e.kind&&r.systemOutTime>r.endTime){let t=g(r.systemOutTime),i=g(r.endTime),a=t+20,n=Math.min(h,a);if(n>i){let[r,o]=Ce(e,s,l);m.push({pathD:p(i,r,n,o),x0:t,x1:a,from:1,to:0})}}}}return m}(e.id,P,T,L,i,R);C.push({id:e.id,pathD:n,fill:m,stroke:y,strokeWidth:b,...null!=s&&{fillOpacity:s},...u&&{hatchFill:u},...k.length>0&&{gradientStubs:k},rawDatum:v,labelX:L("vertical"===d&&e.xExtent?e.xExtent[0]:h.t)-4,labelY:g,labelText:e.label??e.id})});let W=new Map;t.forEach((e,t)=>W.set(e.id,t)),P.forEach(e=>{let t=H.get(e.id);if(!t)return;let r=W.get(e.source)??0,i=c(e.source,r),{pathD:a,bezier:n}=Z(t),o=e.__raw??e,l="function"==typeof s?Number(s(o)):s,u=Number.isFinite(l)?Math.max(0,Math.min(1,l)):.35;O.push({id:e.id,pathD:a,fill:i,opacity:u,rawDatum:o,bezier:n})});let _=function(e,t,r){let i=e.map(e=>({...e})),a=new Map;for(let e of i){let r=t[e.id];if(null==r)continue;let i=a.get(r)??[];i.push(e),a.set(r,i)}let n=e=>{if(2>e.length)return;let t=e.reduce((e,t)=>e+t.labelY,0)/e.length,i=(e.length-1)/2;e.forEach((e,a)=>{e.labelY=Math.max(8,Math.min(r-8,t+16*(a-i)))})};for(let e of a.values()){e.sort((e,t)=>e.labelX-t.labelX||e.id.localeCompare(t.id));let t=[],r=-1/0;for(let i of e){let e=i.labelX-ct(i.labelText);t.length>0&&e>r+3&&(n(t),t=[],r=-1/0),t.push(i),r=Math.max(r,i.labelX)}n(t)}return function(e,t){let r=[...e].sort((e,t)=>e.labelY-t.labelY||e.labelX-t.labelX||e.id.localeCompare(t.id));for(let e=0;3>e;e+=1){for(let e=0;r.length>e;e+=1){let t=8;for(let i=0;e>i;i+=1)dt(r[e],r[i])&&(t=Math.max(t,r[i].labelY+16));r[e].labelY=Math.max(r[e].labelY,t)}for(let e=r.length-1;e>=0;e-=1){let i=t-8;for(let t=e+1;r.length>t;t+=1)dt(r[e],r[t])&&(i=Math.min(i,r[t].labelY-16));r[e].labelY=Math.min(r[e].labelY,i)}}}(i,r),i}(C,T.slotByNode,x).map(e=>function(e,t){return"horizontal"===t?e:{...e,pathD:ft(e.pathD),gradientStubs:e.gradientStubs?.map(gt),labelX:e.labelY,labelY:e.labelX,labelAnchor:"middle",labelBaseline:"auto"}}(e,d)),z="vertical"===d?function(e,t,r){let i=e.map(e=>({...e}));for(let e of i){let r=1.22*ct(e.labelText)+4;e.labelX=t-4>r?Math.max(r/2+2,Math.min(t-r/2-2,e.labelX)):t/2}let a=[],n=[...i].sort((e,t)=>e.labelY-t.labelY||e.labelX-t.labelX);for(let e of n){let t=a[a.length-1];!t||Math.abs(t[0].labelY-e.labelY)>14?a.push([e]):t.push(e)}for(let e of a){e.sort((e,t)=>e.labelX-t.labelX||e.id.localeCompare(t.id));let t=[],i=new Map;for(let r of e){let[e,a]=ut(r),n=t.findIndex(t=>e>t+8);-1===n&&(n=t.length),t[n]=a,i.set(r,n)}let a=e.reduce((e,t)=>e+t.labelY,0)/e.length,n=14*t.length+8>a;for(let t of e){let e=i.get(t)??0;t.labelY=n?Math.min(r-8,12+14*e):Math.max(8,a-14*e)}}return i}(_,a,n):_,j=new Map;if(null!=h)for(let e of t){let t=e.__raw??e,r="function"==typeof h?h(t):Number(t[h]);Number.isFinite(r)&&j.set(e.id,r)}let X=function(e,t,r,i,a={}){if(!1===i)return e.map(e=>({...e,labelText:"",labelDeferred:!1,labelFullText:void 0}));if(!0===i)return e.map(e=>({...e,labelDeferred:!1,labelFullText:void 0}));let n=Math.max(4,Math.min(e.length,Math.floor(Math.max(1,t*r)/14e3)));Number.isFinite(a.maxLabels)&&a.maxLabels>=0&&(n=Math.min(n,Math.floor(a.maxLabels)));let o=e.map((e,t)=>{let r=a.priorityById?.get(e.id),i=Math.abs(e.labelY);return{band:e,index:t,score:null!=r&&Number.isFinite(r)?1e6*r+ct(e.labelText):ct(e.labelText)+.01*i}}).filter(e=>e.band.labelText.trim().length>0).sort((e,t)=>t.score-e.score||e.index-t.index||e.band.id.localeCompare(t.band.id)),l=new Set(o.slice(0,n).map(e=>e.band.id));return e.map(e=>l.has(e.id)||0===e.labelText.trim().length?{...e,labelDeferred:!1,labelFullText:void 0}:{...e,labelFullText:e.labelText,labelText:"",labelDeferred:!0})}(z,a,n,f,{...j.size>0&&{priorityById:j},...null!=g&&{maxLabels:g}});return{layout:T,layoutConfig:{bands:X,ribbons:O.map(e=>function(e,t){return"horizontal"===t?e:{...e,pathD:ft(e.pathD),bezier:ht(e.bezier)}}(e,d)),showLabels:!1!==f,selectionDatum:m},issues:[],warnings:M,xScale:L}}function pt(e,t,r,i="reuse",a="crossing-min",n=5e4){return"sync"!==e&&("worker"===e||function(e,t,r="reuse",i="crossing-min"){return e*e*("reuse"===r?80:1)+t*t*(i&&"insertion"!==i?40:1)+10*(e+t)}(t,r,i,a)>=n)}function yt(){return"u">typeof window&&"u">typeof Worker}function bt(e){if(!e)return null;let t=e.sides,r=t instanceof Map?t:new Map(Array.isArray(t)?t:[]);return{...e,sides:r}}function vt(e){return!!(function(e){if(!e||0===e.length)return!1;for(let t of e)if("function"==typeof t.when||"function"==typeof t.style)return!0;return!1}(e.styleRules)||"function"==typeof e.edgeOpacity||"function"==typeof e.labelPriorityAccessor||e.styleRules&&e.styleRules.length>0&&("function"==typeof e.colorBy||"function"==typeof e.valueAccessor))}function kt(e){if(null!=e&&"object"==typeof e){try{if("function"==typeof structuredClone)return structuredClone(e)}catch{}try{return JSON.parse(JSON.stringify(e))}catch{return}}}function xt(e){let t=kt(e.__raw);return{id:e.id,...null!=e.label&&{label:e.label},...null!=e.group&&{group:e.group},...null!=e.xExtent&&{xExtent:e.xExtent},...null!=t&&{__raw:t}}}function St(e){let t=kt(e.__raw);return{id:e.id,source:e.source,target:e.target,value:e.value,startTime:e.startTime,endTime:e.endTime,...null!=e.systemInTime&&{systemInTime:e.systemInTime},...null!=e.systemOutTime&&{systemOutTime:e.systemOutTime},...null!=t&&{__raw:t}}}function wt(e,t){let r=Ir(),{execution:i="auto",workerThreshold:a,colorById:n,fallbackPalette:o,rawNodeById:l,rawEdgeById:s}=t,c=ta(()=>Object.keys(n).sort().map(e=>`${e}:${n[e]}`).join("|"),[n]),u=ta(()=>e?[e.nodes,e.edges,e.plotW,e.plotH,e.orientation??"horizontal",e.ribbonLane,(e.ribbonMinRun??0)+"",e.edgeOpacity,(e.showLabels??!0)+"",e.layoutOpts.pairing??"temporal",e.layoutOpts.packing??"reuse",e.layoutOpts.laneOrder??"crossing-min",e.layoutOpts.lifetimeMode??"half",e.layoutOpts.maxValueScale??"",e.layoutOpts.lanePlacement??"stack",e.layoutOpts.nodeSizing??"temporal",e.layoutOpts.groupPadding??0,e.domain[0],e.domain[1],e.styleRules,c]:"null",[e,c]),d=!!e&&!r&&function(e,t,r){return!(typeof window>"u"||!yt()||vt(e))&&pt(t,e.nodes.length,e.edges.length,e.layoutOpts.packing??"reuse",e.layoutOpts.laneOrder??"crossing-min",r)}(e,i,a),f=ta(()=>e?d?null:mt(e):ua([0,1],1),[u,d,e]),h=ra(r),[g,m]=ia(()=>e?r?{...mt(e),status:"ready",error:null}:d?{...ua(e.domain,"vertical"===e.orientation?e.plotH:e.plotW),status:"pending",error:null}:{...mt(e),status:"ready",error:null}:{...ua([0,1],1),status:"ready",error:null});return ea(()=>{if(h.current)return void(h.current=!1);if(!e||!d)return;let t=new AbortController;return m(e=>({...e,status:"pending",error:null})),async function(e,t){let{execution:r="auto",workerThreshold:i,signal:a,colorById:n,fallbackPalette:o=["#475569"],rawNodeById:l=new Map,rawEdgeById:s=new Map}=t,c=e.layoutOpts.packing??"reuse",u=e.layoutOpts.laneOrder??"crossing-min";if(!yt()||vt(e)||!pt(r,e.nodes.length,e.edges.length,c,u,i))return mt(e);try{let t=await function(e,t){return yt()?ca.get().request(e,t):Promise.reject(Error("Web Workers are unavailable"))}(function(e,t,r){return{input:{nodes:e.nodes.map(xt),edges:e.edges.map(St),domain:e.domain,plotW:e.plotW,plotH:e.plotH,orientation:e.orientation,ribbonLane:e.ribbonLane,ribbonMinRun:e.ribbonMinRun,edgeOpacity:"number"==typeof e.edgeOpacity?e.edgeOpacity:.35,layoutOpts:{...e.layoutOpts},showLabels:e.showLabels,..."string"==typeof e.labelPriorityAccessor&&{labelPriorityAccessor:e.labelPriorityAccessor},...null!=e.maxLabels&&{maxLabels:e.maxLabels},...null!=e.selectionDatum&&{selectionDatum:e.selectionDatum},...null!=e.usageMode&&{usageMode:e.usageMode},styleRules:e.styleRules,colorBy:"string"==typeof e.colorBy?e.colorBy:void 0,valueAccessor:"string"==typeof e.valueAccessor?e.valueAccessor:void 0},colorById:t,fallbackPalette:r}}(e,n,o),a);return function(e,t,r){let i=(e.layoutConfig.bands??[]).map(e=>({...e,rawDatum:t.get(e.id)??{id:e.id}})),a=(e.layoutConfig.ribbons??[]).map(e=>({...e,rawDatum:r.get(e.id)??{id:e.id}})),n=la().domain(e.domain).range([0,e.timelineExtent]);return{layout:e.layout,layoutConfig:{bands:i,ribbons:a,showLabels:e.layoutConfig.showLabels},issues:e.issues,warnings:e.warnings,xScale:n}}(t,l,s)}catch(t){if("AbortError"===t?.name)throw t;return mt(e)}}(e,{execution:i,workerThreshold:a,signal:t.signal,colorById:n,fallbackPalette:o,rawNodeById:l,rawEdgeById:s}).then(e=>{m({...e,status:"ready",error:null})}).catch(e=>{"AbortError"!==e.name&&m(t=>({...t,status:"error",error:e}))}),()=>t.abort()},[u,d,i,a,o,l,s]),f?{...f,status:"ready",error:null}:g}function Mt(e,t){return"function"==typeof e?e(t):t[e]}function Pt(e,t,r){return!t?.isActive||t.predicate(function(e,t){return"scene"===t?e:e.data}(e,r))}function Lt(e){return"object"==typeof e&&null!==e&&"__kind"in e&&("band"===e.__kind||"ribbon"===e.__kind)}function Tt(e){let[t,r,i]=function(e){if(e.startsWith("#")){let t=e.slice(1);if(3===t.length&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]),6===t.length)return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}let t=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return t?[+t[1],+t[2],+t[3]]:[128,128,128]}(e);return.299*t+.587*r+.114*i>150?"#222":"#fff"}function At(e,t,r){let i=t.nodeIDAccessor;return"function"==typeof i?i(e.data)+"":"string"==typeof i&&void 0!==e.data[i]?e.data[i]+"":void 0!==e.data.name?e.data.name+"":void 0!==e.data.id?e.data.id+"":"node-"+r}function Dt(e){if(!e)return null;if("function"==typeof e){let t=e;return e=>t(e.data??e)}return t=>t.data?.[e]||t[e]||t.id}function It(e){return Array.isArray(e.colorScheme)?e.colorScheme:e.themeCategorical&&e.themeCategorical.length>0?e.themeCategorical:Ca}function Et(e){return Array.isArray(e.colorScheme)&&e.colorScheme.length>0?e.colorScheme[0]:e.themeSemantic?.primary?e.themeSemantic.primary:e.themeCategorical&&e.themeCategorical.length>0?e.themeCategorical[0]:"#4d430c"}function Ct(e,t,r,i,a){if("horizontal"===a){let a=(e+r)/2;return`M ${e},${t} C ${a},${t} ${a},${i} ${r},${i}`}if("radial"===a){let a=(e+r)/2;return`M ${e},${t} Q ${a},${t} ${a},${(t+i)/2} T ${r},${i}`}{let a=(t+i)/2;return`M ${e},${t} C ${e},${a} ${r},${a} ${r},${i}`}}function Ot(e,t,r){let i=r.treeOrientation||"vertical";if("radial"===i){let r=t.x,i=t.y;e.x=i*Math.cos(r-Math.PI/2),e.y=i*Math.sin(r-Math.PI/2)}else"horizontal"===i?(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 Nt(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 Bt(e,t){let r=t.r??0;e.x=t.x,e.y=t.y,e.x0=t.x-r,e.x1=t.x+r,e.y0=t.y-r,e.y1=t.y+r,e.width=2*r,e.height=2*r,e.__radius=r}function $t(e){let t=Pr(e.mode,{width:e.width,height:e.height,enableHover:e.enableHover,showLegend:e.showLegend,showLabels:e.showLabels,title:e.title,description:e.description,accessibleTable:e.accessibleTable,summary:e.summary,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,responsiveRules:e.responsiveRules},{width:600,height:600}),{data:r,margin:i,className:a,layout:s="tree",orientation:u="vertical",childrenAccessor:f="children",valueAccessor:h="value",nodeIdAccessor:g="name",colorBy:m,colorScheme:p,colorByDepth:y=!1,styleRules:b,edgeStyle:v="curve",nodeLabel:k,nodeSize:x=5,tooltip:S,frameProps:w={},onObservation:M,onClick:P,chartId:L,selection:T,linkedHover:A,loading:D,loadingContent:I,legendInteraction:E,legendPosition:C,stroke:O,strokeWidth:N,opacity:B}=e,{width:$,height:H,enableHover:R,showLegend:F,showLabels:W=!0,title:_,description:z,summary:j,accessibleTable:X}=t,Y=d({nodes:Ma(()=>l(r??null,f),[r,f]),edges:void 0,inferNodes:!1,colorBy:y?void 0:m,colorScheme:p,showLegend:F,legendPosition:C,legendInteraction:E,frameLegend:w,selection:T,linkedHover:A,onObservation:M,onClick:P,mobileInteraction:t.mobileInteraction,mobileSemantics:t.mobileSemantics,chartType:"TreeDiagram",chartId:L,marginDefaults:t.marginDefaults,userMargin:i,width:$,height:H,hasTitle:!!_,loading:D,loadingContent:I}),G=Ma(()=>new Map,[]),q=Ma(()=>e=>{let t={stroke:"black",strokeWidth:1};return t.fill=y?Or[(e.depth||0)%Or.length]:m?Br(e.data||e,m,Y.colorScale):xr(void 0,Y.themeCategorical,p,void 0,G),t},[m,y,Y.colorScale,Y.themeCategorical,p,G]),V=Ma(()=>mr(m,h),[m,h]),U=Ma(()=>dr(q,b,V,e=>e.data||e),[q,b,V]),Q=Ma(()=>ar(U,{stroke:O,strokeWidth:N,opacity:B}),[U,O,N,B]),K=Ma(()=>n(Q,Y.effectiveSelectionHook,Y.resolvedSelection),[Q,Y.effectiveSelectionHook,Y.resolvedSelection]),Z=Ma(()=>()=>({stroke:"#999",strokeWidth:1,fill:"none"}),[]),J=Ma(()=>ar(Z,{stroke:O,strokeWidth:N,opacity:B}),[Z,O,N,B]),ee=Ma(()=>o(J,Y.effectiveSelectionHook,Y.resolvedSelection),[J,Y.effectiveSelectionHook,Y.resolvedSelection]),te=Ma(()=>{if("treemap"===s||"circlepack"===s||"partition"===s)return c(h)},[s,h]),re=Vt({componentName:"TreeDiagram",data:r});return re?Na(lr,{componentName:"TreeDiagram",message:re,width:$,height:H}):Y.loadingEl?Y.loadingEl:Na(cr,{componentName:"TreeDiagram",width:$,height:H,children:Na(Kt,{chartType:s,...null!=r&&{data:r},size:[$,H],responsiveWidth:e.responsiveWidth,responsiveHeight:e.responsiveHeight,maxDevicePixelRatio:e.maxDevicePixelRatio,margin:Y.margin,...Y.legendBehaviorProps,nodeIDAccessor:g,childrenAccessor:f,hierarchySum:te,treeOrientation:u,edgeType:v,nodeStyle:K,edgeStyle:ee,colorBy:m,colorScheme:Y.effectivePalette,colorByDepth:y,nodeSize:x,nodeLabel:W?k||g:void 0,showLabels:W,enableHover:R,tooltipContent:!1===S?()=>null:pr(S)||void 0,...ir({linkedHover:A,selection:T,onObservation:M,onClick:P,mobileInteraction:Y.mobileInteraction,customHoverBehavior:Y.customHoverBehavior,customClickBehavior:Y.customClickBehavior,linkedHoverInClickPredicate:!1}),legend:Y.legend,legendPosition:Y.legendPosition,...E&&"none"!==E&&{legendHoverBehavior:Y.legendState.onLegendHover,legendClickBehavior:Y.legendState.onLegendClick,legendHighlightedCategory:Y.legendState.highlightedCategory,legendIsolatedCategories:Y.legendState.isolatedCategories},className:a,title:_,description:z,summary:j,accessibleTable:X,...null!=e.animate&&{animate:e.animate},...w})})}function Ht(e){let t=Pr(e.mode,{width:e.width,height:e.height,enableHover:e.enableHover,showLegend:e.showLegend,showLabels:e.showLabels,title:e.title,description:e.description,accessibleTable:e.accessibleTable,summary:e.summary,linkedHover:e.linkedHover,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,responsiveRules:e.responsiveRules},{width:600,height:600}),{data:r,margin:i,className:a,childrenAccessor:o="children",valueAccessor:s="value",nodeIdAccessor:u="name",colorBy:f,colorScheme:h,colorByDepth:g=!1,styleRules:m,labelMode:p="leaf",nodeLabel:y,padding:b=4,paddingTop:v,nodeStyle:k,tooltip:x,frameProps:S={},selection:w,linkedHover:M,onObservation:P,onClick:L,chartId:T,loading:A,loadingContent:D,legendInteraction:I,legendPosition:E,stroke:C,strokeWidth:O,opacity:N}=e,{nodeStyle:B,...$}=S,{width:H,height:R,enableHover:F,showLegend:W,showLabels:_=!0,title:z,description:j,summary:X,accessibleTable:Y}=t,G=d({nodes:Ba(()=>l(r??null,o),[r,o]),edges:void 0,inferNodes:!1,colorBy:g?void 0:f,colorScheme:h,showLegend:W,legendPosition:E,legendInteraction:I,frameLegend:$,selection:w,linkedHover:M,onObservation:P,onClick:L,mobileInteraction:t.mobileInteraction,mobileSemantics:t.mobileSemantics,chartType:"Treemap",chartId:T,marginDefaults:t.marginDefaults,userMargin:i,width:H,height:R,hasTitle:!!z,loading:A,loadingContent:D}),q=G.customHoverBehavior,V=$a(e=>{if(!e)return q(null);let t=e.data||e;q({data:t?.data||t})},[q]),U=Ba(()=>new Map,[]),Q=Ba(()=>e=>{let t={stroke:"var(--semiotic-cell-border, var(--semiotic-border, #fff))",strokeWidth:1,strokeOpacity:.8};return t.fill=g?Or[(e.depth||0)%Or.length]:f?Br(e.data||e,f,G.colorScale):xr(void 0,G.themeCategorical,h,void 0,U),t},[f,g,G.colorScale,G.themeCategorical,h,U]),K=Ba(()=>mr(f,s),[f,s]),Z=Ba(()=>dr(Q,m,K,e=>e.data||e),[Q,m,K]),J=Ba(()=>k||B?e=>({...Z(e),...B?B(e)??{}:{},...k?k(e)??{}:{}}):Z,[Z,k,B]),ee=Ba(()=>ar(J,{stroke:C,strokeWidth:O,opacity:N}),[J,C,O,N]),te=Ba(()=>n(ee,G.effectiveSelectionHook,G.resolvedSelection),[ee,G.effectiveSelectionHook,G.resolvedSelection]),re=Ba(()=>c(s),[s]),ie=void 0!==v?v:!_||"parent"!==p&&"all"!==p?void 0:18,ae=Vt({componentName:"Treemap",data:r});return ae?Ha(lr,{componentName:"Treemap",message:ae,width:H,height:R}):G.loadingEl?G.loadingEl:Ha(cr,{componentName:"Treemap",width:H,height:R,children:Ha(Kt,{chartType:"treemap",...null!=r&&{data:r},size:[H,R],responsiveWidth:e.responsiveWidth,responsiveHeight:e.responsiveHeight,maxDevicePixelRatio:e.maxDevicePixelRatio,margin:G.margin,...G.legendBehaviorProps,nodeIDAccessor:u,childrenAccessor:o,hierarchySum:re,padding:b,paddingTop:ie,nodeStyle:te,colorBy:f,colorScheme:G.effectivePalette,colorByDepth:g,nodeLabel:_?y||u:void 0,showLabels:_,labelMode:p,enableHover:F,tooltipContent:!1===x?()=>null:pr(x)||void 0,...ir({linkedHover:M,selection:w,onObservation:P,onClick:L,mobileInteraction:G.mobileInteraction,customHoverBehavior:V,customClickBehavior:G.customClickBehavior,linkedHoverInClickPredicate:!1}),legend:G.legend,legendPosition:G.legendPosition,...I&&"none"!==I&&{legendHoverBehavior:G.legendState.onLegendHover,legendClickBehavior:G.legendState.onLegendClick,legendHighlightedCategory:G.legendState.highlightedCategory,legendIsolatedCategories:G.legendState.isolatedCategories},className:a,title:z,description:j,summary:X,accessibleTable:Y,...null!=e.animate&&{animate:e.animate},...$})})}function Rt(e){let t=Pr(e.mode,{width:e.width,height:e.height,enableHover:e.enableHover,showLegend:e.showLegend,showLabels:e.showLabels,title:e.title,description:e.description,accessibleTable:e.accessibleTable,summary:e.summary,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,responsiveRules:e.responsiveRules},{width:600,height:600}),{data:r,margin:i,className:a,childrenAccessor:o="children",valueAccessor:s="value",nodeIdAccessor:u="name",colorBy:f,colorScheme:h,colorByDepth:g=!1,styleRules:m,nodeLabel:p,circleOpacity:y=.7,padding:b=4,tooltip:v,frameProps:k={},onObservation:x,onClick:S,chartId:w,selection:M,linkedHover:P,loading:L,loadingContent:T,legendInteraction:A,legendPosition:D,stroke:I,strokeWidth:E,opacity:C}=e,{width:O,height:N,enableHover:B,showLegend:$,showLabels:H=!0,title:R,description:F,summary:W,accessibleTable:_}=t,z=d({nodes:Ra(()=>l(r??null,o),[r,o]),edges:void 0,inferNodes:!1,colorBy:g?void 0:f,colorScheme:h,showLegend:$,legendPosition:D,legendInteraction:A,frameLegend:k,selection:M,linkedHover:P,onObservation:x,onClick:S,mobileInteraction:t.mobileInteraction,mobileSemantics:t.mobileSemantics,chartType:"CirclePack",chartId:w,marginDefaults:t.marginDefaults,userMargin:i,width:O,height:N,hasTitle:!!R,loading:L,loadingContent:T}),j=Ra(()=>new Map,[]),X=Ra(()=>e=>{let t={stroke:"currentColor",strokeWidth:1,strokeOpacity:.3,fillOpacity:y};return t.fill=g?Or[(e.depth||0)%Or.length]:f?Br(e.data||e,f,z.colorScale):xr(void 0,z.themeCategorical,h,void 0,j),t},[f,g,z.colorScale,y,z.themeCategorical,h,j]),Y=Ra(()=>mr(f,s),[f,s]),G=Ra(()=>dr(X,m,Y,e=>e.data||e),[X,m,Y]),q=Ra(()=>ar(G,{stroke:I,strokeWidth:E,opacity:C}),[G,I,E,C]),V=Ra(()=>n(q,z.effectiveSelectionHook,z.resolvedSelection),[q,z.effectiveSelectionHook,z.resolvedSelection]),U=Ra(()=>c(s),[s]),Q=Vt({componentName:"CirclePack",data:r});return Q?Fa(lr,{componentName:"CirclePack",message:Q,width:O,height:N}):z.loadingEl?z.loadingEl:Fa(cr,{componentName:"CirclePack",width:O,height:N,children:Fa(Kt,{chartType:"circlepack",...null!=r&&{data:r},size:[O,N],responsiveWidth:e.responsiveWidth,responsiveHeight:e.responsiveHeight,maxDevicePixelRatio:e.maxDevicePixelRatio,margin:z.margin,...z.legendBehaviorProps,nodeIDAccessor:u,childrenAccessor:o,hierarchySum:U,padding:b,nodeStyle:V,colorBy:f,colorScheme:z.effectivePalette,colorByDepth:g,nodeLabel:H?p||u:void 0,showLabels:H,enableHover:B,tooltipContent:!1===v?()=>null:pr(v)||void 0,...ir({linkedHover:P,selection:M,onObservation:x,onClick:S,mobileInteraction:z.mobileInteraction,customHoverBehavior:z.customHoverBehavior,customClickBehavior:z.customClickBehavior,linkedHoverInClickPredicate:!1}),legend:z.legend,legendPosition:z.legendPosition,...A&&"none"!==A&&{legendHoverBehavior:z.legendState.onLegendHover,legendClickBehavior:z.legendState.onLegendClick,legendHighlightedCategory:z.legendState.highlightedCategory,legendIsolatedCategories:z.legendState.isolatedCategories},className:a,title:R,description:F,summary:W,accessibleTable:_,...null!=e.animate&&{animate:e.animate},...k})})}function Ft(e){let t=e.__orbitState;return t||(t={metaMap:new Map,startTime:"u">typeof performance?performance.now():Date.now()},e.__orbitState=t),t}function Wt(e){let t=Pr(e.mode,{width:e.width,height:e.height,enableHover:e.enableHover,showLegend:e.showLegend,showLabels:e.showLabels,title:e.title,description:e.description,accessibleTable:e.accessibleTable,summary:e.summary,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,responsiveRules:e.responsiveRules},{width:600,height:600}),{data:r,margin:i,className:a,childrenAccessor:o="children",nodeIdAccessor:s="name",colorBy:c,colorScheme:u,colorByDepth:f=!1,styleRules:h,orbitMode:g="flat",orbitSize:m=2.95,speed:p=.25,revolution:y,revolutionStyle:b,eccentricity:v=1,showRings:k=!0,nodeRadius:x=6,showLabels:S=!1,animated:w=!0,tooltip:M,foregroundGraphics:P,annotations:L,frameProps:T={},onObservation:A,onClick:D,chartId:I,selection:E,linkedHover:C,loading:O,loadingContent:N,legendPosition:B,legendInteraction:$,stroke:H,strokeWidth:R,opacity:F}=e,{width:W,height:_,enableHover:z,showLegend:j,title:X,description:Y,summary:G,accessibleTable:q}=t,V=d({nodes:Wa(()=>l(r,o),[r,o]),edges:void 0,inferNodes:!1,colorBy:f?void 0:c,colorScheme:u,showLegend:j,legendPosition:B,legendInteraction:$,frameLegend:T,selection:E,linkedHover:C,onObservation:A,onClick:D,mobileInteraction:t.mobileInteraction,mobileSemantics:t.mobileSemantics,chartType:"OrbitDiagram",chartId:I,marginDefaults:kr(t),userMargin:i,width:W,height:_,hasTitle:!!X,loading:O,loadingContent:N}),U=Wa(()=>new Map,[]),{colorScale:Q,customClickBehavior:K,customHoverBehavior:Z,themeCategorical:J}=V,ee=Wa(()=>{if(Array.isArray(u))return u;let e=Er[u];return Array.isArray(e)?e:Cr},[u]),te=Wa(()=>e=>{let t={stroke:"#fff",strokeWidth:1},r=0===(e.depth??0);return t.fill=f?r?ee[0]:Xa[(e.depth||0)%Xa.length]:c?Br(e.data||e,c,Q):xr(void 0,J,u,void 0,U),t.opacity=r?1:.85,t},[c,f,Q,ee,J,u,U]),re=Wa(()=>mr(c,"value"),[c]),ie=Wa(()=>dr(te,h,re,e=>e.data||e),[te,h,re]),ae=Wa(()=>ar(ie,{stroke:H,strokeWidth:R,opacity:F}),[ie,H,R,F]),ne=Wa(()=>n(ae,V.effectiveSelectionHook,V.resolvedSelection),[ae,V.effectiveSelectionHook,V.resolvedSelection]),oe=Wa(()=>()=>({stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1}),[]),le=Wa(()=>e=>{Z(e&&e.data&&void 0!==e.data.data?{...e,data:e.data.data}:e)},[Z]),se=Wa(()=>e=>{K(e&&e.data&&void 0!==e.data.data?{...e,data:e.data.data}:e)},[K]),ce=Vt({componentName:"OrbitDiagram",data:r});return ce?ja(lr,{componentName:"OrbitDiagram",message:ce,width:W,height:_}):V.loadingEl?V.loadingEl:ja(cr,{componentName:"OrbitDiagram",width:W,height:_,children:ja(Kt,{chartType:"orbit",...null!=r&&{data:r},size:[W,_],responsiveWidth:e.responsiveWidth,responsiveHeight:e.responsiveHeight,maxDevicePixelRatio:e.maxDevicePixelRatio,margin:V.margin,...V.legendBehaviorProps,nodeIDAccessor:s,childrenAccessor:o,nodeStyle:ne,edgeStyle:oe,colorBy:c,colorScheme:V.effectivePalette,colorByDepth:f,nodeSize:x,nodeLabel:S?s:void 0,showLabels:S,enableHover:!w&&z,tooltipContent:w?void 0:!1===M?()=>null:pr(M)||void 0,...ir({linkedHover:C,selection:E,onObservation:A,onClick:D,mobileInteraction:V.mobileInteraction,customHoverBehavior:le,customClickBehavior:se,linkedHoverInClickPredicate:!1}),legend:V.legend,legendPosition:V.legendPosition,...$&&"none"!==$&&{legendHoverBehavior:V.legendState.onLegendHover,legendClickBehavior:V.legendState.onLegendClick,legendHighlightedCategory:V.legendState.highlightedCategory,legendIsolatedCategories:V.legendState.isolatedCategories},foregroundGraphics:P,annotations:L,className:a,title:X,description:Y,summary:G,orbitMode:g,orbitSize:m,orbitSpeed:p,orbitRevolution:y,orbitRevolutionStyle:b,orbitEccentricity:v,orbitShowRings:k,orbitAnimated:w,accessibleTable:q,...null!=e.animate&&{animate:e.animate},...T})})}function _t(e,t,r={}){let i=r.iterations??260,a=r.repulsion??5200,n=r.linkDistance??165,o=r.linkStrength??.045,l=r.centerStrength??.018,s=r.damping??.84,c=r.nodeRadius??12,u=r.nodePadding??3,d=r.inset??.06,f=nr(r.seed??1),h=new Map;for(let t of e)h.set(t.id,0);for(let e of t)h.set(e.source,(h.get(e.source)??0)+1),h.set(e.target,(h.get(e.target)??0)+1);let g=500,m=e.map(e=>({id:e.id,data:e,x:200+600*f(),y:200+600*f()})),p=new Set(e.map(e=>e.id)),y=t.filter(e=>p.has(e.source)&&p.has(e.target)).map(e=>({source:e.source,target:e.target}));if(i>0){let e=Ja(m).randomSource(f).alphaDecay(1-Math.pow(.001,1/i)).velocityDecay(Math.max(0,Math.min(1,1-s))).force("charge",Za().strength(e=>{let t=h.get(e.id)??0;return 2.5*-Math.sqrt(a)*Math.sqrt(t+1)})).force("collide",Qa(e=>(e=>"function"==typeof c?c(e.data):c)(e)+u).strength(.9).iterations(2)).force("center",Ua(g,g).strength(.8)).force("x",en(g).strength(l)).force("y",tn(g).strength(l));y.length>0&&e.force("link",Ka(y).id(e=>e.id).distance(n).strength(e=>{let t="string"==typeof e.target?e.target:e.target.id,r=Math.max(1,Math.min(h.get("string"==typeof e.source?e.source:e.source.id)??1,h.get(t)??1));return o/.045/r})),e.stop();for(let t=0;i>t;t+=1)e.tick()}let b=1/0,v=1/0,k=-1/0,x=-1/0;for(let e of m){let t=e.x??g,r=e.y??g;b>t&&(b=t),v>r&&(v=r),t>k&&(k=t),r>x&&(x=r)}let S=k-b,w=x-v,M={};for(let e of m)Object.defineProperty(M,e.id,{value:{x:0===S?.5:d+((e.x??g)-b)/S*(1-2*d),y:0===w?.5:d+((e.y??g)-v)/w*(1-2*d)},enumerable:!0,configurable:!0,writable:!0});return M}import{ModuleWorkerSession as zt,createSharedWorkerSessionHolder as jt,errorFromPayload as Xt,parseModuleWorkerErrorField as Yt}from"./c-GXV3C3MO.min.js";import{useCustomChartScaffold as Gt}from"./c-TX7XJM3Z.min.js";import{validateNetworkData as qt,validateObjectData as Vt}from"./c-D6HAAPTX.min.js";import{useFrameImperativeHandle as Ut,useResolvedSelection as Qt}from"./c-RFC7UAG7.min.js";import{StreamNetworkFrame_default as Kt,registerLayoutPlugin as Zt}from"./c-N5NPTJVJ.min.js";import{resolveNodeSizeFn as Jt}from"./c-MVR3RWF3.min.js";import{resolveLabelFn as er,resolveNodeRefId as tr}from"./c-YLZIV3VS.min.js";import{buildBaseMetadataProps as rr,buildCustomBehaviorProps as ir,mergeShapeStyle as ar}from"./c-SGAURYHG.min.js";import{mulberry32 as nr}from"./c-HYW2XA4Q.min.js";import{commonJsWorkerModuleUrl as or}from"./c-VJTDST2R.min.js";import{ChartError as lr,DEFAULT_SELECTION_OPACITY as sr,SafeRender as cr,clampLegendReservation as ur,composeStyleRules as dr,createSeededFrameRandom as fr,distinctCategories as hr,filterSparseArray as gr,makeNodeRuleContext as mr,normalizeTooltip as pr,renderEmptyState as yr,renderLoadingState as br,reserveLegendMargin as vr,resolveAxisFreeMarginDefaults as kr,resolveDefaultFill as xr,resolveMobileInteraction as Sr,resolveStyleRules as wr,useChartLegendAndMargin as Mr,useChartMode as Pr,useChartSelection as Lr,useColorScale as Tr,useLegendInteraction as Ar,useThemeCategorical as Dr,useWasHydratingFromSSR as Ir}from"./c-ODG6TFSY.min.js";import{COLOR_SCHEMES as Er,DEFAULT_COLORS as Cr,DEPTH_PALETTE_COLORS as Or,createColorScale as Nr,getColor as Br,resolveCategoricalPalette as $r,schemeCategory10 as Hr}from"./c-CPV4N35K.min.js";import{getMin as Rr}from"./c-QA3HMQJP.min.js";import{isHatchFill as Fr}from"./c-MB6CV5NC.min.js";import{useMemo as Wr,forwardRef as _r,useRef as zr}from"react";import{forceSimulation as jr,forceCenter as Xr,forceX as Yr,forceY as Gr,forceLink as qr,forceManyBody as Vr,forceCollide as Ur}from"d3-force";var Qr=new Set,Kr=new WeakMap,Zr={supportsStreaming:!0,hierarchical:!1,computeLayout(e,i,a,n){if(0===e.length)return;let o=a.forceStrength??.1,l=n[0]/2,s=n[1]/2,c=Math.max(.1,Math.min(1,Math.min(n[0],n[1])/200)),u=Math.min(.5,.06+1.8*(1-c)),d=a.__previousPositions,f=0,h=[];for(let t of e){let e=null!=t.x&&null!=t.y&&(0!==t.x||0!==t.y),r=d?.get(t.id);e?f++:r?(t.x=r.x,t.y=r.y,f++):h.push(t)}let g=f>0&&.3>=(e.length>0?h.length/e.length:1);if(g){let a=new Map;for(let t of e)a.set(t.id,t);for(let e of h){let n=t(e.id,i,a);if(n.length>0){let t=0,i=0;for(let e of n)t+=e.x,i+=e.y;let a=r(e.id),o=a%360*(Math.PI/180),l=(10+a%20)*c;e.x=t/n.length+l*Math.cos(o),e.y=i/n.length+l*Math.sin(o)}else{let t=r(e.id),i=t%360*(Math.PI/180),a=(15+t%30)*c;e.x=l+a*Math.cos(i),e.y=s+a*Math.sin(i)}}}else{let t=2.399963229728653;for(let r=0;e.length>r;r++){let i=e[r];if(null==i.x||null==i.y||0===i.x&&0===i.y){let e=10*Math.sqrt(r+.5)*c,a=r*t;i.x=l+e*Math.cos(a),i.y=s+e*Math.sin(a)}}}let m=a.__skipForceSimulation||0===a.iterations?0:g?40:a.iterations??Math.max(50,Math.min(300,Math.floor(300-2*(e.length-30)))),p=Jt(a.nodeSize,a.nodeSizeRange,e),y=e=>p(e);if(m>0){let t=new Map,r=new Map;for(let i of e)t.set(i.id,0),r.set(i.id,i);for(let e of i){let r=tr(e.source),i=tr(e.target);t.set(r,(t.get(r)??0)+1),t.set(i,(t.get(i)??0)+1)}let d=qr().strength(e=>{let r=e.weight,i=tr(e.source),a=tr(e.target),n=Math.max(1,Math.min(t.get(i)??1,t.get(a)??1));return Math.min(2.5,(r&&r>0?Math.sqrt(r):1)*o/(.1*n))}).distance(e=>{let t="string"==typeof e.source?r.get(e.source):e.source,i="string"==typeof e.target?r.get(e.target):e.target,a=(t?y(t):0)+(i?y(i):0)+Math.max(6,12*c);return Math.max(16,40*c,a)}).id(e=>e.id),f=jr();if((void 0!==a.random||void 0!==a.seed)&&f.randomSource(a.random??fr(a.seed)),f.force("charge",Vr().strength(e=>{let r=t.get(e.id)??0;return-15*c*y(e)*Math.sqrt(r+1)})).force("collide",Ur(e=>y(e)+3*c).strength(.9).iterations(2)).force("center",Xr(l,s).strength(.8)).force("x",Yr(l).strength(u)).force("y",Gr(s).strength(u)).force("bounds",function(e,t,r=2,i=.6){let a=[],n=n=>{let o=i*Math.max(n,.2);for(let i of a){let a=i.x??e[0]/2,n=i.y??e[1]/2,l=i.vx??0,s=i.vy??0,c=t(i)+r,u=Math.min(e[0]/2,c),d=Math.max(e[0]/2,e[0]-c),f=Math.min(e[1]/2,c),h=Math.max(e[1]/2,e[1]-c),g=a+l,m=n+s;u>g?i.vx=l+(u-g)*o:g>d&&(i.vx=l+(d-g)*o),f>m?i.vy=s+(f-m)*o:m>h&&(i.vy=s+(h-m)*o)}};return n.initialize=e=>{a=e},n}(n,y)),f.nodes(e),i.length>0){let e=i.map(e=>({...e,source:tr(e.source),target:tr(e.target)}));d.links(e),f.force("link",d)}g?f.alpha(.3):.1>f.alpha()&&f.alpha(1),f.stop();for(let e=0;m>e;++e)f.tick()}for(let t of e){if(null==t.x||null==t.y)continue;let e=y(t),r=m>0?2:0,i=Math.min(n[0]/2,e+r),a=Math.min(n[1]/2,e+r);t.x=Math.max(i,Math.min(n[0]-i,t.x)),t.y=Math.max(a,Math.min(n[1]-a,t.y)),t.x0=0,t.x1=0,t.y0=0,t.y1=0}let b=new Map;for(let t of e)b.set(t.id,t);for(let e of i){if("string"==typeof e.source){let t=b.get(e.source);t&&(e.source=t)}if("string"==typeof e.target){let t=b.get(e.target);t&&(e.target=t)}}},buildScene(t,r,i,a){let n=i.nodeStyle,o=i.edgeStyle,l=Jt(i.nodeSize,i.nodeSizeRange,t),s=Array.isArray(i.colorScheme)?i.colorScheme:i.themeCategorical&&i.themeCategorical.length>0?i.themeCategorical:Hr,c=new Map;t.forEach((e,t)=>{c.set(e.id,s[t%s.length])});let u=[],d=[],f=[];for(let r of t){if(null==r.x||null==r.y)continue;let t=l(e(r,"nodeSize")),a=n?n(e(r,"nodeStyle")):{},o={fill:a.fill||c.get(r.id)||i.themeSemantic?.primary||"#007bff",stroke:a.stroke||i.themeSemantic?.surface||"#fff",strokeWidth:a.strokeWidth??2,opacity:a.opacity,cursor:a.cursor};u.push({type:"circle",cx:r.x,cy:r.y,r:t,style:o,datum:r,id:r.id,label:r.id})}let h=new Map;for(let e of t)h.set(e.id,e);for(let t of r){let r="object"==typeof t.source?t.source:h.get(t.source),a="object"==typeof t.target?t.target:h.get(t.target);if(!r||!a||null==r.x||null==r.y||null==a.x||null==a.y)continue;let n=o?o(e(t,"edgeStyle")):{};d.push({type:"line",x1:r.x,y1:r.y,x2:a.x,y2:a.y,style:{stroke:n.stroke||i.themeSemantic?.border||i.themeSemantic?.secondary||"#999",strokeWidth:n.strokeWidth??1,opacity:n.opacity??.6,cursor:n.cursor},datum:t})}if(!1!==i.showLabels){let r=er(i.nodeLabel);for(let i of t){if(null==i.x||null==i.y)continue;let t=r?r(i):i.id;if(!t)continue;let a=l(e(i,"nodeSize"));f.push({x:i.x,y:i.y-a-4,text:t+"",anchor:"middle",baseline:"auto",fontSize:11})}}return{sceneNodes:u,sceneEdges:d,labels:f}}};Zt("force",Zr);import{useCallback as Jr,useMemo as ei,useState as ti}from"react";import{jsx as ri}from"react/jsx-runtime";Zt("force",Zr);var ii=_r(function(e,t){let r=zr(null);Ut(t,{variant:"network",frameRef:r});let i=Pr(e.mode,{width:e.width,height:e.height,enableHover:e.enableHover,showLegend:e.showLegend,showLabels:e.showLabels,title:e.title,description:e.description,accessibleTable:e.accessibleTable,summary:e.summary,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,responsiveRules:e.responsiveRules},{width:600,height:600}),{nodes:a,edges:l,margin:s,className:c,nodeIdAccessor:u,nodeIDAccessor:f,sourceAccessor:h="source",targetAccessor:g="target",nodeLabel:m,colorBy:p,colorScheme:y,styleRules:b,nodeSize:v=8,nodeSizeRange:k=[5,20],nodeStroke:x,nodeStrokeWidth:S,edgeWidth:w,edgeColor:M,edgeOpacity:P,iterations:L=300,forceStrength:T=.1,layoutExecution:A="auto",layoutLoadingContent:D,onLayoutStateChange:I,tooltip:E,frameProps:C={},onObservation:O,onClick:N,chartId:B,selection:$,linkedHover:H,loading:R,loadingContent:F,emptyContent:W,legendInteraction:_,legendPosition:z,stroke:j,strokeWidth:X,opacity:Y}=e,G=u??f??"id",{width:q,height:V,enableHover:U,showLegend:Q,showLabels:K=!1,title:Z,description:J,summary:ee,accessibleTable:te}=i,re=d({nodes:a,edges:l,inferNodes:!1,nodeIdAccessor:G,sourceAccessor:h,targetAccessor:g,colorBy:p,colorScheme:y,showLegend:Q,legendPosition:z,legendInteraction:_,frameLegend:C,selection:$,linkedHover:H,onObservation:O,onClick:N,mobileInteraction:i.mobileInteraction,mobileSemantics:i.mobileSemantics,chartType:"ForceDirectedGraph",chartId:B,marginDefaults:i.marginDefaults,userMargin:s,width:q,height:V,hasTitle:!!Z,loading:R,loadingContent:F,emptyContent:W,emptyDataKey:"nodes"}),ie=Wr(()=>new Map,[]),ae=Wr(()=>e=>{let t={};return t.fill=p?Br(e.data||e,p,re.colorScale):xr(void 0,re.themeCategorical,y,void 0,ie),"number"==typeof v&&(t.r=v),t},[p,re.colorScale,v,re.themeCategorical,y,ie]),ne=Wr(()=>mr(p,"number"==typeof v?void 0:v),[p,v]),oe=Wr(()=>ar(dr(ae,b,ne,e=>e.data||e),{stroke:x??j,strokeWidth:S??X,opacity:Y}),[ae,b,ne,x,j,S,X,Y]),le=Wr(()=>n(oe,re.effectiveSelectionHook,re.resolvedSelection),[oe,re.effectiveSelectionHook,re.resolvedSelection]),se=M??j??"#999",ce=P??Y??.6,ue=X??1,de=Wr(()=>e=>{let t,r=e.data||e;if(void 0===w)t=ue;else if("number"==typeof w)t=w;else if("function"==typeof w)t=w(r);else{let e=r[w],i="number"==typeof e?e:Number(e);t=Number.isFinite(i)&&i>0?i:ue}return{stroke:se,strokeWidth:t,opacity:ce}},[w,se,ce,ue]),fe=Wr(()=>o(de,re.effectiveSelectionHook,re.resolvedSelection),[de,re.effectiveSelectionHook,re.resolvedSelection]),he=Wr(()=>{if(K&&m)return"function"==typeof m?m:e=>e.data?.[m]??e[m]??e.id},[K,m]),ge=qt({componentName:"ForceDirectedGraph",nodes:a,edges:l,nodesRequired:!0,edgesRequired:!0,accessors:{nodeIDAccessor:G}});return ge?ri(lr,{componentName:"ForceDirectedGraph",message:ge,width:q,height:V}):re.loadingEl?re.loadingEl:re.emptyEl?re.emptyEl:ri(cr,{componentName:"ForceDirectedGraph",width:q,height:V,children:ri(Kt,{ref:r,chartType:"force",...null!=a&&{nodes:re.safeNodes},...null!=l&&{edges:re.safeEdges},size:[q,V],responsiveWidth:e.responsiveWidth,responsiveHeight:e.responsiveHeight,maxDevicePixelRatio:e.maxDevicePixelRatio,margin:re.margin,...re.legendBehaviorProps,nodeIDAccessor:G,sourceAccessor:h,targetAccessor:g,iterations:L,forceStrength:T,layoutExecution:A,layoutLoadingContent:D,onLayoutStateChange:I,nodeStyle:le,edgeStyle:fe,colorBy:p,colorScheme:re.effectivePalette,nodeSize:v,nodeSizeRange:k,nodeLabel:he,showLabels:K,enableHover:U,tooltipContent:!1===E?()=>null:pr(E)||void 0,...ir({linkedHover:H,selection:$,onObservation:O,onClick:N,mobileInteraction:re.mobileInteraction,customHoverBehavior:re.customHoverBehavior,customClickBehavior:re.customClickBehavior,linkedHoverInClickPredicate:!1}),legend:re.legend,legendPosition:re.legendPosition,..._&&"none"!==_&&{legendHoverBehavior:re.legendState.onLegendHover,legendClickBehavior:re.legendState.onLegendClick,legendHighlightedCategory:re.legendState.highlightedCategory,legendIsolatedCategories:re.legendState.isolatedCategories},className:c,title:Z,description:J,summary:ee,accessibleTable:te,...null!=e.animate&&{animate:e.animate},...C})})});ii.displayName="ForceDirectedGraph";import{useMemo as ai,forwardRef as ni,useRef as oi}from"react";import{chord as li,ribbon as si}from"d3-chord";import{arc as ci}from"d3-shape";var ui=Hr,di={supportsStreaming:!1,hierarchical:!1,computeLayout(e,t,r,i){if(0===e.length)return;let{padAngle:a=.01,groupWidth:n=20,sortGroups:o}=r,l=Math.min(i[0],i[1])/2,s=l-n,c=i[0]/2,u=i[1]/2,d=(h=r.valueAccessor)?"function"==typeof h?h:e=>e[h]??1:e=>e.value??1,f=new Map;var h;for(let t=0;e.length>t;t++)f.set(e[t].id,t);let g=e.length,m=Array.from({length:g},()=>Array(g).fill(0));for(let e of t){let t=tr(e.source),r=tr(e.target),i=f.get(t),a=f.get(r);if(void 0===i||void 0===a)continue;let n=d(e);m[i][a]=n}let p=li().padAngle(a);o&&p.sortGroups(o);let y=p(m),b=y.groups,v=ci().innerRadius(s).outerRadius(l);for(let t of b){let r=e[t.index],i=v.centroid({innerRadius:s,outerRadius:l,startAngle:t.startAngle,endAngle:t.endAngle});r.x=i[0]+c,r.y=i[1]+u,r.__arcData={startAngle:t.startAngle,endAngle:t.endAngle}}let k=new Map;for(let t of e)k.set(t.id,t);for(let e of t){let t=tr(e.source),r=tr(e.target),i=k.get(t),a=k.get(r);i&&(e.source=i),a&&(e.target=a)}let x=new Map;for(let e of t){let t=tr(e.source),r=tr(e.target);x.set(`${t}\0${r}`,e)}for(let t of y){let r=e[t.source.index].id,i=e[t.target.index].id,a=x.get(`${r}\0${i}`)||x.get(`${i}\0${r}`);a&&(a.__chordData=t)}},buildScene(t,r,i,a){let{groupWidth:n=20,edgeOpacity:o=.5}=i,l=Math.min(a[0],a[1])/2,s=l-n,c=a[0]/2,u=a[1]/2,d=i.nodeStyle,h=i.edgeStyle,g=i.edgeColorBy||"source",m=Array.isArray(i.colorScheme)?i.colorScheme:i.themeCategorical&&i.themeCategorical.length>0?i.themeCategorical:ui,p=new Map;t.forEach((e,t)=>{p.set(e.id,m[t%m.length])});let y=si().radius(s),b=[],v=[],k=[];for(let r=0;t.length>r;r++){let i=t[r],a=i.__arcData;if(!a)continue;let n=d?d(e(i,"nodeStyle")):{},o={fill:("string"==typeof n.fill?n.fill:void 0)||p.get(i.id)||m[r%m.length],stroke:n.stroke||"black",strokeWidth:n.strokeWidth??1,opacity:n.opacity,cursor:n.cursor};b.push({type:"arc",cx:c,cy:u,innerR:s,outerR:l,startAngle:a.startAngle-Math.PI/2,endAngle:a.endAngle-Math.PI/2,style:o,datum:i,id:i.id,label:i.id})}for(let t of r){let r=t.__chordData;if(!r)continue;let a=y(r);if(!a)continue;let n=f(a,c,u),l=i.themeSemantic?.border||i.themeSemantic?.secondary||"#999",s=h?h(e(t,"edgeStyle")):{};if(h)l=("string"==typeof s.fill?s.fill:void 0)||l;else{let e="object"==typeof t.source?t.source:null,r="object"==typeof t.target?t.target:null;"target"===g&&r?l=p.get(r.id)||l:e&&(l=p.get(e.id)||l)}v.push({type:"ribbon",pathD:n,style:{fill:l,fillOpacity:s.fillOpacity??o,stroke:s.stroke||"none",strokeWidth:s.strokeWidth,opacity:s.opacity,cursor:s.cursor},datum:t})}if(!1!==i.showLabels){let e=er(i.nodeLabel),r=l+12;for(let i of t){let t=i.__arcData;if(!t)continue;let a=e?e(i):i.id;if(!a)continue;let n=(t.startAngle+t.endAngle)/2,o=n-Math.PI/2;k.push({x:c+Math.cos(o)*r,y:u+Math.sin(o)*r,text:a+"",anchor:n>Math.PI?"end":"start",baseline:"middle",fontSize:11})}}return{sceneNodes:b,sceneEdges:v,labels:k}}};Zt("chord",di);import{jsx as fi}from"react/jsx-runtime";Zt("chord",di);var hi=ni(function(e,t){let r=oi(null);Ut(t,{variant:"network",frameRef:r,overrides:{getData:()=>r.current?.getTopology()?.edges?.map(e=>e.data)??[]}});let i=Pr(e.mode,{width:e.width,height:e.height,enableHover:e.enableHover,showLegend:e.showLegend,showLabels:e.showLabels,title:e.title,description:e.description,accessibleTable:e.accessibleTable,summary:e.summary,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,responsiveRules:e.responsiveRules},{width:600,height:600}),{nodes:a,edges:l,margin:s,className:c,sourceAccessor:f="source",targetAccessor:h="target",valueAccessor:g="value",nodeIdAccessor:m="id",colorBy:p,colorScheme:y,styleRules:b,edgeColorBy:v="source",padAngle:k=.01,groupWidth:x=20,sortGroups:S,nodeLabel:w,edgeOpacity:M=.5,tooltip:P,frameProps:L={},onObservation:T,onClick:A,chartId:D,selection:I,linkedHover:E,loading:C,loadingContent:O,emptyContent:N,legendPosition:B,legendInteraction:$,stroke:H,strokeWidth:R,opacity:F}=e,{width:W,height:_,enableHover:z,showLegend:j,showLabels:X=!0,title:Y,description:G,summary:q,accessibleTable:V}=i,U=d({nodes:a,edges:l,inferNodes:!0,nodeIdAccessor:m,sourceAccessor:f,targetAccessor:h,colorBy:p,colorScheme:y,showLegend:j,legendPosition:B,legendInteraction:$,frameLegend:L,selection:I,linkedHover:E,onObservation:T,onClick:A,mobileInteraction:i.mobileInteraction,mobileSemantics:i.mobileSemantics,chartType:"ChordDiagram",chartId:D,marginDefaults:i.marginDefaults,userMargin:s,width:W,height:_,hasTitle:!!Y,loading:C,loadingContent:O,emptyContent:N}),Q=ai(()=>new Map,[]),K=ai(()=>new Map,[]),Z=U.safeNodes.length>0||U.allCategories.length>0,J=ai(()=>{if(Z)return(e,t)=>{let r={stroke:"black",strokeWidth:1};if(p)r.fill=Br(e.data||e,p,U.colorScale);else{let i=Array.isArray(y)?y:Er[y]||Cr,a=Array.isArray(i)?i:Cr,n=(e.id??e.data?.[m]??"")+"";K.has(n)||K.set(n,K.size);let o=e.index??t??K.get(n);r.fill=a[o%a.length]}return r}},[Z,p,U.colorScale,y,m,K]),ee=ai(()=>mr(p),[p]),te=ai(()=>{if(J||b&&b.length>0)return ar(dr(J,b,ee,e=>e.data||e),{stroke:H,strokeWidth:R,opacity:F})},[J,b,ee,H,R,F]),re=ai(()=>n(te,U.effectiveSelectionHook,U.resolvedSelection),[te,U.effectiveSelectionHook,U.resolvedSelection]),ie=ai(()=>{if(Z)return u({edgeColorBy:v,colorBy:p,colorScale:U.colorScale,nodeStyleFn:re||(e=>({fill:xr(void 0,U.themeCategorical,y,void 0,Q)})),edgeOpacity:M,baseStyle:{stroke:"black",strokeWidth:.5,strokeOpacity:M}})},[Z,v,p,U.colorScale,re,M,U.themeCategorical,y,Q]),ae=ai(()=>ie?ar(ie,{stroke:H,strokeWidth:R,opacity:F}):void 0,[ie,H,R,F]),ne=ai(()=>o(ae,U.effectiveSelectionHook,U.resolvedSelection),[ae,U.effectiveSelectionHook,U.resolvedSelection]),oe=ai(()=>{if(!X)return;let e=w||m;return"function"==typeof e?e:t=>t.data?.[e]??t[e]??t.id},[X,w,m]),le=qt({componentName:"ChordDiagram",edges:l,edgesRequired:!0});return le?fi(lr,{componentName:"ChordDiagram",message:le,width:W,height:_}):U.loadingEl?U.loadingEl:U.emptyEl?U.emptyEl:fi(cr,{componentName:"ChordDiagram",width:W,height:_,children:fi(Kt,{ref:r,chartType:"chord",...U.safeNodes.length>0&&{nodes:U.safeNodes},...null!=l&&{edges:U.safeEdges},size:[W,_],responsiveWidth:e.responsiveWidth,responsiveHeight:e.responsiveHeight,maxDevicePixelRatio:e.maxDevicePixelRatio,margin:U.margin,...U.legendBehaviorProps,nodeIDAccessor:m,sourceAccessor:f,targetAccessor:h,valueAccessor:g,padAngle:k,groupWidth:x,sortGroups:S,nodeStyle:re,edgeStyle:ne,colorBy:p,colorScheme:U.effectivePalette,edgeColorBy:v,edgeOpacity:M,nodeLabel:oe,showLabels:X,enableHover:z,tooltipContent:!1===P?()=>null:pr(P)||void 0,...ir({linkedHover:E,selection:I,onObservation:T,onClick:A,mobileInteraction:U.mobileInteraction,customHoverBehavior:U.customHoverBehavior,customClickBehavior:U.customClickBehavior,linkedHoverInClickPredicate:!1}),legend:U.legend,legendPosition:U.legendPosition,...$&&"none"!==$&&{legendHoverBehavior:U.legendState.onLegendHover,legendClickBehavior:U.legendState.onLegendClick,legendHighlightedCategory:U.legendState.highlightedCategory,legendIsolatedCategories:U.legendState.isolatedCategories},className:c,title:Y,description:G,summary:q,accessibleTable:V,...null!=e.animate&&{animate:e.animate},...L})})});hi.displayName="ChordDiagram";import{useMemo as gi,forwardRef as mi,useRef as pi}from"react";import{min as yi}from"d3-array";import{min as bi,max as vi,sum as ki,mean as xi,group as Si,groups as wi}from"d3-array";import{interpolateNumber as Mi}from"d3-interpolate";import{line as Pi,curveLinearClosed as Li}from"d3-shape";var Ti=e=>{let t,r,i,a,n,o,l,s,c;if("down"===e.direction)return t=e.y0-e.sankeyWidth/2,r=e.y1-e.sankeyWidth/2,i=e.y1+e.sankeyWidth/2,a=e.y0+e.sankeyWidth/2,n=e.source.x1,o=e.target.x0,l=Mi(n,o),s=l(.5),c=l(.5),`M${t},${n}C${t},${s} ${r},${c} ${r},${o}L${i},${o}C${i},${c} ${a},${s} ${a},${n}Z`;let u=e.sankeyWidth/2,d=Mi(e.source.x1,e.target.x0),{pathD:f}=Z({sx:e.source.x1,sTop:e.y0-u,sBot:e.y0+u,tx:e.target.x0,tTop:e.y1-u,tBot:e.y1+u,cp1X:d(.5),cp2X:d(.5)});return f},Ai={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(A))-1:0},justify:D},Di={supportsStreaming:!0,hierarchical:!1,computeLayout(e,t,r,i){if(0===e.length)return;let a,n="vertical"===r.orientation?"down":"right",o=r.nodeAlign||"justify",l=r.nodeWidth??15,s=r.nodePaddingRatio??.05,c=r.iterations??100,u=e.map(e=>({...e})),d=t.map(e=>({...e,source:tr(e.source),target:tr(e.target),value:Math.sqrt(Math.max(1,e.value||1))}));a="down"===n?[[0,0],[i[1],i[0]]]:[[0,0],[i[0],i[1]]];let f=K().extent(a).links(d).nodes(u).nodeAlign(Ai[o]||D).nodeId(e=>e.id).nodeWidth(l).iterations(c);f.nodePaddingRatio&&f.nodePaddingRatio(s),f();{let e=1/0,t=-1/0,r=1/0,a=-1/0;for(let i of u)e>i.x0&&(e=i.x0),i.x1>t&&(t=i.x1),r>i.y0&&(r=i.y0),i.y1>a&&(a=i.y1);for(let i of d){if(!i.circular||!i.circularPathData)continue;let n=i.circularPathData,o=(i._circularWidth??i.width??0)/2;e>n.leftFullExtent-o&&(e=n.leftFullExtent-o),n.rightFullExtent+o>t&&(t=n.rightFullExtent+o),r>n.verticalFullExtent-o&&(r=n.verticalFullExtent-o),n.verticalFullExtent+o>a&&(a=n.verticalFullExtent+o)}let n=t-e,o=a-r,l=i[0],s=i[1];if(n>0&&o>0&&(0>e||0>r||t>l||a>s)){let t=Math.min(l/n,s/o),i=-e*t+(l-n*t)/2,a=-r*t+(s-o*t)/2;for(let e of u)e.x0=e.x0*t+i,e.x1=e.x1*t+i,e.y0=e.y0*t+a,e.y1=e.y1*t+a;for(let e of d)if(e.y0=e.y0*t+a,e.y1=e.y1*t+a,e.width=(e.width??0)*t,e._circularWidth&&(e._circularWidth*=t),e.circular&&e.circularPathData){let r=e.circularPathData;r.sourceX=r.sourceX*t+i,r.targetX=r.targetX*t+i,r.sourceY=r.sourceY*t+a,r.targetY=r.targetY*t+a,r.rightFullExtent=r.rightFullExtent*t+i,r.leftFullExtent=r.leftFullExtent*t+i,r.verticalFullExtent=r.verticalFullExtent*t+a,r.rightInnerExtent=r.rightInnerExtent*t+i,r.leftInnerExtent=r.leftInnerExtent*t+i,r.verticalRightInnerExtent=r.verticalRightInnerExtent*t+a,r.verticalLeftInnerExtent=r.verticalLeftInnerExtent*t+a,r.rightSmallArcRadius*=t,r.rightLargeArcRadius*=t,r.leftSmallArcRadius*=t,r.leftLargeArcRadius*=t,r.sourceWidth*=t,r.rightNodeBuffer*=t,r.leftNodeBuffer*=t,r.arcRadius*=t}}}let h=new Map;for(let t of e)h.set(t.id,t);for(let e of u){let t=h.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)}let g=new Map;for(let e of t)if(e._edgeKey)g.set(e._edgeKey,e);else{let t=tr(e.source),r=tr(e.target);g.set(`${t}\0${r}`,e)}for(let e of d){let t=tr(e.source),r=tr(e.target),i=g.get(e._edgeKey?e._edgeKey:`${t}\0${r}`);if(i){i.y0=e.y0,i.y1=e.y1,i.sankeyWidth=e.width??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=n;let a=h.get(t),o=h.get(r);a&&(i.source=a),o&&(i.target=o)}}},buildScene(t,r,i,a){let n="vertical"===i.orientation?"down":"right",o=i.nodeStyle,l=i.edgeStyle,s=i.edgeOpacity??.5,c=i.edgeColorBy||"source",u=Array.isArray(i.colorScheme)?i.colorScheme:i.themeCategorical&&i.themeCategorical.length>0?i.themeCategorical:Hr,d=new Map;t.forEach((e,t)=>{d.set(e.id,u[t%u.length])});let f=[],h=[],g=[],m=new Map;for(let r of t){let t=r.x1-r.x0,i=r.y1-r.y0;if(0>=t||0>=i)continue;let a=o?o(e(r,"nodeStyle")):{},l={fill:a.fill||d.get(r.id)||"#4d430c",stroke:a.stroke,strokeWidth:a.strokeWidth,opacity:a.opacity,cursor:a.cursor};m.set(r.id,("string"==typeof l.fill?l.fill:null)||d.get(r.id)||"#4d430c"),f.push("down"===n?{type:"rect",x:r.y0,y:r.x0,w:i,h:t,style:l,datum:r,id:r.id,label:r.id}:{type:"rect",x:r.x0,y:r.y0,w:t,h:i,style:l,datum:r,id:r.id,label:r.id})}let p=[...r].sort((e,t)=>(t.sankeyWidth||0)-(e.sankeyWidth||0));for(let t of p){if(!t.sankeyWidth||0>=t.sankeyWidth)continue;let r="object"==typeof t.source?t.source:null,a="object"==typeof t.target?t.target:null;if(!r||!a)continue;let n=i.themeSemantic?.border||i.themeSemantic?.secondary||"#999";n="function"==typeof c?c(t)||n:"target"===c?m.get(a.id)||d.get(a.id)||n:m.get(r.id)||d.get(r.id)||n;let o,u=l?l(e(t,"edgeStyle")):{};if(t._circularStub&&t.circular&&t.circularPathData){let e=t.circularPathData,r=t.sankeyWidth/2,i=Math.max(15,Math.min(40,.33*(e.rightFullExtent-e.sourceX))),a=Math.max(15,Math.min(40,.33*(e.targetX-e.leftFullExtent))),o=u.fill||n;h.push({type:"bezier",pathD:`M${e.sourceX},${e.sourceY-r}L${e.sourceX+i},${e.sourceY-r}L${e.sourceX+i},${e.sourceY+r}L${e.sourceX},${e.sourceY+r}Z`,style:{fill:o,fillOpacity:u.fillOpacity??s,stroke:"none",opacity:u.opacity,cursor:u.cursor},datum:t,_gradient:{direction:"right",from:1,to:0,x0:e.sourceX,x1:e.sourceX+i}}),h.push({type:"bezier",pathD:`M${e.targetX},${e.targetY-r}L${e.targetX-a},${e.targetY-r}L${e.targetX-a},${e.targetY+r}L${e.targetX},${e.targetY+r}Z`,style:{fill:o,fillOpacity:u.fillOpacity??s,stroke:"none",opacity:u.opacity,cursor:u.cursor},datum:t,_gradient:{direction:"left",from:0,to:1,x0:e.targetX-a,x1:e.targetX}});continue}o=t.circular&&t.circularPathData?J(t):Ti(t),o&&h.push({type:"bezier",pathD:o,bezierCache:t.bezier,style:{fill:u.fill||n,fillOpacity:u.fillOpacity??s,stroke:u.stroke||"none",strokeWidth:u.strokeWidth,opacity:u.opacity,cursor:u.cursor},datum:t})}if(!1!==i.showLabels){let e=er(i.nodeLabel);for(let r of t){let t=r.x1-r.x0,i=r.y1-r.y0;if(0>=t||0>=i)continue;let o,l,s,c=e?e(r):r.id;c&&("down"===n?(o=r.y0+(r.y1-r.y0)/2,l=r.x1+14,s="start"):(a[0]/2>r.x0+t/2?(o=r.x0-6,s="end"):(o=r.x1+6,s="start"),l=r.y0+i/2),g.push({x:o,y:l,text:c+"",anchor:"down"===n?"middle":s,baseline:"middle",fontSize:11}))}}return{sceneNodes:f,sceneEdges:h,labels:g}}};Zt("sankey",Di);import{jsx as Ii}from"react/jsx-runtime";Zt("sankey",Di);var Ei=mi(function(e,t){let r=pi(null);Ut(t,{variant:"network",frameRef:r,overrides:{getData:()=>r.current?.getTopology()?.edges?.map(e=>e.data)??[]}});let i=Pr(e.mode,{width:e.width,height:e.height,enableHover:e.enableHover,showLabels:e.showLabels,title:e.title,description:e.description,accessibleTable:e.accessibleTable,summary:e.summary,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,responsiveRules:e.responsiveRules},{width:800,height:600}),{nodes:a,edges:l,margin:s,className:c,sourceAccessor:f="source",targetAccessor:h="target",valueAccessor:g="value",nodeIdAccessor:m="id",colorBy:p,colorScheme:y,styleRules:b,edgeColorBy:v="source",orientation:k="horizontal",nodeAlign:x="justify",nodePaddingRatio:S=.05,nodeWidth:w=15,nodeLabel:M,edgeOpacity:P=.5,edgeSort:L,tooltip:T,frameProps:A={},onObservation:D,onClick:I,chartId:E,selection:C,linkedHover:O,loading:N,loadingContent:B,emptyContent:$,showLegend:H,legendPosition:R,legendInteraction:F,stroke:W,strokeWidth:_,opacity:z}=e,{width:j,height:X,enableHover:Y,showLabels:G=!0,title:q,description:V,summary:U,accessibleTable:Q}=i,K=d({nodes:a,edges:l,inferNodes:!0,nodeIdAccessor:m,sourceAccessor:f,targetAccessor:h,colorBy:p,colorScheme:y,showLegend:H,legendPosition:R,legendInteraction:F,frameLegend:A,selection:C,linkedHover:O,onObservation:D,onClick:I,mobileInteraction:i.mobileInteraction,mobileSemantics:i.mobileSemantics,chartType:"SankeyDiagram",chartId:E,marginDefaults:i.marginDefaults,userMargin:s,width:j,height:X,hasTitle:!!q,loading:N,loadingContent:B,emptyContent:$}),Z=gi(()=>new Map,[]),J=gi(()=>e=>{let t={stroke:"black",strokeWidth:1};return t.fill=p?Br(e.data||e,p,K.colorScale):xr(void 0,K.themeCategorical,y,void 0,Z),t},[p,K.colorScale,K.themeCategorical,y,Z]),ee=gi(()=>mr(p,g),[p,g]),te=gi(()=>ar(dr(J,b,ee,e=>e.data||e),{stroke:W,strokeWidth:_,opacity:z}),[J,b,ee,W,_,z]),re=gi(()=>n(te,K.effectiveSelectionHook,K.resolvedSelection),[te,K.effectiveSelectionHook,K.resolvedSelection]),ie=gi(()=>u({edgeColorBy:v,colorBy:p,colorScale:K.colorScale,nodeStyleFn:re,edgeOpacity:P,baseStyle:{stroke:"none",strokeWidth:0}}),[v,p,K.colorScale,re,P]),ae=gi(()=>ar(ie,{stroke:W,strokeWidth:_,opacity:z}),[ie,W,_,z]),ne=gi(()=>o(ae,K.effectiveSelectionHook,K.resolvedSelection),[ae,K.effectiveSelectionHook,K.resolvedSelection]),oe=gi(()=>{if(!G)return;let e=M||m;return"function"==typeof e?e:t=>t.data?.[e]??t[e]??t.id},[G,M,m]),le=qt({componentName:"SankeyDiagram",edges:l,edgesRequired:!0});return le?Ii(lr,{componentName:"SankeyDiagram",message:le,width:j,height:X}):K.loadingEl?K.loadingEl:K.emptyEl?K.emptyEl:Ii(cr,{componentName:"SankeyDiagram",width:j,height:X,children:Ii(Kt,{ref:r,chartType:"sankey",...K.safeNodes.length>0&&{nodes:K.safeNodes},...null!=l&&{edges:K.safeEdges},size:[j,X],responsiveWidth:e.responsiveWidth,responsiveHeight:e.responsiveHeight,maxDevicePixelRatio:e.maxDevicePixelRatio,margin:K.margin,...K.legendBehaviorProps,nodeIDAccessor:m,sourceAccessor:f,targetAccessor:h,valueAccessor:g,orientation:k,nodeAlign:x,nodePaddingRatio:S,nodeWidth:w,nodeStyle:re,edgeStyle:ne,colorBy:p,colorScheme:K.effectivePalette,edgeColorBy:v,edgeOpacity:P,edgeSort:L,nodeLabel:oe,showLabels:G,enableHover:Y,tooltipContent:!1===T?()=>null:pr(T)||void 0,...ir({linkedHover:O,selection:C,onObservation:D,onClick:I,mobileInteraction:K.mobileInteraction,customHoverBehavior:K.customHoverBehavior,customClickBehavior:K.customClickBehavior,linkedHoverInClickPredicate:!1}),legend:K.legend,legendPosition:K.legendPosition,...F&&"none"!==F&&{legendHoverBehavior:K.legendState.onLegendHover,legendClickBehavior:K.legendState.onLegendClick,legendHighlightedCategory:K.legendState.highlightedCategory,legendIsolatedCategories:K.legendState.isolatedCategories},className:c,title:q,description:V,summary:U,accessibleTable:Q,...null!=e.animate&&{animate:e.animate},...A})})});Ei.displayName="SankeyDiagram";var Ci={static:{duplicateIds:"fatal",invalidSystemTime:"warn"},mcp:{duplicateIds:"fatal",invalidSystemTime:"warn"},push:{duplicateIds:"warn",invalidSystemTime:"strip"}},Oi=new Set(["invalid-domain","missing-node","backward-edge","invalid-edge-time","invalid-value","invalid-node-time"]),Ni=8,Bi=.92,$i=3,Hi=e=>{let t=1;for(let r=2;e>=r;r++)t*=r;return t},Ri=828*Hi(8),Fi=3e3,Wi=new Map,_i=1e5,zi=1e-9;import{forwardRef as ji,useMemo as Xi,useRef as Yi,useCallback as Gi,useEffect as qi}from"react";import{Fragment as Vi,jsx as Ui,jsxs as Qi}from"react/jsx-runtime";var Ki="var(--semiotic-grid, #94a3b8)",Zi="var(--semiotic-text-secondary, #475569)",Ji="var(--semiotic-text-secondary, #94a3b8)";import{useEffect as ea,useMemo as ta,useRef as ra,useState as ia}from"react";import{scaleTime as aa}from"d3-scale";import{scaleTime as na}from"d3-scale";var oa=/(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?),(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)/gi;import{scaleTime as la}from"d3-scale";var sa=class{constructor(e=function(){let e="string"==typeof import.meta.url&&import.meta.url?new URL("./processSankeyLayoutWorker.js",import.meta.url):or("processSankeyLayoutWorker.js");return new Worker(e,{type:"module",name:"semiotic-process-sankey-layout"})}()){this.session=new zt({name:"ProcessSankey layout",createWorker:()=>e,parseMessage:e=>{let t=e,{requestId:r,error:i}=Yt(t);return i?{requestId:r,ok:!1,error:Xt(i)}:{requestId:r,ok:!0,payload:{layout:bt(t.layout),layoutConfig:t.layoutConfig??{bands:[],ribbons:[],showLabels:!0},issues:t.issues??[],warnings:t.warnings??[],domain:t.domain??[0,1],timelineExtent:t.timelineExtent??0}}}})}get isDead(){return this.session.isDead}request(e,t){return this.session.request(e,t)}terminate(){this.session.terminate()}},ca=jt(()=>new sa),ua=(e,t)=>({layout:null,layoutConfig:{bands:[],ribbons:[],showLabels:!0},issues:[],warnings:[],xScale:aa().domain(e).range([0,t])});import{useCallback as da,useMemo as fa,useRef as ha,useState as ga}from"react";import{useCallback as ma,useMemo as pa}from"react";var ya=e=>{let{bands:t=[],ribbons:r=[],showLabels:i=!0,selectionDatum:a="raw"}=e.config,n=e.selection??null,o=[];for(let e of r){let t={__kind:"ribbon",data:e.rawDatum,id:e.id},r=!Pt(t,n,a);o.push({type:"bezier",pathD:e.pathD,...e.bezier&&{bezierCache:e.bezier},style:{fill:e.fill,opacity:r?Math.min(e.opacity,.22):e.opacity,stroke:"none"},datum:t})}for(let e of t){if(!e.gradientStubs)continue;let t=!Pt({__kind:"band",data:e.rawDatum,id:e.id},n,a);for(let r=0;e.gradientStubs.length>r;r++){let i=e.gradientStubs[r];o.push({type:"bezier",pathD:i.pathD,interactive:!1,style:{fill:e.fill,fillOpacity:t?.22:e.fillOpacity??.86,stroke:"none"},_gradient:{x0:i.x0,x1:i.x1,...null!=i.y0&&{y0:i.y0},...null!=i.y1&&{y1:i.y1},from:i.from,to:i.to},datum:{__kind:"band",data:e.rawDatum,id:`${e.id}__stub${r}`}})}}for(let e of t){let t=!(!e.gradientStubs||0>=e.gradientStubs.length),r={__kind:"band",data:e.rawDatum,id:e.id},i=!Pt(r,n,a);o.push({type:"bezier",pathD:e.pathD,style:{...t?{fill:"none"}:{fill:e.hatchFill??e.fill,fillOpacity:i?.22:e.fillOpacity??.86},stroke:e.stroke??("string"==typeof e.fill?e.fill:"#666"),strokeWidth:e.strokeWidth??.5,...i&&t?{opacity:.22}:{}},datum:r})}let l=i?t.flatMap(e=>{let t=e.labelDeferred&&e.labelFullText?.trim(),r=e.labelText.trim().length>0,i=t&&n?.isActive&&Pt({__kind:"band",data:e.rawDatum,id:e.id},n,a),o=r?e.labelText:i?e.labelFullText:"";return o.trim()?[{x:e.labelX,y:e.labelY,text:o,anchor:e.labelAnchor??"end",baseline:e.labelBaseline??"middle",fontSize:11,fontWeight:600}]:[]}):[];return{sceneNodes:t.map(e=>({type:"circle",id:e.id,cx:-1e4,cy:-1e4,r:0,style:{fill:e.fill},datum:{__kind:"band",data:e.rawDatum,id:e.id}})),sceneEdges:o,labels:l}};import{Fragment as ba,jsx as va,jsxs as ka}from"react/jsx-runtime";import{jsx as xa,jsxs as Sa}from"react/jsx-runtime";var wa=ji(function(e,t){let{nodes:r,edges:i,domain:a,axisTicks:n=[],nodeIdAccessor:o="id",nodeLabel:l,sourceAccessor:c="source",targetAccessor:u="target",valueAccessor:f="value",startTimeAccessor:h="startTime",endTimeAccessor:g="endTime",systemInTimeAccessor:m,systemOutTimeAccessor:p,xExtentAccessor:y="xExtent",groupBy:b,edgeIdAccessor:v="id",colorBy:k,colorScheme:x,showLegend:S,legendPosition:w="right",orientation:M="horizontal",pairing:P="temporal",packing:L="reuse",laneOrder:T="crossing-min",maxValueScale:A,lanePlacement:D="stack",nodeSizing:I="temporal",groupPadding:E=0,ribbonLane:C="both",ribbonMinRun:O=0,lifetimeMode:N="half",showLaneRails:B=!1,showQualityReadout:$=!1,showLabels:H=!0,labelPriorityAccessor:R,maxLabels:F,selectionDatum:W="raw",styleRules:_,layoutExecution:z="auto",layoutWorkerThreshold:j,layoutLoadingContent:X,onLayoutStateChange:Y,width:G=600,height:q=400,margin:V,title:U,description:Q,summary:K,accessibleTable:Z,responsiveWidth:J,responsiveHeight:ee,loading:te,loadingContent:re,emptyContent:ae,edgeOpacity:ne=.35,timeFormat:oe,valueFormat:le,tooltip:ce,enableHover:ue=!0,onObservation:de,onClick:fe,selection:he,linkedHover:ge,showParticles:me=!1,particleStyle:pe,chartId:ye,frameProps:be={}}=e,ve=Yi(null),ke=Yi(null),{rawNodes:xe,rawEdges:Se,frameRef:we,getNodeId:Me,getEdgeId:Pe}=function(e){let{ref:t,rawNodesProp:r,rawEdgesProp:i,nodeIdAccessor:a,edgeIdAccessor:n,sourceAccessor:o,targetAccessor:l,scalesRef:c,layoutSnapshotRef:u}=e,[d,f]=ga([]),[h,g]=ga([]),m=ha(d),p=ha(h);m.current=d,p.current=h;let y=da(e=>{m.current=e,f(e)},[]),b=da(e=>{p.current=e,g(e)},[]),v=void 0!==i,k=gr(v?i:d),x=fa(()=>{let e=gr(r??[]),t=h;if(0===e.length&&0===t.length)return s([],k,o,l);let i=new Set,n=[];for(let t of e){let e=Mt(a,t)+"";i.has(e)||(i.add(e),n.push(t))}for(let e of t){let t=Mt(a,e)+"";i.has(t)||(i.add(t),n.push(e))}let c=s([],k,o,l);for(let e of c)i.has(e.id)||(i.add(e.id),n.push(e));return n},[r,h,k,a,o,l]),S=ha(null),w=da((e,t)=>{let r=Mt(n,e);return null!=r?r+"":`${Mt(o,e)}-${Mt(l,e)}-${t}`},[n,o,l]),M=da(e=>{if(null==e)return!1;let t=e;return null!=Mt(o,t)&&null!=Mt(l,t)},[o,l]),P=da(e=>Mt(a,e)+"",[a]);return Ut(t,{variant:"network",frameRef:S,overrides:{push(e){if(M(e)){if(v)return void console.warn("ProcessSankey.push: edge ignored — `edges` prop is controlled.");y([...m.current,e])}else b([...p.current,e])},pushMany(e){let t=[],r=[];for(let i of e)M(i)?t.push(i):r.push(i);t.length>0&&(v?console.warn("ProcessSankey.pushMany: edges ignored — `edges` prop is controlled."):y([...m.current,...t])),r.length>0&&b([...p.current,...r])},remove(e){let t=new Set(Array.isArray(e)?e:[e]),r=[];if(!v){let e=m.current,i=[];for(let a=0;e.length>a;a++){let n=e[a];t.has(w(n,a))?r.push(n):i.push(n)}i.length!==e.length&&y(i)}let i=p.current,n=[];for(let e of i){let i=Mt(a,e)+"";t.has(i)?r.push(e):n.push(e)}return n.length!==i.length&&b(n),r},update(e,t){let r=new Set(Array.isArray(e)?e:[e]),i=[];if(!v){let e=!1,a=m.current.map((a,n)=>r.has(w(a,n))?(i.push(a),e=!0,t(a)):a);e&&y(a)}let n=!1,o=p.current.map(e=>{let o=Mt(a,e)+"";return r.has(o)?(i.push(e),n=!0,t(e)):e});return n&&b(o),i},clear(){v||y([]),b([]),S.current?.clear()},getData:()=>k??[],getScales:()=>c.current,getCustomLayout:()=>u.current}}),{rawNodes:x,rawEdges:k,frameRef:S,getNodeId:P,getEdgeId:w,isControlled:v}}({ref:t,rawNodesProp:r,rawEdgesProp:i,nodeIdAccessor:o,edgeIdAccessor:v,sourceAccessor:c,targetAccessor:u,scalesRef:ve,layoutSnapshotRef:ke}),{nodes:Le,edges:Te,domain:Ae,rawNodeById:De,rawEdgeById:Ie}=Xi(()=>{let e=(xe??[]).map(e=>{let t=Me(e),r=l?Mt(l,e):t,i={id:t,label:null==r?t:r+"",__raw:e},a=b?Mt(b,e):null;null!=a&&a+""!=""&&(i.group=a+"");let n=y?Mt(y,e):null;if(Array.isArray(n)&&2===n.length){let e=se(n[0]),t=se(n[1]);Number.isFinite(e)&&Number.isFinite(t)&&(i.xExtent=[e,t])}return i}),t=(Se??[]).map((e,t)=>{let r={id:Pe(e,t),source:Mt(c,e)+"",target:Mt(u,e)+"",value:Number(Mt(f,e)),startTime:se(Mt(h,e)),endTime:se(Mt(g,e)),__raw:e};if(m){let t=se(Mt(m,e));Number.isFinite(t)&&(r.systemInTime=t)}if(p){let t=se(Mt(p,e));Number.isFinite(t)&&(r.systemOutTime=t)}return r}),r=[se(a[0]),se(a[1])],i=new Map;for(let t of e)null!=t.__raw&&i.set(t.id,t.__raw);let n=new Map;for(let e of t)null!=e.__raw&&n.set(e.id,e.__raw);return{nodes:e,edges:t,domain:r,rawNodeById:i,rawEdgeById:n}},[xe,Se,a,Me,Pe,l,y,b,c,u,f,h,g,m,p]),Ee=d({nodes:xe,edges:Se,inferNodes:!1,nodeIdAccessor:o,sourceAccessor:c,targetAccessor:u,colorBy:k,colorScheme:x,showLegend:!1,legendPosition:w,frameLegend:be,selection:he,linkedHover:ge,onObservation:de,onClick:fe?(e,t)=>{Lt(e)?fe(e.data,t):fe(e,t)}:void 0,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,chartType:"ProcessSankey",chartId:ye,marginDefaults:lt(!!U,$,n.length>0,M),userMargin:V,width:G,height:q,hasTitle:!!U,loading:te,loadingContent:re,emptyContent:ae}),Ce=Object.hasOwn(be,"legend"),Oe=!Ce&&(S??!!k)&&!!k,Ne=Gi((e,t)=>{if(k&&xe){let t=De.get(e);if(t)return Br(t,k,Ee.colorScale)}return Ee.effectivePalette[t%Ee.effectivePalette.length]||"#475569"},[k,xe,De,Ee.colorScale,Ee.effectivePalette]),Be=Xi(()=>{if(!Oe||!k)return;let e=new Map;(xe??[]).forEach((t,r)=>{let i=Mt(k,t),a=null==i?"":i+"";!a||e.has(a)||e.set(a,{label:a,color:Ne(Me(t),r)})});let t=Array.from(e.values());return 0===t.length?void 0:{legendGroups:[{type:"fill",label:"",items:t,styleFn:e=>{let t=e.color||"#333";return{fill:t,stroke:t}}}]}},[Oe,k,xe,Ne,Me]),$e=Ce?be.legend:Be,He=Xi(()=>{let e={...Ee.margin};if($e){let t={...e};vr(e,{legend:$e,position:Ee.legendPosition,size:[G,q],hasTitle:!!U,legendLayout:be.legendLayout,minimumMargin:"right"===Ee.legendPosition||"left"===Ee.legendPosition?140:"top"===Ee.legendPosition?50:80}),ur(e,t,[G,q],Ee.legendPosition)}return e},[Ee.margin,Ee.legendPosition,$e,G,q,U,be.legendLayout]),Re=G-He.left-He.right,Fe=q-He.top-He.bottom,We="vertical"===M?Fe:Re,_e=wt(Xi(()=>Re>0&&Fe>0?{nodes:Le,edges:Te,domain:Ae,plotW:Re,plotH:Fe,orientation:M,ribbonLane:C,ribbonMinRun:O,edgeOpacity:"function"==typeof ne?e=>ne(e):ne,colorOf:Ne,showLabels:H,labelPriorityAccessor:R,maxLabels:F,selectionDatum:W,styleRules:_,usageMode:"push",colorBy:k,valueAccessor:f,layoutOpts:{pairing:P,packing:L,laneOrder:T,lifetimeMode:N,maxValueScale:A,lanePlacement:D,nodeSizing:I,groupPadding:E}}:null,[Le,Te,Ae,Re,Fe,M,C,O,ne,Ne,H,R,F,W,_,k,f,P,L,T,N,A,D,I,E]),{execution:z,workerThreshold:j,colorById:Xi(()=>Object.fromEntries(Le.map((e,t)=>[e.id,Ne(e.id,t)])),[Le,Ne]),fallbackPalette:Ee.effectivePalette,rawNodeById:De,rawEdgeById:Ie}),{issues:ze,warnings:je,layout:Xe,xScale:Ye}=_e,Ge=_e.layoutConfig,qe=_e.status;ve.current=Xe?{time:Ye,centerlines:Xe.centerlines}:{time:Ye},ke.current=Xe?{layout:Xe,nodes:Le,edges:Te,bands:Ge.bands,ribbons:Ge.ribbons,warnings:je,status:qe}:null;let Ve=Yi(Y);Ve.current=Y,qi(()=>{Ve.current?.(qe)},[qe]),qi(()=>{0!==je.length&&console.warn("ProcessSankey warnings:",je.map(ie).join("; "))},[je]);let Ue=void 0!==$e&&!Object.hasOwn(be,"margin"),Qe=function(e){let{tooltip:t,enableHover:r,layout:i,timeFormat:a,valueFormat:n,sourceAccessor:o,targetAccessor:l,valueAccessor:s,startTimeAccessor:c,endTimeAccessor:u}=e,d=pa(()=>!1!==t&&r&&void 0!==t&&!0!==t&&pr(t)||null,[t,r]),f=ma(e=>a?a(new Date(e)):Number.isFinite(e)?1e10>Math.abs(e)?Number.isInteger(e)?e+"":e.toFixed(2):new Date(e).toISOString().slice(0,10):"",[a]),h=ma(e=>n?n(e):e+"",[n]);return ma(e=>{if(!e||!e.data)return null;let t=e.data;if(!Lt(t))return null;let r=t.data;if(d)return d(r);if("band"===t.__kind){let e=t.id,r=i?function(e){if(!e)return[];let t=new Set,r=[];for(let i of e.samples){let e=i.topMass+i.botMass,a=`${i.t}:${e}`;t.has(a)||(t.add(a),r.push({t:i.t,total:e}))}return r}(i.nodeData[e]):[],a=5,n=r.length>a?r.length:null,o=function(e,t=5){if(t>=e.length)return e.slice();let r=[...e].sort((e,t)=>e.total-t.total),i=r.length-1,a=[{...r[0],mark:"min"},{...r[Math.floor(.25*i)],mark:"q25"},{...r[Math.floor(.5*i)],mark:"median"},{...r[Math.floor(.75*i)],mark:"q75"},{...r[i],mark:"max"}],n=new Set,o=[];for(let e of a)n.has(e.t)||(n.add(e.t),o.push(e));return o.sort((e,t)=>e.t-t.t)}(r,a);return ka("div",{style:{minWidth:160},children:[va("div",{style:{fontWeight:600,marginBottom:4},children:e}),o.length>0&&ka("table",{style:{borderCollapse:"collapse",fontSize:11,width:"100%"},children:[va("thead",{children:ka("tr",{style:{opacity:.6},children:[va("th",{style:{textAlign:"left",fontWeight:500,paddingRight:8},children:"Time"}),va("th",{style:{textAlign:"right",fontWeight:500},children:"Mass"}),null!=n&&va("th",{})]})}),va("tbody",{children:o.map((e,t)=>ka("tr",{children:[va("td",{style:{paddingRight:8},children:f(e.t)}),va("td",{style:{textAlign:"right"},children:h(e.total)}),null!=n&&va("td",{style:{textAlign:"right",paddingLeft:8,opacity:.55},children:e.mark})]},t))})]}),null!=n&&ka("div",{style:{marginTop:4,fontSize:10,opacity:.55},children:["showing ",o.length," of ",n," samples"]})]})}let a=r,n=Mt(o,a),g=Mt(l,a),m=Mt(s,a),p=Mt(c,a),y=Mt(u,a);return ka("div",{style:{minWidth:160},children:[ka("div",{style:{fontWeight:600,marginBottom:4},children:[n+""," → ",g+""]}),ka("div",{style:{display:"grid",gridTemplateColumns:"auto 1fr",columnGap:8,fontSize:11},children:[null!=m&&ka(ba,{children:[va("span",{style:{opacity:.6},children:"value"}),va("span",{style:{textAlign:"right"},children:h(Number(m))})]}),null!=p&&ka(ba,{children:[va("span",{style:{opacity:.6},children:"start"}),va("span",{style:{textAlign:"right"},children:f(se(p))})]}),null!=y&&ka(ba,{children:[va("span",{style:{opacity:.6},children:"end"}),va("span",{style:{textAlign:"right"},children:f(se(y))})]})]})]})},[i,d,f,h,o,l,s,c,u])}({tooltip:ce,enableHover:ue,layout:Xe,timeFormat:oe,valueFormat:le,sourceAccessor:c,targetAccessor:u,valueAccessor:f,startTimeAccessor:h,endTimeAccessor:g}),Ke=Xi(()=>{if(!Xe)return null;let e=je.map(e=>ie(e));return function(e){let t=e.layout,r=e.nodes,i=e.orientation,a=e.plotW,n=e.plotH,o=e.timelineExtent,l=e.axisTicks,s=e.showQualityReadout??!1,c=e.showLaneRails??!1,u=(e.warnings??[]).slice(0,3),d=e.timeFormat,f=e.colorOf,h=e.toTime,g=e.xScale,{centerlines:m,laneLifetime:p,nodeData:y,valueScale:b,compressedPadding:v,crossingsBefore:k,crossingsAfter:x,layoutQualityBefore:S,layoutQuality:w}=t,M=null,P=null;for(let e of r){let t=p[e.id];if(!t||null===t.start||null===t.end)continue;let r=g(t.start),i=g(t.end);(null===M||M>r)&&(M=r),(null===P||i>P)&&(P=i)}let L=e=>Math.max(0,Math.min(o,e)),T=L(M??0),A=Math.max(T,L(P??o)),D=l.map((e,t)=>({tick:e,index:t,coordinate:g(h(e.date))})).filter(({coordinate:e})=>e>=T-.5&&A+.5>=e),I=null!==(x??null)&&null!=S&&null!=w,E=s&&(I||u.length>0)?Qi("g",{fill:Ji,fontSize:10,textAnchor:"end",children:[I&&Qi(Vi,{children:[Qi("text",{x:a,y:-14,children:["crossings: ",k," → ",x," ","pixel length: ",Math.round(S.pixelLength)," → ",Math.round(w.pixelLength)]}),Qi("text",{x:a,y:-3,children:["transit: ",S.transitOcclusion.toFixed(1)," → ",w.transitOcclusion.toFixed(1)," ","lane use: ",Math.round(100*w.verticalUtilization),"%"]})]}),u.map((e,t)=>Qi("text",{x:a,y:I?10+11*t:11*t-3,fill:"var(--semiotic-warning, #b45309)",children:["warn: ",e]},"warn-"+t))]}):null,C=v?Ui("text",{x:a,y:"vertical"===i?-3:2,fontSize:10,fill:Ji,textAnchor:"end",children:"dense layout: lane gaps compressed"}):null,O=(e,t)=>f?f(e,t):Ki;return Qi("g","vertical"===i?{children:[E,C,D.map(({index:e,coordinate:t})=>Ui("line",{x1:0,y1:t,x2:a,y2:t,stroke:Ki,strokeOpacity:.15,strokeDasharray:"2 4"},"grid-"+e)),c&&r.map((e,t)=>{let r=p[e.id];if(!r||null===r.start)return null;let i=y[e.id],a=i?{topPeak:i.topPeak,botPeak:i.botPeak}:{topPeak:0,botPeak:0},n=m[e.id]+(a.botPeak-a.topPeak)*b/2,o=g(r.start),l=g(r.end),s=O(e.id,t);return Qi("g",{children:[Ui("line",{x1:n,y1:o,x2:n,y2:l,stroke:s,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),Ui("line",{x1:n-4,y1:o,x2:n+4,y2:o,stroke:s,strokeOpacity:.5}),Ui("line",{x1:n-4,y1:l,x2:n+4,y2:l,stroke:s,strokeOpacity:.5})]},"lane-"+e.id)}),Ui("line",{x1:-4,y1:T,x2:-4,y2:A,stroke:Ki}),D.map(({tick:e,index:t,coordinate:r})=>{let i=h(e.date),a=null!=e.label?e.label:d?d(new Date(i)):"";return Qi("g",{transform:`translate(-4,${r})`,children:[Ui("line",{x2:-6,stroke:Ki}),Ui("text",{x:-10,y:4,textAnchor:"end",fontSize:11,fill:Zi,children:a})]},t)})]}:{children:[E,C,D.map(({index:e,coordinate:t})=>Ui("line",{x1:t,y1:0,x2:t,y2:n,stroke:Ki,strokeOpacity:.15,strokeDasharray:"2 4"},"grid-"+e)),c&&r.map((e,t)=>{let r=p[e.id];if(!r||null===r.start)return null;let i=y[e.id],a=i?{topPeak:i.topPeak,botPeak:i.botPeak}:{topPeak:0,botPeak:0},n=m[e.id]+(a.botPeak-a.topPeak)*b/2,o=g(r.start),l=g(r.end),s=O(e.id,t);return Qi("g",{children:[Ui("line",{x1:o,y1:n,x2:l,y2:n,stroke:s,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),Ui("line",{x1:o,y1:n-4,x2:o,y2:n+4,stroke:s,strokeOpacity:.5}),Ui("line",{x1:l,y1:n-4,x2:l,y2:n+4,stroke:s,strokeOpacity:.5})]},"lane-"+e.id)}),Ui("line",{x1:T,y1:n+4,x2:A,y2:n+4,stroke:Ki}),D.map(({tick:e,index:t,coordinate:r})=>{let i=h(e.date),a=null!=e.label?e.label:d?d(new Date(i)):"";return Qi("g",{transform:`translate(${r},${n+4})`,children:[Ui("line",{y2:6,stroke:Ki}),Ui("text",{y:20,textAnchor:"middle",fontSize:11,fill:Zi,children:a})]},t)})]})}({layout:Xe,nodes:Le,orientation:M,plotW:Re,plotH:Fe,timelineExtent:We,axisTicks:n,showQualityReadout:$,showLaneRails:B,warnings:e,timeFormat:oe?e=>oe(e):void 0,colorOf:Ne,toTime:se,xScale:e=>Number(Ye(e))})},[Xe,Le,M,Re,Fe,We,n,$,B,je,oe,Ne,Ye]),Ze=Xi(()=>(xe??[]).map(e=>({id:Me(e),data:e})),[xe,Me]),Je=Xi(()=>{let e=new Map;for(let t of Ge.ribbons)t.bezier&&e.set(t.id,t.bezier);return e},[Ge]),et=Xi(()=>(Se??[]).map((e,t)=>{let r=Pe(e,t),i=Number(Mt(f,e));return{id:r,source:Mt(c,e)+"",target:Mt(u,e)+"",value:Number.isFinite(i)?i:0,bezier:Je.get(r),data:e}}),[Se,Pe,c,u,f,Je]);return ze.length>0?Sa("svg",{width:G,height:q,role:"img","aria-label":U??"Process Sankey validation failed",children:[xa("text",{x:20,y:30,fontSize:13,fontWeight:600,fill:"var(--semiotic-danger, #dc2626)",children:"ProcessSankey: data invalid"}),ze.map((e,t)=>xa("text",{x:20,y:56+18*t,fontSize:12,fill:"#64748b",children:"• "+ie(e)},t))]}):Ee.loadingEl?Ee.loadingEl:Ee.emptyEl?Ee.emptyEl:Sa("div",{style:{position:"relative",width:G,height:q},children:["pending"===qe&&!1!==X&&!Xe&&xa("div",{style:{position:"absolute",inset:0,zIndex:3,background:"var(--semiotic-bg, #fff)"},children:br(!0,G,q,X)}),xa(Kt,{ref:we,chartType:"force",nodes:Ze,edges:et,customNetworkLayout:ya,layoutConfig:Ge,size:[G,q],responsiveWidth:J,responsiveHeight:ee,maxDevicePixelRatio:e.maxDevicePixelRatio,margin:He,title:U,description:Q??"Temporal process flow with lifetime-bounded node lanes, mass bands, and value-scaled ribbons.",summary:K,accessibleTable:Z,enableHover:ue,tooltipContent:!1===ce?()=>null:Qe,backgroundGraphics:Ke,showParticles:me,particleStyle:pe,legend:$e,legendPosition:Ee.legendPosition,...Ue&&{__legendMarginReservedFor:$e},...ir({linkedHover:ge,selection:he,onObservation:de,onClick:fe,mobileInteraction:Ee.mobileInteraction,customHoverBehavior:Ee.customHoverBehavior,customClickBehavior:Ee.customClickBehavior,linkedHoverInClickPredicate:!1}),chartId:ye,colorScheme:Array.isArray(x)?x:void 0,layoutSelection:Ee.effectiveSelectionHook,...be})]})});wa.displayName="ProcessSankey";import{useMemo as Ma}from"react";import{hierarchy as Pa,tree as La,cluster as Ta,treemap as Aa,pack as Da,partition as Ia,treemapBinary as Ea}from"d3-hierarchy";var Ca=["#e8d5b7","#b8d4e3","#d4e3b8","#e3c4d4","#d4d4e3","#e3d4b8","#b8e3d4","#e3b8b8"],Oa={supportsStreaming:!1,hierarchical:!0,computeLayout(e,t,r,i){let a=r.__hierarchyRoot;if(!a)return;let n=r.chartType,o=function(e){if(e)return"function"==typeof e?e:t=>t[e]}(r.childrenAccessor),l=r.hierarchySum,s="function"==typeof l?l:"string"==typeof l?e=>Number(e[l])||0:e=>Number(e.value)||0,c=Pa(a,o);c.sum(s),c.sort((e,t)=>(t.value??0)-(e.value??0));let[u,d]=i;switch(n){case"tree":!function(e,t,r,i){let a=t.treeOrientation||"vertical",n=La();n.size("horizontal"===a?[i,r]:"radial"===a?[2*Math.PI,Math.min(r,i)/2*.8]:[r,i]),n(e)}(c,r,u,d);break;case"cluster":!function(e,t,r,i){let a=t.treeOrientation||"vertical",n=Ta();n.size("horizontal"===a?[i,r]:"radial"===a?[2*Math.PI,Math.min(r,i)/2*.8]:[r,i]),n(e)}(c,r,u,d);break;case"treemap":!function(e,t,r,i){let a=t.padding??4,n=t.paddingTop??0,o=Aa().size([r,i]).tile(Ea).padding(a);n>0&&o.paddingTop(n),o(e)}(c,r,u,d);break;case"circlepack":!function(e,t,r,i){let a=t.padding??4;Da().size([r,i]).padding(a)(e)}(c,r,u,d);break;case"partition":!function(e,t,r,i){Ia().size([r,i]).padding(t.padding??1)(e)}(c,r,u,d)}let f=c.descendants();e.length=0,t.length=0;let h=new Map;for(let t=0;f.length>t;t++){let i=f[t],a={id:At(i,r,t),x:0,y:0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:i.value??0,depth:i.depth,data:i.data,createdByFrame:!0};"tree"===n||"cluster"===n?Ot(a,i,r):"treemap"===n||"partition"===n?Nt(a,i):"circlepack"===n&&Bt(a,i),a.__hierarchyNode=i,e.push(a),h.set(i,a)}if("tree"===n||"cluster"===n)for(let e of f)if(e.parent){let r=h.get(e.parent),i=h.get(e);r&&i&&t.push({source:r,target:i,value:1,y0:0,y1:0,sankeyWidth:0,data:{depth:e.depth}})}},buildScene(t,r,i,a){let n=i.nodeStyle||(()=>({})),o=i.edgeStyle||(()=>({}));switch(i.chartType){case"tree":case"cluster":return function(t,r,i,a,n,o){let l=[],s=[],c=[],u=i.treeOrientation||"vertical",d="radial"===u,f=a[0]/2,h=a[1]/2,g="number"==typeof(m=i.nodeSize)?m:5;var m;for(let r of t){let t=r.x,a=r.y;d&&(t+=f,a+=h);let o=n(e(r,"nodeStyle")),s=o.fill||Et(i);if(i.colorByDepth&&void 0!==r.depth){let e=It(i);s=e[r.depth%e.length]}l.push({type:"circle",cx:t,cy:a,r:g,style:{fill:s,stroke:o.stroke||i.themeSemantic?.surface||"#fff",strokeWidth:o.strokeWidth??1,opacity:o.opacity,cursor:o.cursor},datum:r,id:r.id,label:r.id,depth:r.depth})}let p=i.edgeOpacity??.5;for(let t of r){let r="object"==typeof t.source?t.source:null,a="object"==typeof t.target?t.target:null;if(!r||!a)continue;let n=r.x,l=r.y,c=a.x,g=a.y;d&&(n+=f,l+=h,c+=f,g+=h);let m=Ct(n,l,c,g,u),y=o(e(t,"edgeStyle"));s.push({type:"curved",pathD:m,style:{fill:"none",stroke:y.stroke||i.themeSemantic?.border||i.themeSemantic?.secondary||"#999",strokeWidth:y.strokeWidth??1.5,opacity:y.opacity??p,cursor:y.cursor},datum:t})}if(!1!==i.showLabels){let e=Dt(i.nodeLabel);for(let r of t){let t=e?e(r):r.id;if(!t)continue;let i,a,n,o=r.x,l=r.y;if(d&&(o+=f,l+=h),d){let e=o-f,t=l-h,r=Math.sqrt(e*e+t*t);r>0?(i=o+e/r*10,a=l+t/r*10,n=0>e?"end":"start"):(i=o,a=l-12,n="middle")}else"horizontal"===u?(r.data?.children&&0!==r.data.children.length?(i=o-g-6,n="end"):(i=o+g+6,n="start"),a=l):(i=o,a=l+g+14,n="middle");c.push({x:i,y:a,text:t+"",anchor:n,baseline:"middle",fontSize:11})}}return{sceneNodes:l,sceneEdges:s,labels:c}}(t,r,i,a,n,o);case"treemap":case"partition":return function(t,r,i,a){let n=[],o=[];for(let i of t){let t=i.x1-i.x0,o=i.y1-i.y0;if(0>=t||0>=o)continue;let l=a(e(i,"nodeStyle")),s=l.fill||Et(r);if(r.colorByDepth&&void 0!==i.depth){let e=It(r);s=e[i.depth%e.length]}n.push({type:"rect",x:i.x0,y:i.y0,w:t,h:o,style:{fill:s,stroke:l.stroke||r.themeSemantic?.surface||"#fff",strokeWidth:l.strokeWidth??1,opacity:l.opacity,fillOpacity:l.fillOpacity,strokeOpacity:l.strokeOpacity,cursor:l.cursor},datum:i,id:i.id,label:i.id,depth:i.depth})}if(!1!==r.showLabels){let i=Dt(r.nodeLabel),n=r.labelMode||"leaf",l="partition"===r.chartType;for(let s of t){let t=s.x1-s.x0,c=s.y1-s.y0;if(0>=t||0>=c)continue;let u=!(s.data?.children&&s.data.children.length>0);if(!l&&("leaf"===n&&!u||"parent"===n&&u))continue;let d=i?i(s):s.id;if(!d)continue;if((u?30:40)>t||(u?16:14)>c)continue;let f=a(e(s,"nodeStyle")).fill||Et(r);if(r.colorByDepth&&void 0!==s.depth){let e=It(r);f=e[s.depth%e.length]}let h="string"==typeof f?Tt(f):r.themeSemantic?.text??"#000";o.push(u?{x:s.x0+t/2,y:s.y0+c/2,text:d+"",anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,Math.min(t,c)/6)),fill:h}:{x:s.x0+4,y:s.y0+12,text:d+"",anchor:"start",baseline:"auto",fontSize:11,fontWeight:600,fill:h})}}return{sceneNodes:n,sceneEdges:[],labels:o}}(t,i,0,n);case"circlepack":return function(t,r,i,a){let n=[],o=[];for(let i of t){let t=i.__radius??5;if(0>=t)continue;let o=a(e(i,"nodeStyle")),l=o.fill||Et(r);if(r.colorByDepth&&void 0!==i.depth){let e=It(r);l=e[i.depth%e.length]}n.push({type:"circle",cx:i.x,cy:i.y,r:t,style:{fill:l,stroke:o.stroke||r.themeSemantic?.surface||"#fff",strokeWidth:o.strokeWidth??1,opacity:o.opacity??.7,cursor:o.cursor},datum:i,id:i.id,label:i.id,depth:i.depth})}if(!1!==r.showLabels){let i=Dt(r.nodeLabel);for(let n of t){let t=n.__radius??5,l=i?i(n):n.id;if(!l||15>t)continue;let s=!(n.data?.children&&n.data.children.length>0),c=a(e(n,"nodeStyle")).fill||Et(r);if(r.colorByDepth&&void 0!==n.depth){let e=It(r);c=e[n.depth%e.length]}if(s){let e="string"==typeof c?Tt(c):r.themeSemantic?.text??"#000";o.push({x:n.x,y:n.y,text:l+"",anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,t/3)),fill:e})}else o.push({x:n.x,y:n.y-t+14,text:l+"",anchor:"middle",baseline:"hanging",fontSize:Math.min(11,Math.max(8,t/3)),fill:r.themeSemantic?.text||"#000",stroke:r.themeSemantic?.surface||"#fff",strokeWidth:3,paintOrder:"stroke"})}}return{sceneNodes:n,sceneEdges:[],labels:o}}(t,i,0,n);default:return{sceneNodes:[],sceneEdges:[],labels:[]}}}};Zt("tree",Oa),Zt("cluster",Oa),Zt("treemap",Oa),Zt("circlepack",Oa),Zt("partition",Oa);import{jsx as Na}from"react/jsx-runtime";Zt("tree",Oa),Zt("cluster",Oa),Zt("treemap",Oa),Zt("circlepack",Oa),Zt("partition",Oa),$t.displayName="TreeDiagram";import{useMemo as Ba,useCallback as $a}from"react";import{jsx as Ha}from"react/jsx-runtime";Zt("treemap",Oa),Ht.displayName="Treemap";import{useMemo as Ra}from"react";import{jsx as Fa}from"react/jsx-runtime";Zt("circlepack",Oa),Rt.displayName="CirclePack";import{useMemo as Wa}from"react";import{pie as _a}from"d3-shape";var za={supportsStreaming:!1,hierarchical:!0,supportsAnimation:!0,computeLayout(e,t,r,i){let a=r.__hierarchyRoot;a&&function(e,t,r,i,a){function n(e){let t=g.get(e)??0;return g.set(e,t+1),0===t?e:`${e}__${t}`}let o=function(e){if("function"==typeof e)return e;let t=e||"children";return e=>e[t]||null}(r.childrenAccessor),l=function(e){if("function"==typeof e)return e;let t=e||"name";return e=>(e[t]??"")+""}(r.nodeIDAccessor),s=function(e){if(Array.isArray(e))return e;switch(e){case"solar":return[1];case"atomic":return[2,8];default:return[9999]}}(r.orbitMode),c=r.orbitSize??2.95,u=r.orbitEccentricity??1,d="number"==typeof c?()=>c:c,f="number"==typeof u?()=>u:u,h=Ft(r);h.metaMap.clear(),i.length=0,a.length=0;let g=new Map,m=t[0]/2,p=t[1]/2,y=Math.min(t[0],t[1])/2*.85,b=n(l(e));i.push({id:b,x:m,y:p,x0:m,x1:m,y0:p,y1:p,width:0,height:0,value:0,depth:0,data:e}),h.metaMap.set(b,{ring:y,angle:0,depth:0,parentId:null,eccentricity:1}),function e(t,r,c,u,g,m,p){let y=o(t);if(!y?.length)return;let b=y.length,v=0,k=0,x=0;for(;b>k;)k+=s[Math.min(x,s.length-1)],x++,v++;let S=0;for(let b=0;v>b;b++){let k=s[Math.min(b,s.length-1)],x=y.slice(S,S+k);if(!x.length)break;let w=(b+1)/v,M={id:r,depth:m,data:t,parentId:r},P=p?g/d(M)*w:g*w,L=_a().value(e=>o(e)?.length?4:1).sort(null)(x),T=f(M);for(let t=0;x.length>t;t++){let o=(L[t].startAngle+L[t].endAngle)/2,s=x[t],d=n(l(s)),f=c+P*Math.sin(o),g=u+P*Math.cos(o)*T;i.push({id:d,x:f,y:g,x0:f,x1:f,y0:g,y1:g,width:0,height:0,value:0,depth:m,data:s}),h.metaMap.set(d,{ring:P,angle:o,depth:m,parentId:r,eccentricity:T}),a.push({source:r,target:d,value:1,y0:0,y1:0,sankeyWidth:0,data:{source:r,target:d}}),e(s,d,f,g,P,m+1,!0)}S+=k}}(e,b,m,p,y,1,!1)}(a,i,r,e,t)},buildScene(t,r,i,a){let n=i.nodeStyle,o=i.edgeStyle,l=i.nodeSize,s="number"==typeof l?()=>l:"function"==typeof l?l:()=>6,c=[],u=[],d=[];if(!1!==i.orbitShowRings){let e=Ft(i),r=new Map;for(let e of t)r.set(e.id,e);let a=new Map;for(let[,t]of e.metaMap){if(!t.parentId)continue;let e=r.get(t.parentId);if(!e)continue;let i=`${t.parentId}:${t.ring}`;a.has(i)||a.set(i,{parentX:e.x,parentY:e.y,ring:t.ring,ecc:t.eccentricity})}let n=48,o={stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1};for(let[,{parentX:e,parentY:t,ring:r,ecc:i}]of a)for(let a=0;n>a;a++){let l=a/n*Math.PI*2,s=(a+1)/n*Math.PI*2;u.push({type:"line",x1:e+r*Math.sin(l),y1:t+r*Math.cos(l)*i,x2:e+r*Math.sin(s),y2:t+r*Math.cos(s)*i,style:o,datum:null})}}for(let r of t){if(null==r.x||null==r.y)continue;let t=s(e(r,"nodeSize")),a=n?n(e(r,"nodeStyle")):{};c.push({type:"circle",cx:r.x,cy:r.y,r:t,style:{fill:a.fill||i.themeSemantic?.primary||"#6366f1",stroke:a.stroke||i.themeSemantic?.surface||"#fff",strokeWidth:a.strokeWidth??1,opacity:a.opacity??(0===(r.depth??0)?1:.85),cursor:a.cursor},datum:r,id:r.id,label:r.id,depth:r.depth})}let f=new Map;for(let e of t)f.set(e.id,e);for(let t of r){let r="object"==typeof t.source?t.source:f.get(t.source),i="object"==typeof t.target?t.target:f.get(t.target);if(!r||!i||null==r.x||null==i.x)continue;let a=o?o(e(t,"edgeStyle")):{};u.push({type:"line",x1:r.x,y1:r.y,x2:i.x,y2:i.y,style:{stroke:a.stroke||"rgba(128,128,128,0.35)",strokeWidth:a.strokeWidth??.5,opacity:a.opacity??1,cursor:a.cursor},datum:t})}if(i.showLabels){let r=i.nodeLabel;for(let i of t){let t=s(e(i,"nodeSize"));if(4>=t)continue;let a="function"==typeof r?r(i):r?i.data?.[r]??i.id:i.id;d.push({x:i.x,y:i.y+t+12,text:a+"",anchor:"middle",fontSize:10,fill:"currentColor"})}}return{sceneNodes:c,sceneEdges:u,labels:d}},tick:(e,t,r,i,a)=>!1!==r.orbitAnimated&&(function(e,t){let r=Ft(t),i=t.orbitSpeed??.25,a=t.orbitRevolution??function(e){switch(e){case"decay":return e=>Math.pow(.6,e.depth??0);case"alternate":return e=>{let t=e.depth??0;return(t%2==0?1:-1)/(t+1)};default:return e=>1/((e.depth??0)+1)}}(t.orbitRevolutionStyle),n=(("u">typeof performance?performance.now():Date.now())-r.startTime)/1e3,o=i*(Math.PI/6),l=new Map;for(let t of e)l.set(t.id,t);for(let t of e){let e=r.metaMap.get(t.id);if(!e||!e.parentId)continue;let i=l.get(e.parentId);if(!i)continue;let s=e.angle+n*o*a({id:t.id,depth:e.depth,data:t.data,parentId:e.parentId});t.x=i.x+e.ring*Math.sin(s),t.y=i.y+e.ring*Math.cos(s)*e.eccentricity,t.x0=t.x,t.x1=t.x,t.y0=t.y,t.y1=t.y}}(e,r),!0)};Zt("orbit",za);import{jsx as ja}from"react/jsx-runtime";Zt("orbit",za);var Xa=Or;Wt.displayName="OrbitDiagram";import{forwardRef as Ya,useMemo as Ga}from"react";import{jsx as qa}from"react/jsx-runtime";var Va=Ya(function(e,t){let{nodes:r,edges:i,layout:a,layoutConfig:n,onLayoutError:o,nodeIDAccessor:l="id",sourceAccessor:s="source",targetAccessor:c="target",margin:u,className:d,colorBy:f,colorScheme:h,tooltip:g,selection:m,linkedHover:p,onObservation:y,onClick:b,chartId:v,annotations:k,autoPlaceAnnotations:x,frameProps:S={}}=e,{frameRef:w,resolved:M,normalizedMargin:P}=Gt({imperativeRef:t,imperativeVariant:"network",margin:u,width:e.width,height:e.height,enableHover:e.enableHover,title:e.title,description:e.description,summary:e.summary,accessibleTable:e.accessibleTable,mode:e.mode,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,responsiveRules:e.responsiveRules}),L=Ga(()=>gr(r),[r]),T=Ga(()=>gr(i),[i]),A=Ga(()=>void 0===r&&void 0===i?void 0:[...L,...T],[i,r,T,L]),D=Sr(e.mobileInteraction,{mode:e.mode,width:M.width,mobileSemantics:e.mobileSemantics}),{customHoverBehavior:I,customClickBehavior:E,activeSelectionHook:C}=Lr({selection:m,linkedHover:p,fallbackFields:"string"==typeof f?[f]:[],onObservation:y,onClick:b,chartType:"NetworkCustomChart",chartId:v,colorByField:"string"==typeof f?f:void 0,mobileInteraction:D}),O=Ga(()=>C?.isActive?{isActive:!0,predicate:C.predicate}:null,[C?.isActive,C?.predicate]),{width:N,height:B,enableHover:$,title:H,description:R,summary:F,accessibleTable:W}=M,_=Ga(()=>pr(g),[g]),z=br(e.loading,N,B,e.loadingContent),j=z?null:yr(A,N,B,e.emptyContent);if(z||j)return z||j;let X={chartType:"force",...null!=r&&{nodes:L},...null!=i&&{edges:T},customNetworkLayout:a,layoutConfig:n,onLayoutError:o,nodeIDAccessor:l,sourceAccessor:s,targetAccessor:c,colorBy:f,colorScheme:h,size:[N,B],responsiveWidth:e.responsiveWidth,responsiveHeight:e.responsiveHeight,margin:P,enableHover:$,...rr({title:H,description:R,summary:F,accessibleTable:W,className:d,animate:e.animate,maxDevicePixelRatio:e.maxDevicePixelRatio,autoPlaceAnnotations:x}),...!1===g?{tooltipContent:()=>null}:_?{tooltipContent:_}:{},...ir({forceHoverBehavior:null!=v,forceClickBehavior:null!=v,linkedHover:p,selection:m,onObservation:y,onClick:b,mobileInteraction:D,customHoverBehavior:I,customClickBehavior:E,linkedHoverInClickPredicate:!1}),layoutSelection:O,...null!=k&&{annotations:k},...S};return qa(cr,{componentName:"NetworkCustomChart",width:N,height:B,children:qa(Kt,{ref:w,...X})})});Va.displayName="NetworkCustomChart";import{forceCenter as Ua,forceCollide as Qa,forceLink as Ka,forceManyBody as Za,forceSimulation as Ja,forceX as en,forceY as tn}from"d3-force";export{Zr as forceLayoutPlugin,ii as ForceDirectedGraph,di as chordLayoutPlugin,hi as ChordDiagram,Di as sankeyLayoutPlugin,Ei as SankeyDiagram,re as validateProcessSankey,ie as formatProcessSankeyIssue,ae as diagnoseProcessSankeyLayout,ne as explainProcessSankeyLayout,oe as diagnoseProcessSankeyProps,le as inventoryAtTime,se as toProcessSankeyTime,wa as ProcessSankey,Oa as hierarchyLayoutPlugin,$t as TreeDiagram,Ht as Treemap,Rt as CirclePack,za as orbitLayoutPlugin,Wt as OrbitDiagram,Va as NetworkCustomChart,_t as forceLayout};