mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-10-26 21:12:51 +08:00
2 lines
1.9 KiB
JavaScript
2 lines
1.9 KiB
JavaScript
import{r as x,j as r}from"./vendor-react-Bf71BWbF.js";import{aI as k,fx as P,fy as S}from"./index-BOpK0UVB.js";import{u as T,C as B,f as W,n as v,g as j}from"./layout-Bzzn7HLw.js";import{G as I,C as L}from"./AreaCurve-BriPYJva.js";import"./array-C0P64tl-.js";function R(i){let t=i.parentElement;for(;t&&getComputedStyle(t).overflow==="visible";)t=t.parentElement;const l=i.getBoundingClientRect();if(!t)return{x:-l.left,y:-l.top,width:document.documentElement.clientWidth,height:document.documentElement.clientHeight};const h=t.getBoundingClientRect();return{x:h.left+t.clientLeft-l.left,y:h.top+t.clientTop-l.top,width:t.clientWidth,height:t.clientHeight}}function A({values:i,timestamps:t,color:l,fmt:h,locale:p,height:f=32,floor:m=0}){const g=x.useId(),C=k(),[o,y]=x.useState(null),[u,e]=P(Math.round,120),{tip:M,showAt:b,hide:E}=T(),c=i.filter(n=>n!==null),w=[m>0?0:Math.min(...c)*.85,Math.max(Math.max(...c)*1.05||1,m)],d=n=>j(n,[Math.min(...t),Math.max(...t)],[0,e?.width??0]),a=n=>j(n,w,[(e?.height??f)-2,2]);return x.useLayoutEffect(()=>{if(o===null||i[o]==null||!h||!p||!u.current||!e){E();return}b({x:d(t[o]),y:a(i[o]),width:e.width,bounds:R(u.current),label:S(p).format(t[o]),lines:[h(i[o])]})}),r.jsx("div",{ref:u,style:{height:f,width:"100%",position:"relative"},"aria-hidden":c.length?!0:void 0,onPointerLeave:()=>y(null),children:c.length>0&&e&&r.jsxs(r.Fragment,{children:[r.jsx(B,{tip:M}),r.jsxs("svg",{className:"rp-activity-surface",width:e.width,height:e.height,viewBox:`0 0 ${e.width} ${e.height}`,style:{display:"block"},onPointerMove:n=>{const s=W(n,n.currentTarget,e);y(s.x<0||s.x>e.width||s.y<2||s.y>e.height-2?null:v(t.map(d),s.x))},children:[r.jsx("defs",{children:r.jsx(I,{id:g,color:l})}),r.jsx(L,{points:i.map((n,s)=>n===null?null:{x:d(t[s]),y:a(n)}),baseline:a(Math.max(0,w[0])),color:l,id:g,strokeWidth:1.5}),o!==null&&i[o]!=null&&r.jsx("circle",{cx:d(t[o]),cy:a(i[o]),r:4,fill:l,stroke:C.base,strokeWidth:2})]})]})})}export{A as SparkPlot};
|