import{r as b,j as a,a2 as G,E as I,w as z,p as f,x as E,l as R}from"./index-B-YXshIJ.js";import{a as P,c as T}from"./index-Brfj1MB8.js";const J=t=>{const e=Number.parseInt(t.slice(1,3),16)/255,s=Number.parseInt(t.slice(3,5),16)/255,c=Number.parseInt(t.slice(5,7),16)/255,n=Math.max(e,s,c),r=Math.min(e,s,c),i=(n+r)/2,l=n===r?0:i<.5?(n-r)/(n+r):(n-r)/(2-n-r);return[(n===r?0:e===n?(s-c)/(n-r):s===n?2+(c-e)/(n-r):4+(e-s)/(n-r))*60,l*100,i*100]},p=80,$=80,A=100,g=80,u=400,h=30,y=70,H=30,v=115,M=10,L=7,O=5,N=20,k=L,U=t=>t.flatMap(({data:e,yAxisPoint:s})=>Object.values(e||{}).flatMap(I(s))),X=t=>{const e=[...t].sort(P(T(R))),s=Math.floor(e.length/2);return e[s]},w=t=>Object.values(t.data||{}).length*v,_=t=>Object.values(t).map(w).filter(e=>e>0).reduce((e,s)=>e+s+y,0)+g-y+H,q=(t,e)=>t.slice(0,t.indexOf(e)).map(w).filter(s=>s>0).reduce((s,c)=>s+c+y,0)+y/2+g+H,S=(()=>{const t=new WeakMap;return e=>(t.has(e)||t.set(e,Math.random()),t.get(e))})(),K=({items:t,yAxisPoint:e,xCoord:s,tooltip:c,yCoord:n,pointColor:r,label:i,linkForItem:l,onPointHover:d,pointTooltipId:x})=>{const o=t.length?t.map(e).reduce(E,0)/t.length:0,j=X(t.map(e));return a.jsxs("g",{children:[a.jsxs("foreignObject",{x:s-A/2,y:n(0)+k,width:A,height:$,children:[a.jsx("div",{className:"text-sm text-theme-helptext text-center",children:i}),a.jsxs("div",{className:"text-sm text-theme-icon text-center",children:["Average: ",f(o)]})]}),t.map((m,B)=>{const V=J((r==null?void 0:r(m))||"#197fe6"),F="hsla(".concat(Math.round(S(m)*30)+(V[0]-15),", 80%, 50%, 0.7)"),W=e(m);return a.jsx("a",{href:l(m),target:"_blank",rel:"noreferrer",children:a.jsx("circle",{cx:S(m)*h+s-h/2,cy:n(W),r:L,fill:F,stroke:"0",...d?{onMouseOver:()=>d(m),"data-tooltip-id":x||"scatter-tooltip"}:{"data-tooltip-id":x||"scatter-tooltip","data-tooltip-html":c(m,i,W)}})},B)}),t.length?a.jsx("line",{x1:s-h,y1:n(o),x2:s+h,y2:n(o),stroke:"rgba(255,0,0,0.6)",strokeWidth:5,"data-tooltip-id":"scatter-tooltip","data-tooltip-content":"Average ".concat(i," time: ").concat(f(o)," of ").concat(t.length," items")}):null,t.length?a.jsx("line",{x1:s-h,y1:n(j),x2:s+h,y2:n(j),stroke:"rgba(0,0,255,0.6)",strokeWidth:5,"data-tooltip-id":"scatter-tooltip","data-tooltip-content":"Median ".concat(i," time: ").concat(f(j)," of ").concat(t.length," items")}):null]})},Q=({group:t,xCoord:e,yCoord:s,linkForItem:c,pointToColor:n,onPointHover:r,pointTooltipId:i})=>a.jsxs("g",{children:[Object.entries(t.data||{}).length>1?a.jsx("foreignObject",{x:e-h/2,y:s(0)+$,width:(Object.entries(t.data).length-1)*(v+h)-v/2,height:p,children:a.jsx("div",{className:"text-sm text-gray-700 text-center",children:t.label})}):null,Object.entries(t.data||{}).map(([l,d],x)=>a.jsx(K,{items:d,label:Object.entries(t.data||{}).length===1?t.label:l,yAxisPoint:t.yAxisPoint,xCoord:e+v*x,yCoord:s,pointColor:n,tooltip:t.tooltip,linkForItem:c,onPointHover:r,pointTooltipId:i},l))]}),Y=({width:t,maxValue:e,yCoord:s})=>a.jsxs(a.Fragment,{children:[a.jsx("line",{x1:g-M,y1:u-p,x2:t,y2:u-p,stroke:"#ddd",strokeWidth:1}),a.jsx("line",{x1:g,y1:0,x2:g,y2:u-p+M,stroke:"#ddd",strokeWidth:1}),z(0,O).map(c=>{const n=e*(O-c)/O;return a.jsxs(b.Fragment,{children:[a.jsx("line",{x1:g-M,y1:s(n),x2:t,y2:s(n),stroke:"#ddd",strokeWidth:1}),a.jsx("foreignObject",{x:0,y:s(n)-N/2,width:g,height:N,children:a.jsx("div",{className:"text-right text-sm text-gray-700 pr-3",children:n>0?f(n):"-"})})]},c)})]}),C=({graphData:t,height:e,linkForItem:s,className:c,pointColor:n,onPointHover:r,pointTooltipId:i})=>{const l=b.useMemo(()=>Math.max(...U(t)),[t]),d=b.useMemo(()=>_(t),[t]),x=b.useCallback(o=>{const j=u-p-k;return j-o/l*j+k},[l]);return a.jsxs(a.Fragment,{children:[a.jsxs("svg",{viewBox:"0 0 ".concat(d," ").concat(u),height:e,className:c,children:[a.jsx(Y,{width:d,maxValue:l,yCoord:x}),t.map(o=>a.jsx(Q,{group:o,xCoord:q(t,o),yCoord:x,pointToColor:n,linkForItem:s,onPointHover:r,pointTooltipId:i},o.label))]}),a.jsx(G,{id:"scatter-tooltip",className:"z-50 text-base",style:{borderRadius:"0.375rem",fontSize:"0.875rem",lineHeight:"1.25rem"}})]})};export{C as S};
