Files
op-packages/luci-app-honk/root/etc/honk/dashboard/assets/Sparkline-B2EO782x.js
T

2 lines
1.9 KiB
JavaScript

import{r as x,j as r}from"./vendor-react-Bf71BWbF.js";import{aB as k,eH as P,eI as B}from"./index-CXHBmSa5.js";import{u as S,C as T,f as W,n as v,g as j}from"./layout-BRLew_nj.js";import{G as H,C as I}from"./AreaCurve-BriPYJva.js";import"./array-C0P64tl-.js";function L(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,w]=x.useState(null),[u,e]=P(Math.round,120),{tip:M,showAt:b,hide:E}=S(),c=i.filter(n=>n!==null),y=[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,y,[(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:L(u.current),label:B(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:()=>w(null),children:c.length>0&&e&&r.jsxs(r.Fragment,{children:[r.jsx(T,{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);w(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(H,{id:g,color:l})}),r.jsx(I,{points:i.map((n,s)=>n===null?null:{x:d(t[s]),y:a(n)}),baseline:a(Math.max(0,y[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};