semiotic 3.13.1 → 3.13.3
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.
- package/README.md +48 -48
- package/ai/artifact-surface-inventory.json +1 -1
- package/ai/dist/mcp-server.js +4 -4
- package/ai/reference.md +23 -12
- package/ai/schema.json +258 -96
- package/ai/surface-manifest.json +1 -1
- package/ai/task-packets/compare-category-totals.json +5 -5
- package/ai/task-packets/compare-category-totals.md +2 -2
- package/ai/task-packets/correct-published-chart.json +5 -5
- package/ai/task-packets/correct-published-chart.md +2 -2
- package/ai/task-packets/index.json +6 -6
- package/ai/task-packets/update-live-chart.json +5 -5
- package/ai/task-packets/update-live-chart.md +2 -2
- package/dist/c-2YFVDRU4.min.js +1 -0
- package/dist/c-4OVDIXAR.min.js +1 -0
- package/dist/c-57IIWW46.min.js +1 -0
- package/dist/c-5HTUQRJT.min.js +1 -0
- package/dist/c-5NAU4JAY.min.js +1 -0
- package/dist/c-62UTMRQE.min.js +1 -0
- package/dist/c-6QV6F3U7.min.js +1 -0
- package/dist/c-73ORHEHO.min.js +1 -0
- package/dist/c-7S46KBYD.min.js +2 -0
- package/dist/c-AJSS332Z.min.js +2 -0
- package/dist/{c-ZWJDTDEV.min.js → c-AMQAAW7G.min.js} +1 -1
- package/dist/c-B3X2IJRQ.min.js +1 -0
- package/dist/c-BLLDBVFK.min.js +38 -0
- package/dist/c-BQWX6NBX.min.js +1 -0
- package/dist/c-C7TT4J7K.min.js +1 -0
- package/dist/c-CJ5GA7DM.min.js +1 -0
- package/dist/c-D7YDFHLY.min.js +1 -0
- package/dist/c-DHNROAXY.min.js +1 -0
- package/dist/c-DMDFJQU4.min.js +1 -0
- package/dist/{c-RAIBDXDV.min.js → c-FRVHZIGR.min.js} +1 -1
- package/dist/{c-I54V24WG.min.js → c-HAZCVHI7.min.js} +1 -1
- package/dist/c-HN5U72U7.min.js +1 -0
- package/dist/c-JA5F7ITS.min.js +1 -0
- package/dist/{c-VZNIIKL6.min.js → c-JDI7HKEM.min.js} +1 -1
- package/dist/{c-ISHYKYII.min.js → c-JVZRD4GL.min.js} +1 -1
- package/dist/{c-HGWITEJI.min.js → c-KJGJEOSV.min.js} +1 -1
- package/dist/c-LDGV6TDQ.min.js +1 -0
- package/dist/c-LW3GP7RY.min.js +1 -0
- package/dist/c-M2TPZE7P.min.js +1 -0
- package/dist/{c-XOGN3524.min.js → c-NBBYSAQY.min.js} +2 -2
- package/dist/c-OA6RJZ7S.min.js +1 -0
- package/dist/c-OBBSIOYU.min.js +1 -0
- package/dist/c-OMTJIC3P.min.js +1 -0
- package/dist/{c-SQQZPFVY.min.js → c-QPHM7AWW.min.js} +1 -1
- package/dist/{c-XZJWL7UL.min.js → c-QSEAAHEU.min.js} +1 -1
- package/dist/c-RQWI623R.min.js +1 -0
- package/dist/{c-62JIVHK5.min.js → c-RWFADOKS.min.js} +1 -1
- package/dist/c-TFESQSWE.min.js +1 -0
- package/dist/{c-SDGGMIYI.min.js → c-TJGC5JEM.min.js} +1 -1
- package/dist/{c-4P2EM44G.min.js → c-TOXWQRXS.min.js} +3 -3
- package/dist/c-TX53234M.min.js +1 -0
- package/dist/c-TZBEQ5UY.min.js +1 -0
- package/dist/c-UALVQIIJ.min.js +1 -0
- package/dist/c-VBDWHTC7.min.js +1 -0
- package/dist/c-VBIPDCE7.min.js +1 -0
- package/dist/c-WTNRBWZZ.min.js +51 -0
- package/dist/{c-3GIPT46Z.min.js → c-XG4LL2VI.min.js} +1 -1
- package/dist/c-XPNBS3W2.min.js +1 -0
- package/dist/c-XT3G3YWU.min.js +1 -0
- package/dist/c-YCBCZFOC.min.js +1 -0
- package/dist/c-ZBSL4Y32.min.js +1 -0
- package/dist/c-ZP6O6UHV.min.js +1 -0
- package/dist/c-ZVL7ULNH.min.js +1 -0
- package/dist/components/ChartErrorBoundary.d.ts +5 -1
- package/dist/components/ai/intentWeights.d.ts +22 -0
- package/dist/components/ai/streamSchema.d.ts +98 -0
- package/dist/components/ai/streamingTypes.d.ts +27 -4
- package/dist/components/ai/suggestCharts.d.ts +10 -2
- package/dist/components/ai/suggestStreamCharts.d.ts +60 -13
- package/dist/components/ai/suggestStreamDashboard.d.ts +9 -1
- package/dist/components/charts/network/processSankey/frameMargins.d.ts +1 -1
- package/dist/components/charts/network/processSankey/labelPlacement.d.ts +1 -1
- package/dist/components/charts/physics/physicsHocUtils.d.ts +1 -1
- package/dist/components/charts/realtime/RealtimeAccumulator.d.ts +7 -0
- package/dist/components/charts/realtime/RealtimeHeatmap.d.ts +9 -2
- package/dist/components/charts/realtime/RealtimeHistogram.d.ts +13 -1
- package/dist/components/charts/realtime/RealtimeLineChart.types.d.ts +5 -1
- package/dist/components/charts/realtime/RealtimeSwarmChart.d.ts +5 -1
- package/dist/components/charts/realtime/RealtimeWaterfallChart.d.ts +7 -1
- package/dist/components/charts/realtime/TemporalHistogram.capability.d.ts +5 -3
- package/dist/components/charts/realtime/aggregate.d.ts +11 -12
- package/dist/components/charts/realtime/defaultRealtimeTooltip.d.ts +9 -0
- package/dist/components/charts/realtime/eventTime.d.ts +7 -1
- package/dist/components/charts/realtime/useRealtimeLineIngestion.d.ts +13 -0
- package/dist/components/charts/shared/ChartError.d.ts +4 -6
- package/dist/components/charts/shared/GaugeReadout.d.ts +39 -4
- package/dist/components/charts/shared/axisExtent.d.ts +2 -1
- package/dist/components/charts/shared/chartMode.d.ts +2 -2
- package/dist/components/charts/shared/gaugeLayout.d.ts +69 -0
- package/dist/components/charts/shared/types.d.ts +4 -1
- package/dist/components/charts/shared/useNetworkChartSetup.d.ts +3 -0
- package/dist/components/charts/shared/useStreamStatus.d.ts +2 -2
- package/dist/components/charts/shared/withChartErrorBoundary.d.ts +14 -0
- package/dist/components/charts/xy/Scatterplot.streamCapability.d.ts +2 -0
- package/dist/components/charts/xy/WaterfallChart.d.ts +2 -0
- package/dist/components/charts/xy/WaterfallIndex.d.ts +12 -0
- package/dist/components/charts/xy/lineGapStrategy.d.ts +15 -3
- package/dist/components/legendGeometry.d.ts +148 -0
- package/dist/components/legendLayout.d.ts +20 -38
- package/dist/components/realtime/ReorderBuffer.d.ts +14 -0
- package/dist/components/realtime/SlidingExtent.d.ts +18 -0
- package/dist/components/realtime/WindowAccumulator.d.ts +5 -1
- package/dist/components/realtime/renderers/types.d.ts +1 -0
- package/dist/components/realtime/renderers/waterfallRenderer.d.ts +1 -1
- package/dist/components/recipes/atlas/resolution/appearance.d.ts +1 -1
- package/dist/components/recipes/atlas/resolution/scene.d.ts +1 -1
- package/dist/components/recipes/compositional/edgeRouting.d.ts +9 -0
- package/dist/components/recipes/compositional/metrics.d.ts +2 -2
- package/dist/components/recipes/compositional/projection.d.ts +3 -1
- package/dist/components/recipes/compositional/routing.d.ts +3 -1
- package/dist/components/recipes/compositional/testFixtures.d.ts +4 -0
- package/dist/components/recipes/compositional/topology.d.ts +2 -0
- package/dist/components/recipes/compositional/types.d.ts +10 -1
- package/dist/components/recipes/compositional/useCompositionalInterfaces.d.ts +20 -0
- package/dist/components/semiotic-ai-core.d.ts +3 -2
- package/dist/components/semiotic-ai-stream.d.ts +3 -2
- package/dist/components/semiotic-network-zoom.d.ts +1 -1
- package/dist/components/semiotic-recipes-react.d.ts +2 -0
- package/dist/components/semiotic-utils-core.d.ts +2 -0
- package/dist/components/server/serverChartConfigHeatmap.d.ts +13 -0
- package/dist/components/server/staticLegend.d.ts +5 -0
- package/dist/components/server/staticLegendText.d.ts +13 -0
- package/dist/components/server/staticSVGChrome.d.ts +2 -2
- package/dist/components/store/ThemeStore.d.ts +4 -1
- package/dist/components/store/themeCore.d.ts +2 -0
- package/dist/components/stream/DataSourceAdapter.d.ts +15 -62
- package/dist/components/stream/FrameRuntime.d.ts +3 -0
- package/dist/components/stream/GeoPipelineStore.d.ts +2 -0
- package/dist/components/stream/IngestActivity.d.ts +9 -0
- package/dist/components/stream/NetworkPipelineStore.d.ts +3 -1
- package/dist/components/stream/OrdinalPipelineStore.d.ts +5 -2
- package/dist/components/stream/OrdinalSVGOverlay.d.ts +1 -1
- package/dist/components/stream/PipelineStore.d.ts +8 -3
- package/dist/components/stream/accessibleDataRows.d.ts +1 -0
- package/dist/components/stream/axisTickUtils.d.ts +25 -5
- package/dist/components/stream/frameDefaultMargins.d.ts +26 -4
- package/dist/components/stream/frameKeyboardNavigation.d.ts +8 -1
- package/dist/components/stream/geoTypes.d.ts +2 -0
- package/dist/components/stream/graphKeyboardNavigation.d.ts +4 -2
- package/dist/components/stream/hitTestUtils.d.ts +7 -0
- package/dist/components/stream/keyboardNav.d.ts +3 -1
- package/dist/components/stream/mediaQuery.d.ts +2 -0
- package/dist/components/stream/navigationGraph.d.ts +10 -3
- package/dist/components/stream/networkEdgeHitIndex.d.ts +6 -2
- package/dist/components/stream/networkFrameKeyboardNavigation.d.ts +2 -0
- package/dist/components/stream/networkNavGroups.d.ts +3 -0
- package/dist/components/stream/networkPipelineConfig.d.ts +1 -0
- package/dist/components/stream/networkSceneTypes.d.ts +10 -0
- package/dist/components/stream/networkSpatialNavigation.d.ts +3 -0
- package/dist/components/stream/networkTypes.d.ts +2 -0
- package/dist/components/stream/networkZoom/ZoomableNetworkCustomChart.d.ts +6 -4
- package/dist/components/stream/networkZoom/gestures.d.ts +5 -0
- package/dist/components/stream/networkZoom/types.d.ts +10 -0
- package/dist/components/stream/ordinalAxisTicks.d.ts +27 -0
- package/dist/components/stream/ordinalSceneBuilders/pieScene.d.ts +10 -0
- package/dist/components/stream/ordinalSceneBuilders/types.d.ts +2 -0
- package/dist/components/stream/ordinalTypes.d.ts +11 -2
- package/dist/components/stream/pipelineBufferUtils.d.ts +9 -0
- package/dist/components/stream/pipelineConfig.d.ts +7 -0
- package/dist/components/stream/pipelineDomainResolution.d.ts +3 -2
- package/dist/components/stream/pipelineTransitionTypes.d.ts +3 -5
- package/dist/components/stream/pipelineTransitionUtils.d.ts +4 -0
- package/dist/components/stream/pipelineTransitions.d.ts +1 -13
- package/dist/components/stream/renderers/networkArcRenderer.d.ts +1 -3
- package/dist/components/stream/renderers/networkCircleRenderer.d.ts +1 -3
- package/dist/components/stream/renderers/networkPrimitiveRenderer.d.ts +5 -0
- package/dist/components/stream/renderers/networkRectRenderer.d.ts +1 -3
- package/dist/components/stream/renderers/renderPulse.d.ts +8 -14
- package/dist/components/stream/roundScaleDomain.d.ts +9 -0
- package/dist/components/stream/sceneToSVGShared.d.ts +9 -0
- package/dist/components/stream/shallowEqual.d.ts +2 -0
- package/dist/components/stream/stalenessBands.d.ts +1 -1
- package/dist/components/stream/svgOverlayUtils.d.ts +12 -0
- package/dist/components/stream/types.d.ts +10 -2
- package/dist/components/stream/useFrame.d.ts +7 -4
- package/dist/components/stream/useMediaPreferences.d.ts +1 -4
- package/dist/components/stream/useOrdinalFrameHandle.d.ts +4 -14
- package/dist/components/stream/useStalenessCheck.d.ts +5 -3
- package/dist/components/stream/useStreamingDataHandle.d.ts +24 -0
- package/dist/components/stream/useXYFrameHandle.d.ts +4 -14
- package/dist/components/stream/xyDateTicks.d.ts +33 -4
- package/dist/components/stream/xyFrameAxisTypes.d.ts +2 -0
- package/dist/components/stream/xyPlugins/registry.d.ts +7 -0
- package/dist/components/stream/xySceneBuilders/heatmapScene.d.ts +11 -2
- package/dist/components/stream/xySceneBuilders/types.d.ts +4 -0
- package/dist/components/types/legendTypes.d.ts +12 -1
- package/dist/geo.min.js +155 -152
- package/dist/geo.module.min.js +1 -1
- package/dist/network.module.min.js +1 -1
- package/dist/ordinal.module.min.js +1 -1
- package/dist/physics.module.min.js +1 -1
- package/dist/processSankeyLayoutWorker.js +1 -1
- package/dist/semiotic-ai-core.d.ts +3 -2
- package/dist/semiotic-ai-core.min.js +5 -5
- package/dist/semiotic-ai-core.module.min.js +4 -4
- package/dist/semiotic-ai.module.min.js +2 -2
- package/dist/semiotic-artifact.min.js +6 -6
- package/dist/semiotic-artifact.module.min.js +5 -5
- package/dist/semiotic-atlas-selection.module.min.js +1 -1
- package/dist/semiotic-atlas.module.min.js +1 -1
- package/dist/semiotic-client-cjs-shared.min.js +1021 -1024
- package/dist/semiotic-client-compositional.module.min.js +1 -1
- package/dist/semiotic-client-shared.module.min.js +1 -1
- package/dist/semiotic-experimental-auxiliary.module.min.js +2 -2
- package/dist/semiotic-experimental-network-resolution-react.module.min.js +1 -1
- package/dist/semiotic-experimental-node-auxiliary.module.min.js +3 -3
- package/dist/semiotic-line.module.min.js +1 -1
- package/dist/semiotic-network-zoom.d.ts +1 -1
- package/dist/semiotic-network-zoom.min.js +7 -7
- package/dist/semiotic-network-zoom.module.min.js +1 -1
- package/dist/semiotic-realtime-core.module.min.js +1 -1
- package/dist/semiotic-realtime-react.module.min.js +1 -1
- package/dist/semiotic-recipes-core-cjs-base.min.js +101 -101
- package/dist/semiotic-recipes-core.module.min.js +1 -1
- package/dist/semiotic-recipes-react.d.ts +2 -0
- package/dist/semiotic-recipes-react.min.js +8 -8
- package/dist/semiotic-server-edge-node.module.min.js +3 -3
- package/dist/semiotic-server-edge.min.js +399 -397
- package/dist/semiotic-server-edge.module.min.js +3 -3
- package/dist/semiotic-server-node.min.js +399 -397
- package/dist/semiotic-themes-core.min.js +2 -2
- package/dist/semiotic-themes-core.module.min.js +1 -1
- package/dist/semiotic-themes.min.js +2 -2
- package/dist/semiotic-themes.module.min.js +1 -1
- package/dist/semiotic-utils-core.d.ts +2 -0
- package/dist/semiotic-utils-core.min.js +11 -11
- package/dist/semiotic-utils-core.module.min.js +3 -3
- package/dist/semiotic-value.module.min.js +1 -1
- package/dist/semiotic.module.min.js +1 -1
- package/dist/server.min.js +399 -397
- package/dist/server.module.min.js +3 -3
- package/dist/xy.module.min.js +1 -1
- package/package.json +11 -11
- package/dist/c-2M2OPWVA.min.js +0 -37
- package/dist/c-2N7IU2NY.min.js +0 -1
- package/dist/c-3UXQGCQT.min.js +0 -1
- package/dist/c-4RVDKSMQ.min.js +0 -1
- package/dist/c-4YPPVFZH.min.js +0 -1
- package/dist/c-6WJKNYIG.min.js +0 -1
- package/dist/c-7UN2WUMI.min.js +0 -1
- package/dist/c-AQUX6L2O.min.js +0 -1
- package/dist/c-BR5QDUCR.min.js +0 -1
- package/dist/c-C3YQVUB6.min.js +0 -1
- package/dist/c-COP4OISO.min.js +0 -1
- package/dist/c-ENRZPF5E.min.js +0 -1
- package/dist/c-FAOZZE77.min.js +0 -1
- package/dist/c-HBLICBM6.min.js +0 -1
- package/dist/c-I4BEWAKT.min.js +0 -1
- package/dist/c-IDCFMBA4.min.js +0 -2
- package/dist/c-KLJDKRD5.min.js +0 -1
- package/dist/c-LEICSI5V.min.js +0 -1
- package/dist/c-MOK4RWNO.min.js +0 -1
- package/dist/c-N2TVSOYL.min.js +0 -2
- package/dist/c-NHZ2E3CI.min.js +0 -1
- package/dist/c-OIJL2WZH.min.js +0 -1
- package/dist/c-OSLNYZ3Q.min.js +0 -51
- package/dist/c-OWRVBUSL.min.js +0 -1
- package/dist/c-QIVKWHDL.min.js +0 -1
- package/dist/c-QUAEYF34.min.js +0 -1
- package/dist/c-RDFFLRKC.min.js +0 -1
- package/dist/c-RTU5425Z.min.js +0 -1
- package/dist/c-SIQVOV6A.min.js +0 -1
- package/dist/c-SU6Z75M2.min.js +0 -1
- package/dist/c-SWVXFUDL.min.js +0 -1
- package/dist/c-TC47SNSI.min.js +0 -1
- package/dist/c-VLWWXOM5.min.js +0 -1
- package/dist/c-VNFIRKU5.min.js +0 -1
- package/dist/c-W5ATXREF.min.js +0 -1
- package/dist/c-WFX456JK.min.js +0 -5
- package/dist/c-WSWMQDFZ.min.js +0 -1
- package/dist/c-XORVM6C5.min.js +0 -1
- package/dist/c-YGTMWEEF.min.js +0 -1
- package/dist/c-ZDCTFRA6.min.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{scaleTime as t}from"d3-scale";var e={static:{duplicateIds:"fatal",invalidSystemTime:"warn"},mcp:{duplicateIds:"fatal",invalidSystemTime:"warn"},push:{duplicateIds:"warn",invalidSystemTime:"strip"}};function n(t="static"){return e[t]??e.static}var o=new Set(["invalid-domain","missing-node","backward-edge","invalid-edge-time","invalid-value","invalid-node-time"]);function s(t){return"fatal"===t.severity||"warn"===t.severity?t.severity:o.has(t.kind)?"fatal":"warn"}function i(t,e,o="static"){if("strip"!==n(o).invalidSystemTime)return t;const s=new Set(e.filter(t=>"invalid-system-time"===t.kind).map(t=>t.id));return 0===s.size?t:t.map(t=>{if(!s.has(t.id))return t;const e={...t};return null==e.systemInTime||Number.isFinite(e.systemInTime)||delete e.systemInTime,null==e.systemOutTime||Number.isFinite(e.systemOutTime)||delete e.systemOutTime,e})}function a(t,e=1/0){let n=e;for(const e of t)e<n&&(n=e);return n}function r(t,e=-1/0){let n=e;for(const e of t)e>n&&(n=e);return n}function l(t){const{desired:e,minGaps:n,weights:o}=t,s=e.length;if(0===s)return[];if(n.length!==Math.max(0,s-1))throw new Error("placeWithMinGap: minGaps must have desired.length - 1 entries");const i=new Array(s).fill(0);for(let t=1;t<s;t++)i[t]=i[t-1]+Math.max(0,Number.isFinite(n[t-1])?n[t-1]:0);const a=[];for(let t=0;t<s;t++){const n=Math.max(Number.EPSILON,Number.isFinite(o?.[t])?o[t]:1),s=(Number.isFinite(e[t])?e[t]:0)-i[t];for(a.push({start:t,end:t,weight:n,mean:s});a.length>1;){const t=a[a.length-1],e=a[a.length-2];if(e.mean<=t.mean)break;const n=e.weight+t.weight;a.splice(a.length-2,2,{start:e.start,end:t.end,weight:n,mean:(e.mean*e.weight+t.mean*t.weight)/n})}}const r=Number.isFinite(t.min)?t.min:-1/0,l=Number.isFinite(t.max)?t.max-i[s-1]:1/0,c=l<r?r:l,u=new Array(s);for(const t of a){const e=Math.max(r,Math.min(c,t.mean));for(let n=t.start;n<=t.end;n++)u[n]=e+i[n]}return u}function c(t,e){let n=0,o=t.length-1,s=-1;for(;n<=o;){const i=n+o>>>1;t[i].at<=e?(s=i,n=i+1):o=i-1}return s<0?{at:e,before:0,after:0}:t[s]}function u(t,e=0){if(0===t.length)return{adjacentClearance:[],positions:[]};const n=[],o=[0];for(let s=0;s<t.length-1;s++){const i=t[s],a=t[s+1],r=[...new Set([...i.map(t=>t.at),...a.map(t=>t.at)])].sort((t,e)=>t-e);let l=0;for(const t of r){const e=c(i,t),n=c(a,t);l=Math.max(l,e.after+n.before)}n.push(l),o.push(o[o.length-1]+l+e)}return{adjacentClearance:n,positions:o}}function f(t,e,n,o={}){let s=[...t];if(s.length<=1)return s;let i=[...s],a=n(s),r=1;const l=Math.max(0,o.passes??6),c=Math.max(1,o.maxEvaluations??1/0);for(let t=0;t<l&&r<c;t++){const t=new Map(s.map((t,e)=>[t,e])),l=new Map,c=new Map;for(const n of e){const e=t.get(n.source),o=t.get(n.target);if(null==e||null==o)continue;const s=Number.isFinite(n.weight)&&n.weight>0?n.weight:1;l.set(n.source,(l.get(n.source)??0)+o*s),c.set(n.source,(c.get(n.source)??0)+s),l.set(n.target,(l.get(n.target)??0)+e*s),c.set(n.target,(c.get(n.target)??0)+s)}s=s.map((t,e)=>({item:t,index:e,barycenter:(l.get(t)??e)/(c.get(t)??1)})).sort((t,e)=>t.barycenter-e.barycenter||(o.compare?.(t.item,e.item)??t.index-e.index)).map(t=>t.item);const u=n(s);if(r++,u<a)a=u,i=[...s];else if(u===a)break}return i}function d(t,e,n={}){const o=[...t];if(o.length<=1)return o;let s=e(o),i=1;const a=Math.max(0,n.passes??6),r=Math.max(1,n.maxEvaluations??1/0);for(let t=0;t<a&&i<r;t++){let t=!1;for(let n=0;n<o.length-1&&i<r;n++){[o[n],o[n+1]]=[o[n+1],o[n]];const a=e(o);i++,a<s?(s=a,t=!0):[o[n],o[n+1]]=[o[n+1],o[n]]}if(!t)break}return o}function g(t,e,n={}){const o=[...t],s=o.length;if(s<=1||s>(n.maxItems??8))return o;const i=Math.max(1,n.maxEvaluations??1/0);let a=0,r=[...o],l=1/0;const c=()=>{if(a>=i)return;const t=e(o);a++,t<l&&(l=t,r=[...o])};c();const u=new Array(s).fill(0);let f=0;for(;f<s&&a<i;)if(u[f]<f){const t=f%2==0?0:u[f];[o[t],o[f]]=[o[f],o[t]],c(),u[f]++,f=0}else u[f]=0,f++;return r}function m(){return Object.create(null)}function p(t,e){return t<e?-1:t>e?1:0}function h(t){return t.occupants.map(t=>t.id).sort(p).join("\0")}function b(t,e,n=0){return t.slice(0,-1).map((o,s)=>{const i=t[s+1];return null!=o.group&&o.group===i.group?n:e})}function M(t,e){return t.map(t=>{const n=new Map;for(const o of t.occupants){const t=e[o.id];if(t)for(const e of t.samples){const t=n.get(e.t)??{before:0,after:0},o=e.boundaryOffset??0;n.set(e.t,{before:Math.max(t.before,e.topMass-o),after:Math.max(t.after,e.botMass+o)})}}return[...n].sort((t,e)=>t[0]-e[0]).map(([t,e])=>({at:t,...e}))})}function y(t,e,n){if(0===t.length)return[];const{padding:o,plotH:s,valueScale:i}=n,a=n.stackValueScale??i,r=b(t,o,n.groupPadding??0),l=[o+t[0].peak.topPeak*a];for(let n=1;n<t.length;n++)l.push(l[n-1]+e[n-1]*a+r[n-1]);const c=l[l.length-1]+t[t.length-1].peak.botPeak*a+o;if(c>s&&c>0){const t=s/c;for(let e=0;e<l.length;e++)l[e]*=t}return l}function x(t,e){const n=(t.boundaryOffset??0)*e,o=t.value*e;if("out"===t.kind){const s=t.sideMassBefore*e;return n+("top"===t.side?o/2-s:s-o/2)}const s=t.sideMassAfter*e;return n+("top"===t.side?o/2-s:s-o/2)}function w(t,e,n,o,s,i){const a=i.adjacentClearance?[...i.adjacentClearance]:u(M(o,n)).adjacentClearance,r=y(o,a,i);let c="hug"===i.lanePlacement?function(t,e,n,o,s,i,a){const r=t.length;if(0===r)return[];const{padding:c,plotH:u,valueScale:f}=a,d=b(t,c,a.groupPadding??0),g=s.map((t,e)=>t*f+d[e]),m=c+t[0].peak.topPeak*f,p=u-c-t[r-1].peak.botPeak*f;if(p-m<=g.reduce((t,e)=>t+e,0)+1e-6)return y(t,s,a);let h=1===r?[(m+p)/2]:[...i];for(let t=0;t<12;t++){const t=new Array(r).fill(0),s=new Array(r).fill(0);for(const i of n){const n=e[i.source],a=e[i.target];if(null==n||null==a||n===a)continue;const r=o[i.source]?.localAttachments.get(i.id),l=o[i.target]?.localAttachments.get(i.id);if(!r||!l)continue;const c=i.value>0&&Number.isFinite(i.value)?i.value:1,u=x(r,f),d=x(l,f);t[n]+=(h[a]+d-u)*c,s[n]+=c,t[a]+=(h[n]+u-d)*c,s[a]+=c}const i=l({desired:h.map((e,n)=>0===s[n]?e:.45*e+t[n]/s[n]*.55),minGaps:g,weights:s.map(t=>Math.max(1,t)),min:m,max:p});let a=0;for(let t=0;t<r;t++)a=Math.max(a,Math.abs(i[t]-h[t]));if(h=i,a<.01)break}return h}(o,s,e,n,a,r,i):[...r];if("hug"===i.lanePlacement){const n=e=>{const n=m();for(const o of t)n[o.id]=e[s[o.id]];return n};v(n(c),e)>v(n(r),e)+1e-6&&(c=[...r])}const f=m();for(const e of t)f[e.id]=c[s[e.id]];let d=1/0,g=-1/0;for(const e of t){const t=f[e.id],o=n[e.id];Number.isFinite(t)&&o&&(d=Math.min(d,t-o.topPeak*i.valueScale),g=Math.max(g,t+o.botPeak*i.valueScale))}return{adjacentClearance:a,centerlines:f,slotCenter:c,stackCenter:r,verticalUtilization:Number.isFinite(d)&&Number.isFinite(g)&&i.plotH>0?Math.max(0,Math.min(1,(g-d)/i.plotH)):0}}function v(t,e){let n=0;for(const o of e){const e=t[o.source],s=t[o.target];Number.isFinite(e)&&Number.isFinite(s)&&(n+=Math.abs(e-s)*(o.value>0?o.value:1))}return n}function k(t,e){const n=t?.samples;if(!n||0===n.length||e<n[0].t)return{top:0,bot:0};let o=0,s=n.length-1,i=0;for(;o<=s;){const t=o+s>>>1;n[t].t<=e?(i=t,o=t+1):s=t-1}const a=n[i].boundaryOffset??0;return{top:n[i].topMass-a,bot:n[i].botMass+a}}function T(t,e,n,o,s){const i=1-s;return i*i*i*t+3*i*i*s*e+3*i*s*s*n+s*s*s*o}function S(t,e){let n=0,o=1;for(let s=0;s<28;s++){const s=(n+o)/2;T(0,e,e,1,s)<t?n=s:o=s}return(n+o)/2}function N(t,e,n){const o=e+x(t,n),s=t.value*n/2;return[o-s,o+s]}function O(t,e,n,o){return Math.max(0,Math.min(e,o)-Math.max(t,n))/Math.max(1e-9,e-t)}function P(t,e,n,o,s,i,a){const{valueScale:r,domain:l,mode:c="quality"}=a,u="source"===a.ribbonLane?.85:"target"===a.ribbonLane?.15:.5;let f=0;for(const a of t){const t=o[a.source],d=o[a.target];if(null==t||null==d||Math.abs(t-d)<2)continue;const g=e[a.source]?.localAttachments.get(a.id),m=e[a.target]?.localAttachments.get(a.id);if(!g||!m)continue;const p=Math.max(a.startTime,l?.[0]??-1/0),h=Math.min(a.endTime,l?.[1]??1/0);if(!(h>p))continue;const[b,M]=N(g,s[a.source],r),[y,x]=N(m,s[a.target],r),w=Math.min(t,d)+1,v=Math.max(t,d)-1;for(let t=w;t<=v;t++){const o=n[t];if(!o)continue;const l=[p,h];if("quality"===c)for(const t of o.occupants)for(const n of e[t.id]?.samples??[])n.t>p&&n.t<h&&l.push(n.t);const d=t=>{const n=S((t-p)/(h-p),u),l=T(b,b,y,y,n),c=T(M,M,x,x,n);let f=0;for(const n of o.occupants){if(n.id===a.source||n.id===a.target)continue;const o=i[n.id];if(null!=o?.start&&t<o.start)continue;if(null!=o?.end&&t>o.end)continue;const u=k(e[n.id],t),d=s[n.id];f=Math.max(f,O(l,c,d-u.top*r,d+u.bot*r))}return f},g=[...new Set(l)].sort((t,e)=>t-e);let m=0;for(let t=0;t<g.length-1;t++){const e=g[t],n=g[t+1]-e;m+=(d(e+.25*n)+d(e+.5*n)+d(e+.75*n))/3*n}f+=m/(h-p)*(a.value>0?a.value:1)}}return f}function F(t,e,n,o,s,i,a,r,l,c,u="both",f){return{crossings:t,weightedLength:e,pixelLength:v(a,n),transitOcclusion:P(n,o,s,i,a,r,{valueScale:l,ribbonLane:u,domain:f,mode:"quality"}),verticalUtilization:c}}function A(t,e){return e?Math.max(e[0],Math.min(e[1],t)):t}function $(t,e){return t.map(t=>({t:A(t.t,e),topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}}))}function I(t,e,n){const o=e+(t.boundaryOffset??0)*n,s=t.value*n;if("out"===t.kind){const e=t.sideMassBefore*n;if("top"===t.side){const t=o-e;return[t,t+s]}const i=o+e;return[i-s,i]}const i=t.sideMassAfter*n;if("top"===t.side){const t=o-i;return[t,t+s]}const a=o+i;return[a-s,a]}function E(t,e,n,o,s="temporal"){const i=e.incoming[t.id],r=e.outgoing[t.id],l=[];for(const t of i)l.push({time:t.endTime,delta:+t.value,edge:t,kind:"in",side:n.get(t.id).targetSide});for(const t of r)l.push({time:t.startTime,delta:-t.value,edge:t,kind:"out",side:n.get(t.id).sourceSide});const c={create:0,in:1,"transfer-out":2,"transfer-in":3,out:4},u=()=>{l.sort((t,e)=>t.time-e.time||(t.phase??0)-(e.phase??0)||(t.sequence??0)-(e.sequence??0)||(c[t.kind]??99)-(c[e.kind]??99)||((t,e)=>{if(!o||!t.edge||!e.edge||t.kind!==e.kind||t.side!==e.side)return 0;if("out"===t.kind){if(t.edge.target===e.edge.target&&t.edge.endTime===e.edge.endTime)return 0;const n=o.get(t.edge.id)?.target,s=o.get(e.edge.id)?.target;return"number"==typeof n&&Number.isFinite(n)&&"number"==typeof s&&Number.isFinite(s)&&n!==s?"top"===t.side?n-s:s-n:0}if("in"===t.kind){if(t.edge.source===e.edge.source&&t.edge.startTime===e.edge.startTime)return 0;const n=o.get(t.edge.id)?.source,s=o.get(e.edge.id)?.source;return"number"==typeof n&&Number.isFinite(n)&&"number"==typeof s&&Number.isFinite(s)&&n!==s?"top"===t.side?s-n:n-s:0}return 0})(t,e)||p(t.edge?.id??"",e.edge?.id??"")||p(t.side,e.side)||t.delta-e.delta)},f=l.length?a(l.map(t=>t.time)):null,d=Array.isArray(t.xExtent)&&Number.isFinite(t.xExtent[0])?t.xExtent[0]:null,g=null!=d?d-1:null!=f&&Number.isFinite(f)?f-1:null;u();let m=null,h=0;for(const t of l)t.time!==m&&(m=t.time,h=0),t.sequence=h++;const b=t=>({time:t.time,phase:0,sequence:t.sequence??0}),M=[];let y=0,x=0;for(const t of l)if("out"===t.kind){const e=Math.abs(t.delta);let n=e-("top"===t.side?y:x);if(n>0){const e="top"===t.side?"bot":"top",o="top"===e?y:x,s=Math.min(n,o);if(s>0){const o=b(t);M.push({...o,delta:-s,kind:"transfer-out",side:e}),M.push({...o,delta:+s,kind:"transfer-in",side:t.side}),"top"===e?y-=s:x-=s,"top"===t.side?y+=s:x+=s,n-=s}n>0&&null!==g&&(M.push({time:g,delta:+n,kind:"create",side:t.side}),"top"===t.side?y+=n:x+=n)}"top"===t.side?y-=e:x-=e}else if("in"===t.kind){const e=Math.abs(t.delta);"top"===t.side?y+=e:x+=e}l.push(...M),u();let w=0,v=0,k=0,T=0,S=0,N=0;const O=[],P=new Map,F=t=>{O.push({t:t,topMass:w,botMass:v,...Math.abs(k)>1e-12&&{boundaryOffset:k}})},A=()=>{T=Math.max(T,w+v),S=Math.max(S,w-k),N=Math.max(N,v+k)};for(const t of l){if("transfer-out"!==t.kind&&"transfer-in"!==t.kind&&F(t.time),("in"===t.kind||"out"===t.kind)&&t.edge){const e="top"===t.side?w:v,n=e+t.delta;P.set(t.edge.id,{side:t.side,time:t.time,sideMassBefore:e,sideMassAfter:n,kind:t.kind,value:Math.abs(t.delta),...Math.abs(k)>1e-12&&{boundaryOffset:k}})}"top"===t.side?w+=t.delta:v+=t.delta,"transfer-in"===t.kind?(k+="top"===t.side?t.delta:-t.delta,A(),F(t.time)):"transfer-out"!==t.kind&&(A(),"out"===t.kind&&w+v<=1e-12&&(k=0),F(t.time))}const $=[];let I=0;for(;I<O.length;){let t=I;for(;t+1<O.length&&O[t+1].t===O[I].t;)t++;$.push(O[I]);for(let e=I+1;e<=t;e++){const t=$[$.length-1];O[e].topMass===t.topMass&&O[e].botMass===t.botMass&&(O[e].boundaryOffset??0)===(t.boundaryOffset??0)||$.push(O[e])}I=t+1}const E=Array.isArray(t.xExtent)&&Number.isFinite(t.xExtent[1])?t.xExtent[1]:null;let L=null;for(const t of r)null!=t.systemInTime&&Number.isFinite(t.systemInTime)&&t.systemInTime<t.startTime&&(null===L||t.systemInTime<L)&&(L=t.systemInTime);let z=null;for(const t of i)null!=t.systemOutTime&&Number.isFinite(t.systemOutTime)&&t.systemOutTime>t.endTime&&(null===z||t.systemOutTime>z)&&(z=t.systemOutTime);if($.length>0){const t=$[$.length-1],e=Math.max(null!=E?E:-1/0,null!=z?z:-1/0);Number.isFinite(e)&&e>t.t&&t.topMass+t.botMass>0&&$.push({t:e,topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}});const n=$[0],o=$.find(t=>t.topMass+t.botMass>0);let s,i=1/0;null!=d&&Number.isFinite(d)&&d<n.t&&n.topMass+n.botMass>0&&(i=d,s=n),o&&null!=L&&Number.isFinite(L)&&L<o.t&&L<i&&(i=L,s=o),s&&Number.isFinite(i)&&$.unshift({t:i,topMass:s.topMass,botMass:s.botMass,...null!=s.boundaryOffset&&{boundaryOffset:s.boundaryOffset}})}let B=$;if("max"===s&&null!=d&&null!=E&&E>d){let t,e=0;for(const n of $){const o=n.topMass+n.botMass;o>e&&(e=o,t=n)}if(t){const e={topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}};B=[...$.filter(t=>t.t<d),{t:d,...e},{t:E,...e},...$.filter(t=>t.t>E)]}}return{samples:B,peak:T,topPeak:S,botPeak:N,localAttachments:P}}var L=(t,e)=>{let n=0,o=t.length;for(;n<o;){const s=n+o>>>1;t[s]<e?n=s+1:o=s}return n},z=class{constructor(t){this.coordinates=[...new Set(t)].sort((t,e)=>t-e),this.tree=new Int32Array(this.coordinates.length+1)}add(t,e){for(let n=L(this.coordinates,t)+1;n<this.tree.length;n+=n&-n)this.tree[n]+=e}below(t){let e=0;for(let n=L(this.coordinates,t);n>0;n-=n&-n)e+=this.tree[n];return e}};function B(t,e){return t.source!==e.source&&t.target!==e.target&&t.source!==e.target&&t.target!==e.source&&Math.max(t.startTime,e.startTime)<Math.min(t.endTime,e.endTime)}var C=class{constructor(t,e,n){this.size=n,this.routes=[],this.outgoing=Array.from({length:n},()=>[]),this.incoming=Array.from({length:n},()=>[]);const o=new Map,s=new Map;for(const t of e.keys())s.set(t,s.size);this.nodeCount=s.size;for(const n of t){const t=e.get(n.source),i=e.get(n.target);if(void 0===t||void 0===i||!(n.startTime<n.endTime))continue;const a=s.get(n.source),r=s.get(n.target),l=`${a}:${r}`;o.has(l)||o.set(l,o.size);const c=this.routes.length;this.routes.push({edge:n,source:t,target:i,sourceNode:a,targetNode:r,pair:o.get(l),reverse:-1}),this.outgoing[t].push(c),this.incoming[i].push(c)}for(const t of this.routes)t.reverse=o.get(`${t.targetNode}:${t.sourceNode}`)??-1;if(this.events=this.routes.flatMap((t,e)=>[{time:t.edge.startTime,route:e,delta:1},{time:t.edge.endTime,route:e,delta:-1}]).sort((t,e)=>t.time-e.time||t.delta-e.delta||t.route-e.route),this.smallPairs=this.routes.length<=80?[]:null,this.smallPairs)for(let t=0;t<this.routes.length;t++)for(let e=t+1;e<this.routes.length;e++)B(this.routes[t].edge,this.routes[e].edge)&&this.smallPairs.push([t,e]);this.work=this.smallPairs?.length??1/0}crossing(t,e,n){return(n[t.source]-n[e.source])*(n[t.target]-n[e.target])<0?1:0}count(t){if(this.smallPairs){let e=0;for(const[n,o]of this.smallPairs)e+=this.crossing(this.routes[n],this.routes[o],t);return e}const e=Array.from({length:this.size+1},()=>[]);for(const n of this.routes){const o=t[n.source],s=t[n.target];for(let t=o+1;t<=this.size;t+=t&-t)e[t].push(s)}const n=e.map(t=>new z(t)),o=new Int32Array(4*this.nodeCount),s=new Int32Array(this.routes.length),i=(t,e)=>{let o=0;for(let s=t;s>0;s-=s&-s)o+=n[s].below(e);return o};let a=0;for(const e of this.events){const r=this.routes[e.route],l=t[r.source],c=t[r.target];1===e.delta&&(a+=i(l,this.size)-i(l,c+1)+i(this.size,c)-i(l+1,c),l!==c&&(a-=o[4*r.sourceNode+(l<c?1:0)],a-=o[4*r.targetNode+(l<c?2:3)],r.reverse>=0&&(a+=s[r.reverse])));for(let t=l+1;t<=this.size;t+=t&-t)n[t].add(c,e.delta);l!==c&&(o[4*r.sourceNode+(l<c?3:2)]+=e.delta,o[4*r.targetNode+(l<c?0:1)]+=e.delta),s[r.pair]+=e.delta}return a}swapDelta(t,e,n){let o=0,s=0;const i=o=>n[o===t?e:o===e?t:o],a=(t,e)=>{const a=this.routes[t],r=this.routes[e];if(!B(a.edge,r.edge))return;s++;const l=(i(a.source)-i(r.source))*(i(a.target)-i(r.target))<0?1:0;o+=l-this.crossing(a,r,n)};for(const n of this.outgoing[t])for(const t of this.outgoing[e])a(n,t);for(const n of this.incoming[t])for(const o of this.incoming[e]){const s=this.routes[n],i=this.routes[o];s.source===t&&i.source===e||s.source===e&&i.source===t||a(n,o)}return{delta:o,evaluations:s}}};function X(t){const e=m();return t.forEach((t,n)=>{for(const o of t.occupants)e[o.id]=n}),e}function j(t,e,n){t.length=n.length;for(let e=0;e<n.length;e++)t[e]=n[e];const o=X(n);for(const t of Object.keys(e))delete e[t];Object.assign(e,o)}function D(t){const e=new Map,n=[];t.forEach((t,o)=>{if(!t.group)return void n.push({anchor:o,stableId:h(t),slots:[t]});const s=e.get(t.group)??{indexes:[],slots:[]};s.indexes.push(o),s.slots.push(t),e.set(t.group,s)});for(const[t,o]of e)n.push({anchor:o.indexes.reduce((t,e)=>t+e,0)/o.indexes.length,stableId:`${t}\0${o.slots.map(h).join("\0")}`,slots:o.slots});return n.sort((t,e)=>t.anchor-e.anchor||p(t.stableId,e.stableId))}function H(t){return t.some(t=>t.group)?D(t).flatMap(t=>t.slots):[...t]}function Y(t){return t.flatMap(t=>t.slots)}function q(t,e,n){const o=new Map;return t.forEach((t,e)=>{for(const n of t.slots)o.set(n,e)}),t.map((t,s)=>{if(t.slots.length<=1)return t;const i=new Map;for(const e of t.slots)i.set(e,0);for(const t of e){const e=o.get(t.source),n=o.get(t.target);if(null==e||null==n)continue;const a=Number.isFinite(t.weight)&&t.weight>0?t.weight:1;if(e===s&&n!==s){const e=n>s?1:-1;i.set(t.source,(i.get(t.source)??0)+a*e)}else if(n===s&&e!==s){const n=e>s?1:-1;i.set(t.target,(i.get(t.target)??0)+a*n)}}const a=[...t.slots].sort((t,e)=>(i.get(t)??0)-(i.get(e)??0)||n(t,e));return{...t,slots:a}})}function V(t,e){t.some(t=>t.group)&&j(t,e,H(t))}function W(t,e){const n=[...new Set(Object.values(t))].sort((t,e)=>t-e),o=new Map(n.map((t,e)=>[t,e])),s=new Map(Object.entries(t).map(([t,e])=>[t,o.get(e)]));return new C(e,s,n.length).count(n.map((t,e)=>e))}function G(t,e){let n=0;for(const o of e){const e=t[o.source],s=t[o.target];null!=e&&null!=s&&(n+=Math.abs(e-s)*(o.value>0?o.value:1))}return n}var R=t=>{let e=1;for(let n=2;n<=t;n++)e*=n;return e},U=828*R(8),_=3e3;function Z(t){const e=new Array(t.length),n=Math.floor((t.length-1)/2);let o=n-1,s=n+1;t.length>0&&(e[n]=t[0]);for(let n=1;n<t.length;n++)n%2==1&&s<t.length?e[s++]=t[n]:o>=0?e[o--]=t[n]:e[s++]=t[n];return e}function Q(t,e,n){let o=n(t),s=o,i=[...t];const a=Math.floor((t.length-1)/2);for(const r of e){const e=t.indexOf(r);if(e===a)continue;t.splice(e,1),t.splice(a,0,r);const l=n(t);l<=o?(o=l,l<s&&(i=[...t],s=l)):(t.splice(a,1),t.splice(e,0,r))}return i}function J(t,e,n,o,s,i,a){const r=[...s],l=new Map(s.map(t=>[t,h(t)])),c=new Map;for(const t of s)for(const e of t.occupants)c.set(e.id,t);const m=new Map,b=[];for(const t of e){const e=c.get(t.source),n=c.get(t.target);e&&n&&(m.set(t,[e,n]),e!==n&&b.push({source:e,target:n,weight:t.value}))}const y=e.reduce((t,e)=>t+(e.value>0?e.value:1),0),x=a.plotH/Math.max(1,s.length),k=s.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),T=Math.max(1,y)*(Math.max(1,a.plotH)+x*Math.max(k,s.length)+1e-6*Math.max(1,s.length-1))+1,S=4*x,N={fullCrossing:0,localCrossing:0},O=new Map,F=(t,e)=>{let o=O.get(t);o||(o=new Map,O.set(t,o));const s=o.get(e);if(null!=s)return s;const i=function(t,e,n){return u(M([t,e],n)).adjacentClearance[0]??0}(t,e,n);return o.set(e,i),i},A=new Map(s.map((t,e)=>[t,e])),$=new C(e,new Map([...c].map(([t,e])=>[t,A.get(e)])),s.length),I=t=>{const e=new Int32Array(s.length);for(let n=0;n<t.length;n++)e[A.get(t[n])]=n;return e},E=new Map([...m].map(([t,[e,n]])=>[t,{source:A.get(e),target:A.get(n),weight:t.value>0?t.value:1}])),L=[...E.values()],z=new Map,B=new Map,V=new Map,W=(t,e,n)=>{t.has(e)||t.set(e,new Set),t.get(e).add(n)};for(const t of e)W(z,t.source,t.target),W(B,t.target,t.source),W(V,t.source,t.target),W(V,t.target,t.source);const J=e.flatMap(t=>{if(!(t=>1===z.get(t.source)?.size&&z.get(t.source).has(t.target)||1===V.get(t.source)?.size||1===V.get(t.target)?.size)(t))return[];const e=E.get(t);return e&&e.source!==e.target?[e]:[]}),K=t=>{let e=0;for(const n of J)e+=Math.max(0,Math.abs(t[n.source]-t[n.target])-1)*n.weight;return e*S},tt=t=>K(I(t)),et=new Int32Array(s.length),nt=new Float64Array(s.length),ot=new Float64Array(s.length+1),st=t=>{for(let e=0;e<t.length;e++)et[A.get(t[e])]=e;const e=$.count(et);if(t.length>0){const e=A.get(t[0]);nt[e]=a.padding+t[0].peak.topPeak*a.valueScale;for(let e=1;e<t.length;e++){const n=A.get(t[e-1]),o=A.get(t[e]);nt[o]=nt[n]+F(t[e-1],t[e])*a.valueScale+a.padding}const n=A.get(t[t.length-1]),o=nt[n]+t[t.length-1].peak.botPeak*a.valueScale+a.padding;if(o>a.plotH&&o>0){const t=a.plotH/o;for(let e=0;e<nt.length;e++)nt[e]*=t}}ot[0]=0;for(let e=0;e<t.length;e++)ot[e+1]=ot[e]+t[e].peak.topPeak+t[e].peak.botPeak;let n=0,o=0,s=0;for(const t of L){const e=et[t.source],i=et[t.target];if(n+=Math.abs(e-i)*t.weight,o+=Math.abs(nt[t.source]-nt[t.target])*t.weight,Math.abs(e-i)>=2){const n=Math.min(e,i)+1,o=Math.max(e,i);s+=(ot[o]-ot[n])*t.weight}}return e*T+o+s*x+K(et)+1e-6*n},it=(s,i,r)=>{let l=i;null==l&&(l=$.count(I(s)),N.fullCrossing++);const{map:c,geometry:u,weightedLength:f,pixelLength:d}=(o=>{const s=X(o),i=o.slice(0,-1).map((t,e)=>F(t,o[e+1])),r=w(t,e,n,o,s,{plotH:a.plotH,padding:a.padding,valueScale:a.valueScale,lanePlacement:a.lanePlacement??"stack",groupPadding:a.groupPadding,adjacentClearance:i});return{map:s,geometry:r,weightedLength:G(s,e),pixelLength:v(r.centerlines,e)}})(s),g=r?P(e,n,s,c,u.centerlines,o,{valueScale:a.valueScale,ribbonLane:a.ribbonLane,domain:a.domain,mode:r}):((t,n)=>{const o=new Array(t.length+1).fill(0);for(let e=0;e<t.length;e++)o[e+1]=o[e]+t[e].peak.topPeak+t[e].peak.botPeak;let s=0;for(const t of e){const e=n[t.source],i=n[t.target];if(null==e||null==i||Math.abs(e-i)<2)continue;const a=Math.min(e,i)+1;s+=(o[Math.max(e,i)]-o[a])*(t.value>0?t.value:1)}return s})(s,c);return{crossings:l,weightedLength:f,pixelLength:d,transitOcclusion:g,cost:l*T+d+g*x+tt(s)+1e-6*f}},at=(t,e,n="quality")=>it(t,e,n);let rt=[...r];const lt=(t,e)=>p(l.get(t),l.get(e)),ct=function(t){const e=new Set;for(const n of t)if(n.group){if(e.has(n.group))return!0;e.add(n.group)}return!1}(rt),ut=(t,e,n,o=3e3)=>{let s=e(t);for(let i=0;i<n&&o>0;i++){let n=!1;const a=Array.from({length:t.length-1},(t,e)=>e);i%2==1&&a.reverse();for(const i of a){if(o--<=0)break;const a=t[i],r=t[i+1],l=$.swapDelta(A.get(a),A.get(r),I(t));[t[i],t[i+1]]=[r,a],N.localCrossing+=l.evaluations;const c=e(t,s.crossings+l.delta);c.cost<s.cost?(s=c,n=!0):[t[i],t[i+1]]=[a,r]}if(!n)break}return t},ft=t=>{const e=(t=>{const e=f(t,b,t=>it(t).cost,{passes:6,compare:lt,maxEvaluations:_});return ut(e,it,6)})(t);if((t.length<=8?R(t.length)*(t.length+L.length+$.work):1/0)>U)return e;const n=g(t,st,{maxItems:8,maxEvaluations:5e4}),o=at(n),s=at(e);return o.crossings!==s.crossings&&o.crossings<s.crossings?n:e},dt=t=>{let e=D(t);if(e.length<=1)return Y(e);const n=t=>it(Y(t)).cost;e=D(ft(t)),e=q(e,b,lt);const o=function(t,e){const n=new Map;for(const e of t)for(const t of e.slots)n.set(t,e);const o=new Map;for(const t of e){const e=n.get(t.source),s=n.get(t.target);if(!e||!s||e===s)continue;const i=Number.isFinite(t.weight)&&t.weight>0?t.weight:1,a=e.stableId<s.stableId?`${e.stableId}\0${s.stableId}`:`${s.stableId}\0${e.stableId}`,r=o.get(a);r?r.weight=(r.weight??0)+i:o.set(a,{source:e,target:s,weight:i})}return[...o.values()]}(e,b);e=f(e,o,n,{passes:6,compare:(t,e)=>p(t.stableId,e.stableId),maxEvaluations:_}),e=d(e,n,{passes:8,maxEvaluations:_});if((e.length<=8?R(e.length)*(e.length+L.length+$.work):1/0)<=U){const t=g(e,t=>st(Y(t)),{maxItems:8,maxEvaluations:5e4}),n=Y(t),o=Y(e),s=at(n),i=at(o);s.crossings!==i.crossings?e=s.crossings<i.crossings?t:e:s.cost<i.cost&&(e=t)}return e=q(e,b,lt),Y(e)},gt=t=>t.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),mt=(t,e)=>gt(e)-gt(t)||p(t.stableId,e.stableId),pt=(t,e)=>e.peak.topPeak+e.peak.botPeak-(t.peak.topPeak+t.peak.botPeak)||lt(t,e),ht="geometry-refine"===a.mode;if(ht||"crossing-min"!==a.laneOrder&&"crossing-min+inside-out"!==a.laneOrder){if(!ht&&"inside-out"===a.laneOrder)if(ct){rt=Y(Z([...D(rt)].sort(mt)))}else{rt=Z([...rt].sort(pt))}}else rt=ct?dt(rt):ft(rt);if(!ht&&"crossing-min+inside-out"===a.laneOrder&&rt.length>1)if(ct){const t=D(rt);rt=Y(Q(t,[...t].sort(mt),t=>it(Y(t)).cost))}else{rt=Q(rt,[...rt].sort(pt),t=>it(t).cost)}if((ht||"crossing-min"===a.laneOrder||"crossing-min+inside-out"===a.laneOrder)&&rt.length>1)if(ct){let t=d(D(rt),t=>at(Y(t),void 0,"score").cost,{passes:6});t=q(t,b,lt),rt=Y(t)}else ut(rt,(t,e)=>at(t,e,"score"),1,1/0);const bt=H(r);rt=H(rt);let Mt=at(rt);const yt=at(bt);if(ht){const t=tt(bt),e=tt(rt);(Mt.crossings>yt.crossings||Mt.crossings===yt.crossings&&e>t+1e-9||Mt.cost>yt.cost)&&(rt=bt,Mt=yt)}else Mt.cost>yt.cost&&(rt=bt,Mt=yt);const xt=function({order:t,after:e,nodes:n,edges:o,outgoingPartners:s,incomingPartners:i,slotForNode:a,averageGap:r,evaluate:l}){const c=(n,s)=>{const i=[...new Set(s.map(e=>t.indexOf(e)))].sort((t,e)=>t-e),a=t.indexOf(n),c=i[0],u=i[i.length-1];if(i.length<3||!i.includes(a)||u-c+1!==i.length||Math.abs(2*a-c-u)<=1)return;const f=[...t];f.splice(a,1),f.splice(c+u>>1,0,n);const d=H(f),g=l(d),m=new Set(n.occupants.map(t=>t.id)),p=new Set(s.flatMap(t=>t.occupants.map(t=>t.id))),h=o.reduce((t,e)=>m.has(e.source)&&p.has(e.target)||m.has(e.target)&&p.has(e.source)?t+(e.value>0?e.value:1):t,0),b=Math.abs(2*a-c-u)*r*Math.max(1,h);(function(t,e,n=0){return t.crossings<e.crossings||t.crossings===e.crossings&&t.cost<=e.cost+n})(g,e,b)&&(t=d,e=g)};for(const[t,e]of s)!i.has(t)&&e.size>=3&&c(a.get(t),[...e].map(t=>a.get(t)));for(const t of n){const e=a.get(t.id);!t.group&&e.group&&(i.get(t.id)?.size??0)>=3&&c(e,[...i.get(t.id)??[]].map(t=>a.get(t)).filter(t=>t===e||t.group===e.group).filter((t,e,n)=>n.indexOf(t)===e))}return{order:t,after:e}}({order:rt,after:Mt,nodes:t,edges:e,outgoingPartners:z,incomingPartners:B,slotForNode:c,averageGap:x,evaluate:at});return rt=xt.order,Mt=xt.after,j(s,i,rt),{before:yt,after:Mt,initialOrder:r.map(t=>l.get(t)),evaluations:N}}function K(t,e,n){const o=t.map(t=>{const o=t.occupants.map(t=>({id:t.id,end:n[t.id]?.end??t.end}));let s=0,i=0;for(const t of o){const n=e[t.id];s=Math.max(s,n?.topPeak||0),i=Math.max(i,n?.botPeak||0)}return{occupants:o,peak:{topPeak:s,botPeak:i},...null!=t.group?{group:t.group}:{}}}),s=m();return o.forEach((t,e)=>{for(const n of t.occupants)s[n.id]=e}),{slots:o,slotByNode:s}}var tt=new Map;var et=1e5,nt=1e-9;function ot(t,e){return null!=t.start&&null!=t.end&&null!=e.start&&null!=e.end&&!(t.end<=e.start||e.end<=t.start)}function st(t,e){return p(t,e)<=0?`${t}\0${e}`:`${e}\0${t}`}function it(t){const e=new Map,n=new Map;for(const o of t)n.has(o.source)||n.set(o.source,new Set),e.has(o.target)||e.set(o.target,new Set),n.get(o.source).add(o.target),e.get(o.target).add(o.source);return{incoming:new Map([...e].map(([t,e])=>[t,e.size])),outgoing:new Map([...n].map(([t,e])=>[t,e.size]))}}function at(t){const e=new Map,n=new Map,o=(t,e,n,o)=>{let s=t.get(e);s||(s=new Map,t.set(e,s)),s.set(n,(s.get(n)??0)+o)};for(const s of t){const t=s.value>0&&Number.isFinite(s.value)?s.value:1;o(e,s.source,s.target,t),o(n,s.target,s.source,t)}const s=new Map,i=t=>{if(s.has(t))return;const o=e.get(t),i=n.get(t),a=new Map;for(const[t,e]of o??[])a.set(t,(a.get(t)??0)+e);for(const[t,e]of i??[])a.set(t,(a.get(t)??0)+e);if(1===a.size){const[e,n]=[...a][0];s.set(t,{partner:e,weight:n})}};for(const e of t)i(e.source),i(e.target);return s}function rt(t,e,n){const o=n.get(t),s=n.get(e);return!o||!s||o.partner===s.partner||o.partner===e||s.partner===t}function lt(t,e,n){return!!n.has(t)&&e.some(e=>!rt(t,e,n))}function ct(t,e){return(t.value>0&&Number.isFinite(t.value)?t.value:1)*(1+(1===e.outgoing.get(t.source)?1:0)+(1===e.incoming.get(t.target)?1:0))}function ut(t,e,n,o){if(t.length<=12||o.slotCount<=1)return o.assignment;const s=new Map(t.map((t,e)=>[t,e])),i=Array.from({length:t.length},()=>new Map),a=it(n);for(const t of n){const e=s.get(t.source),n=s.get(t.target);if(null==e||null==n||e===n)continue;const o=ct(t,a);i[e].set(n,(i[e].get(n)??0)+o),i[n].set(e,(i[n].get(e)??0)+o)}const r=at(n),l=t.map(t=>r.get(t)?.weight??0),c=Array.from({length:t.length},()=>new Map);let u=0;for(let n=0;n<t.length-1&&u<5e4;n++)if(r.has(t[n]))for(let o=n+1;o<t.length;o++){if(!r.has(t[o]))continue;if(e.conflicts(t[n],t[o]))continue;u++;const s=Math.min(l[n],l[o])||Math.max(l[n],l[o]),i=rt(t[n],t[o],r)?s:-s;if(!(Math.abs(i)<=nt)&&(c[n].set(o,i),c[o].set(n,i),u>=5e4))break}const f=[...o.assignment],d=Array.from({length:o.slotCount},()=>[]);f.forEach((t,e)=>d[t].push(e));const g=(t,e,n)=>{const o=f[e],s=f[n];let i=0;const a=new Set;for(const r of[e,n])for(const[l,c]of t[r]){const t=r<l?`${r}:${l}`:`${l}:${r}`;if(a.has(t))continue;a.add(t);const u=f[r]===f[l],d=(r===e?s:o)===(l===e?s:l===n?o:f[l]);u!==d&&(i+=d?c:-c)}return i},m=(t,e,n)=>{let o=0;for(const[s,i]of t[e]){const t=f[e]===f[s],a=n===f[s];t!==a&&(o+=a?i:-i)}return o},p=(t,e)=>t>nt||Math.abs(t)<=nt&&e>nt,h=(t,e,n,o)=>t>n+nt||Math.abs(t-n)<=nt&&e>o+nt;let b=0;for(let n=0;n<32&&b<et;n++){let n=null,o=-1,s=-1,a=-1,r=-1/0,l=-1/0;for(let u=0;u<t.length;u++){for(let g=0;g<d.length&&!(b++>=et);g++){if(g===f[u])continue;if(!d[g].every(n=>!e.conflicts(t[u],t[n])))continue;const b=m(i,u,g),M=m(c,u,g);p(b,M)&&h(b,M,r,l)&&(n="move",o=u,s=-1,a=g,r=b,l=M)}if(b>=et)break}for(let u=0;u<t.length-1;u++){for(let m=u+1;m<t.length&&!(b++>=et);m++){const b=f[u],M=f[m];if(b===M)continue;if(!d[M].every(n=>n===m||!e.conflicts(t[u],t[n])))continue;if(!d[b].every(n=>n===u||!e.conflicts(t[m],t[n])))continue;const y=g(i,u,m),x=g(c,u,m);p(y,x)&&h(y,x,r,l)&&(n="swap",o=u,s=m,a=-1,r=y,l=x)}if(b>=et)break}if(null==n||-1===o)break;if("move"===n){const t=f[o];d[t].splice(d[t].indexOf(o),1),d[a].push(o),f[o]=a;continue}const u=f[o],M=f[s];d[u].splice(d[u].indexOf(o),1,s),d[M].splice(d[M].indexOf(s),1,o),f[o]=M,f[s]=u}return f}function ft(t,e,n,o){if(0===t.length||t.length>12||o.slotCount<=1)return o.assignment;const s=new Map(t.map((t,e)=>[t,e])),i=Array.from({length:t.length},()=>new Float64Array(t.length)),a=Array.from({length:t.length},()=>new Map),r=Array.from({length:t.length},()=>new Map),l=it(n);for(const t of n){const e=s.get(t.source),n=s.get(t.target);if(null==e||null==n||e===n)continue;const o=ct(t,l);i[e][n]+=o,i[n][e]+=o,r[e].set(n,(r[e].get(n)??0)+o),a[n].set(e,(a[n].get(e)??0)+o)}const c=at(n),u=t.map(t=>c.get(t)?.weight??0),f=Array.from({length:t.length},()=>new Float64Array(t.length));for(let e=0;e<t.length;e++)for(let n=e+1;n<t.length;n++){for(const[t,o]of a[e])f[e][n]+=Math.min(o,a[n].get(t)??0);for(const[t,o]of r[e])f[e][n]+=Math.min(o,r[n].get(t)??0);if(c.has(t[e])&&c.has(t[n])){const o=Math.min(u[e],u[n])||Math.max(u[e],u[n]);f[e][n]+=rt(t[e],t[n],c)?o:-o}f[n][e]=f[e][n]}let d=[...o.assignment],g=(e=>{let n=0,o=0;for(let s=0;s<t.length;s++)for(let a=s+1;a<t.length;a++)e[s]===e[a]&&(n+=i[s][a],o+=f[s][a]);return{flow:n,affinity:o}})(d),m=0;const p=new Array(t.length).fill(-1),h=Array.from({length:o.slotCount},()=>[]),b=(n,s,a,r)=>{if(m>=75e3)return;if(n===t.length)return m++,void((a>g.flow||a===g.flow&&r>g.affinity||a===g.flow&&r===g.affinity&&function(t,e){for(let n=0;n<Math.min(t.length,e.length);n++)if(t[n]!==e[n])return t[n]<e[n];return t.length<e.length}(p,d))&&(d=[...p],g={flow:a,affinity:r}));const l=Math.min(s+1,o.slotCount-1);for(let o=0;o<=l;o++){if(h[o].some(o=>e.conflicts(t[n],t[o])))continue;let l=0,c=0;for(const t of h[o])l+=i[n][t],c+=f[n][t];if(p[n]=o,h[o].push(n),b(n+1,Math.max(s,o),a+l,r+c),h[o].pop(),p[n]=-1,m>=75e3)return}};return p[0]=0,h[0].push(0),b(1,0,0,0),d}function dt(t,e){let n=1/0,o=-1/0;for(const e of t?.samples??[])e.topMass+e.botMass<=1e-9||(n=Math.min(n,e.t),o=Math.max(o,e.t));return Number.isFinite(n)&&Number.isFinite(o)?(null!=e.start&&(n=Math.max(n,e.start)),null!=e.end&&(o=Math.min(o,e.end)),o>=n?{start:n,end:o}:{start:null,end:null}):{start:null,end:null}}function gt(t,e,n,o){const s=function(t,e,n,o){return`${t.map(t=>{const e=n[t.id],s=o[t.id];return[t.id,t.group??"",t.xExtent?.[0]??"",t.xExtent?.[1]??"",e?.topPeak??0,e?.botPeak??0,s?.start??"",s?.end??""].join(":")}).join("|")}#${e.map(t=>[t.id,t.source,t.target,t.value,t.startTime,t.endTime].join(":")).join("|")}`}(t,e,n,o),i=(a=s,tt.get(a));var a;if(i)return K(i.slots,n,o);const r=m();for(const e of t)r[e.id]=dt(n[e.id],o[e.id]);const l=function(t,e){return t.filter(t=>null!=e[t.id].start).sort((t,n)=>e[t.id].start-e[n.id].start||e[t.id].end-e[n.id].end||p(t.id,n.id)).map(t=>t.id)}(t,r),c=new Map(t.map(t=>[t.id,t])),u=new Map(t.map(t=>[t.id,t.group||void 0])),f=at(e),d=function(t,e,n,o,s,i){const a=new Set,r=new Map(t.map(t=>[t,new Set])),l=new Map(t.map(t=>[t,new Set]));for(const t of o)a.add(st(t.source,t.target)),r.get(t.target)?.add(t.source),l.get(t.source)?.add(t.target);const c=new Map,u=new Set,f=(t,e)=>{for(let n=0;n<t.length;n++)for(let o=n+1;o<t.length;o++){const s=st(t[n],t[o]);e instanceof Map?e.set(s,[t[n],t[o]]):e.add(s)}};for(const t of l.values())f([...t],c);for(const t of r.values())f([...t],u);const d=new Set;for(const[t,[o,s]]of c)u.has(t)&&(ot(e[o],e[s])||ot(n[o],n[s])&&(d.add(o),d.add(s)));return{conflicts:(t,n)=>{const o=s.get(t),r=s.get(n);return null!=o&&null!=r&&o!==r||!(null!=o==(null!=r)||a.has(st(t,n))||i.has(t)&&i.has(n)&&rt(t,n,i))||!!ot(e[t],e[n])||!(!d.has(t)&&!d.has(n))&&!a.has(st(t,n))}}}(l,r,o,e,u,f),g=function(t,e,n=new Map){const o=[],s=[];for(const i of t){let t=o.findIndex(t=>t.every(t=>!e.conflicts(i,t))&&!lt(i,t,n));-1!==t||n.has(i)||(t=o.findIndex(t=>t.every(t=>!e.conflicts(i,t)))),-1===t&&(t=o.length,o.push([])),o[t].push(i),s.push(t)}return{assignment:s,slotCount:o.length}}(l,d,f),h=ft(l,d,e,{...g,assignment:ut(l,d,e,g)}),b=new Map,M=h.map(t=>(b.has(t)||b.set(t,b.size),b.get(t))),y=Array.from({length:b.size||(t.length>0?1:0)},()=>({occupants:[],peak:{topPeak:0,botPeak:0}})),x=m();l.forEach((t,e)=>{const n=M[e],o=y[n];o.occupants.push({id:t,end:r[t].end??-1/0});const s=c.get(t)?.group;s&&(o.group=s),x[t]=n});for(const e of[...t].sort((t,e)=>p(t.id,e.id)))null==x[e.id]&&(y[0].occupants.push({id:e.id,end:-1/0}),x[e.id]=0);for(const t of y){t.occupants.sort((t,e)=>(r[t.id].start??1/0)-(r[e.id].start??1/0)||p(t.id,e.id));for(const e of t.occupants){const o=n[e.id];t.peak.topPeak=Math.max(t.peak.topPeak,o?.topPeak||0),t.peak.botPeak=Math.max(t.peak.botPeak,o?.botPeak||0)}}const w={slots:y,slotByNode:x};return function(t,e){for(tt.has(t)&&tt.delete(t),tt.set(t,{slots:e.slots.map(t=>({occupants:t.occupants.map(t=>({...t})),peak:{...t.peak},...null!=t.group?{group:t.group}:{}})),slotByNode:Object.assign(m(),e.slotByNode)});tt.size>12;){const t=tt.keys().next().value;if(null==t)break;tt.delete(t)}}(s,w),w}function mt(t){return t.topMass+t.botMass}function pt(t){const e=new Map;for(const n of t.samples){if(Number.isNaN(n.t))continue;let t=e.get(n.t);t||(t=[],e.set(n.t,t)),t.push(n)}let n=0,o=-1/0;return s=>{s>=o||(n=0),o=s;const i=e.get(s);if(i){const t=i.reduce((t,e)=>mt(e)>=mt(t)?e:t,i[0]);return{exact:i,sample:t}}for(;n<t.samples.length&&!(t.samples[n].t>s);)n++;return{exact:i,sample:t.samples[n-1]??null}}}function ht(t,e,n,o,s,i,a=0){const l=new Map;for(const n of t){if(!n.group||!e[n.id])continue;const t=l.get(n.group)??[];t.push(n),l.set(n.group,t)}if(0===l.size||!(i>0))return e;const c=(u=e,Object.fromEntries(Object.entries(u).map(([t,e])=>[t,{...e,samples:e.samples.map(t=>({...t})),localAttachments:new Map([...e.localAttachments].map(([t,e])=>[t,{...e}]))}])));var u;for(const[t,u]of l){const l=n.map((t,e)=>({slot:t,index:e})).filter(({slot:e})=>e.group===t);if(0===l.length)continue;const f=l[0].slot,d=l.at(-1).slot,g=s[f.occupants[0]?.id],m=s[d.occupants[0]?.id];if(!Number.isFinite(g)||!Number.isFinite(m))continue;const p=(g-f.peak.topPeak*i+(m+d.peak.botPeak*i))/2,h=[...new Set(u.flatMap(t=>e[t.id].samples.map(t=>t.t)))].sort((t,e)=>t-e),b=new Map;for(const t of u)b.set(t.id,new Map);const M=new Map(u.map(t=>[t.id,pt(e[t.id])]));for(const t of h){const e=new Map;for(const n of u){const{sample:s}=M.get(n.id)(t);if(!s||mt(s)<=1e-9)continue;const i=o[n.id];if(null==i)continue;const a=e.get(i)??[];a.push({node:n,sample:s}),e.set(i,a)}const n=[...e].sort((t,e)=>t[0]-e[0]).map(([t,e])=>({slot:t,active:e,mass:r(e.map(({sample:t})=>mt(t)))}));if(0===n.length)continue;let l=p-(n.reduce((t,e)=>t+e.mass,0)*i+Math.max(0,a)*Math.max(0,n.length-1))/2;for(const e of n){for(const{node:n,sample:o}of e.active){const e=(l-s[n.id])/i+o.topMass-(o.boundaryOffset??0);b.get(n.id).set(t,e)}l+=e.mass*i+Math.max(0,a)}}for(const t of u){const n=e[t.id],o=c[t.id],s=b.get(t.id),i=M.get(t.id),a=[];for(const t of h){const e=s.get(t),{exact:n,sample:o}=i(t);n?a.push(...n.map(t=>({...t,...null!=e?{boundaryOffset:(t.boundaryOffset??0)+e}:{}}))):null==e||!o||mt(o)<=1e-9||a.push({...o,t:t,boundaryOffset:(o.boundaryOffset??0)+e})}o.samples=a,o.localAttachments=new Map([...n.localAttachments].map(([t,e])=>{const n=s.get(e.time);return[t,{...e,...null!=n?{boundaryOffset:(e.boundaryOffset??0)+n}:{}}]}))}}return c}function bt(t,e,n,o,s){const{plotH:i,padding:a,valueScale:r,packing:l,laneOrder:c,lifetimeMode:u="half",lanePlacement:f="stack",groupPadding:d=0,ribbonLane:g="both",domain:b}=s,M=m(),y=m();for(const e of t)M[e.id]=n[e.id].topPeak||0,y[e.id]=n[e.id].botPeak||0;const x="half"===u,v=m();for(const e of t){const t=Array.isArray(e.xExtent)?e.xExtent[0]:null,n=Array.isArray(e.xExtent)?e.xExtent[1]:null;let s=null!=t&&Number.isFinite(t)?t:1/0,i=null!=n&&Number.isFinite(n)?n:-1/0;for(const t of o.outgoing[e.id]){t.startTime<s&&(s=t.startTime),null!=t.systemInTime&&Number.isFinite(t.systemInTime)&&t.systemInTime<s&&(s=t.systemInTime);const e=x?(t.startTime+t.endTime)/2:t.endTime;e>i&&(i=e)}for(const t of o.incoming[e.id]){const e=x?(t.startTime+t.endTime)/2:t.startTime;e<s&&(s=e),t.endTime>i&&(i=t.endTime),null!=t.systemOutTime&&Number.isFinite(t.systemOutTime)&&t.systemOutTime>i&&(i=t.systemOutTime)}v[e.id]={start:Number.isFinite(s)?s:null,end:Number.isFinite(i)?i:null}}let k=m(),T=[],S=[];if(s.frozenSlots){const t=K(s.frozenSlots,n,v);T=t.slots,k=t.slotByNode,S=T.map(h)}else if("reuse"===l){const o=gt(t,e,n,v);T=o.slots,k=o.slotByNode}else t.forEach((t,e)=>{T.push({occupants:[{id:t.id,end:v[t.id]?.end??-1/0}],peak:{topPeak:M[t.id],botPeak:y[t.id]},...t.group?{group:t.group}:{}}),k[t.id]=e});V(T,k),0===S.length&&(S=T.map(h));let N=null;s.frozenSlots||(s.fixedSlotOrder?function(t,e,n){const o=new Map(n.map((t,e)=>[t,e]));j(t,e,[...t].sort((t,e)=>(o.get(h(t))??1/0)-(o.get(h(e))??1/0)||p(h(t),h(e))))}(T,k,s.fixedSlotOrder):s.runOrdering&&c&&"insertion"!==c&&(N=J(t,e,n,v,T,k,{plotH:i,padding:a,valueScale:r,groupPadding:d,laneOrder:c,ribbonLane:g,domain:b}))),V(T,k);const O=w(t,e,n,T,k,{plotH:i,padding:a,valueScale:r,stackValueScale:s.stackValueScale,lanePlacement:f,groupPadding:d}),P=0===T.length?0:T[0].peak.topPeak+O.adjacentClearance.reduce((t,e)=>t+e,0)+T[T.length-1].peak.botPeak,F=N?.before.crossings??null,A=N?.after.crossings??null,$=N?.before.weightedLength??null,I=N?.after.weightedLength??null;return{effectiveSlotsHeight:P,centerlines:O.centerlines,laneLifetime:v,slots:T,slotByNode:k,slotCenter:O.slotCenter,stackCenter:O.stackCenter,verticalUtilization:O.verticalUtilization,selectedSlotOrder:T.map(h),initialSlotOrder:S,ordering:N,crossingsBefore:F,crossingsAfter:A,lengthBefore:$,lengthAfter:I}}function Mt(t,e,n){const{plotH:o,pairing:s="temporal",packing:i="reuse",laneOrder:a="crossing-min",lifetimeMode:r="half",maxValueScale:l,lanePlacement:c="stack",nodeSizing:u="temporal",groupPadding:f=0,ribbonLane:d="both",domain:g}=n,M=Number.isFinite(f)?Math.max(0,f):0,y=function(t,e){const n=m(),o=m();for(const e of t)n[e.id]=[],o[e.id]=[];for(const t of e)o[t.source]&&o[t.source].push(t),n[t.target]&&n[t.target].push(t);return{incoming:n,outgoing:o}}(t,e),x=function(t,e,n,o="temporal"){const s="temporal"===o?(t,e)=>t.endTime-e.endTime||p(t.id,e.id):(t,e)=>e.value-t.value||p(t.id,e.id),i="temporal"===o?(t,e)=>t.startTime-e.startTime||p(t.id,e.id):(t,e)=>e.value-t.value||p(t.id,e.id),a=new Map;for(const t of e)a.set(t.id,{});const r=(t,e)=>{const n=new Map;for(const o of t){const t=o[e];n.has(t)||n.set(t,{partner:t,edges:[],total:0,earliestStart:1/0,latestEnd:-1/0});const s=n.get(t);s.edges.push(o),s.total+=o.value,s.earliestStart=Math.min(s.earliestStart,o.startTime),s.latestEnd=Math.max(s.latestEnd,o.endTime)}const a=[...n.values()];"temporal"===o?a.sort((t,n)=>"target"===e?t.earliestStart-n.earliestStart||p(t.partner,n.partner):t.latestEnd-n.latestEnd||p(t.partner,n.partner)):a.sort((t,e)=>e.total-t.total||p(t.partner,e.partner));for(const t of a)t.edges.sort("target"===e?i:s);return a};for(const e of t){const t=n.outgoing[e.id],o=n.incoming[e.id];if(0===o.length)r(t,"target").forEach((t,e)=>{const n=e%2==0?"top":"bot";for(const e of t.edges)a.get(e.id).sourceSide=n});else if(0===t.length)r(o,"source").forEach((t,e)=>{const n=e%2==0?"top":"bot";for(const e of t.edges)a.get(e.id).targetSide=n});else{const e=r(o,"source"),n=r(t,"target"),s=Math.max(e.length,n.length);for(let t=0;t<s;t++){const o=t%2==0?"top":"bot";if(e[t])for(const n of e[t].edges)a.get(n.id).targetSide=o;if(n[t])for(const e of n[t].edges)a.get(e.id).sourceSide=o}}}return a}(t,e,y,s);let v=m();for(const e of t)v[e.id]=E(e,y,x,void 0,u);const k=bt(t,e,v,y,{plotH:o,padding:12,valueScale:1,packing:i,laneOrder:a,lifetimeMode:r,runOrdering:!0,lanePlacement:"stack",groupPadding:M,ribbonLane:d,domain:g}),T=k.slots.map(t=>({occupants:t.occupants.map(t=>({...t})),peak:{...t.peak},...null!=t.group?{group:t.group}:{}})),S=new Set;for(const t of e){const e=k.slotByNode[t.source],n=k.slotByNode[t.target];if(void 0===e||void 0===n)continue;const o=x.get(t.id);e!==n?n<e?(o.sourceSide="top",o.targetSide="bot"):(o.sourceSide="bot",o.targetSide="top"):(S.add(t.id),o.sourceSide="bot",o.targetSide="bot")}for(const e of t){const t=y.outgoing[e.id],n=y.incoming[e.id],o=new Set(t.map(t=>x.get(t.id).sourceSide)),s=new Set(n.map(t=>x.get(t.id).targetSide));if(1===o.size&&n.length>0){const t=[...o][0];for(const e of n)k.slotByNode[e.source]===k.slotByNode[e.target]&&(x.get(e.id).targetSide=t)}if(1===s.size&&t.length>0){const e=[...s][0];for(const n of t)k.slotByNode[n.source]===k.slotByNode[n.target]&&(x.get(n.id).sourceSide=e)}}!function(t,e,n){const o=new Map,s=[];for(const e of t)s.push({time:e.startTime,kind:"out",edge:e}),s.push({time:e.endTime,kind:"in",edge:e});s.sort((t,e)=>t.time-e.time||(t.kind===e.kind?0:"in"===t.kind?-1:1)||("out"===t.kind?e.edge.value-t.edge.value:0)||p(t.edge.id,e.edge.id));const i=t=>{let e=o.get(t);return e||(e={top:0,bot:0},o.set(t,e)),e},a=(t,e,n)=>{const o="top"===e?"bot":"top",s=Math.min(n,t[e]);t[e]-=s;const i=n-s;i>0&&(t[o]=Math.max(0,t[o]-i))};for(const t of s){const{edge:o}=t;if("in"===t.kind){const t=e.get(o.id)?.targetSide??"bot";i(o.target)[t]+=o.value;continue}const s=i(o.source),r=e.get(o.id);let l=r.sourceSide??"bot";if(n[o.source]===n[o.target]){const t=s.top>=o.value,e=s.bot>=o.value;t!==e?l=t?"top":"bot":t||e||s.top===s.bot||(l=s.top>s.bot?"top":"bot"),r.sourceSide=l,r.targetSide=l}a(s,l,o.value)}}(e,x,k.slotByNode),function(t,e,n,o){for(const s of t){const t=e.incoming[s.id],i=e.outgoing[s.id];if(0===t.length||0===i.length)continue;const a=()=>{const e={inTop:0,inBot:0,outTop:0,outBot:0};for(const o of t)"top"===n.get(o.id).targetSide?e.inTop+=o.value:e.inBot+=o.value;for(const t of i)"top"===n.get(t.id).sourceSide?e.outTop+=t.value:e.outBot+=t.value;return e},r=(t,e)=>{const s=a(),r="top"===t?s.outTop-s.inTop:s.outBot-s.inBot,l="top"===e?s.inTop-s.outTop:s.inBot-s.outBot;if(r<=0||l<=0)return!1;const c=Math.min(r,l),u=i.filter(e=>!o.has(e.id)&&n.get(e.id).sourceSide===t&&e.value<=c).sort((t,e)=>e.value-t.value||p(t.id,e.id));return 0!==u.length&&(n.get(u[0].id).sourceSide=e,!0)};let l=i.length+1;for(;l-- >0&&(r("top","bot")||r("bot","top")););}}(t,y,x,S),v=m();for(const e of t)v[e.id]=E(e,y,x,void 0,u);const N=bt(t,e,v,y,{plotH:o,padding:12,valueScale:1,packing:i,laneOrder:a,lifetimeMode:r,frozenSlots:T,lanePlacement:"stack",groupPadding:M,ribbonLane:d,domain:g}),O=N.effectiveSlotsHeight??N.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),P=N.slots.slice(0,-1).reduce((t,e,n)=>t+(null!=e.group&&e.group===N.slots[n+1].group?1:0),0),A=Math.max(1,N.slots.length+1-P),$=Math.min(12,Math.max(0,.35*o-P*M)/A),L=2*$+b(N.slots,$,M).reduce((t,e)=>t+e,0),z=O>0?Math.max(0,(o-L)/O):1,B=Number.isFinite(l)&&l>0?Math.min(z,l):z;let C=bt(t,e,v,y,{plotH:o,padding:$,valueScale:B,packing:i,laneOrder:a,lifetimeMode:r,frozenSlots:T,lanePlacement:c,groupPadding:M,ribbonLane:d,domain:g,stackValueScale:z});const X=Number.isFinite(l)&&l>0&&l+1e-12<z;if("insertion"!==a&&("hug"===c||X)&&C.slots.length>1&&(J(t,e,v,C.laneLifetime,C.slots,C.slotByNode,{plotH:o,padding:$,valueScale:B,groupPadding:M,laneOrder:a,ribbonLane:d,domain:g,lanePlacement:c,mode:"geometry-refine"}),C=bt(t,e,v,y,{plotH:o,padding:$,valueScale:B,packing:i,laneOrder:a,lifetimeMode:r,frozenSlots:C.slots,fixedSlotOrder:C.slots.map(h),lanePlacement:c,groupPadding:M,ribbonLane:d,domain:g,stackValueScale:z})),function(t,e){const n=(t,n)=>{for(const o of t){const t=new Map;for(const s of o){const o=`${("out"===n?e.get(s.id)?.sourceSide:e.get(s.id)?.targetSide)??""}\0${"out"===n?s.startTime:s.endTime}`,i="out"===n?`${s.target}\0${s.endTime}`:`${s.source}\0${s.startTime}`,a=t.get(o);if(null!=a&&a!==i)return!0;t.set(o,i)}}return!1};return n(Object.values(t.outgoing),"out")||n(Object.values(t.incoming),"in")}(y,x)){const n=function(t,e,n,o){const s=new Map;for(const i of t){const t=e[i.source]?.localAttachments.get(i.id),a=e[i.target]?.localAttachments.get(i.id),r=n[i.source],l=n[i.target];if(!(t&&a&&Number.isFinite(r)&&Number.isFinite(l)))continue;const c=I(t,r,o),u=I(a,l,o);s.set(i.id,{source:(c[0]+c[1])/2,target:(u[0]+u[1])/2})}return s}(e,v,C.centerlines,B);v=m();for(const e of t)v[e.id]=E(e,y,x,n,u);C=bt(t,e,v,y,{plotH:o,padding:$,valueScale:B,packing:i,laneOrder:a,lifetimeMode:r,frozenSlots:C.slots,fixedSlotOrder:C.slots.map(h),lanePlacement:c,groupPadding:M,ribbonLane:d,domain:g,stackValueScale:z})}const j=new Map(k.initialSlotOrder.map((t,e)=>[t,e])),D=[...C.slots].sort((t,e)=>(j.get(h(t))??1/0)-(j.get(h(e))??1/0)||p(h(t),h(e))),H=m();D.forEach((t,e)=>{for(const n of t.occupants)H[n.id]=e});const Y=w(t,e,v,D,H,{plotH:o,padding:$,valueScale:B,stackValueScale:z,lanePlacement:"stack",groupPadding:M}),q=ht(t,v,D,H,Y.centerlines,B,M),V=F(W(H,e),G(H,e),e,q,D,H,Y.centerlines,C.laneLifetime,B,Y.verticalUtilization,d,g);v=ht(t,v,C.slots,C.slotByNode,C.centerlines,B,M);const R=F(W(C.slotByNode,e),G(C.slotByNode,e),e,v,C.slots,C.slotByNode,C.centerlines,C.laneLifetime,B,C.verticalUtilization,d,g);return{nodeData:v,sides:x,valueScale:B,padding:$,compressedPadding:$<12,centerlines:C.centerlines,laneLifetime:C.laneLifetime,slots:C.slots,slotByNode:C.slotByNode,crossingsBefore:"insertion"===a?null:V.crossings,crossingsAfter:"insertion"===a?null:R.crossings,lengthBefore:"insertion"===a?null:V.weightedLength,lengthAfter:"insertion"===a?null:R.weightedLength,layoutQualityBefore:V,layoutQuality:R}}function yt(t,e,n,o,s,i,a,r,l={}){const c=s,u=t=>r?Math.max(r[0],Math.min(r[1],t)):t;let f=i(u(t.time));const d=i(u(n.time)),g=t.value*c,m=n.value*c,p=e+(t.boundaryOffset??0)*c,h=o+(n.boundaryOffset??0)*c,b=t.sideMassBefore*c,M=n.sideMassAfter*c;let y,x,w,v;"top"===t.side?(y=p-b,x=y+g):(x=p+b,y=x-g),"top"===n.side?(w=h-M,v=w+m):(v=h+M,w=v-m);const k=l.sourceRunwayStart,T=l.minRun,S=(y+x)/2,N=(w+v)/2,O=Math.abs(N-S),P=d-f,F="number"==typeof k&&Number.isFinite(k),A="number"==typeof T&&Number.isFinite(T)&&T>0;if(F&&O>1e-9&&P>0&&("auto"===T||A)){const e="source"===a?.85:"target"===a?.15:.5,n=1.5*Math.min(e*e,(1-e)*(1-e)),o="auto"===T?Math.min(144,Math.sqrt(8*O/n)):T;if(o>P){const e=i(u(Math.min(k,t.time)));if(Number.isFinite(e)){const t=Math.min(f,e);f=Math.min(f,Math.max(t,d-o))}}}const $="source"===a?f+.85*(d-f):"target"===a?f+.15*(d-f):(f+d)/2;return{sx:f,sTop:y,sBot:x,tx:d,tTop:w,tBot:v,cp1X:$,cp2X:$}}function xt(t){return Math.max(18,11*t.length*.58)}function wt(t){const e=1.22*xt(t.labelText)+4;return"start"===t.labelAnchor?[t.labelX,t.labelX+e]:"middle"===t.labelAnchor?[t.labelX-e/2,t.labelX+e/2]:[t.labelX-e,t.labelX]}function vt(t,e){const n=t.labelX-xt(t.labelText),o=e.labelX-xt(e.labelText);return n<=e.labelX+3&&o<=t.labelX+3}function kt(t,e,n){const o=t.map(t=>({...t})),s=new Map;for(const t of o){const n=e[t.id];if(null==n)continue;const o=s.get(n)??[];o.push(t),s.set(n,o)}const i=t=>{if(t.length<2)return;const e=t.reduce((t,e)=>t+e.labelY,0)/t.length,o=(t.length-1)/2;t.forEach((t,s)=>{t.labelY=Math.max(8,Math.min(n-8,e+16*(s-o)))})};for(const t of s.values()){t.sort((t,e)=>t.labelX-e.labelX||t.id.localeCompare(e.id));let e=[],n=-1/0;for(const o of t){const t=o.labelX-xt(o.labelText);e.length>0&&t>n+3&&(i(e),e=[],n=-1/0),e.push(o),n=Math.max(n,o.labelX)}i(e)}return function(t,e){const n=[...t].sort((t,e)=>t.labelY-e.labelY||t.labelX-e.labelX||t.id.localeCompare(e.id));for(let t=0;t<3;t+=1){for(let t=0;t<n.length;t+=1){let e=8;for(let o=0;o<t;o+=1)vt(n[t],n[o])&&(e=Math.max(e,n[o].labelY+16));n[t].labelY=Math.max(n[t].labelY,e)}for(let t=n.length-1;t>=0;t-=1){let o=e-8;for(let e=t+1;e<n.length;e+=1)vt(n[t],n[e])&&(o=Math.min(o,n[e].labelY-16));n[t].labelY=Math.min(n[t].labelY,o)}}}(o,n),o}var Tt=/(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?),(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)/gi;function St(t){return t.replace(Tt,(t,e,n)=>`${n},${e}`)}function Nt(t){if(!t)return;const e=t=>({x:t.y,y:t.x});return{...t,...t.points&&{points:t.points.map(e)},...t.segments&&{segments:t.segments.map(t=>t.map(e))}}}function Ot(t){return{...t,pathD:St(t.pathD),y0:t.x0,y1:t.x1,x0:0,x1:0}}function Pt(t,e){const n=function(t){if(null==t)return()=>{};const e="function"==typeof t?t:e=>e[t];return t=>Ft(e(t))}(e??"value"),o=null==t?void 0:"function"==typeof t?t:e=>e[t];return t=>{const e=o?o(t):void 0;return{value:n(t),category:null==e?void 0:String(e)}}}function Ft(t){if("number"==typeof t)return Number.isFinite(t)?t:void 0;if("string"==typeof t&&""!==t.trim()){const e=Number(t);return Number.isFinite(e)?e:void 0}}function At(t,e,n){const o=t.when;return void 0===o||!0===o||!1!==o&&("function"==typeof o?o(e,n):function(t,e,n){const o=null!=t.axis?n[t.axis]:null!=t.field?e[t.field]:n.value;if(void 0!==t.eq&&o!==t.eq)return!1;if(void 0!==t.ne&&o===t.ne)return!1;if(void 0!==t.in&&!t.in.includes(o))return!1;if(void 0===t.gt&&void 0===t.gte&&void 0===t.lt&&void 0===t.lte&&void 0===t.within&&void 0===t.outside)return!0;const s=Ft(o);if(void 0===s)return!1;if(void 0!==t.gt&&!(s>t.gt))return!1;if(void 0!==t.gte&&!(s>=t.gte))return!1;if(void 0!==t.lt&&!(s<t.lt))return!1;if(void 0!==t.lte&&!(s<=t.lte))return!1;if(void 0!==t.within){const[e,n]=t.within;if(!(s>=e&&s<=n))return!1}if(void 0!==t.outside){const[e,n]=t.outside;if(!(s<e||s>n))return!1}return!0}(o,e,n))}import{jsx as $t,jsxs as It}from"react/jsx-runtime";function Et(t){const{nodes:e,edges:o,domain:a,usageMode:r="static"}=t,l=function(t,e,o,s={}){const i=n(s.usageMode??"static"),a=[],r=new Set;for(const e of t)r.has(e.id)&&a.push({kind:"duplicate-node",id:e.id,severity:i.duplicateIds}),r.add(e.id);const l=new Set,c=Array.isArray(o)&&2===o.length,u=c&&Number.isFinite(o[0])&&Number.isFinite(o[1]),f=u&&o[0]<=o[1];c&&u&&f||a.push({kind:"invalid-domain"});for(const e of t)null!=e.xExtent&&(Array.isArray(e.xExtent)&&2===e.xExtent.length&&Number.isFinite(e.xExtent[0])&&Number.isFinite(e.xExtent[1])&&e.xExtent[0]<=e.xExtent[1]||a.push({kind:"invalid-node-time",id:e.id}));for(const t of e)l.has(t.id)&&a.push({kind:"duplicate-edge",id:t.id,severity:i.duplicateIds}),l.add(t.id),r.has(t.source)||a.push({kind:"missing-node",id:t.id,endpoint:"source",nodeId:t.source}),r.has(t.target)||a.push({kind:"missing-node",id:t.id,endpoint:"target",nodeId:t.target}),Number.isFinite(t.startTime)&&Number.isFinite(t.endTime)?((null!=t.systemInTime&&!Number.isFinite(t.systemInTime)||null!=t.systemOutTime&&!Number.isFinite(t.systemOutTime))&&a.push({kind:"invalid-system-time",id:t.id,severity:"warn"}),(!Number.isFinite(t.value)||t.value<=0)&&a.push({kind:"invalid-value",id:t.id}),t.endTime<t.startTime&&a.push({kind:"backward-edge",severity:"fatal",id:t.id,source:t.source,target:t.target})):a.push({kind:"invalid-edge-time",id:t.id});return a}(e,o,a,{usageMode:r}),{fatal:c,warnings:u}=function(t){const e=[],n=[];for(const o of t)"fatal"===s(o)?e.push(o):n.push(o);return{fatal:e,warnings:n}}(l),f=i(o,l,r);return{layout:c.length?null:Mt(e,f,{plotH:"vertical"===t.orientation?t.plotW:t.plotH,...t.layoutOpts,ribbonLane:t.ribbonLane,domain:a}),issues:c,warnings:u}}function Lt(e,n=Et(e)){const{nodes:o,edges:s,domain:l,plotW:c,plotH:u,ribbonLane:f,ribbonMinRun:d=0,edgeOpacity:g,colorOf:m,orientation:p="horizontal",showLabels:h=!0,labelPriorityAccessor:b,maxLabels:M,selectionDatum:y="raw",styleRules:x,colorBy:w,valueAccessor:v,usageMode:k="static"}=e,T="vertical"===p?u:c,S="vertical"===p?c:u,{layout:N,issues:O,warnings:P}=n,F=i(s,[...O,...P],k),E=t().domain(l).range([0,T]);if(!N)return{layout:null,layoutConfig:{bands:[],ribbons:[],showLabels:!1!==h},issues:O,warnings:P,xScale:E};const{centerlines:L,nodeData:z,valueScale:B}=N,C=Pt(w,v),X=[],j=[],D=0===d?new Map:function(t,e,n){const o=new Set(e.map(t=>t.target)),s=new Map(t.map(t=>[t.id,t])),i=new Map;for(const t of e){if(o.has(t.source))continue;const e=i.get(t.source)??[];e.push(t),i.set(t.source,e)}const a=new Map;for(const e of t){if(!e.group)continue;const t=a.get(e.group)??[];t.push(e),a.set(e.group,t)}const l=new Set;for(const[t,e]of a){const n=e.flatMap(t=>i.get(t.id)??[]),s=new Set(n.map(t=>t.startTime));n.length>0&&1===s.size&&e.every(t=>{const e=t.xExtent?.[0],s=n[0].startTime;return!o.has(t.id)&&(i.get(t.id)?.length??0)>0&&Number.isFinite(e)&&e<s})&&l.add(t)}const c=new Map;for(const[t,e]of i){const o=s.get(t);if(o?.group&&!l.has(o.group))continue;const i=o?.xExtent?.[0],a=[...e].sort((t,e)=>t.startTime-e.startTime||t.id.localeCompare(e.id)),r=a[0]?.startTime-1;let u=null;for(let t=0;t<a.length;){const e=a[t].startTime;let o=t+1;for(;o<a.length&&a[o].startTime===e;)o++;for(let e=t;e<o;e++){const t=a[e],o=Number.isFinite(i)&&i<t.startTime,s=Number.isFinite(t.systemInTime)&&t.systemInTime<t.startTime;if(!o&&!s)continue;let l=n[0];o&&(l=Math.max(l,i)),s&&(l=Math.max(l,t.systemInTime)),!o&&s&&Number.isFinite(r)&&(l=Math.max(l,r)),null!=u&&(l=Math.max(l,u)),l<t.startTime&&c.set(t.id,l)}u=e,t=o}}for(const[t,e]of a){if(!l.has(t))continue;const n=e.flatMap(t=>i.get(t.id)??[]);if(!n.every(t=>c.has(t.id))){for(const t of n)c.delete(t.id);continue}const o=r(n.map(t=>c.get(t.id)));for(const t of n)c.set(t.id,o)}return c}(o,F,l),H=new Map(o.filter(t=>t.group).map(t=>[t.id,t.group])),Y=new Map;for(const t of F){const e=z[t.source]?.localAttachments.get(t.id),n=z[t.target]?.localAttachments.get(t.id);e&&n&&Y.set(t.id,yt(e,L[t.source],n,L[t.target],B,E,f,l,{minRun:d,sourceRunwayStart:D.get(t.id)}))}const q=function(t,e,n,o,s,i){const l=new Map(e),c=new Map;for(const e of t){const t=i?.get(e.source),n=null==t?`node:${e.source}`:`group:${t}`,o=c.get(n)??new Map,s=o.get(e.startTime)??[];s.push(e),o.set(e.startTime,s),c.set(n,o)}for(const t of c.values())for(const[i,c]of t){if(!c.some(t=>n.has(t.id)))continue;const t=c.map(t=>e.get(t.id));if(t.some(t=>null==t))continue;const u=o(i),f=a(t.map(t=>t.sx));if(!(f<u-1e-9))continue;const d=r(c.map(t=>{const e=n.get(t.id);return null==e?u:Math.min(u,o(e))})),g=Math.min(u,Math.max(f,d));for(const t of c){const n=e.get(t.id),o="source"===s?.85:"target"===s?.15:.5,i=g+(n.tx-g)*o;l.set(t.id,{...n,sx:g,cp1X:i,cp2X:i})}}return l}(F,Y,D,E,f,H),V=function(t,e,n,o,s){const i=new Map;for(const a of t){if(!n.has(a.id))continue;const t=e.get(a.id);if(!(t&&t.sx<o(a.startTime)-1e-9))continue;const r=s(t.sx);Number.isFinite(r)&&r<a.startTime&&i.set(a.id,r)}return i}(F,q,D,E,t=>l[0]+t/T*(l[1]-l[0])),W=function(t,e,n){const o=new Map,s=new Map;for(const[t,e]of n??[]){const n=s.get(e)??[];n.push(t),s.set(e,n)}for(const i of t){const t=e.get(i.id);if(!(null!=t&&Number.isFinite(t)&&t<i.startTime))continue;const a=n?.get(i.source),r=null==a?[i.source]:s.get(a)??[i.source];for(const e of r){const n=o.get(e)??new Map,s=n.get(i.startTime);n.set(i.startTime,null==s?t:Math.min(s,t)),o.set(e,n)}}return o}(F,V,H);o.forEach((t,e)=>{const n=z[t.id];if(!n||0===n.samples.length)return;const o=(s=n.samples,(i=W.get(t.id))&&0!==i.size?s.map(t=>{const e=i.get(t.t);return null==e?t:{...t,t:e}}):s);var s,i;const a=function(t,e,n,o,s){if(0===t.length)return null;const i=$(t,s),a=t=>e+(i[t].boundaryOffset??0)*n,r=t=>a(t)-i[t].topMass*n,l=t=>a(t)+i[t].botMass*n;let c=`M${o(i[0].t)},${r(0)}`;for(let t=1;t<i.length;t++)c+=` L${o(i[t].t)},${r(t)}`;c+=` L${o(i[i.length-1].t)},${l(i.length-1)}`;for(let t=i.length-2;t>=0;t--)c+=` L${o(i[t].t)},${l(t)}`;return c+" Z"}(o,L[t.id],B,E,l);if(!a)return;const r=$(o,l),c=r.find(t=>t.topMass+t.botMass>0)||r[0],u=(c.botMass-c.topMass+2*(c.boundaryOffset??0))*B/2,f=L[t.id]+u;let d,g,h=m(t.id,e),b=h,M=.5;const y=t.__raw??t;if(x&&x.length>0){const t=function(t,e,n){if(!e||0===e.length)return{};let o={};for(const s of e){if(!At(s,t,n))continue;const e="function"==typeof s.style?s.style(t,n):s.style;e&&(o={...o,...e})}return o}(y,x,C(y));"string"==typeof t.fill?h=t.fill:null!=t.fill&&("object"==typeof(w=t.fill)&&null!==w&&"hatch"===w.type)&&(g=t.fill,h=t.fill.background&&"transparent"!==t.fill.background?t.fill.background:h),"string"==typeof t.stroke&&(b=t.stroke),"number"==typeof t.strokeWidth&&(M=t.strokeWidth),"number"==typeof t.fillOpacity&&(d=t.fillOpacity),"number"==typeof t.opacity&&null==d&&(d=t.opacity)}var w;const v=function(t,e,n,o,s,i){const a=n.nodeData[t];if(!a||0===a.samples.length)return[];const r=n.valueScale,l=n.centerlines[t],c=$(a.samples,s),u=c.find(t=>t.topMass+t.botMass>0)||c[0],f=[...c].reverse().find(t=>t.topMass+t.botMass>0)||c[c.length-1],d=o(u.t),g=o(f.t),m=t=>o(A(t,s)),p=[],h=(t,e,n,o)=>`M${t},${e} L${n},${e} L${n},${o} L${t},${o} Z`;for(const n of e){if(n.source===t&&null!=n.systemInTime&&Number.isFinite(n.systemInTime)){const t=a.localAttachments.get(n.id),e=i?.get(n.id)??n.startTime;if(t&&"out"===t.kind&&n.systemInTime<e){const o=m(n.systemInTime),i=m(e),a=null!=s&&n.systemInTime<s[0],c=a?o:o-20,u=a?Math.min(i,o+20):o,f=Math.max(d,c);if(i>f){const[e,n]=I(t,l,r);p.push({pathD:h(f,e,i,n),x0:c,x1:u,from:0,to:1})}}}if(n.target===t&&null!=n.systemOutTime&&Number.isFinite(n.systemOutTime)){const t=a.localAttachments.get(n.id);if(t&&"in"===t.kind&&n.systemOutTime>n.endTime){const e=m(n.systemOutTime),o=m(n.endTime),s=e+20,i=Math.min(g,s);if(i>o){const[n,a]=I(t,l,r);p.push({pathD:h(o,n,i,a),x0:e,x1:s,from:1,to:0})}}}}return p}(t.id,F,N,E,l,V);X.push({id:t.id,pathD:a,fill:h,stroke:b,strokeWidth:M,...null!=d&&{fillOpacity:d},...g&&{hatchFill:g},...v.length>0&&{gradientStubs:v},rawDatum:y,labelX:E("vertical"===p&&t.xExtent?t.xExtent[0]:c.t)-4,labelY:f,labelText:t.label??t.id})});const G=new Map;o.forEach((t,e)=>G.set(t.id,e)),F.forEach(t=>{const e=q.get(t.id);if(!e)return;const n=G.get(t.source)??0,o=m(t.source,n),{pathD:s,bezier:i}=function(t){const{sx:e,sTop:n,sBot:o,tx:s,tTop:i,tBot:a,cp1X:r,cp2X:l}=t,c=(n+o)/2,u=(i+a)/2;return{pathD:[`M${e},${n}`,`C${r},${n} ${l},${i} ${s},${i}`,`L${s},${a}`,`C${l},${a} ${r},${o} ${e},${o}`,"Z"].join(" "),bezier:{circular:!1,points:[{x:e,y:c},{x:r,y:c},{x:l,y:u},{x:s,y:u}],halfWidth:(o-n)/2}}}(e),a=t.__raw??t,r="function"==typeof g?Number(g(a)):g,l=Number.isFinite(r)?Math.max(0,Math.min(1,r)):.35;j.push({id:t.id,pathD:s,fill:o,opacity:l,rawDatum:a,bezier:i})});const R=kt(X,N.slotByNode,S).map(t=>function(t,e){return"horizontal"===e?t:{...t,pathD:St(t.pathD),gradientStubs:t.gradientStubs?.map(Ot),labelX:t.labelY,labelY:t.labelX,labelAnchor:"middle",labelBaseline:"auto"}}(t,p)),U="vertical"===p?function(t,e,n){const o=t.map(t=>({...t}));for(const t of o){const n=1.22*xt(t.labelText)+4;t.labelX=n>=e-4?e/2:Math.max(n/2+2,Math.min(e-n/2-2,t.labelX))}const s=[],i=[...o].sort((t,e)=>t.labelY-e.labelY||t.labelX-e.labelX);for(const t of i){const e=s[s.length-1];!e||Math.abs(e[0].labelY-t.labelY)>14?s.push([t]):e.push(t)}for(const t of s){t.sort((t,e)=>t.labelX-e.labelX||t.id.localeCompare(e.id));const e=[],o=new Map;for(const n of t){const[t,s]=wt(n);let i=e.findIndex(e=>t>e+8);-1===i&&(i=e.length),e[i]=s,o.set(n,i)}const s=t.reduce((t,e)=>t+e.labelY,0)/t.length,i=s<14*e.length+8;for(const e of t){const t=o.get(e)??0;e.labelY=i?Math.min(n-8,12+14*t):Math.max(8,s-14*t)}}return o}(R,c,u):R,_=new Map;if(null!=b)for(const t of o){const e=t.__raw??t,n="function"==typeof b?b(e):Number(e[b]);Number.isFinite(n)&&_.set(t.id,n)}const Z=function(t,e,n,o,s={}){if(!1===o)return t.map(t=>({...t,labelText:"",labelDeferred:!1,labelFullText:void 0}));if(!0===o)return t.map(t=>({...t,labelDeferred:!1,labelFullText:void 0}));const i=Math.max(1,e*n);let a=Math.max(4,Math.min(t.length,Math.floor(i/14e3)));Number.isFinite(s.maxLabels)&&s.maxLabels>=0&&(a=Math.min(a,Math.floor(s.maxLabels)));const r=t.map((t,e)=>{const n=s.priorityById?.get(t.id),o=Math.abs(t.labelY);return{band:t,index:e,score:null!=n&&Number.isFinite(n)?1e6*n+xt(t.labelText):xt(t.labelText)+.01*o}}).filter(t=>t.band.labelText.trim().length>0).sort((t,e)=>e.score-t.score||t.index-e.index||t.band.id.localeCompare(e.band.id)),l=new Set(r.slice(0,a).map(t=>t.band.id));return t.map(t=>l.has(t.id)||0===t.labelText.trim().length?{...t,labelDeferred:!1,labelFullText:void 0}:{...t,labelFullText:t.labelText,labelText:"",labelDeferred:!0})}(U,c,u,h,{..._.size>0&&{priorityById:_},...null!=M&&{maxLabels:M}});return{layout:N,layoutConfig:{bands:Z,ribbons:j.map(t=>function(t,e){return"horizontal"===e?t:{...t,pathD:St(t.pathD),bezier:Nt(t.bezier)}}(t,p)),showLabels:!1!==h,selectionDatum:y},issues:[],warnings:P,xScale:E}}self.onmessage=t=>{const e=t.data,n=e?.requestId,o=e?.request??e;try{const t=o.colorById??{},e=o.fallbackPalette??["#475569"],a=(n,o)=>t[n]??e[o%e.length]??"#475569",r=Lt({...o.input,colorOf:a});self.postMessage({requestId:n,layout:(i=r.layout,i?{...i,sides:i.sides instanceof Map?[...i.sides.entries()]:i.sides}:null),layoutConfig:(s=r.layoutConfig,{bands:(s.bands??[]).map(({rawDatum:t,...e})=>e),ribbons:(s.ribbons??[]).map(({rawDatum:t,...e})=>e),showLabels:s.showLabels}),issues:r.issues,warnings:r.warnings,domain:o.input.domain,timelineExtent:"vertical"===o.input.orientation?o.input.plotH:o.input.plotW})}catch(t){self.postMessage({requestId:n,error:{message:t instanceof Error?t.message:String(t),name:t instanceof Error?t.name:"Error",stack:t instanceof Error?t.stack:void 0}})}var s,i};
|
|
1
|
+
import{scaleTime as t}from"d3-scale";var e={static:{duplicateIds:"fatal",invalidSystemTime:"warn"},mcp:{duplicateIds:"fatal",invalidSystemTime:"warn"},push:{duplicateIds:"warn",invalidSystemTime:"strip"}};function n(t="static"){return e[t]??e.static}var o=new Set(["invalid-domain","missing-node","backward-edge","invalid-edge-time","invalid-value","invalid-node-time"]);function s(t){return"fatal"===t.severity||"warn"===t.severity?t.severity:o.has(t.kind)?"fatal":"warn"}function i(t,e,o="static"){if("strip"!==n(o).invalidSystemTime)return t;const s=new Set(e.filter(t=>"invalid-system-time"===t.kind).map(t=>t.id));return 0===s.size?t:t.map(t=>{if(!s.has(t.id))return t;const e={...t};return null==e.systemInTime||Number.isFinite(e.systemInTime)||delete e.systemInTime,null==e.systemOutTime||Number.isFinite(e.systemOutTime)||delete e.systemOutTime,e})}function a(t,e=1/0){let n=e;for(const e of t)e<n&&(n=e);return n}function r(t,e=-1/0){let n=e;for(const e of t)e>n&&(n=e);return n}function l(t){const{desired:e,minGaps:n,weights:o}=t,s=e.length;if(0===s)return[];if(n.length!==Math.max(0,s-1))throw new Error("placeWithMinGap: minGaps must have desired.length - 1 entries");const i=new Array(s).fill(0);for(let t=1;t<s;t++)i[t]=i[t-1]+Math.max(0,Number.isFinite(n[t-1])?n[t-1]:0);const a=[];for(let t=0;t<s;t++){const n=Math.max(Number.EPSILON,Number.isFinite(o?.[t])?o[t]:1),s=(Number.isFinite(e[t])?e[t]:0)-i[t];for(a.push({start:t,end:t,weight:n,mean:s});a.length>1;){const t=a[a.length-1],e=a[a.length-2];if(e.mean<=t.mean)break;const n=e.weight+t.weight;a.splice(a.length-2,2,{start:e.start,end:t.end,weight:n,mean:(e.mean*e.weight+t.mean*t.weight)/n})}}const r=Number.isFinite(t.min)?t.min:-1/0,l=Number.isFinite(t.max)?t.max-i[s-1]:1/0,c=l<r?r:l,u=new Array(s);for(const t of a){const e=Math.max(r,Math.min(c,t.mean));for(let n=t.start;n<=t.end;n++)u[n]=e+i[n]}return u}function c(t,e){let n=0,o=t.length-1,s=-1;for(;n<=o;){const i=n+o>>>1;t[i].at<=e?(s=i,n=i+1):o=i-1}return s<0?{at:e,before:0,after:0}:t[s]}function u(t,e=0){if(0===t.length)return{adjacentClearance:[],positions:[]};const n=[],o=[0];for(let s=0;s<t.length-1;s++){const i=t[s],a=t[s+1],r=[...new Set([...i.map(t=>t.at),...a.map(t=>t.at)])].sort((t,e)=>t-e);let l=0;for(const t of r){const e=c(i,t),n=c(a,t);l=Math.max(l,e.after+n.before)}n.push(l),o.push(o[o.length-1]+l+e)}return{adjacentClearance:n,positions:o}}function f(t,e,n,o={}){let s=[...t];if(s.length<=1)return s;let i=[...s],a=n(s),r=1;const l=Math.max(0,o.passes??6),c=Math.max(1,o.maxEvaluations??1/0);for(let t=0;t<l&&r<c;t++){const t=new Map(s.map((t,e)=>[t,e])),l=new Map,c=new Map;for(const n of e){const e=t.get(n.source),o=t.get(n.target);if(null==e||null==o)continue;const s=Number.isFinite(n.weight)&&n.weight>0?n.weight:1;l.set(n.source,(l.get(n.source)??0)+o*s),c.set(n.source,(c.get(n.source)??0)+s),l.set(n.target,(l.get(n.target)??0)+e*s),c.set(n.target,(c.get(n.target)??0)+s)}s=s.map((t,e)=>({item:t,index:e,barycenter:(l.get(t)??e)/(c.get(t)??1)})).sort((t,e)=>t.barycenter-e.barycenter||(o.compare?.(t.item,e.item)??t.index-e.index)).map(t=>t.item);const u=n(s);if(r++,u<a)a=u,i=[...s];else if(u===a)break}return i}function d(t,e,n={}){const o=[...t];if(o.length<=1)return o;let s=e(o),i=1;const a=Math.max(0,n.passes??6),r=Math.max(1,n.maxEvaluations??1/0);for(let t=0;t<a&&i<r;t++){let t=!1;for(let n=0;n<o.length-1&&i<r;n++){[o[n],o[n+1]]=[o[n+1],o[n]];const a=e(o);i++,a<s?(s=a,t=!0):[o[n],o[n+1]]=[o[n+1],o[n]]}if(!t)break}return o}function g(t,e,n={}){const o=[...t],s=o.length;if(s<=1||s>(n.maxItems??8))return o;const i=Math.max(1,n.maxEvaluations??1/0);let a=0,r=[...o],l=1/0;const c=()=>{if(a>=i)return;const t=e(o);a++,t<l&&(l=t,r=[...o])};c();const u=new Array(s).fill(0);let f=0;for(;f<s&&a<i;)if(u[f]<f){const t=f%2==0?0:u[f];[o[t],o[f]]=[o[f],o[t]],c(),u[f]++,f=0}else u[f]=0,f++;return r}function m(){return Object.create(null)}function p(t,e){return t<e?-1:t>e?1:0}function h(t){return t.occupants.map(t=>t.id).sort(p).join("\0")}function b(t,e,n=0){return t.slice(0,-1).map((o,s)=>{const i=t[s+1];return null!=o.group&&o.group===i.group?n:e})}function M(t,e){return t.map(t=>{const n=new Map;for(const o of t.occupants){const t=e[o.id];if(t)for(const e of t.samples){const t=n.get(e.t)??{before:0,after:0},o=e.boundaryOffset??0;n.set(e.t,{before:Math.max(t.before,e.topMass-o),after:Math.max(t.after,e.botMass+o)})}}return[...n].sort((t,e)=>t[0]-e[0]).map(([t,e])=>({at:t,...e}))})}function y(t,e,n){if(0===t.length)return[];const{padding:o,plotH:s,valueScale:i}=n,a=n.stackValueScale??i,r=b(t,o,n.groupPadding??0),l=[o+t[0].peak.topPeak*a];for(let n=1;n<t.length;n++)l.push(l[n-1]+e[n-1]*a+r[n-1]);const c=l[l.length-1]+t[t.length-1].peak.botPeak*a+o;if(c>s&&c>0){const t=s/c;for(let e=0;e<l.length;e++)l[e]*=t}return l}function x(t,e){const n=(t.boundaryOffset??0)*e,o=t.value*e;if("out"===t.kind){const s=t.sideMassBefore*e;return n+("top"===t.side?o/2-s:s-o/2)}const s=t.sideMassAfter*e;return n+("top"===t.side?o/2-s:s-o/2)}function v(t,e,n,o,s,i){const a=i.adjacentClearance?[...i.adjacentClearance]:u(M(o,n)).adjacentClearance,r=y(o,a,i);let c="hug"===i.lanePlacement?function(t,e,n,o,s,i,a){const r=t.length;if(0===r)return[];const{padding:c,plotH:u,valueScale:f}=a,d=b(t,c,a.groupPadding??0),g=s.map((t,e)=>t*f+d[e]),m=c+t[0].peak.topPeak*f,p=u-c-t[r-1].peak.botPeak*f;if(p-m<=g.reduce((t,e)=>t+e,0)+1e-6)return y(t,s,a);let h=1===r?[(m+p)/2]:[...i];for(let t=0;t<12;t++){const t=new Array(r).fill(0),s=new Array(r).fill(0);for(const i of n){const n=e[i.source],a=e[i.target];if(null==n||null==a||n===a)continue;const r=o[i.source]?.localAttachments.get(i.id),l=o[i.target]?.localAttachments.get(i.id);if(!r||!l)continue;const c=i.value>0&&Number.isFinite(i.value)?i.value:1,u=x(r,f),d=x(l,f);t[n]+=(h[a]+d-u)*c,s[n]+=c,t[a]+=(h[n]+u-d)*c,s[a]+=c}const i=l({desired:h.map((e,n)=>0===s[n]?e:.45*e+t[n]/s[n]*.55),minGaps:g,weights:s.map(t=>Math.max(1,t)),min:m,max:p});let a=0;for(let t=0;t<r;t++)a=Math.max(a,Math.abs(i[t]-h[t]));if(h=i,a<.01)break}return h}(o,s,e,n,a,r,i):[...r];if("hug"===i.lanePlacement){const n=e=>{const n=m();for(const o of t)n[o.id]=e[s[o.id]];return n};w(n(c),e)>w(n(r),e)+1e-6&&(c=[...r])}const f=m();for(const e of t)f[e.id]=c[s[e.id]];let d=1/0,g=-1/0;for(const e of t){const t=f[e.id],o=n[e.id];Number.isFinite(t)&&o&&(d=Math.min(d,t-o.topPeak*i.valueScale),g=Math.max(g,t+o.botPeak*i.valueScale))}return{adjacentClearance:a,centerlines:f,slotCenter:c,stackCenter:r,verticalUtilization:Number.isFinite(d)&&Number.isFinite(g)&&i.plotH>0?Math.max(0,Math.min(1,(g-d)/i.plotH)):0}}function w(t,e){let n=0;for(const o of e){const e=t[o.source],s=t[o.target];Number.isFinite(e)&&Number.isFinite(s)&&(n+=Math.abs(e-s)*(o.value>0?o.value:1))}return n}function k(t,e){const n=t?.samples;if(!n||0===n.length||e<n[0].t)return{top:0,bot:0};let o=0,s=n.length-1,i=0;for(;o<=s;){const t=o+s>>>1;n[t].t<=e?(i=t,o=t+1):s=t-1}const a=n[i].boundaryOffset??0;return{top:n[i].topMass-a,bot:n[i].botMass+a}}function T(t,e,n,o,s){const i=1-s;return i*i*i*t+3*i*i*s*e+3*i*s*s*n+s*s*s*o}function S(t,e){let n=0,o=1;for(let s=0;s<28;s++){const s=(n+o)/2;T(0,e,e,1,s)<t?n=s:o=s}return(n+o)/2}function N(t,e,n){const o=e+x(t,n),s=t.value*n/2;return[o-s,o+s]}function O(t,e,n,o){return Math.max(0,Math.min(e,o)-Math.max(t,n))/Math.max(1e-9,e-t)}function P(t,e,n,o,s,i,a){const{valueScale:r,domain:l,mode:c="quality"}=a,u="source"===a.ribbonLane?.85:"target"===a.ribbonLane?.15:.5;let f=0;for(const a of t){const t=o[a.source],d=o[a.target];if(null==t||null==d||Math.abs(t-d)<2)continue;const g=e[a.source]?.localAttachments.get(a.id),m=e[a.target]?.localAttachments.get(a.id);if(!g||!m)continue;const p=Math.max(a.startTime,l?.[0]??-1/0),h=Math.min(a.endTime,l?.[1]??1/0);if(!(h>p))continue;const[b,M]=N(g,s[a.source],r),[y,x]=N(m,s[a.target],r),v=Math.min(t,d)+1,w=Math.max(t,d)-1;for(let t=v;t<=w;t++){const o=n[t];if(!o)continue;const l=[p,h];if("quality"===c)for(const t of o.occupants)for(const n of e[t.id]?.samples??[])n.t>p&&n.t<h&&l.push(n.t);const d=t=>{const n=S((t-p)/(h-p),u),l=T(b,b,y,y,n),c=T(M,M,x,x,n);let f=0;for(const n of o.occupants){if(n.id===a.source||n.id===a.target)continue;const o=i[n.id];if(null!=o?.start&&t<o.start)continue;if(null!=o?.end&&t>o.end)continue;const u=k(e[n.id],t),d=s[n.id];f=Math.max(f,O(l,c,d-u.top*r,d+u.bot*r))}return f},g=[...new Set(l)].sort((t,e)=>t-e);let m=0;for(let t=0;t<g.length-1;t++){const e=g[t],n=g[t+1]-e;m+=(d(e+.25*n)+d(e+.5*n)+d(e+.75*n))/3*n}f+=m/(h-p)*(a.value>0?a.value:1)}}return f}function F(t,e,n,o,s,i,a,r,l,c,u="both",f){return{crossings:t,weightedLength:e,pixelLength:w(a,n),transitOcclusion:P(n,o,s,i,a,r,{valueScale:l,ribbonLane:u,domain:f,mode:"quality"}),verticalUtilization:c}}function A(t,e){return e?Math.max(e[0],Math.min(e[1],t)):t}function $(t,e){return t.map(t=>({t:A(t.t,e),topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}}))}function I(t,e,n){const o=e+(t.boundaryOffset??0)*n,s=t.value*n;if("out"===t.kind){const e=t.sideMassBefore*n;if("top"===t.side){const t=o-e;return[t,t+s]}const i=o+e;return[i-s,i]}const i=t.sideMassAfter*n;if("top"===t.side){const t=o-i;return[t,t+s]}const a=o+i;return[a-s,a]}function E(t,e,n,o,s="temporal"){const i=e.incoming[t.id],r=e.outgoing[t.id],l=[];for(const t of i)l.push({time:t.endTime,delta:+t.value,edge:t,kind:"in",side:n.get(t.id).targetSide});for(const t of r)l.push({time:t.startTime,delta:-t.value,edge:t,kind:"out",side:n.get(t.id).sourceSide});const c={create:0,in:1,"transfer-out":2,"transfer-in":3,out:4},u=()=>{l.sort((t,e)=>t.time-e.time||(t.phase??0)-(e.phase??0)||(t.sequence??0)-(e.sequence??0)||(c[t.kind]??99)-(c[e.kind]??99)||((t,e)=>{if(!o||!t.edge||!e.edge||t.kind!==e.kind||t.side!==e.side)return 0;if("out"===t.kind){if(t.edge.target===e.edge.target&&t.edge.endTime===e.edge.endTime)return 0;const n=o.get(t.edge.id)?.target,s=o.get(e.edge.id)?.target;return"number"==typeof n&&Number.isFinite(n)&&"number"==typeof s&&Number.isFinite(s)&&n!==s?"top"===t.side?n-s:s-n:0}if("in"===t.kind){if(t.edge.source===e.edge.source&&t.edge.startTime===e.edge.startTime)return 0;const n=o.get(t.edge.id)?.source,s=o.get(e.edge.id)?.source;return"number"==typeof n&&Number.isFinite(n)&&"number"==typeof s&&Number.isFinite(s)&&n!==s?"top"===t.side?s-n:n-s:0}return 0})(t,e)||p(t.edge?.id??"",e.edge?.id??"")||p(t.side,e.side)||t.delta-e.delta)},f=l.length?a(l.map(t=>t.time)):null,d=Array.isArray(t.xExtent)&&Number.isFinite(t.xExtent[0])?t.xExtent[0]:null,g=null!=d?d-1:null!=f&&Number.isFinite(f)?f-1:null;u();let m=null,h=0;for(const t of l)t.time!==m&&(m=t.time,h=0),t.sequence=h++;const b=t=>({time:t.time,phase:0,sequence:t.sequence??0}),M=[];let y=0,x=0;for(const t of l)if("out"===t.kind){const e=Math.abs(t.delta);let n=e-("top"===t.side?y:x);if(n>0){const e="top"===t.side?"bot":"top",o="top"===e?y:x,s=Math.min(n,o);if(s>0){const o=b(t);M.push({...o,delta:-s,kind:"transfer-out",side:e}),M.push({...o,delta:+s,kind:"transfer-in",side:t.side}),"top"===e?y-=s:x-=s,"top"===t.side?y+=s:x+=s,n-=s}n>0&&null!==g&&(M.push({time:g,delta:+n,kind:"create",side:t.side}),"top"===t.side?y+=n:x+=n)}"top"===t.side?y-=e:x-=e}else if("in"===t.kind){const e=Math.abs(t.delta);"top"===t.side?y+=e:x+=e}l.push(...M),u();let v=0,w=0,k=0,T=0,S=0,N=0;const O=[],P=new Map,F=t=>{O.push({t:t,topMass:v,botMass:w,...Math.abs(k)>1e-12&&{boundaryOffset:k}})},A=()=>{T=Math.max(T,v+w),S=Math.max(S,v-k),N=Math.max(N,w+k)};for(const t of l){if("transfer-out"!==t.kind&&"transfer-in"!==t.kind&&F(t.time),("in"===t.kind||"out"===t.kind)&&t.edge){const e="top"===t.side?v:w,n=e+t.delta;P.set(t.edge.id,{side:t.side,time:t.time,sideMassBefore:e,sideMassAfter:n,kind:t.kind,value:Math.abs(t.delta),...Math.abs(k)>1e-12&&{boundaryOffset:k}})}"top"===t.side?v+=t.delta:w+=t.delta,"transfer-in"===t.kind?(k+="top"===t.side?t.delta:-t.delta,A(),F(t.time)):"transfer-out"!==t.kind&&(A(),"out"===t.kind&&v+w<=1e-12&&(k=0),F(t.time))}const $=[];let I=0;for(;I<O.length;){let t=I;for(;t+1<O.length&&O[t+1].t===O[I].t;)t++;$.push(O[I]);for(let e=I+1;e<=t;e++){const t=$[$.length-1];O[e].topMass===t.topMass&&O[e].botMass===t.botMass&&(O[e].boundaryOffset??0)===(t.boundaryOffset??0)||$.push(O[e])}I=t+1}const E=Array.isArray(t.xExtent)&&Number.isFinite(t.xExtent[1])?t.xExtent[1]:null;let L=null;for(const t of r)null!=t.systemInTime&&Number.isFinite(t.systemInTime)&&t.systemInTime<t.startTime&&(null===L||t.systemInTime<L)&&(L=t.systemInTime);let z=null;for(const t of i)null!=t.systemOutTime&&Number.isFinite(t.systemOutTime)&&t.systemOutTime>t.endTime&&(null===z||t.systemOutTime>z)&&(z=t.systemOutTime);if($.length>0){const t=$[$.length-1],e=Math.max(null!=E?E:-1/0,null!=z?z:-1/0);Number.isFinite(e)&&e>t.t&&t.topMass+t.botMass>0&&$.push({t:e,topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}});const n=$[0],o=$.find(t=>t.topMass+t.botMass>0);let s,i=1/0;null!=d&&Number.isFinite(d)&&d<n.t&&n.topMass+n.botMass>0&&(i=d,s=n),o&&null!=L&&Number.isFinite(L)&&L<o.t&&L<i&&(i=L,s=o),s&&Number.isFinite(i)&&$.unshift({t:i,topMass:s.topMass,botMass:s.botMass,...null!=s.boundaryOffset&&{boundaryOffset:s.boundaryOffset}})}let B=$;if("max"===s&&null!=d&&null!=E&&E>d){let t,e=0;for(const n of $){const o=n.topMass+n.botMass;o>e&&(e=o,t=n)}if(t){const e={topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}};B=[...$.filter(t=>t.t<d),{t:d,...e},{t:E,...e},...$.filter(t=>t.t>E)]}}return{samples:B,peak:T,topPeak:S,botPeak:N,localAttachments:P}}var L=(t,e)=>{let n=0,o=t.length;for(;n<o;){const s=n+o>>>1;t[s]<e?n=s+1:o=s}return n},z=class{constructor(t){this.coordinates=[...new Set(t)].sort((t,e)=>t-e),this.tree=new Int32Array(this.coordinates.length+1)}add(t,e){for(let n=L(this.coordinates,t)+1;n<this.tree.length;n+=n&-n)this.tree[n]+=e}below(t){let e=0;for(let n=L(this.coordinates,t);n>0;n-=n&-n)e+=this.tree[n];return e}};function B(t,e){return t.source!==e.source&&t.target!==e.target&&t.source!==e.target&&t.target!==e.source&&Math.max(t.startTime,e.startTime)<Math.min(t.endTime,e.endTime)}var C=class{constructor(t,e,n){this.size=n,this.routes=[],this.outgoing=Array.from({length:n},()=>[]),this.incoming=Array.from({length:n},()=>[]);const o=new Map,s=new Map;for(const t of e.keys())s.set(t,s.size);this.nodeCount=s.size;for(const n of t){const t=e.get(n.source),i=e.get(n.target);if(void 0===t||void 0===i||!(n.startTime<n.endTime))continue;const a=s.get(n.source),r=s.get(n.target),l=`${a}:${r}`;o.has(l)||o.set(l,o.size);const c=this.routes.length;this.routes.push({edge:n,source:t,target:i,sourceNode:a,targetNode:r,pair:o.get(l),reverse:-1}),this.outgoing[t].push(c),this.incoming[i].push(c)}for(const t of this.routes)t.reverse=o.get(`${t.targetNode}:${t.sourceNode}`)??-1;if(this.events=this.routes.flatMap((t,e)=>[{time:t.edge.startTime,route:e,delta:1},{time:t.edge.endTime,route:e,delta:-1}]).sort((t,e)=>t.time-e.time||t.delta-e.delta||t.route-e.route),this.smallPairs=this.routes.length<=80?[]:null,this.smallPairs)for(let t=0;t<this.routes.length;t++)for(let e=t+1;e<this.routes.length;e++)B(this.routes[t].edge,this.routes[e].edge)&&this.smallPairs.push([t,e]);this.work=this.smallPairs?.length??1/0}crossing(t,e,n){return(n[t.source]-n[e.source])*(n[t.target]-n[e.target])<0?1:0}count(t){if(this.smallPairs){let e=0;for(const[n,o]of this.smallPairs)e+=this.crossing(this.routes[n],this.routes[o],t);return e}const e=Array.from({length:this.size+1},()=>[]);for(const n of this.routes){const o=t[n.source],s=t[n.target];for(let t=o+1;t<=this.size;t+=t&-t)e[t].push(s)}const n=e.map(t=>new z(t)),o=new Int32Array(4*this.nodeCount),s=new Int32Array(this.routes.length),i=(t,e)=>{let o=0;for(let s=t;s>0;s-=s&-s)o+=n[s].below(e);return o};let a=0;for(const e of this.events){const r=this.routes[e.route],l=t[r.source],c=t[r.target];1===e.delta&&(a+=i(l,this.size)-i(l,c+1)+i(this.size,c)-i(l+1,c),l!==c&&(a-=o[4*r.sourceNode+(l<c?1:0)],a-=o[4*r.targetNode+(l<c?2:3)],r.reverse>=0&&(a+=s[r.reverse])));for(let t=l+1;t<=this.size;t+=t&-t)n[t].add(c,e.delta);l!==c&&(o[4*r.sourceNode+(l<c?3:2)]+=e.delta,o[4*r.targetNode+(l<c?0:1)]+=e.delta),s[r.pair]+=e.delta}return a}swapDelta(t,e,n){let o=0,s=0;const i=o=>n[o===t?e:o===e?t:o],a=(t,e)=>{const a=this.routes[t],r=this.routes[e];if(!B(a.edge,r.edge))return;s++;const l=(i(a.source)-i(r.source))*(i(a.target)-i(r.target))<0?1:0;o+=l-this.crossing(a,r,n)};for(const n of this.outgoing[t])for(const t of this.outgoing[e])a(n,t);for(const n of this.incoming[t])for(const o of this.incoming[e]){const s=this.routes[n],i=this.routes[o];s.source===t&&i.source===e||s.source===e&&i.source===t||a(n,o)}return{delta:o,evaluations:s}}};function X(t){const e=m();return t.forEach((t,n)=>{for(const o of t.occupants)e[o.id]=n}),e}function j(t,e,n){t.length=n.length;for(let e=0;e<n.length;e++)t[e]=n[e];const o=X(n);for(const t of Object.keys(e))delete e[t];Object.assign(e,o)}function D(t){const e=new Map,n=[];t.forEach((t,o)=>{if(!t.group)return void n.push({anchor:o,stableId:h(t),slots:[t]});const s=e.get(t.group)??{indexes:[],slots:[]};s.indexes.push(o),s.slots.push(t),e.set(t.group,s)});for(const[t,o]of e)n.push({anchor:o.indexes.reduce((t,e)=>t+e,0)/o.indexes.length,stableId:`${t}\0${o.slots.map(h).join("\0")}`,slots:o.slots});return n.sort((t,e)=>t.anchor-e.anchor||p(t.stableId,e.stableId))}function H(t){return t.some(t=>t.group)?D(t).flatMap(t=>t.slots):[...t]}function Y(t){return t.flatMap(t=>t.slots)}function q(t,e,n){const o=new Map;return t.forEach((t,e)=>{for(const n of t.slots)o.set(n,e)}),t.map((t,s)=>{if(t.slots.length<=1)return t;const i=new Map;for(const e of t.slots)i.set(e,0);for(const t of e){const e=o.get(t.source),n=o.get(t.target);if(null==e||null==n)continue;const a=Number.isFinite(t.weight)&&t.weight>0?t.weight:1;if(e===s&&n!==s){const e=n>s?1:-1;i.set(t.source,(i.get(t.source)??0)+a*e)}else if(n===s&&e!==s){const n=e>s?1:-1;i.set(t.target,(i.get(t.target)??0)+a*n)}}const a=[...t.slots].sort((t,e)=>(i.get(t)??0)-(i.get(e)??0)||n(t,e));return{...t,slots:a}})}function V(t,e){t.some(t=>t.group)&&j(t,e,H(t))}function W(t,e){const n=[...new Set(Object.values(t))].sort((t,e)=>t-e),o=new Map(n.map((t,e)=>[t,e])),s=new Map(Object.entries(t).map(([t,e])=>[t,o.get(e)]));return new C(e,s,n.length).count(n.map((t,e)=>e))}function G(t,e){let n=0;for(const o of e){const e=t[o.source],s=t[o.target];null!=e&&null!=s&&(n+=Math.abs(e-s)*(o.value>0?o.value:1))}return n}var R=t=>{let e=1;for(let n=2;n<=t;n++)e*=n;return e},U=828*R(8),_=3e3;function Z(t){const e=new Array(t.length),n=Math.floor((t.length-1)/2);let o=n-1,s=n+1;t.length>0&&(e[n]=t[0]);for(let n=1;n<t.length;n++)n%2==1&&s<t.length?e[s++]=t[n]:o>=0?e[o--]=t[n]:e[s++]=t[n];return e}function Q(t,e,n){let o=n(t),s=o,i=[...t];const a=Math.floor((t.length-1)/2);for(const r of e){const e=t.indexOf(r);if(e===a)continue;t.splice(e,1),t.splice(a,0,r);const l=n(t);l<=o?(o=l,l<s&&(i=[...t],s=l)):(t.splice(a,1),t.splice(e,0,r))}return i}function J(t,e,n,o,s,i,a){const r=[...s],l=new Map(s.map(t=>[t,h(t)])),c=new Map;for(const t of s)for(const e of t.occupants)c.set(e.id,t);const m=new Map,b=[];for(const t of e){const e=c.get(t.source),n=c.get(t.target);e&&n&&(m.set(t,[e,n]),e!==n&&b.push({source:e,target:n,weight:t.value}))}const y=e.reduce((t,e)=>t+(e.value>0?e.value:1),0),x=a.plotH/Math.max(1,s.length),k=s.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),T=Math.max(1,y)*(Math.max(1,a.plotH)+x*Math.max(k,s.length)+1e-6*Math.max(1,s.length-1))+1,S=4*x,N={fullCrossing:0,localCrossing:0},O=new Map,F=(t,e)=>{let o=O.get(t);o||(o=new Map,O.set(t,o));const s=o.get(e);if(null!=s)return s;const i=function(t,e,n){return u(M([t,e],n)).adjacentClearance[0]??0}(t,e,n);return o.set(e,i),i},A=new Map(s.map((t,e)=>[t,e])),$=new C(e,new Map([...c].map(([t,e])=>[t,A.get(e)])),s.length),I=t=>{const e=new Int32Array(s.length);for(let n=0;n<t.length;n++)e[A.get(t[n])]=n;return e},E=new Map([...m].map(([t,[e,n]])=>[t,{source:A.get(e),target:A.get(n),weight:t.value>0?t.value:1}])),L=[...E.values()],z=new Map,B=new Map,V=new Map,W=(t,e,n)=>{t.has(e)||t.set(e,new Set),t.get(e).add(n)};for(const t of e)W(z,t.source,t.target),W(B,t.target,t.source),W(V,t.source,t.target),W(V,t.target,t.source);const J=e.flatMap(t=>{if(!(t=>1===z.get(t.source)?.size&&z.get(t.source).has(t.target)||1===V.get(t.source)?.size||1===V.get(t.target)?.size)(t))return[];const e=E.get(t);return e&&e.source!==e.target?[e]:[]}),K=t=>{let e=0;for(const n of J)e+=Math.max(0,Math.abs(t[n.source]-t[n.target])-1)*n.weight;return e*S},tt=t=>K(I(t)),et=new Int32Array(s.length),nt=new Float64Array(s.length),ot=new Float64Array(s.length+1),st=t=>{for(let e=0;e<t.length;e++)et[A.get(t[e])]=e;const e=$.count(et);if(t.length>0){const e=A.get(t[0]);nt[e]=a.padding+t[0].peak.topPeak*a.valueScale;for(let e=1;e<t.length;e++){const n=A.get(t[e-1]),o=A.get(t[e]);nt[o]=nt[n]+F(t[e-1],t[e])*a.valueScale+a.padding}const n=A.get(t[t.length-1]),o=nt[n]+t[t.length-1].peak.botPeak*a.valueScale+a.padding;if(o>a.plotH&&o>0){const t=a.plotH/o;for(let e=0;e<nt.length;e++)nt[e]*=t}}ot[0]=0;for(let e=0;e<t.length;e++)ot[e+1]=ot[e]+t[e].peak.topPeak+t[e].peak.botPeak;let n=0,o=0,s=0;for(const t of L){const e=et[t.source],i=et[t.target];if(n+=Math.abs(e-i)*t.weight,o+=Math.abs(nt[t.source]-nt[t.target])*t.weight,Math.abs(e-i)>=2){const n=Math.min(e,i)+1,o=Math.max(e,i);s+=(ot[o]-ot[n])*t.weight}}return e*T+o+s*x+K(et)+1e-6*n},it=(s,i,r)=>{let l=i;null==l&&(l=$.count(I(s)),N.fullCrossing++);const{map:c,geometry:u,weightedLength:f,pixelLength:d}=(o=>{const s=X(o),i=o.slice(0,-1).map((t,e)=>F(t,o[e+1])),r=v(t,e,n,o,s,{plotH:a.plotH,padding:a.padding,valueScale:a.valueScale,lanePlacement:a.lanePlacement??"stack",groupPadding:a.groupPadding,adjacentClearance:i});return{map:s,geometry:r,weightedLength:G(s,e),pixelLength:w(r.centerlines,e)}})(s),g=r?P(e,n,s,c,u.centerlines,o,{valueScale:a.valueScale,ribbonLane:a.ribbonLane,domain:a.domain,mode:r}):((t,n)=>{const o=new Array(t.length+1).fill(0);for(let e=0;e<t.length;e++)o[e+1]=o[e]+t[e].peak.topPeak+t[e].peak.botPeak;let s=0;for(const t of e){const e=n[t.source],i=n[t.target];if(null==e||null==i||Math.abs(e-i)<2)continue;const a=Math.min(e,i)+1;s+=(o[Math.max(e,i)]-o[a])*(t.value>0?t.value:1)}return s})(s,c);return{crossings:l,weightedLength:f,pixelLength:d,transitOcclusion:g,cost:l*T+d+g*x+tt(s)+1e-6*f}},at=(t,e,n="quality")=>it(t,e,n);let rt=[...r];const lt=(t,e)=>p(l.get(t),l.get(e)),ct=function(t){const e=new Set;for(const n of t)if(n.group){if(e.has(n.group))return!0;e.add(n.group)}return!1}(rt),ut=(t,e,n,o=3e3)=>{let s=e(t);for(let i=0;i<n&&o>0;i++){let n=!1;const a=Array.from({length:t.length-1},(t,e)=>e);i%2==1&&a.reverse();for(const i of a){if(o--<=0)break;const a=t[i],r=t[i+1],l=$.swapDelta(A.get(a),A.get(r),I(t));[t[i],t[i+1]]=[r,a],N.localCrossing+=l.evaluations;const c=e(t,s.crossings+l.delta);c.cost<s.cost?(s=c,n=!0):[t[i],t[i+1]]=[a,r]}if(!n)break}return t},ft=t=>{const e=(t=>{const e=f(t,b,t=>it(t).cost,{passes:6,compare:lt,maxEvaluations:_});return ut(e,it,6)})(t);if((t.length<=8?R(t.length)*(t.length+L.length+$.work):1/0)>U)return e;const n=g(t,st,{maxItems:8,maxEvaluations:5e4}),o=at(n),s=at(e);return o.crossings!==s.crossings&&o.crossings<s.crossings?n:e},dt=t=>{let e=D(t);if(e.length<=1)return Y(e);const n=t=>it(Y(t)).cost;e=D(ft(t)),e=q(e,b,lt);const o=function(t,e){const n=new Map;for(const e of t)for(const t of e.slots)n.set(t,e);const o=new Map;for(const t of e){const e=n.get(t.source),s=n.get(t.target);if(!e||!s||e===s)continue;const i=Number.isFinite(t.weight)&&t.weight>0?t.weight:1,a=e.stableId<s.stableId?`${e.stableId}\0${s.stableId}`:`${s.stableId}\0${e.stableId}`,r=o.get(a);r?r.weight=(r.weight??0)+i:o.set(a,{source:e,target:s,weight:i})}return[...o.values()]}(e,b);e=f(e,o,n,{passes:6,compare:(t,e)=>p(t.stableId,e.stableId),maxEvaluations:_}),e=d(e,n,{passes:8,maxEvaluations:_});if((e.length<=8?R(e.length)*(e.length+L.length+$.work):1/0)<=U){const t=g(e,t=>st(Y(t)),{maxItems:8,maxEvaluations:5e4}),n=Y(t),o=Y(e),s=at(n),i=at(o);s.crossings!==i.crossings?e=s.crossings<i.crossings?t:e:s.cost<i.cost&&(e=t)}return e=q(e,b,lt),Y(e)},gt=t=>t.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),mt=(t,e)=>gt(e)-gt(t)||p(t.stableId,e.stableId),pt=(t,e)=>e.peak.topPeak+e.peak.botPeak-(t.peak.topPeak+t.peak.botPeak)||lt(t,e),ht="geometry-refine"===a.mode;if(ht||"crossing-min"!==a.laneOrder&&"crossing-min+inside-out"!==a.laneOrder){if(!ht&&"inside-out"===a.laneOrder)if(ct){rt=Y(Z([...D(rt)].sort(mt)))}else{rt=Z([...rt].sort(pt))}}else rt=ct?dt(rt):ft(rt);if(!ht&&"crossing-min+inside-out"===a.laneOrder&&rt.length>1)if(ct){const t=D(rt);rt=Y(Q(t,[...t].sort(mt),t=>it(Y(t)).cost))}else{rt=Q(rt,[...rt].sort(pt),t=>it(t).cost)}if((ht||"crossing-min"===a.laneOrder||"crossing-min+inside-out"===a.laneOrder)&&rt.length>1)if(ct){let t=d(D(rt),t=>at(Y(t),void 0,"score").cost,{passes:6});t=q(t,b,lt),rt=Y(t)}else ut(rt,(t,e)=>at(t,e,"score"),1,1/0);const bt=H(r);rt=H(rt);let Mt=at(rt);const yt=at(bt);if(ht){const t=tt(bt),e=tt(rt);(Mt.crossings>yt.crossings||Mt.crossings===yt.crossings&&e>t+1e-9||Mt.cost>yt.cost)&&(rt=bt,Mt=yt)}else Mt.cost>yt.cost&&(rt=bt,Mt=yt);const xt=function({order:t,after:e,nodes:n,edges:o,outgoingPartners:s,incomingPartners:i,slotForNode:a,averageGap:r,evaluate:l}){const c=(n,s)=>{const i=[...new Set(s.map(e=>t.indexOf(e)))].sort((t,e)=>t-e),a=t.indexOf(n),c=i[0],u=i[i.length-1];if(i.length<3||!i.includes(a)||u-c+1!==i.length||Math.abs(2*a-c-u)<=1)return;const f=[...t];f.splice(a,1),f.splice(c+u>>1,0,n);const d=H(f),g=l(d),m=new Set(n.occupants.map(t=>t.id)),p=new Set(s.flatMap(t=>t.occupants.map(t=>t.id))),h=o.reduce((t,e)=>m.has(e.source)&&p.has(e.target)||m.has(e.target)&&p.has(e.source)?t+(e.value>0?e.value:1):t,0),b=Math.abs(2*a-c-u)*r*Math.max(1,h);(function(t,e,n=0){return t.crossings<e.crossings||t.crossings===e.crossings&&t.cost<=e.cost+n})(g,e,b)&&(t=d,e=g)};for(const[t,e]of s)!i.has(t)&&e.size>=3&&c(a.get(t),[...e].map(t=>a.get(t)));for(const t of n){const e=a.get(t.id);!t.group&&e.group&&(i.get(t.id)?.size??0)>=3&&c(e,[...i.get(t.id)??[]].map(t=>a.get(t)).filter(t=>t===e||t.group===e.group).filter((t,e,n)=>n.indexOf(t)===e))}return{order:t,after:e}}({order:rt,after:Mt,nodes:t,edges:e,outgoingPartners:z,incomingPartners:B,slotForNode:c,averageGap:x,evaluate:at});return rt=xt.order,Mt=xt.after,j(s,i,rt),{before:yt,after:Mt,initialOrder:r.map(t=>l.get(t)),evaluations:N}}function K(t,e,n){const o=t.map(t=>{const o=t.occupants.map(t=>({id:t.id,end:n[t.id]?.end??t.end}));let s=0,i=0;for(const t of o){const n=e[t.id];s=Math.max(s,n?.topPeak||0),i=Math.max(i,n?.botPeak||0)}return{occupants:o,peak:{topPeak:s,botPeak:i},...null!=t.group?{group:t.group}:{}}}),s=m();return o.forEach((t,e)=>{for(const n of t.occupants)s[n.id]=e}),{slots:o,slotByNode:s}}var tt=new Map;var et=1e5,nt=1e-9;function ot(t,e){return null!=t.start&&null!=t.end&&null!=e.start&&null!=e.end&&!(t.end<=e.start||e.end<=t.start)}function st(t,e){return p(t,e)<=0?`${t}\0${e}`:`${e}\0${t}`}function it(t){const e=new Map,n=new Map;for(const o of t)n.has(o.source)||n.set(o.source,new Set),e.has(o.target)||e.set(o.target,new Set),n.get(o.source).add(o.target),e.get(o.target).add(o.source);return{incoming:new Map([...e].map(([t,e])=>[t,e.size])),outgoing:new Map([...n].map(([t,e])=>[t,e.size]))}}function at(t){const e=new Map,n=new Map,o=(t,e,n,o)=>{let s=t.get(e);s||(s=new Map,t.set(e,s)),s.set(n,(s.get(n)??0)+o)};for(const s of t){const t=s.value>0&&Number.isFinite(s.value)?s.value:1;o(e,s.source,s.target,t),o(n,s.target,s.source,t)}const s=new Map,i=t=>{if(s.has(t))return;const o=e.get(t),i=n.get(t),a=new Map;for(const[t,e]of o??[])a.set(t,(a.get(t)??0)+e);for(const[t,e]of i??[])a.set(t,(a.get(t)??0)+e);if(1===a.size){const[e,n]=[...a][0];s.set(t,{partner:e,weight:n})}};for(const e of t)i(e.source),i(e.target);return s}function rt(t,e,n){const o=n.get(t),s=n.get(e);return!o||!s||o.partner===s.partner||o.partner===e||s.partner===t}function lt(t,e,n){return!!n.has(t)&&e.some(e=>!rt(t,e,n))}function ct(t,e){return(t.value>0&&Number.isFinite(t.value)?t.value:1)*(1+(1===e.outgoing.get(t.source)?1:0)+(1===e.incoming.get(t.target)?1:0))}function ut(t,e,n,o){if(t.length<=12||o.slotCount<=1)return o.assignment;const s=new Map(t.map((t,e)=>[t,e])),i=Array.from({length:t.length},()=>new Map),a=it(n);for(const t of n){const e=s.get(t.source),n=s.get(t.target);if(null==e||null==n||e===n)continue;const o=ct(t,a);i[e].set(n,(i[e].get(n)??0)+o),i[n].set(e,(i[n].get(e)??0)+o)}const r=at(n),l=t.map(t=>r.get(t)?.weight??0),c=Array.from({length:t.length},()=>new Map);let u=0;for(let n=0;n<t.length-1&&u<5e4;n++)if(r.has(t[n]))for(let o=n+1;o<t.length;o++){if(!r.has(t[o]))continue;if(e.conflicts(t[n],t[o]))continue;u++;const s=Math.min(l[n],l[o])||Math.max(l[n],l[o]),i=rt(t[n],t[o],r)?s:-s;if(!(Math.abs(i)<=nt)&&(c[n].set(o,i),c[o].set(n,i),u>=5e4))break}const f=[...o.assignment],d=Array.from({length:o.slotCount},()=>[]);f.forEach((t,e)=>d[t].push(e));const g=(t,e,n)=>{const o=f[e],s=f[n];let i=0;const a=new Set;for(const r of[e,n])for(const[l,c]of t[r]){const t=r<l?`${r}:${l}`:`${l}:${r}`;if(a.has(t))continue;a.add(t);const u=f[r]===f[l],d=(r===e?s:o)===(l===e?s:l===n?o:f[l]);u!==d&&(i+=d?c:-c)}return i},m=(t,e,n)=>{let o=0;for(const[s,i]of t[e]){const t=f[e]===f[s],a=n===f[s];t!==a&&(o+=a?i:-i)}return o},p=(t,e)=>t>nt||Math.abs(t)<=nt&&e>nt,h=(t,e,n,o)=>t>n+nt||Math.abs(t-n)<=nt&&e>o+nt;let b=0;for(let n=0;n<32&&b<et;n++){let n=null,o=-1,s=-1,a=-1,r=-1/0,l=-1/0;for(let u=0;u<t.length;u++){for(let g=0;g<d.length&&!(b++>=et);g++){if(g===f[u])continue;if(!d[g].every(n=>!e.conflicts(t[u],t[n])))continue;const b=m(i,u,g),M=m(c,u,g);p(b,M)&&h(b,M,r,l)&&(n="move",o=u,s=-1,a=g,r=b,l=M)}if(b>=et)break}for(let u=0;u<t.length-1;u++){for(let m=u+1;m<t.length&&!(b++>=et);m++){const b=f[u],M=f[m];if(b===M)continue;if(!d[M].every(n=>n===m||!e.conflicts(t[u],t[n])))continue;if(!d[b].every(n=>n===u||!e.conflicts(t[m],t[n])))continue;const y=g(i,u,m),x=g(c,u,m);p(y,x)&&h(y,x,r,l)&&(n="swap",o=u,s=m,a=-1,r=y,l=x)}if(b>=et)break}if(null==n||-1===o)break;if("move"===n){const t=f[o];d[t].splice(d[t].indexOf(o),1),d[a].push(o),f[o]=a;continue}const u=f[o],M=f[s];d[u].splice(d[u].indexOf(o),1,s),d[M].splice(d[M].indexOf(s),1,o),f[o]=M,f[s]=u}return f}function ft(t,e,n,o){if(0===t.length||t.length>12||o.slotCount<=1)return o.assignment;const s=new Map(t.map((t,e)=>[t,e])),i=Array.from({length:t.length},()=>new Float64Array(t.length)),a=Array.from({length:t.length},()=>new Map),r=Array.from({length:t.length},()=>new Map),l=it(n);for(const t of n){const e=s.get(t.source),n=s.get(t.target);if(null==e||null==n||e===n)continue;const o=ct(t,l);i[e][n]+=o,i[n][e]+=o,r[e].set(n,(r[e].get(n)??0)+o),a[n].set(e,(a[n].get(e)??0)+o)}const c=at(n),u=t.map(t=>c.get(t)?.weight??0),f=Array.from({length:t.length},()=>new Float64Array(t.length));for(let e=0;e<t.length;e++)for(let n=e+1;n<t.length;n++){for(const[t,o]of a[e])f[e][n]+=Math.min(o,a[n].get(t)??0);for(const[t,o]of r[e])f[e][n]+=Math.min(o,r[n].get(t)??0);if(c.has(t[e])&&c.has(t[n])){const o=Math.min(u[e],u[n])||Math.max(u[e],u[n]);f[e][n]+=rt(t[e],t[n],c)?o:-o}f[n][e]=f[e][n]}let d=[...o.assignment],g=(e=>{let n=0,o=0;for(let s=0;s<t.length;s++)for(let a=s+1;a<t.length;a++)e[s]===e[a]&&(n+=i[s][a],o+=f[s][a]);return{flow:n,affinity:o}})(d),m=0;const p=new Array(t.length).fill(-1),h=Array.from({length:o.slotCount},()=>[]),b=(n,s,a,r)=>{if(m>=75e3)return;if(n===t.length)return m++,void((a>g.flow||a===g.flow&&r>g.affinity||a===g.flow&&r===g.affinity&&function(t,e){for(let n=0;n<Math.min(t.length,e.length);n++)if(t[n]!==e[n])return t[n]<e[n];return t.length<e.length}(p,d))&&(d=[...p],g={flow:a,affinity:r}));const l=Math.min(s+1,o.slotCount-1);for(let o=0;o<=l;o++){if(h[o].some(o=>e.conflicts(t[n],t[o])))continue;let l=0,c=0;for(const t of h[o])l+=i[n][t],c+=f[n][t];if(p[n]=o,h[o].push(n),b(n+1,Math.max(s,o),a+l,r+c),h[o].pop(),p[n]=-1,m>=75e3)return}};return p[0]=0,h[0].push(0),b(1,0,0,0),d}function dt(t,e){let n=1/0,o=-1/0;for(const e of t?.samples??[])e.topMass+e.botMass<=1e-9||(n=Math.min(n,e.t),o=Math.max(o,e.t));return Number.isFinite(n)&&Number.isFinite(o)?(null!=e.start&&(n=Math.max(n,e.start)),null!=e.end&&(o=Math.min(o,e.end)),o>=n?{start:n,end:o}:{start:null,end:null}):{start:null,end:null}}function gt(t,e,n,o){const s=function(t,e,n,o){return`${t.map(t=>{const e=n[t.id],s=o[t.id];return[t.id,t.group??"",t.xExtent?.[0]??"",t.xExtent?.[1]??"",e?.topPeak??0,e?.botPeak??0,s?.start??"",s?.end??""].join(":")}).join("|")}#${e.map(t=>[t.id,t.source,t.target,t.value,t.startTime,t.endTime].join(":")).join("|")}`}(t,e,n,o),i=(a=s,tt.get(a));var a;if(i)return K(i.slots,n,o);const r=m();for(const e of t)r[e.id]=dt(n[e.id],o[e.id]);const l=function(t,e){return t.filter(t=>null!=e[t.id].start).sort((t,n)=>e[t.id].start-e[n.id].start||e[t.id].end-e[n.id].end||p(t.id,n.id)).map(t=>t.id)}(t,r),c=new Map(t.map(t=>[t.id,t])),u=new Map(t.map(t=>[t.id,t.group||void 0])),f=at(e),d=function(t,e,n,o,s,i){const a=new Set,r=new Map(t.map(t=>[t,new Set])),l=new Map(t.map(t=>[t,new Set]));for(const t of o)a.add(st(t.source,t.target)),r.get(t.target)?.add(t.source),l.get(t.source)?.add(t.target);const c=new Map,u=new Set,f=(t,e)=>{for(let n=0;n<t.length;n++)for(let o=n+1;o<t.length;o++){const s=st(t[n],t[o]);e instanceof Map?e.set(s,[t[n],t[o]]):e.add(s)}};for(const t of l.values())f([...t],c);for(const t of r.values())f([...t],u);const d=new Set;for(const[t,[o,s]]of c)u.has(t)&&(ot(e[o],e[s])||ot(n[o],n[s])&&(d.add(o),d.add(s)));return{conflicts:(t,n)=>{const o=s.get(t),r=s.get(n);return null!=o&&null!=r&&o!==r||!(null!=o==(null!=r)||a.has(st(t,n))||i.has(t)&&i.has(n)&&rt(t,n,i))||!!ot(e[t],e[n])||!(!d.has(t)&&!d.has(n))&&!a.has(st(t,n))}}}(l,r,o,e,u,f),g=function(t,e,n=new Map){const o=[],s=[];for(const i of t){let t=o.findIndex(t=>t.every(t=>!e.conflicts(i,t))&&!lt(i,t,n));-1!==t||n.has(i)||(t=o.findIndex(t=>t.every(t=>!e.conflicts(i,t)))),-1===t&&(t=o.length,o.push([])),o[t].push(i),s.push(t)}return{assignment:s,slotCount:o.length}}(l,d,f),h=ft(l,d,e,{...g,assignment:ut(l,d,e,g)}),b=new Map,M=h.map(t=>(b.has(t)||b.set(t,b.size),b.get(t))),y=Array.from({length:b.size||(t.length>0?1:0)},()=>({occupants:[],peak:{topPeak:0,botPeak:0}})),x=m();l.forEach((t,e)=>{const n=M[e],o=y[n];o.occupants.push({id:t,end:r[t].end??-1/0});const s=c.get(t)?.group;s&&(o.group=s),x[t]=n});for(const e of[...t].sort((t,e)=>p(t.id,e.id)))null==x[e.id]&&(y[0].occupants.push({id:e.id,end:-1/0}),x[e.id]=0);for(const t of y){t.occupants.sort((t,e)=>(r[t.id].start??1/0)-(r[e.id].start??1/0)||p(t.id,e.id));for(const e of t.occupants){const o=n[e.id];t.peak.topPeak=Math.max(t.peak.topPeak,o?.topPeak||0),t.peak.botPeak=Math.max(t.peak.botPeak,o?.botPeak||0)}}const v={slots:y,slotByNode:x};return function(t,e){for(tt.has(t)&&tt.delete(t),tt.set(t,{slots:e.slots.map(t=>({occupants:t.occupants.map(t=>({...t})),peak:{...t.peak},...null!=t.group?{group:t.group}:{}})),slotByNode:Object.assign(m(),e.slotByNode)});tt.size>12;){const t=tt.keys().next().value;if(null==t)break;tt.delete(t)}}(s,v),v}function mt(t){return t.topMass+t.botMass}function pt(t){const e=new Map;for(const n of t.samples){if(Number.isNaN(n.t))continue;let t=e.get(n.t);t||(t=[],e.set(n.t,t)),t.push(n)}let n=0,o=-1/0;return s=>{s>=o||(n=0),o=s;const i=e.get(s);if(i){const t=i.reduce((t,e)=>mt(e)>=mt(t)?e:t,i[0]);return{exact:i,sample:t}}for(;n<t.samples.length&&!(t.samples[n].t>s);)n++;return{exact:i,sample:t.samples[n-1]??null}}}function ht(t,e,n,o,s,i,a=0){const l=new Map;for(const n of t){if(!n.group||!e[n.id])continue;const t=l.get(n.group)??[];t.push(n),l.set(n.group,t)}if(0===l.size||!(i>0))return e;const c=(u=e,Object.fromEntries(Object.entries(u).map(([t,e])=>[t,{...e,samples:e.samples.map(t=>({...t})),localAttachments:new Map([...e.localAttachments].map(([t,e])=>[t,{...e}]))}])));var u;for(const[t,u]of l){const l=n.map((t,e)=>({slot:t,index:e})).filter(({slot:e})=>e.group===t);if(0===l.length)continue;const f=l[0].slot,d=l.at(-1).slot,g=s[f.occupants[0]?.id],m=s[d.occupants[0]?.id];if(!Number.isFinite(g)||!Number.isFinite(m))continue;const p=(g-f.peak.topPeak*i+(m+d.peak.botPeak*i))/2,h=[...new Set(u.flatMap(t=>e[t.id].samples.map(t=>t.t)))].sort((t,e)=>t-e),b=new Map;for(const t of u)b.set(t.id,new Map);const M=new Map(u.map(t=>[t.id,pt(e[t.id])]));for(const t of h){const e=new Map;for(const n of u){const{sample:s}=M.get(n.id)(t);if(!s||mt(s)<=1e-9)continue;const i=o[n.id];if(null==i)continue;const a=e.get(i)??[];a.push({node:n,sample:s}),e.set(i,a)}const n=[...e].sort((t,e)=>t[0]-e[0]).map(([t,e])=>({slot:t,active:e,mass:r(e.map(({sample:t})=>mt(t)))}));if(0===n.length)continue;let l=p-(n.reduce((t,e)=>t+e.mass,0)*i+Math.max(0,a)*Math.max(0,n.length-1))/2;for(const e of n){for(const{node:n,sample:o}of e.active){const e=(l-s[n.id])/i+o.topMass-(o.boundaryOffset??0);b.get(n.id).set(t,e)}l+=e.mass*i+Math.max(0,a)}}for(const t of u){const n=e[t.id],o=c[t.id],s=b.get(t.id),i=M.get(t.id),a=[];for(const t of h){const e=s.get(t),{exact:n,sample:o}=i(t);n?a.push(...n.map(t=>({...t,...null!=e?{boundaryOffset:(t.boundaryOffset??0)+e}:{}}))):null==e||!o||mt(o)<=1e-9||a.push({...o,t:t,boundaryOffset:(o.boundaryOffset??0)+e})}o.samples=a,o.localAttachments=new Map([...n.localAttachments].map(([t,e])=>{const n=s.get(e.time);return[t,{...e,...null!=n?{boundaryOffset:(e.boundaryOffset??0)+n}:{}}]}))}}return c}function bt(t,e,n,o,s){const{plotH:i,padding:a,valueScale:r,packing:l,laneOrder:c,lifetimeMode:u="half",lanePlacement:f="stack",groupPadding:d=0,ribbonLane:g="both",domain:b}=s,M=m(),y=m();for(const e of t)M[e.id]=n[e.id].topPeak||0,y[e.id]=n[e.id].botPeak||0;const x="half"===u,w=m();for(const e of t){const t=Array.isArray(e.xExtent)?e.xExtent[0]:null,n=Array.isArray(e.xExtent)?e.xExtent[1]:null;let s=null!=t&&Number.isFinite(t)?t:1/0,i=null!=n&&Number.isFinite(n)?n:-1/0;for(const t of o.outgoing[e.id]){t.startTime<s&&(s=t.startTime),null!=t.systemInTime&&Number.isFinite(t.systemInTime)&&t.systemInTime<s&&(s=t.systemInTime);const e=x?(t.startTime+t.endTime)/2:t.endTime;e>i&&(i=e)}for(const t of o.incoming[e.id]){const e=x?(t.startTime+t.endTime)/2:t.startTime;e<s&&(s=e),t.endTime>i&&(i=t.endTime),null!=t.systemOutTime&&Number.isFinite(t.systemOutTime)&&t.systemOutTime>i&&(i=t.systemOutTime)}w[e.id]={start:Number.isFinite(s)?s:null,end:Number.isFinite(i)?i:null}}let k=m(),T=[],S=[];if(s.frozenSlots){const t=K(s.frozenSlots,n,w);T=t.slots,k=t.slotByNode,S=T.map(h)}else if("reuse"===l){const o=gt(t,e,n,w);T=o.slots,k=o.slotByNode}else t.forEach((t,e)=>{T.push({occupants:[{id:t.id,end:w[t.id]?.end??-1/0}],peak:{topPeak:M[t.id],botPeak:y[t.id]},...t.group?{group:t.group}:{}}),k[t.id]=e});V(T,k),0===S.length&&(S=T.map(h));let N=null;s.frozenSlots||(s.fixedSlotOrder?function(t,e,n){const o=new Map(n.map((t,e)=>[t,e]));j(t,e,[...t].sort((t,e)=>(o.get(h(t))??1/0)-(o.get(h(e))??1/0)||p(h(t),h(e))))}(T,k,s.fixedSlotOrder):s.runOrdering&&c&&"insertion"!==c&&(N=J(t,e,n,w,T,k,{plotH:i,padding:a,valueScale:r,groupPadding:d,laneOrder:c,ribbonLane:g,domain:b}))),V(T,k);const O=v(t,e,n,T,k,{plotH:i,padding:a,valueScale:r,stackValueScale:s.stackValueScale,lanePlacement:f,groupPadding:d}),P=0===T.length?0:T[0].peak.topPeak+O.adjacentClearance.reduce((t,e)=>t+e,0)+T[T.length-1].peak.botPeak,F=N?.before.crossings??null,A=N?.after.crossings??null,$=N?.before.weightedLength??null,I=N?.after.weightedLength??null;return{effectiveSlotsHeight:P,centerlines:O.centerlines,laneLifetime:w,slots:T,slotByNode:k,slotCenter:O.slotCenter,stackCenter:O.stackCenter,verticalUtilization:O.verticalUtilization,selectedSlotOrder:T.map(h),initialSlotOrder:S,ordering:N,crossingsBefore:F,crossingsAfter:A,lengthBefore:$,lengthAfter:I}}function Mt(t,e,n){const{plotH:o,pairing:s="temporal",packing:i="reuse",laneOrder:a="crossing-min",lifetimeMode:r="half",maxValueScale:l,lanePlacement:c="stack",nodeSizing:u="temporal",groupPadding:f=0,ribbonLane:d="both",domain:g}=n,M=Number.isFinite(f)?Math.max(0,f):0,y=function(t,e){const n=m(),o=m();for(const e of t)n[e.id]=[],o[e.id]=[];for(const t of e)o[t.source]&&o[t.source].push(t),n[t.target]&&n[t.target].push(t);return{incoming:n,outgoing:o}}(t,e),x=function(t,e,n,o="temporal"){const s="temporal"===o?(t,e)=>t.endTime-e.endTime||p(t.id,e.id):(t,e)=>e.value-t.value||p(t.id,e.id),i="temporal"===o?(t,e)=>t.startTime-e.startTime||p(t.id,e.id):(t,e)=>e.value-t.value||p(t.id,e.id),a=new Map;for(const t of e)a.set(t.id,{});const r=(t,e)=>{const n=new Map;for(const o of t){const t=o[e];n.has(t)||n.set(t,{partner:t,edges:[],total:0,earliestStart:1/0,latestEnd:-1/0});const s=n.get(t);s.edges.push(o),s.total+=o.value,s.earliestStart=Math.min(s.earliestStart,o.startTime),s.latestEnd=Math.max(s.latestEnd,o.endTime)}const a=[...n.values()];"temporal"===o?a.sort((t,n)=>"target"===e?t.earliestStart-n.earliestStart||p(t.partner,n.partner):t.latestEnd-n.latestEnd||p(t.partner,n.partner)):a.sort((t,e)=>e.total-t.total||p(t.partner,e.partner));for(const t of a)t.edges.sort("target"===e?i:s);return a};for(const e of t){const t=n.outgoing[e.id],o=n.incoming[e.id];if(0===o.length)r(t,"target").forEach((t,e)=>{const n=e%2==0?"top":"bot";for(const e of t.edges)a.get(e.id).sourceSide=n});else if(0===t.length)r(o,"source").forEach((t,e)=>{const n=e%2==0?"top":"bot";for(const e of t.edges)a.get(e.id).targetSide=n});else{const e=r(o,"source"),n=r(t,"target"),s=Math.max(e.length,n.length);for(let t=0;t<s;t++){const o=t%2==0?"top":"bot";if(e[t])for(const n of e[t].edges)a.get(n.id).targetSide=o;if(n[t])for(const e of n[t].edges)a.get(e.id).sourceSide=o}}}return a}(t,e,y,s);let w=m();for(const e of t)w[e.id]=E(e,y,x,void 0,u);const k=bt(t,e,w,y,{plotH:o,padding:12,valueScale:1,packing:i,laneOrder:a,lifetimeMode:r,runOrdering:!0,lanePlacement:"stack",groupPadding:M,ribbonLane:d,domain:g}),T=k.slots.map(t=>({occupants:t.occupants.map(t=>({...t})),peak:{...t.peak},...null!=t.group?{group:t.group}:{}})),S=new Set;for(const t of e){const e=k.slotByNode[t.source],n=k.slotByNode[t.target];if(void 0===e||void 0===n)continue;const o=x.get(t.id);e!==n?n<e?(o.sourceSide="top",o.targetSide="bot"):(o.sourceSide="bot",o.targetSide="top"):(S.add(t.id),o.sourceSide="bot",o.targetSide="bot")}for(const e of t){const t=y.outgoing[e.id],n=y.incoming[e.id],o=new Set(t.map(t=>x.get(t.id).sourceSide)),s=new Set(n.map(t=>x.get(t.id).targetSide));if(1===o.size&&n.length>0){const t=[...o][0];for(const e of n)k.slotByNode[e.source]===k.slotByNode[e.target]&&(x.get(e.id).targetSide=t)}if(1===s.size&&t.length>0){const e=[...s][0];for(const n of t)k.slotByNode[n.source]===k.slotByNode[n.target]&&(x.get(n.id).sourceSide=e)}}!function(t,e,n){const o=new Map,s=[];for(const e of t)s.push({time:e.startTime,kind:"out",edge:e}),s.push({time:e.endTime,kind:"in",edge:e});s.sort((t,e)=>t.time-e.time||(t.kind===e.kind?0:"in"===t.kind?-1:1)||("out"===t.kind?e.edge.value-t.edge.value:0)||p(t.edge.id,e.edge.id));const i=t=>{let e=o.get(t);return e||(e={top:0,bot:0},o.set(t,e)),e},a=(t,e,n)=>{const o="top"===e?"bot":"top",s=Math.min(n,t[e]);t[e]-=s;const i=n-s;i>0&&(t[o]=Math.max(0,t[o]-i))};for(const t of s){const{edge:o}=t;if("in"===t.kind){const t=e.get(o.id)?.targetSide??"bot";i(o.target)[t]+=o.value;continue}const s=i(o.source),r=e.get(o.id);let l=r.sourceSide??"bot";if(n[o.source]===n[o.target]){const t=s.top>=o.value,e=s.bot>=o.value;t!==e?l=t?"top":"bot":t||e||s.top===s.bot||(l=s.top>s.bot?"top":"bot"),r.sourceSide=l,r.targetSide=l}a(s,l,o.value)}}(e,x,k.slotByNode),function(t,e,n,o){for(const s of t){const t=e.incoming[s.id],i=e.outgoing[s.id];if(0===t.length||0===i.length)continue;const a=()=>{const e={inTop:0,inBot:0,outTop:0,outBot:0};for(const o of t)"top"===n.get(o.id).targetSide?e.inTop+=o.value:e.inBot+=o.value;for(const t of i)"top"===n.get(t.id).sourceSide?e.outTop+=t.value:e.outBot+=t.value;return e},r=(t,e)=>{const s=a(),r="top"===t?s.outTop-s.inTop:s.outBot-s.inBot,l="top"===e?s.inTop-s.outTop:s.inBot-s.outBot;if(r<=0||l<=0)return!1;const c=Math.min(r,l),u=i.filter(e=>!o.has(e.id)&&n.get(e.id).sourceSide===t&&e.value<=c).sort((t,e)=>e.value-t.value||p(t.id,e.id));return 0!==u.length&&(n.get(u[0].id).sourceSide=e,!0)};let l=i.length+1;for(;l-- >0&&(r("top","bot")||r("bot","top")););}}(t,y,x,S),w=m();for(const e of t)w[e.id]=E(e,y,x,void 0,u);const N=bt(t,e,w,y,{plotH:o,padding:12,valueScale:1,packing:i,laneOrder:a,lifetimeMode:r,frozenSlots:T,lanePlacement:"stack",groupPadding:M,ribbonLane:d,domain:g}),O=N.effectiveSlotsHeight??N.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),P=N.slots.slice(0,-1).reduce((t,e,n)=>t+(null!=e.group&&e.group===N.slots[n+1].group?1:0),0),A=Math.max(1,N.slots.length+1-P),$=Math.min(12,Math.max(0,.35*o-P*M)/A),L=2*$+b(N.slots,$,M).reduce((t,e)=>t+e,0),z=O>0?Math.max(0,(o-L)/O):1,B=Number.isFinite(l)&&l>0?Math.min(z,l):z;let C=bt(t,e,w,y,{plotH:o,padding:$,valueScale:B,packing:i,laneOrder:a,lifetimeMode:r,frozenSlots:T,lanePlacement:c,groupPadding:M,ribbonLane:d,domain:g,stackValueScale:z});const X=Number.isFinite(l)&&l>0&&l+1e-12<z;if("insertion"!==a&&("hug"===c||X)&&C.slots.length>1&&(J(t,e,w,C.laneLifetime,C.slots,C.slotByNode,{plotH:o,padding:$,valueScale:B,groupPadding:M,laneOrder:a,ribbonLane:d,domain:g,lanePlacement:c,mode:"geometry-refine"}),C=bt(t,e,w,y,{plotH:o,padding:$,valueScale:B,packing:i,laneOrder:a,lifetimeMode:r,frozenSlots:C.slots,fixedSlotOrder:C.slots.map(h),lanePlacement:c,groupPadding:M,ribbonLane:d,domain:g,stackValueScale:z})),function(t,e){const n=(t,n)=>{for(const o of t){const t=new Map;for(const s of o){const o=`${("out"===n?e.get(s.id)?.sourceSide:e.get(s.id)?.targetSide)??""}\0${"out"===n?s.startTime:s.endTime}`,i="out"===n?`${s.target}\0${s.endTime}`:`${s.source}\0${s.startTime}`,a=t.get(o);if(null!=a&&a!==i)return!0;t.set(o,i)}}return!1};return n(Object.values(t.outgoing),"out")||n(Object.values(t.incoming),"in")}(y,x)){const n=function(t,e,n,o){const s=new Map;for(const i of t){const t=e[i.source]?.localAttachments.get(i.id),a=e[i.target]?.localAttachments.get(i.id),r=n[i.source],l=n[i.target];if(!(t&&a&&Number.isFinite(r)&&Number.isFinite(l)))continue;const c=I(t,r,o),u=I(a,l,o);s.set(i.id,{source:(c[0]+c[1])/2,target:(u[0]+u[1])/2})}return s}(e,w,C.centerlines,B);w=m();for(const e of t)w[e.id]=E(e,y,x,n,u);C=bt(t,e,w,y,{plotH:o,padding:$,valueScale:B,packing:i,laneOrder:a,lifetimeMode:r,frozenSlots:C.slots,fixedSlotOrder:C.slots.map(h),lanePlacement:c,groupPadding:M,ribbonLane:d,domain:g,stackValueScale:z})}const j=new Map(k.initialSlotOrder.map((t,e)=>[t,e])),D=[...C.slots].sort((t,e)=>(j.get(h(t))??1/0)-(j.get(h(e))??1/0)||p(h(t),h(e))),H=m();D.forEach((t,e)=>{for(const n of t.occupants)H[n.id]=e});const Y=v(t,e,w,D,H,{plotH:o,padding:$,valueScale:B,stackValueScale:z,lanePlacement:"stack",groupPadding:M}),q=ht(t,w,D,H,Y.centerlines,B,M),V=F(W(H,e),G(H,e),e,q,D,H,Y.centerlines,C.laneLifetime,B,Y.verticalUtilization,d,g);w=ht(t,w,C.slots,C.slotByNode,C.centerlines,B,M);const R=F(W(C.slotByNode,e),G(C.slotByNode,e),e,w,C.slots,C.slotByNode,C.centerlines,C.laneLifetime,B,C.verticalUtilization,d,g);return{nodeData:w,sides:x,valueScale:B,padding:$,compressedPadding:$<12,centerlines:C.centerlines,laneLifetime:C.laneLifetime,slots:C.slots,slotByNode:C.slotByNode,crossingsBefore:"insertion"===a?null:V.crossings,crossingsAfter:"insertion"===a?null:R.crossings,lengthBefore:"insertion"===a?null:V.weightedLength,lengthAfter:"insertion"===a?null:R.weightedLength,layoutQualityBefore:V,layoutQuality:R}}function yt(t,e,n,o,s,i,a,r,l={}){const c=s,u=t=>r?Math.max(r[0],Math.min(r[1],t)):t;let f=i(u(t.time));const d=i(u(n.time)),g=t.value*c,m=n.value*c,p=e+(t.boundaryOffset??0)*c,h=o+(n.boundaryOffset??0)*c,b=t.sideMassBefore*c,M=n.sideMassAfter*c;let y,x,v,w;"top"===t.side?(y=p-b,x=y+g):(x=p+b,y=x-g),"top"===n.side?(v=h-M,w=v+m):(w=h+M,v=w-m);const k=l.sourceRunwayStart,T=l.minRun,S=(y+x)/2,N=(v+w)/2,O=Math.abs(N-S),P=d-f,F="number"==typeof k&&Number.isFinite(k),A="number"==typeof T&&Number.isFinite(T)&&T>0;if(F&&O>1e-9&&P>0&&("auto"===T||A)){const e="source"===a?.85:"target"===a?.15:.5,n=1.5*Math.min(e*e,(1-e)*(1-e)),o="auto"===T?Math.min(144,Math.sqrt(8*O/n)):T;if(o>P){const e=i(u(Math.min(k,t.time)));if(Number.isFinite(e)){const t=Math.min(f,e);f=Math.min(f,Math.max(t,d-o))}}}const $="source"===a?f+.85*(d-f):"target"===a?f+.15*(d-f):(f+d)/2;return{sx:f,sTop:y,sBot:x,tx:d,tTop:v,tBot:w,cp1X:$,cp2X:$}}function xt(t){return Math.max(18,11*t.length*.58)}function vt(t){const e=1.22*xt(t.labelText)+4;return"start"===t.labelAnchor?[t.labelX,t.labelX+e]:"middle"===t.labelAnchor?[t.labelX-e/2,t.labelX+e/2]:[t.labelX-e,t.labelX]}function wt(t,e){const n=t.labelX-xt(t.labelText),o=e.labelX-xt(e.labelText);return n<=e.labelX+3&&o<=t.labelX+3}function kt(t,e,n,o){const s=t.map(t=>({...t,labelX:void 0===o?t.labelX:Math.min(o-4,Math.max(xt(t.labelText)+4,t.labelX))})),i=new Map;for(const t of s){const n=e[t.id];if(null==n)continue;const o=i.get(n)??[];o.push(t),i.set(n,o)}const a=t=>{if(t.length<2)return;const e=t.reduce((t,e)=>t+e.labelY,0)/t.length,o=(t.length-1)/2;t.forEach((t,s)=>{t.labelY=Math.max(8,Math.min(n-8,e+16*(s-o)))})};for(const t of i.values()){t.sort((t,e)=>t.labelX-e.labelX||t.id.localeCompare(e.id));let e=[],n=-1/0;for(const o of t){const t=o.labelX-xt(o.labelText);e.length>0&&t>n+3&&(a(e),e=[],n=-1/0),e.push(o),n=Math.max(n,o.labelX)}a(e)}return function(t,e){const n=[...t].sort((t,e)=>t.labelY-e.labelY||t.labelX-e.labelX||t.id.localeCompare(e.id));for(let t=0;t<3;t+=1){for(let t=0;t<n.length;t+=1){let e=8;for(let o=0;o<t;o+=1)wt(n[t],n[o])&&(e=Math.max(e,n[o].labelY+16));n[t].labelY=Math.max(n[t].labelY,e)}for(let t=n.length-1;t>=0;t-=1){let o=e-8;for(let e=t+1;e<n.length;e+=1)wt(n[t],n[e])&&(o=Math.min(o,n[e].labelY-16));n[t].labelY=Math.min(n[t].labelY,o)}}}(s,n),s}var Tt=/(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?),(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)/gi;function St(t){return t.replace(Tt,(t,e,n)=>`${n},${e}`)}function Nt(t){if(!t)return;const e=t=>({x:t.y,y:t.x});return{...t,...t.points&&{points:t.points.map(e)},...t.segments&&{segments:t.segments.map(t=>t.map(e))}}}function Ot(t){return{...t,pathD:St(t.pathD),y0:t.x0,y1:t.x1,x0:0,x1:0}}function Pt(t,e){const n=function(t){if(null==t)return()=>{};const e="function"==typeof t?t:e=>e[t];return t=>Ft(e(t))}(e??"value"),o=null==t?void 0:"function"==typeof t?t:e=>e[t];return t=>{const e=o?o(t):void 0;return{value:n(t),category:null==e?void 0:String(e)}}}function Ft(t){if("number"==typeof t)return Number.isFinite(t)?t:void 0;if("string"==typeof t&&""!==t.trim()){const e=Number(t);return Number.isFinite(e)?e:void 0}}function At(t,e,n){const o=t.when;return void 0===o||!0===o||!1!==o&&("function"==typeof o?o(e,n):function(t,e,n){const o=null!=t.axis?n[t.axis]:null!=t.field?e[t.field]:n.value;if(void 0!==t.eq&&o!==t.eq)return!1;if(void 0!==t.ne&&o===t.ne)return!1;if(void 0!==t.in&&!t.in.includes(o))return!1;if(void 0===t.gt&&void 0===t.gte&&void 0===t.lt&&void 0===t.lte&&void 0===t.within&&void 0===t.outside)return!0;const s=Ft(o);if(void 0===s)return!1;if(void 0!==t.gt&&!(s>t.gt))return!1;if(void 0!==t.gte&&!(s>=t.gte))return!1;if(void 0!==t.lt&&!(s<t.lt))return!1;if(void 0!==t.lte&&!(s<=t.lte))return!1;if(void 0!==t.within){const[e,n]=t.within;if(!(s>=e&&s<=n))return!1}if(void 0!==t.outside){const[e,n]=t.outside;if(!(s<e||s>n))return!1}return!0}(o,e,n))}import{jsx as $t,jsxs as It}from"react/jsx-runtime";function Et(t){const{nodes:e,edges:o,domain:a,usageMode:r="static"}=t,l=function(t,e,o,s={}){const i=n(s.usageMode??"static"),a=[],r=new Set;for(const e of t)r.has(e.id)&&a.push({kind:"duplicate-node",id:e.id,severity:i.duplicateIds}),r.add(e.id);const l=new Set,c=Array.isArray(o)&&2===o.length,u=c&&Number.isFinite(o[0])&&Number.isFinite(o[1]),f=u&&o[0]<=o[1];c&&u&&f||a.push({kind:"invalid-domain"});for(const e of t)null!=e.xExtent&&(Array.isArray(e.xExtent)&&2===e.xExtent.length&&Number.isFinite(e.xExtent[0])&&Number.isFinite(e.xExtent[1])&&e.xExtent[0]<=e.xExtent[1]||a.push({kind:"invalid-node-time",id:e.id}));for(const t of e)l.has(t.id)&&a.push({kind:"duplicate-edge",id:t.id,severity:i.duplicateIds}),l.add(t.id),r.has(t.source)||a.push({kind:"missing-node",id:t.id,endpoint:"source",nodeId:t.source}),r.has(t.target)||a.push({kind:"missing-node",id:t.id,endpoint:"target",nodeId:t.target}),Number.isFinite(t.startTime)&&Number.isFinite(t.endTime)?((null!=t.systemInTime&&!Number.isFinite(t.systemInTime)||null!=t.systemOutTime&&!Number.isFinite(t.systemOutTime))&&a.push({kind:"invalid-system-time",id:t.id,severity:"warn"}),(!Number.isFinite(t.value)||t.value<=0)&&a.push({kind:"invalid-value",id:t.id}),t.endTime<t.startTime&&a.push({kind:"backward-edge",severity:"fatal",id:t.id,source:t.source,target:t.target})):a.push({kind:"invalid-edge-time",id:t.id});return a}(e,o,a,{usageMode:r}),{fatal:c,warnings:u}=function(t){const e=[],n=[];for(const o of t)"fatal"===s(o)?e.push(o):n.push(o);return{fatal:e,warnings:n}}(l),f=i(o,l,r);return{layout:c.length?null:Mt(e,f,{plotH:"vertical"===t.orientation?t.plotW:t.plotH,...t.layoutOpts,ribbonLane:t.ribbonLane,domain:a}),issues:c,warnings:u}}function Lt(e,n=Et(e)){const{nodes:o,edges:s,domain:l,plotW:c,plotH:u,ribbonLane:f,ribbonMinRun:d=0,edgeOpacity:g,colorOf:m,orientation:p="horizontal",showLabels:h=!0,labelPriorityAccessor:b,maxLabels:M,selectionDatum:y="raw",styleRules:x,colorBy:v,valueAccessor:w,usageMode:k="static"}=e,T="vertical"===p?u:c,S="vertical"===p?c:u,{layout:N,issues:O,warnings:P}=n,F=i(s,[...O,...P],k),E=t().domain(l).range([0,T]);if(!N)return{layout:null,layoutConfig:{bands:[],ribbons:[],showLabels:!1!==h},issues:O,warnings:P,xScale:E};const{centerlines:L,nodeData:z,valueScale:B}=N,C=Pt(v,w),X=[],j=[],D=0===d?new Map:function(t,e,n){const o=new Set(e.map(t=>t.target)),s=new Map(t.map(t=>[t.id,t])),i=new Map;for(const t of e){if(o.has(t.source))continue;const e=i.get(t.source)??[];e.push(t),i.set(t.source,e)}const a=new Map;for(const e of t){if(!e.group)continue;const t=a.get(e.group)??[];t.push(e),a.set(e.group,t)}const l=new Set;for(const[t,e]of a){const n=e.flatMap(t=>i.get(t.id)??[]),s=new Set(n.map(t=>t.startTime));n.length>0&&1===s.size&&e.every(t=>{const e=t.xExtent?.[0],s=n[0].startTime;return!o.has(t.id)&&(i.get(t.id)?.length??0)>0&&Number.isFinite(e)&&e<s})&&l.add(t)}const c=new Map;for(const[t,e]of i){const o=s.get(t);if(o?.group&&!l.has(o.group))continue;const i=o?.xExtent?.[0],a=[...e].sort((t,e)=>t.startTime-e.startTime||t.id.localeCompare(e.id)),r=a[0]?.startTime-1;let u=null;for(let t=0;t<a.length;){const e=a[t].startTime;let o=t+1;for(;o<a.length&&a[o].startTime===e;)o++;for(let e=t;e<o;e++){const t=a[e],o=Number.isFinite(i)&&i<t.startTime,s=Number.isFinite(t.systemInTime)&&t.systemInTime<t.startTime;if(!o&&!s)continue;let l=n[0];o&&(l=Math.max(l,i)),s&&(l=Math.max(l,t.systemInTime)),!o&&s&&Number.isFinite(r)&&(l=Math.max(l,r)),null!=u&&(l=Math.max(l,u)),l<t.startTime&&c.set(t.id,l)}u=e,t=o}}for(const[t,e]of a){if(!l.has(t))continue;const n=e.flatMap(t=>i.get(t.id)??[]);if(!n.every(t=>c.has(t.id))){for(const t of n)c.delete(t.id);continue}const o=r(n.map(t=>c.get(t.id)));for(const t of n)c.set(t.id,o)}return c}(o,F,l),H=new Map(o.filter(t=>t.group).map(t=>[t.id,t.group])),Y=new Map;for(const t of F){const e=z[t.source]?.localAttachments.get(t.id),n=z[t.target]?.localAttachments.get(t.id);e&&n&&Y.set(t.id,yt(e,L[t.source],n,L[t.target],B,E,f,l,{minRun:d,sourceRunwayStart:D.get(t.id)}))}const q=function(t,e,n,o,s,i){const l=new Map(e),c=new Map;for(const e of t){const t=i?.get(e.source),n=null==t?`node:${e.source}`:`group:${t}`,o=c.get(n)??new Map,s=o.get(e.startTime)??[];s.push(e),o.set(e.startTime,s),c.set(n,o)}for(const t of c.values())for(const[i,c]of t){if(!c.some(t=>n.has(t.id)))continue;const t=c.map(t=>e.get(t.id));if(t.some(t=>null==t))continue;const u=o(i),f=a(t.map(t=>t.sx));if(!(f<u-1e-9))continue;const d=r(c.map(t=>{const e=n.get(t.id);return null==e?u:Math.min(u,o(e))})),g=Math.min(u,Math.max(f,d));for(const t of c){const n=e.get(t.id),o="source"===s?.85:"target"===s?.15:.5,i=g+(n.tx-g)*o;l.set(t.id,{...n,sx:g,cp1X:i,cp2X:i})}}return l}(F,Y,D,E,f,H),V=function(t,e,n,o,s){const i=new Map;for(const a of t){if(!n.has(a.id))continue;const t=e.get(a.id);if(!(t&&t.sx<o(a.startTime)-1e-9))continue;const r=s(t.sx);Number.isFinite(r)&&r<a.startTime&&i.set(a.id,r)}return i}(F,q,D,E,t=>l[0]+t/T*(l[1]-l[0])),W=function(t,e,n){const o=new Map,s=new Map;for(const[t,e]of n??[]){const n=s.get(e)??[];n.push(t),s.set(e,n)}for(const i of t){const t=e.get(i.id);if(!(null!=t&&Number.isFinite(t)&&t<i.startTime))continue;const a=n?.get(i.source),r=null==a?[i.source]:s.get(a)??[i.source];for(const e of r){const n=o.get(e)??new Map,s=n.get(i.startTime);n.set(i.startTime,null==s?t:Math.min(s,t)),o.set(e,n)}}return o}(F,V,H);o.forEach((t,e)=>{const n=z[t.id];if(!n||0===n.samples.length)return;const o=(s=n.samples,(i=W.get(t.id))&&0!==i.size?s.map(t=>{const e=i.get(t.t);return null==e?t:{...t,t:e}}):s);var s,i;const a=function(t,e,n,o,s){if(0===t.length)return null;const i=$(t,s),a=t=>e+(i[t].boundaryOffset??0)*n,r=t=>a(t)-i[t].topMass*n,l=t=>a(t)+i[t].botMass*n;let c=`M${o(i[0].t)},${r(0)}`;for(let t=1;t<i.length;t++)c+=` L${o(i[t].t)},${r(t)}`;c+=` L${o(i[i.length-1].t)},${l(i.length-1)}`;for(let t=i.length-2;t>=0;t--)c+=` L${o(i[t].t)},${l(t)}`;return c+" Z"}(o,L[t.id],B,E,l);if(!a)return;const r=$(o,l),c=r.find(t=>t.topMass+t.botMass>0)||r[0],u=(c.botMass-c.topMass+2*(c.boundaryOffset??0))*B/2,f=L[t.id]+u;let d,g,h=m(t.id,e),b=h,M=.5;const y=t.__raw??t;if(x&&x.length>0){const t=function(t,e,n){if(!e||0===e.length)return{};let o={};for(const s of e){if(!At(s,t,n))continue;const e="function"==typeof s.style?s.style(t,n):s.style;e&&(o={...o,...e})}return o}(y,x,C(y));"string"==typeof t.fill?h=t.fill:null!=t.fill&&("object"==typeof(v=t.fill)&&null!==v&&"hatch"===v.type)&&(g=t.fill,h=t.fill.background&&"transparent"!==t.fill.background?t.fill.background:h),"string"==typeof t.stroke&&(b=t.stroke),"number"==typeof t.strokeWidth&&(M=t.strokeWidth),"number"==typeof t.fillOpacity&&(d=t.fillOpacity),"number"==typeof t.opacity&&null==d&&(d=t.opacity)}var v;const w=function(t,e,n,o,s,i){const a=n.nodeData[t];if(!a||0===a.samples.length)return[];const r=n.valueScale,l=n.centerlines[t],c=$(a.samples,s),u=c.find(t=>t.topMass+t.botMass>0)||c[0],f=[...c].reverse().find(t=>t.topMass+t.botMass>0)||c[c.length-1],d=o(u.t),g=o(f.t),m=t=>o(A(t,s)),p=[],h=(t,e,n,o)=>`M${t},${e} L${n},${e} L${n},${o} L${t},${o} Z`;for(const n of e){if(n.source===t&&null!=n.systemInTime&&Number.isFinite(n.systemInTime)){const t=a.localAttachments.get(n.id),e=i?.get(n.id)??n.startTime;if(t&&"out"===t.kind&&n.systemInTime<e){const o=m(n.systemInTime),i=m(e),a=null!=s&&n.systemInTime<s[0],c=a?o:o-20,u=a?Math.min(i,o+20):o,f=Math.max(d,c);if(i>f){const[e,n]=I(t,l,r);p.push({pathD:h(f,e,i,n),x0:c,x1:u,from:0,to:1})}}}if(n.target===t&&null!=n.systemOutTime&&Number.isFinite(n.systemOutTime)){const t=a.localAttachments.get(n.id);if(t&&"in"===t.kind&&n.systemOutTime>n.endTime){const e=m(n.systemOutTime),o=m(n.endTime),s=e+20,i=Math.min(g,s);if(i>o){const[n,a]=I(t,l,r);p.push({pathD:h(o,n,i,a),x0:e,x1:s,from:1,to:0})}}}}return p}(t.id,F,N,E,l,V);X.push({id:t.id,pathD:a,fill:h,stroke:b,strokeWidth:M,...null!=d&&{fillOpacity:d},...g&&{hatchFill:g},...w.length>0&&{gradientStubs:w},rawDatum:y,labelX:E("vertical"===p&&t.xExtent?t.xExtent[0]:c.t)-4,labelY:f,labelText:t.label??t.id})});const G=new Map;o.forEach((t,e)=>G.set(t.id,e)),F.forEach(t=>{const e=q.get(t.id);if(!e)return;const n=G.get(t.source)??0,o=m(t.source,n),{pathD:s,bezier:i}=function(t){const{sx:e,sTop:n,sBot:o,tx:s,tTop:i,tBot:a,cp1X:r,cp2X:l}=t,c=(n+o)/2,u=(i+a)/2;return{pathD:[`M${e},${n}`,`C${r},${n} ${l},${i} ${s},${i}`,`L${s},${a}`,`C${l},${a} ${r},${o} ${e},${o}`,"Z"].join(" "),bezier:{circular:!1,points:[{x:e,y:c},{x:r,y:c},{x:l,y:u},{x:s,y:u}],halfWidth:(o-n)/2}}}(e),a=t.__raw??t,r="function"==typeof g?Number(g(a)):g,l=Number.isFinite(r)?Math.max(0,Math.min(1,r)):.35;j.push({id:t.id,pathD:s,fill:o,opacity:l,rawDatum:a,bezier:i})});const R=kt(X,N.slotByNode,S,"horizontal"===p?c:void 0).map(t=>function(t,e){return"horizontal"===e?t:{...t,pathD:St(t.pathD),gradientStubs:t.gradientStubs?.map(Ot),labelX:t.labelY,labelY:t.labelX,labelAnchor:"middle",labelBaseline:"auto"}}(t,p)),U="vertical"===p?function(t,e,n){const o=t.map(t=>({...t}));for(const t of o){const n=1.22*xt(t.labelText)+4;t.labelX=n>=e-4?e/2:Math.max(n/2+2,Math.min(e-n/2-2,t.labelX))}const s=[],i=[...o].sort((t,e)=>t.labelY-e.labelY||t.labelX-e.labelX);for(const t of i){const e=s[s.length-1];!e||Math.abs(e[0].labelY-t.labelY)>14?s.push([t]):e.push(t)}for(const t of s){t.sort((t,e)=>t.labelX-e.labelX||t.id.localeCompare(e.id));const e=[],o=new Map;for(const n of t){const[t,s]=vt(n);let i=e.findIndex(e=>t>e+8);-1===i&&(i=e.length),e[i]=s,o.set(n,i)}const s=t.reduce((t,e)=>t+e.labelY,0)/t.length,i=s<14*e.length+8;for(const e of t){const t=o.get(e)??0;e.labelY=i?Math.min(n-8,12+14*t):Math.max(8,s-14*t)}}return o}(R,c,u):R,_=new Map;if(null!=b)for(const t of o){const e=t.__raw??t,n="function"==typeof b?b(e):Number(e[b]);Number.isFinite(n)&&_.set(t.id,n)}const Z=function(t,e,n,o,s={}){if(!1===o)return t.map(t=>({...t,labelText:"",labelDeferred:!1,labelFullText:void 0}));if(!0===o)return t.map(t=>({...t,labelDeferred:!1,labelFullText:void 0}));const i=Math.max(1,e*n);let a=Math.max(4,Math.min(t.length,Math.floor(i/14e3)));Number.isFinite(s.maxLabels)&&s.maxLabels>=0&&(a=Math.min(a,Math.floor(s.maxLabels)));const r=t.map((t,e)=>{const n=s.priorityById?.get(t.id),o=Math.abs(t.labelY);return{band:t,index:e,score:null!=n&&Number.isFinite(n)?1e6*n+xt(t.labelText):xt(t.labelText)+.01*o}}).filter(t=>t.band.labelText.trim().length>0).sort((t,e)=>e.score-t.score||t.index-e.index||t.band.id.localeCompare(e.band.id)),l=new Set(r.slice(0,a).map(t=>t.band.id));return t.map(t=>l.has(t.id)||0===t.labelText.trim().length?{...t,labelDeferred:!1,labelFullText:void 0}:{...t,labelFullText:t.labelText,labelText:"",labelDeferred:!0})}(U,c,u,h,{..._.size>0&&{priorityById:_},...null!=M&&{maxLabels:M}});return{layout:N,layoutConfig:{bands:Z,ribbons:j.map(t=>function(t,e){return"horizontal"===e?t:{...t,pathD:St(t.pathD),bezier:Nt(t.bezier)}}(t,p)),showLabels:!1!==h,selectionDatum:y},issues:[],warnings:P,xScale:E}}self.onmessage=t=>{const e=t.data,n=e?.requestId,o=e?.request??e;try{const t=o.colorById??{},e=o.fallbackPalette??["#475569"],a=(n,o)=>t[n]??e[o%e.length]??"#475569",r=Lt({...o.input,colorOf:a});self.postMessage({requestId:n,layout:(i=r.layout,i?{...i,sides:i.sides instanceof Map?[...i.sides.entries()]:i.sides}:null),layoutConfig:(s=r.layoutConfig,{bands:(s.bands??[]).map(({rawDatum:t,...e})=>e),ribbons:(s.ribbons??[]).map(({rawDatum:t,...e})=>e),showLabels:s.showLabels}),issues:r.issues,warnings:r.warnings,domain:o.input.domain,timelineExtent:"vertical"===o.input.orientation?o.input.plotH:o.input.plotW})}catch(t){self.postMessage({requestId:n,error:{message:t instanceof Error?t.message:String(t),name:t instanceof Error?t.name:"Error",stack:t instanceof Error?t.stack:void 0}})}var s,i};
|
|
@@ -61,9 +61,10 @@ export type { DashboardPanel, DashboardSuggestion, SuggestDashboardOptions } fro
|
|
|
61
61
|
export { applyAudienceBias, effectiveFamiliarity, stretchFamiliarityCeiling, receivabilityBias } from "./components/ai/audienceProfile";
|
|
62
62
|
export type { AudienceProfile, AudienceTarget, AudienceBiasResult, ReceptionModality, ReceivabilitySignal, DashboardLayoutPolicy } from "./components/ai/audienceProfile";
|
|
63
63
|
export { suggestStreamCharts, explainStreamCapabilityFit, registerStreamChartCapability, unregisterStreamChartCapability, getStreamCapabilities } from "./components/ai/suggestStreamCharts";
|
|
64
|
-
export type { SuggestStreamChartsOptions, SuggestStreamChartsResult, RejectedStreamCapability, StreamStretchSuggestion } from "./components/ai/suggestStreamCharts";
|
|
64
|
+
export type { SuggestStreamChartsOptions, SuggestStreamChartsResult, RejectedStreamCapability, StreamStretchSuggestion, StreamCapabilityExplanation } from "./components/ai/suggestStreamCharts";
|
|
65
65
|
export type { StreamSchema, StreamFieldSchema, StreamFieldKind, StreamFieldRole, StreamShape, StreamThroughput, StreamThroughputBand, StreamThroughputThresholds, StreamChartCapability, StreamIntentScorer, StreamSuggestion } from "./components/ai/streamingTypes";
|
|
66
|
-
export { resolveStreamShape, streamKeyFields, streamThroughputBand, pickValueField, pickCategoryField, pickTimeField, pickSeriesField } from "./components/ai/streamSchema";
|
|
66
|
+
export { resolveStreamShape, streamKeyFields, streamThroughputBand, pickValueField, pickCategoryField, pickTimeField, pickSeriesField, pickSplitField, pickMeasureFields, normalizeStreamSchema } from "./components/ai/streamSchema";
|
|
67
|
+
export type { NormalizedStreamSchema } from "./components/ai/streamSchema";
|
|
67
68
|
export { suggestStreamDashboard } from "./components/ai/suggestStreamDashboard";
|
|
68
69
|
export type { StreamDashboardPanel, StreamDashboardSuggestion, SuggestStreamDashboardOptions } from "./components/ai/suggestStreamDashboard";
|
|
69
70
|
export { suggestStretchCharts } from "./components/ai/suggestStretchCharts";
|