Files
pymc_console-dist/frontend/dist/assets/PathMapMapLibre-XobAbpvk.js
T
GitHub Actions Bot b86355e768 Sync build v0.9.69
Automated sync from private repository.
Commit: c692a066a1b1313daf1a017aa3dbee7a9c5762f2
2026-01-02 05:01:36 +00:00

2 lines
5.0 KiB
JavaScript

import{j as e}from"./index-DrB7gR15.js";import{b as t}from"./recharts-bmHCCfxU.js";import{M as n,S as o,L as r,a as s,P as i}from"./maplibre-gl-Ce8MxbYi.js";import"./maplibre-gl-CFO9X1Ek.js";const a="#4F46E5",l="#F9D26F",d="#B49DFF",c="#39D98A",u="#B49DFF";function p(e,t,n,o=!1,r=!1,s=!1){let i;i=r?c:s?u:e?a:t?"#6366F1":n?"transparent":l;const p=e||t||!n||r||s;return`<div style="\n width: 14px;\n height: 14px;\n background: ${i};\n border-radius: 50%;\n border: ${p?0:5}px solid ${p?"transparent":"#4338CA"};\n box-sizing: border-box;\n transition: box-shadow 0.15s ease;\n ${o?`box-shadow: 0 0 0 3px ${d}40, 0 0 8px ${d}60;`:""}\n "></div>`}const m={id:"path-line",type:"line",paint:{"line-color":"#3B3F4A","line-width":2,"line-opacity":.7},layout:{"line-cap":"round","line-join":"round"}};function x({resolvedPath:d,localNode:x,hubNodes:h=[],hoveredHopIndex:f,onHoverHop:b}){const g=t.useRef(null),y=t.useMemo(()=>new Set(h),[h]),[v,j]=t.useState(null),[k,C]=t.useState(0);t.useEffect(()=>{var e;const t=null==(e=g.current)?void 0:e.getMap();if(!t)return;const n=t.getCanvas();if(!n)return;const o=e=>{e.preventDefault()},r=()=>{C(e=>e+1)};return n.addEventListener("webglcontextlost",o),n.addEventListener("webglcontextrestored",r),()=>{n.removeEventListener("webglcontextlost",o),n.removeEventListener("webglcontextrestored",r)}},[k]);const{positions:N,markers:S,pathLineGeoJSON:F}=t.useMemo(()=>{const e=[],t=[],n=[];d.hops.forEach((o,r)=>{const s=o.candidates.filter(e=>{return t=e.latitude,n=e.longitude,0!==t||0!==n;var t,n});if(0===s.length)return;const i=[...s].sort((e,t)=>t.probability-e.probability)[0];n.push([i.longitude,i.latitude]);const a=!0===o.isSource,l=!0===o.isDestination;s.forEach((n,i)=>{const d=[n.latitude,n.longitude];e.push(d);const c=0===i;t.push({position:d,prefix:o.prefix,confidence:o.confidence,candidateCount:s.length,hopIndex:r,candidate:n,isHub:y.has(n.hash),isPrimary:c,isSource:a,isDestination:l})})});const o={type:"FeatureCollection",features:n.length>=2?[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:n}}]:[]};return{positions:e,markers:t,pathLineGeoJSON:o}},[d,y]),{center:L,zoom:w}=t.useMemo(()=>{if(0===N.length)return x?{center:[x.longitude,x.latitude],zoom:10}:{center:[0,0],zoom:2};let e=1/0,t=-1/0,n=1/0,o=-1/0;for(const[c,u]of N)c<e&&(e=c),c>t&&(t=c),u<n&&(n=u),u>o&&(o=u);const r=(e+t)/2,s=(n+o)/2,i=t-e,a=o-n,l=Math.max(i,a);let d;return d=l<.01?15:l<.05?13:l<.1?12:l<.5?10:l<1?9:l<5?7:5,{center:[s,r],zoom:d}},[N,x]);t.useEffect(()=>{if(!g.current||N.length<2)return;let e=1/0,t=-1/0,n=1/0,o=-1/0;for(const[r,s]of N)r<e&&(e=r),r>t&&(t=r),s<n&&(n=s),s>o&&(o=s);g.current.fitBounds([[n,e],[o,t]],{padding:30,maxZoom:16,duration:0})},[N]);const D=t.useCallback(e=>{j({longitude:e.position[1],latitude:e.position[0],marker:e})},[]);return 0===N.length?e.jsx("div",{className:"h-[200px] flex items-center justify-center text-text-muted text-sm bg-bg-elevated",children:"No mappable path data"}):e.jsxs(n,{ref:g,initialViewState:{longitude:L[0],latitude:L[1],zoom:w},style:{height:"200px",width:"100%"},mapStyle:"https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json",attributionControl:!1,children:[F.features.length>0&&e.jsx(o,{id:"path-line-source",type:"geojson",data:F,children:e.jsx(r,{...m})}),S.map(t=>{const n=f===t.hopIndex;return e.jsx(s,{longitude:t.position[1],latitude:t.position[0],anchor:"center",onClick:()=>D(t),children:e.jsx("div",{style:{cursor:"pointer",opacity:t.isPrimary?1:.5},onMouseEnter:()=>null==b?void 0:b(t.hopIndex),onMouseLeave:()=>null==b?void 0:b(null),dangerouslySetInnerHTML:{__html:p(t.candidate.isLocal||!1,t.isHub,t.isPrimary,n,t.isSource,t.isDestination)}})},`${t.hopIndex}-${t.candidate.hash}`)}),v&&e.jsx(i,{longitude:v.longitude,latitude:v.latitude,anchor:"bottom",offset:[0,-12],closeOnClick:!1,onClose:()=>j(null),className:"maplibre-popup",children:e.jsxs("div",{className:"text-xs",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"font-semibold",children:v.marker.candidate.name}),v.marker.isSource&&e.jsx("span",{className:"px-1 py-0.5 text-[8px] font-bold rounded",style:{backgroundColor:c,color:"#000"},children:"SRC"}),v.marker.isDestination&&e.jsx("span",{className:"px-1 py-0.5 text-[8px] font-bold rounded",style:{backgroundColor:u,color:"#000"},children:"DST"}),v.marker.isHub&&e.jsx("span",{className:"px-1 py-0.5 text-[8px] font-bold rounded",style:{backgroundColor:"#FBBF24",color:"#000"},children:"HUB"}),v.marker.candidate.isLocal&&e.jsx("span",{className:"px-1 py-0.5 text-[8px] font-bold rounded",style:{backgroundColor:a,color:"#fff"},children:"LOCAL"})]}),e.jsxs("div",{className:"text-text-muted font-mono text-[10px]",children:[v.marker.prefix," • ",v.marker.candidate.hash.slice(0,10),"..."]}),!v.marker.isPrimary&&v.marker.candidateCount>1&&e.jsxs("div",{style:{color:l},children:["Alternative (",(100*v.marker.candidate.probability).toFixed(0),"%)"]}),v.marker.isPrimary&&v.marker.candidateCount>1&&e.jsxs("div",{className:"text-text-muted",children:[v.marker.candidateCount," candidates"]})]})})]},k)}export{x as default};