@verifiedinc-public/shared-ui-elements 3.12.2 → 3.13.0
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.
@@ -10,6 +10,10 @@ interface ErrorCodesChartProps {
|
|
10
10
|
* Example: { OCE000: 150, OCE001: 75 }
|
11
11
|
*/
|
12
12
|
data: Record<string, number> | undefined;
|
13
|
+
/**
|
14
|
+
* Threshold value for the reference line
|
15
|
+
*/
|
16
|
+
threshold?: number;
|
13
17
|
/**
|
14
18
|
* MUI System props object for custom styling of the chart container
|
15
19
|
*/
|
@@ -29,9 +33,10 @@ interface ErrorCodesChartProps {
|
|
29
33
|
* OCE000: 150,
|
30
34
|
* OCE001: 75
|
31
35
|
* }}
|
36
|
+
* threshold={200}
|
32
37
|
* sx={{ width: 800, height: 400 }}
|
33
38
|
* />
|
34
39
|
* ```
|
35
40
|
*/
|
36
|
-
export declare function ErrorCodesChart({ data, sx, }: ErrorCodesChartProps): ReactElement;
|
41
|
+
export declare function ErrorCodesChart({ data, threshold, sx, }: ErrorCodesChartProps): ReactElement;
|
37
42
|
export {};
|
@@ -1 +1 @@
|
|
1
|
-
"use strict";import{j as i}from"../../shared/jsx-runtime-DHlBLioN.mjs";import*as P from"react";import{useCallback as te,useMemo as re,createElement as Fe,useState as K,useRef as Ie,useEffect as ge}from"react";import{Box as z,Stack as U,Typography as W,useTheme as F,Paper as Pe}from"@mui/material";import{ResponsiveContainer as Z,LineChart as ze,CartesianGrid as ne,XAxis as ae,YAxis as oe,Label as ye,Tooltip as ie,Legend as ve,Line as Ve,AreaChart as Be,Area as We,ComposedChart as qe,ReferenceLine as be,ReferenceArea as we,Bar as Ke,Sector as je,PieChart as Ue,Pie as Ze,Cell as Ye}from"recharts";import{b as ke,c as Oe}from"../../shared/date-Cq0LS2Mr.mjs";import Y,{Decimal as le}from"decimal.js";import{AnimatePresence as He}from"framer-motion";import{u as Xe}from"../../shared/useCopyToClipboard-BALOSYVW.mjs";import"qrcode";import{u as se}from"../../shared/usePrevious-DyvR1iCQ.mjs";import{a as Je,C as Se}from"../../shared/motions-BBPeWBPV.mjs";import{c as $e,i as Qe,_ as H,s as et,a as $,d as tt,e as rt,f as nt,h as at,j as ot,k as it,l as lt,m as st,n as ct,o as ut,p as dt,u as pt}from"../../shared/index-KVVTzcea.mjs";import{u as mt}from"../../shared/useCounter-BV32zXDQ.mjs";const ft=["ownerState"],ht=["variants"],xt=["name","slot","skipVariantsResolver","skipSx","overridesResolver"];function gt(e){return Object.keys(e).length===0}function yt(e){return typeof e=="string"&&e.charCodeAt(0)>96}function ce(e){return e!=="ownerState"&&e!=="theme"&&e!=="sx"&&e!=="as"}const vt=$e(),bt=e=>e&&e.charAt(0).toLowerCase()+e.slice(1);function X({defaultTheme:e,theme:t,themeId:r}){return gt(t)?e:t[r]||t}function wt(e){return e?(t,r)=>r[e]:null}function J(e,t){let{ownerState:r}=t,n=H(t,ft);const a=typeof e=="function"?e($({ownerState:r},n)):e;if(Array.isArray(a))return a.flatMap(l=>J(l,$({ownerState:r},n)));if(a&&typeof a=="object"&&Array.isArray(a.variants)){const{variants:l=[]}=a;let o=H(a,ht);return l.forEach(c=>{let s=!0;typeof c.props=="function"?s=c.props($({ownerState:r},n,r)):Object.keys(c.props).forEach(d=>{r?.[d]!==c.props[d]&&n[d]!==c.props[d]&&(s=!1)}),s&&(Array.isArray(o)||(o=[o]),o.push(typeof c.style=="function"?c.style($({ownerState:r},n,r)):c.style))}),o}return a}function jt(e={}){const{themeId:t,defaultTheme:r=vt,rootShouldForwardProp:n=ce,slotShouldForwardProp:a=ce}=e,l=o=>tt($({},o,{theme:X($({},o,{defaultTheme:r,themeId:t}))}));return l.__mui_systemSx=!0,(o,c={})=>{Qe(o,g=>g.filter(k=>!(k!=null&&k.__mui_systemSx)));const{name:s,slot:d,skipVariantsResolver:m,skipSx:x,overridesResolver:p=wt(bt(d))}=c,f=H(c,xt),S=m!==void 0?m:d&&d!=="Root"&&d!=="root"||!1,y=x||!1;let w,v=ce;d==="Root"||d==="root"?v=n:d?v=a:yt(o)&&(v=void 0);const b=et(o,$({shouldForwardProp:v,label:w},f)),j=g=>typeof g=="function"&&g.__emotion_real!==g||rt(g)?k=>J(g,$({},k,{theme:X({theme:k.theme,defaultTheme:r,themeId:t})})):g,A=(g,...k)=>{let L=j(g);const T=k?k.map(j):[];s&&p&&T.push(u=>{const h=X($({},u,{defaultTheme:r,themeId:t}));if(!h.components||!h.components[s]||!h.components[s].styleOverrides)return null;const O=h.components[s].styleOverrides,M={};return Object.entries(O).forEach(([_,C])=>{M[_]=J(C,$({},u,{theme:h}))}),p(u,M)}),s&&!S&&T.push(u=>{var h;const O=X($({},u,{defaultTheme:r,themeId:t})),M=O==null||(h=O.components)==null||(h=h[s])==null?void 0:h.variants;return J({variants:M},$({},u,{theme:O}))}),y||T.push(l);const E=T.length-k.length;if(Array.isArray(g)&&E>0){const u=new Array(E).fill("");L=[...g,...u],L.raw=[...g.raw,...u]}const R=b(L,...T);return o.muiName&&(R.muiName=o.muiName),R};return b.withConfig&&(A.withConfig=b.withConfig),A}}const kt=jt(),Ot=(e,t)=>e.filter(r=>t.includes(r)),V=(e,t,r)=>{const n=e.keys[0];Array.isArray(t)?t.forEach((a,l)=>{r((o,c)=>{l<=e.keys.length-1&&(l===0?Object.assign(o,c):o[e.up(e.keys[l])]=c)},a)}):t&&typeof t=="object"?(Object.keys(t).length>e.keys.length?e.keys:Ot(e.keys,Object.keys(t))).forEach(a=>{if(e.keys.indexOf(a)!==-1){const l=t[a];l!==void 0&&r((o,c)=>{n===a?Object.assign(o,c):o[e.up(a)]=c},l)}}):(typeof t=="number"||typeof t=="string")&&r((a,l)=>{Object.assign(a,l)},t)};function G(e){return e?`Level${e}`:""}function q(e){return e.unstable_level>0&&e.container}function Te(e){return function(t){return`var(--Grid-${t}Spacing${G(e.unstable_level)})`}}function ue(e){return function(t){return e.unstable_level===0?`var(--Grid-${t}Spacing)`:`var(--Grid-${t}Spacing${G(e.unstable_level-1)})`}}function de(e){return e.unstable_level===0?"var(--Grid-columns)":`var(--Grid-columns${G(e.unstable_level-1)})`}const St=({theme:e,ownerState:t})=>{const r=Te(t),n={};return V(e.breakpoints,t.gridSize,(a,l)=>{let o={};l===!0&&(o={flexBasis:0,flexGrow:1,maxWidth:"100%"}),l==="auto"&&(o={flexBasis:"auto",flexGrow:0,flexShrink:0,maxWidth:"none",width:"auto"}),typeof l=="number"&&(o={flexGrow:0,flexBasis:"auto",width:`calc(100% * ${l} / ${de(t)}${q(t)?` + ${r("column")}`:""})`}),a(n,o)}),n},$t=({theme:e,ownerState:t})=>{const r={};return V(e.breakpoints,t.gridOffset,(n,a)=>{let l={};a==="auto"&&(l={marginLeft:"auto"}),typeof a=="number"&&(l={marginLeft:a===0?"0px":`calc(100% * ${a} / ${de(t)})`}),n(r,l)}),r},Tt=({theme:e,ownerState:t})=>{if(!t.container)return{};const r=q(t)?{[`--Grid-columns${G(t.unstable_level)}`]:de(t)}:{"--Grid-columns":12};return V(e.breakpoints,t.columns,(n,a)=>{n(r,{[`--Grid-columns${G(t.unstable_level)}`]:a})}),r},At=({theme:e,ownerState:t})=>{if(!t.container)return{};const r=ue(t),n=q(t)?{[`--Grid-rowSpacing${G(t.unstable_level)}`]:r("row")}:{};return V(e.breakpoints,t.rowSpacing,(a,l)=>{var o;a(n,{[`--Grid-rowSpacing${G(t.unstable_level)}`]:typeof l=="string"?l:(o=e.spacing)==null?void 0:o.call(e,l)})}),n},Rt=({theme:e,ownerState:t})=>{if(!t.container)return{};const r=ue(t),n=q(t)?{[`--Grid-columnSpacing${G(t.unstable_level)}`]:r("column")}:{};return V(e.breakpoints,t.columnSpacing,(a,l)=>{var o;a(n,{[`--Grid-columnSpacing${G(t.unstable_level)}`]:typeof l=="string"?l:(o=e.spacing)==null?void 0:o.call(e,l)})}),n},Et=({theme:e,ownerState:t})=>{if(!t.container)return{};const r={};return V(e.breakpoints,t.direction,(n,a)=>{n(r,{flexDirection:a})}),r},Ct=({ownerState:e})=>{const t=Te(e),r=ue(e);return $({minWidth:0,boxSizing:"border-box"},e.container&&$({display:"flex",flexWrap:"wrap"},e.wrap&&e.wrap!=="wrap"&&{flexWrap:e.wrap},{margin:`calc(${t("row")} / -2) calc(${t("column")} / -2)`},e.disableEqualOverflow&&{margin:`calc(${t("row")} * -1) 0px 0px calc(${t("column")} * -1)`}),(!e.container||q(e))&&$({padding:`calc(${r("row")} / 2) calc(${r("column")} / 2)`},(e.disableEqualOverflow||e.parentDisableEqualOverflow)&&{padding:`${r("row")} 0px 0px ${r("column")}`}))},Nt=e=>{const t=[];return Object.entries(e).forEach(([r,n])=>{n!==!1&&n!==void 0&&t.push(`grid-${r}-${String(n)}`)}),t},Lt=(e,t="xs")=>{function r(n){return n===void 0?!1:typeof n=="string"&&!Number.isNaN(Number(n))||typeof n=="number"&&n>0}if(r(e))return[`spacing-${t}-${String(e)}`];if(typeof e=="object"&&!Array.isArray(e)){const n=[];return Object.entries(e).forEach(([a,l])=>{r(l)&&n.push(`spacing-${a}-${String(l)}`)}),n}return[]},_t=e=>e===void 0?[]:typeof e=="object"?Object.entries(e).map(([t,r])=>`direction-${t}-${r}`):[`direction-xs-${String(e)}`],Dt=["className","children","columns","container","component","direction","wrap","spacing","rowSpacing","columnSpacing","disableEqualOverflow","unstable_level"],Mt=$e(),Gt=kt("div",{name:"MuiGrid",slot:"Root",overridesResolver:(e,t)=>t.root});function Ft(e){return lt({props:e,name:"MuiGrid",defaultTheme:Mt})}function It(e={}){const{createStyledComponent:t=Gt,useThemeProps:r=Ft,componentName:n="MuiGrid"}=e,a=P.createContext(void 0),l=(s,d)=>{const{container:m,direction:x,spacing:p,wrap:f,gridSize:S}=s,y={root:["root",m&&"container",f!=="wrap"&&`wrap-xs-${String(f)}`,..._t(x),...Nt(S),...m?Lt(p,d.breakpoints.keys[0]):[]]};return st(y,w=>ct(n,w),{})},o=t(Tt,Rt,At,St,Et,Ct,$t),c=P.forwardRef(function(s,d){var m,x,p,f,S,y,w,v;const b=nt(),j=r(s),A=at(j),g=P.useContext(a),{className:k,children:L,columns:T=12,container:E=!1,component:R="div",direction:u="row",wrap:h="wrap",spacing:O=0,rowSpacing:M=O,columnSpacing:_=O,disableEqualOverflow:C,unstable_level:N=0}=A,Q=H(A,Dt);let B=C;N&&C!==void 0&&(B=s.disableEqualOverflow);const me={},fe={},he={};Object.entries(Q).forEach(([D,I])=>{b.breakpoints.values[D]!==void 0?me[D]=I:b.breakpoints.values[D.replace("Offset","")]!==void 0?fe[D.replace("Offset","")]=I:he[D]=I});const Le=(m=s.columns)!=null?m:N?void 0:T,_e=(x=s.spacing)!=null?x:N?void 0:O,De=(p=(f=s.rowSpacing)!=null?f:s.spacing)!=null?p:N?void 0:M,Me=(S=(y=s.columnSpacing)!=null?y:s.spacing)!=null?S:N?void 0:_,xe=$({},A,{level:N,columns:Le,container:E,direction:u,wrap:h,spacing:_e,rowSpacing:De,columnSpacing:Me,gridSize:me,gridOffset:fe,disableEqualOverflow:(w=(v=B)!=null?v:g)!=null?w:!1,parentDisableEqualOverflow:g}),Ge=l(xe,b);let ee=i.jsx(o,$({ref:d,as:R,ownerState:xe,className:ot(Ge.root,k)},he,{children:P.Children.map(L,D=>{if(P.isValidElement(D)&&it(D,["Grid"])){var I;return P.cloneElement(D,{unstable_level:(I=D.props.unstable_level)!=null?I:N+1})}return D})}));return B!==void 0&&B!==(g??!1)&&(ee=i.jsx(a.Provider,{value:B,children:ee})),ee});return c.muiName="Grid",c}const Ae=It({createStyledComponent:ut("div",{name:"MuiGrid2",slot:"Root",overridesResolver:(e,t)=>t.root}),componentName:"MuiGrid2",useThemeProps:e=>dt({props:e,name:"MuiGrid2"})});function Pt({entry:e,payload:t}){const r=te(x=>{var p,f,S;return(S=(f=(p=x.payload)==null?void 0:p.data)==null?void 0:f.reduce)==null?void 0:S.call(f,(y,w)=>y+w.value,0)},[]),n=te(x=>{const p=new le(r(x)||0),f=t?.reduce((w,v)=>w+r(v),0)||0,S=new le(f),y=Number(p.div(S).times(100).toFixed(2,le.ROUND_DOWN));return isNaN(y)||!isFinite(y)?0:y},[r,t]),a=re(()=>r(e),[e,r]),l=se(a),o=re(()=>Number(n(e)),[e,n]),c=se(o),s=te(x=>Math.floor(x).toLocaleString(),[]),d=Xe({type:"text/plain"}),m=pt();return i.jsxs(Je,{component:"li",direction:"row",spacing:1,sx:{color:e.color},layout:"position",initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},children:[i.jsx(z,{sx:{width:"3px",height:"100%",backgroundColor:e.color,borderRadius:3}}),i.jsxs(U,{children:[i.jsxs(W,{component:"p",variant:"caption",children:[i.jsx(U,{component:"span",display:"inline-flex",mr:.5,children:i.jsx(Se,{from:l??0,to:a,map:s,children:"0"})}),i.jsxs(U,{component:"span",direction:"row",display:"inline-flex",children:["(",i.jsx(Se,{from:c??0,to:o,map:s,children:"0"}),"%)"]})]}),i.jsx(W,{variant:"body1",children:e.value}),e.payload.uuid&&i.jsxs(W,{variant:"body2",sx:{cursor:"pointer","&:hover":{textDecoration:"underline"}},onClick:()=>{d.copy(e.payload.uuid).catch(()=>{}),m.enqueueSnackbar("UUID copied to clipboard","success")},children:[e.payload.uuid.slice(0,5),"..."]})]})]})}function Re(e){const{payload:t}=e;return i.jsx(Ae,{container:!0,direction:"row",component:"ul",gap:2,sx:{mt:2,justifyContent:"flex-start",alignItem:"center",flexWrap:"wrap"},children:i.jsx(He,{children:t?.map(r=>i.jsx(Ae,{children:i.jsx(Pt,{entry:r,payload:t})},`item-${r.value}`))})})}function zt(e){const t=F();return i.jsx(z,{sx:{width:"100%",height:"100%",...e.sx},children:i.jsx(Z,{children:i.jsxs(ze,{width:500,height:300,margin:{top:5,right:60,left:20,bottom:5},children:[i.jsx(ne,{vertical:!1}),i.jsx(ae,{dataKey:"date",type:"number",domain:["dataMin","dataMax"],tickFormatter:r=>ke(r,{timeZone:e.filter.timezone,hour12:!1,hour:"numeric"}),allowDuplicatedCategory:!1,tickLine:!1,fontSize:12,tickMargin:12}),i.jsx(oe,{textAnchor:"end",dataKey:"value",tickLine:!1,tickFormatter:r=>Number(r).toLocaleString(),allowDecimals:!1,domain:[1,"dataMax"],children:e.label&&i.jsx(ye,{value:e.label,angle:-90,position:"insideLeft",style:{textAnchor:"middle"}})}),i.jsx(ie,{cursor:{stroke:t.palette.neutral.main,strokeWidth:1},formatter:r=>Number(r).toLocaleString(),labelFormatter:r=>Oe(r,{timeZone:e.filter.timezone,hour12:!1})}),i.jsx(ve,{content:i.jsx(Re,{})}),e.data.map(r=>Fe(Ve,{uuid:r.uuid,key:r.uuid,name:r.name,dataKey:"value",data:r.chartData,type:"monotone",stroke:r.color,strokeWidth:2}))]})})})}const Vt=(e,t)=>{const r=new Map;return e.forEach(n=>{n.chartData.forEach(a=>{const l=new Date(a.date).getTime().toString();if(!r.has(l)){const o={date:l,total:0,diff:0,totalKey:"",originalTotal:0};t.forEach(({key:c})=>{o[c]=0,o[`${c}_absolute`]=0}),r.set(l,o)}t.forEach(({key:o})=>{const c=r.get(l),s=a[o],d=typeof s=="string"?s.trim()===""?0:parseInt(s,10):typeof s=="number"?s:0;c[`${o}_absolute`]=d,c[o]=0})})}),Array.from(r.values()).map(n=>{var a;const l=(a=t.find(s=>s.isTotal))==null?void 0:a.key,o=t.filter(s=>!s.isTotal).map(s=>s.key);if(!l||o.length===0)return n;const c=n[`${l}_absolute`];return n.originalTotal=c,n.total=c,n[l]=100,o.forEach(s=>{const d=n[`${s}_absolute`],m=c>0?new Y(d.toString()).div(c).mul(100).toFixed(2,Y.ROUND_DOWN):"0.00";n[s]=parseFloat(m)}),{...n,totalKey:l}}).sort((n,a)=>parseInt(n.date)-parseInt(a.date))};function Bt(e){const t=F(),r=re(()=>e.data?Vt(e.data,e.keyValues):[],[e.data,e.keyValues]);return i.jsx(z,{sx:{width:"100%",height:"100%",...e.sx},children:i.jsx(Z,{width:"100%",height:"100%",children:i.jsxs(Be,{data:r,width:500,height:300,margin:{top:5,right:60,left:20,bottom:5},children:[i.jsx(ne,{strokeDasharray:"3 3"}),i.jsx(ae,{dataKey:"date",type:"number",domain:["dataMin","dataMax"],tickFormatter:n=>ke(n,{timeZone:e.filter.timezone,hour12:!1,hour:"numeric"}),allowDuplicatedCategory:!1,tickLine:!1,fontSize:12,tickMargin:12}),i.jsx(oe,{textAnchor:"end",tickLine:!1,tickFormatter:n=>`${n.toFixed(2)}%`}),i.jsx(ie,{cursor:{stroke:t.palette.neutral.main,strokeWidth:1},labelFormatter:n=>Oe(n,{timeZone:e.filter.timezone,hour12:!1}),formatter:(n,a,l)=>{const o=l.payload.totalKey,c=l.dataKey,s=c===o,d=l.payload[`${c}_absolute`],m=l.payload.originalTotal,x=s?null:m===0?"0.00":new Y(d.toString()).div(m).mul(100).toFixed(2,Y.ROUND_DOWN);return[x?`${d.toLocaleString()} (${x}%)`:`${d.toLocaleString()} (TOTAL)`,a]}}),e.keyValues.sort((n,a)=>n.isTotal?-1:a.isTotal?1:0).map(n=>i.jsx(We,{type:"monotone",dataKey:n.key,name:n.name,stroke:n.color,fill:n.color,strokeWidth:2,fillOpacity:.6},n.key))]})})})}function Wt(e){const t=se(e.value),{ref:r}=mt({from:t??0,to:e.value,duration:1,map:e.map});return i.jsx(Pe,{sx:{p:3,flex:1,...e.sx},children:i.jsxs(U,{spacing:1,alignItems:"center",children:[i.jsx(W,{ref:r,variant:"h4",fontWeight:"bold",children:e.initialValue}),i.jsx(W,{color:"text.secondary",children:e.label})]})})}const Ee={margin:{top:5,right:30,left:20,bottom:5}},qt={tickLine:!1,fontSize:12,tickMargin:12},Kt={textAnchor:"end",tickLine:!1};function pe({data:e,series:t,xAxis:r,yAxis:n,tooltip:a,bar:l,referenceLines:o,referenceAreas:c,sx:s}){const d=F(),m=p=>!p.isFront,x=p=>!!p.isFront;return i.jsx(z,{sx:{width:"100%",height:"100%",...s},children:i.jsx(Z,{children:i.jsxs(qe,{data:e,...Ee,children:[i.jsx(ne,{strokeDasharray:"3 3",vertical:!1}),i.jsx(ae,{...qt,...r}),i.jsx(oe,{...Kt,...n}),i.jsx(ie,{cursor:{stroke:d.palette.neutral.main,strokeWidth:1},...a}),o?.filter(m).map((p,f)=>i.jsx(be,{...p},p.label??f)),c?.filter(m).map((p,f)=>i.jsx(we,{...p},p.label??f)),t.map(p=>i.jsx(Ke,{name:p.key,dataKey:p.dataKey,fill:p.color,stackId:"stack",isAnimationActive:!1,...l},p.key)),o?.filter(x).map((p,f)=>i.jsx(be,{...p},p.label??f)),c?.filter(x).map((p,f)=>i.jsx(we,{...p},p.label??f))]})})})}function Ut({data:e,sx:t}){const r=F(),n=Object.entries(e??{}).map(([l,o])=>({key:l,[l]:o})),a=n.map(({key:l})=>({key:l,dataKey:l,color:r.palette.error.light}));return i.jsx(pe,{sx:t,data:n,series:a,xAxis:{tickLine:!1,dataKey:"key"},yAxis:{tickLine:!1,domain:[0,"dataMax + 100"]},tooltip:{labelFormatter:l=>"Total"},referenceLines:[{y:100,stroke:r.palette.error.dark,strokeDasharray:"3 3",label:i.jsx(ye,{value:"Unhealthy threshold",position:"insideBottomRight"}),isFront:!0}]})}function Ce({payload:e=[],hiddenItems:t,onToggle:r,legendLabel:n}){return i.jsx(z,{sx:{display:"flex",justifyContent:"center",gap:"20px",paddingTop:"20px"},children:e.map((a,l)=>{const o=t.has(a.payload.name);return i.jsxs("div",{style:{display:"flex",alignItems:"center",cursor:"pointer",opacity:o?.4:1},onClick:()=>{r?.(a.payload)},children:[i.jsx("div",{style:{width:"12px",height:"12px",backgroundColor:a.color,marginRight:"8px",borderRadius:"2px"}}),i.jsx("span",{style:{color:a.color},children:n?`${n}: ${a.value}`:a.value})]},`legend-${l}`)})})}const Zt=e=>{const t=Math.PI/180,{cx:r,cy:n,midAngle:a,innerRadius:l,outerRadius:o,startAngle:c,endAngle:s,fill:d,payload:m,percent:x,value:p,valueText:f,valuePercentage:S,needleVisible:y,customText:w,allActive:v}=e,b=Math.sin(-t*a),j=Math.cos(-t*a),A=r+(o+5)*j,g=n+(o+5)*b,k=r+(o+15)*j,L=n+(o+15)*b,T=k+(j>=0?1:-1)*22,E=L,R=j>=0?"start":"end",u=p.toLocaleString(void 0,{minimumFractionDigits:0,maximumFractionDigits:0}),h=()=>y||v?null:i.jsx("text",{x:r,y:n,dy:8,textAnchor:"middle",fill:"#333",fontSize:14,children:m.name});return i.jsxs("g",{children:[h(),i.jsx(je,{cx:r,cy:n,innerRadius:l,outerRadius:o,startAngle:c,endAngle:s,fill:d}),i.jsx(je,{cx:r,cy:n,startAngle:c,endAngle:s,innerRadius:o+2,outerRadius:o+6,fill:d}),i.jsx("path",{d:`M${A},${g}L${k},${L}L${T},${E}`,stroke:d,fill:"none"}),i.jsx("circle",{cx:T,cy:E,r:2,fill:d,stroke:"none"}),i.jsx("text",{x:T+(j>=0?1:-1)*12,y:E,textAnchor:R,fill:"#333",fontSize:12,children:w||(f?`${f} ${u}`:u)}),S&&i.jsxs("text",{x:T+(j>=0?1:-1)*12,y:E,dy:16,textAnchor:R,fill:"#999",fontSize:11,children:[`${(x*100).toFixed(2)}%`," (",u,")"]})]})},Yt=e=>{const{value:t,data:r,color:n,innerRadius:a,outerRadius:l,boxDimensions:o,legendDimensions:c,valueText:s}=e,d=Math.PI/180;let m=0;r.forEach(h=>{m+=h.value});const x=o?o.width/2:150,p=(o?o.height/2:200)-c.height/2,f=180*(1-Math.max(0,Math.min(1,t/m))),S=(Number(a)+2*Number(l))/3,y=Math.sin(-d*f),w=Math.cos(-d*f),v=5,b=x-v,j=p,A=b+v*y,g=j-v*w,k=b-v*y,L=j+v*w,T=b+S*w,E=j+S*y,R=t.toLocaleString(void 0,{minimumFractionDigits:0,maximumFractionDigits:0}),u=s??R;return i.jsxs(i.Fragment,{children:[i.jsx("circle",{cx:b,cy:j,r:v,fill:n,stroke:"none",style:{pointerEvents:"none"}},"needle-circle"),i.jsx("path",{d:`M${A} ${g}L${k} ${L} L${T} ${E} L${A} ${g}`,stroke:"none",fill:n,style:{pointerEvents:"none"}},"needle-path"),i.jsx("text",{x:b+v,y:j+26,textAnchor:"middle",fill:"#333",fontSize:12,children:u},"needle-value")]})},Ht=(e,t)=>({Allow:t.palette.success.main,Flag:t.palette.warning.main,Block:t.palette.error.main})[e]??t.palette.primary.main;function Ne({data:e,sx:t,legendLabel:r,legendToggle:n=!1,valueText:a="",valuePercentage:l=!0,pie:o,needleVisible:c=!1,needleValue:s,needleColor:d="#aaa",allActive:m=!1}){const{innerRadius:x=60,outerRadius:p=100}=o??{},f=F(),[S,y]=K(void 0),[w,v]=K(new Set),b=Ie(null),[j,A]=K(null),[g,k]=K(null),L=(u,h)=>{m||y(h)},T=()=>{m||y(void 0)},E=u=>{n&&u&&v(h=>{const O=new Set(h);return O.has(u.name)?O.delete(u.name):O.size<e.length-1&&O.add(u.name),O})},R=e.map((u,h)=>({...u,index:h,value:w.has(u.name)?0:u.value}));return ge(()=>{const u=b.current;if(!u)return;const h=new ResizeObserver(M=>{var _;const C=(_=M[0])==null?void 0:_.contentRect;C&&A(C)});h.observe(u);const O=u.getBoundingClientRect();return A(O),()=>{h.disconnect()}},[]),ge(()=>{var u;const h=(u=b.current)==null?void 0:u.querySelector(".recharts-legend-wrapper");if(!h){const _=setInterval(()=>{var C;const N=(C=b.current)==null?void 0:C.querySelector(".recharts-legend-wrapper");if(N){const Q=N.getBoundingClientRect();k(Q),clearInterval(_)}},100);return()=>{clearInterval(_)}}const O=new ResizeObserver(_=>{var C;const N=(C=_[0])==null?void 0:C.contentRect;N&&k(N)});O.observe(h);const M=h.getBoundingClientRect();return k(M),()=>{O.disconnect()}},[]),i.jsx(z,{ref:b,sx:{width:"100%",height:"100%","& g":{outline:"none"},...t},children:i.jsx(Z,{children:i.jsxs(Ue,{...Ee,children:[i.jsx(Ze,{data:R,nameKey:"name",dataKey:"value",innerRadius:x,outerRadius:p,activeIndex:m?R.filter(u=>u.value>0).map(u=>u.index):S,activeShape:u=>Zt({...u,valueText:a,valuePercentage:l,needleVisible:c,allActive:m}),paddingAngle:0,onMouseEnter:L,onMouseLeave:T,...o,children:R.map(u=>i.jsx(Ye,{fill:u.color??Ht(u.name,f),opacity:w.has(u.name)?.5:1,stroke:"none"},u.name))}),i.jsx(ve,{content:i.jsx(Ce,{legendLabel:r,hiddenItems:w,onToggle:E})}),c&&s!==void 0&&j&&g&&Yt({data:R,value:s,color:d,innerRadius:x,outerRadius:p,boxDimensions:j,legendDimensions:g,valueText:a})]})})})}function Xt({sx:e,data:t,score:r=200,legendLabel:n}){const a=F(),l=[{name:"Allow",customText:"0-299",value:t[0].value,color:a.palette.primary.main},{name:"Flag",customText:"300-599",value:t[1].value,color:a.palette.warning.main},{name:"Block",customText:"Over 600",value:t[2].value,color:a.palette.error.main}];return i.jsx(Ne,{data:l,legendToggle:!0,needleValue:r,legendLabel:n,allActive:!0,sx:e})}function Jt({data:e,sx:t}){const r=F(),n=(l=>{const o={};return l.forEach(c=>{Object.entries(c).forEach(([s,d])=>{const m=parseInt(s);m<=1e3&&(o[m]=(o[m]||0)+d)})}),Array.from({length:1001},(c,s)=>({key:s.toString(),value:o[s]||0}))})(e),a=[{key:"Risk Score",dataKey:"value",color:r.palette.error.main}];return i.jsx(pe,{data:n,series:a,sx:t,yAxis:{label:{value:"Count",angle:-90,position:"insideLeft"},domain:[0,"dataMax + 10"]},xAxis:{domain:[0,"dataMax"],interval:"preserveStartEnd"},tooltip:{labelFormatter:()=>"Risk Score",formatter:(l,o,c)=>[l,c.payload.key]},referenceAreas:[{x1:0,x2:299,fill:"#ffffff00",isFront:!1,label:"Allow"},{x1:300,x2:600,fill:r.palette.warning.light,isFront:!1,label:"Flag"},{x1:600,fill:r.palette.error.light,isFront:!1,label:"Block"}]})}export{Wt as BigNumber,Ut as ErrorCodesChart,Ne as PieChart,Jt as RiskScoreBarChart,Xt as RiskScorePieChart,zt as SeriesChart,Re as SeriesChartLegend,Bt as SeriesPercentageChart,pe as SimpleBarChart,Ce as SimpleLegend};
|
1
|
+
"use strict";import{j as i}from"../../shared/jsx-runtime-DHlBLioN.mjs";import*as P from"react";import{useCallback as te,useMemo as re,createElement as Fe,useState as K,useRef as Ie,useEffect as ge}from"react";import{Box as z,Stack as U,Typography as W,useTheme as F,Paper as Pe}from"@mui/material";import{ResponsiveContainer as Z,LineChart as ze,CartesianGrid as ne,XAxis as ae,YAxis as oe,Label as ye,Tooltip as ie,Legend as ve,Line as Ve,AreaChart as Be,Area as We,ComposedChart as qe,ReferenceLine as be,ReferenceArea as we,Bar as Ke,Sector as je,PieChart as Ue,Pie as Ze,Cell as Ye}from"recharts";import{b as ke,c as Oe}from"../../shared/date-Cq0LS2Mr.mjs";import Y,{Decimal as le}from"decimal.js";import{AnimatePresence as He}from"framer-motion";import{u as Xe}from"../../shared/useCopyToClipboard-BALOSYVW.mjs";import"qrcode";import{u as se}from"../../shared/usePrevious-DyvR1iCQ.mjs";import{a as Je,C as Se}from"../../shared/motions-BBPeWBPV.mjs";import{c as $e,i as Qe,_ as H,s as et,a as $,d as tt,e as rt,f as nt,h as at,j as ot,k as it,l as lt,m as st,n as ct,o as ut,p as dt,u as pt}from"../../shared/index-KVVTzcea.mjs";import{u as mt}from"../../shared/useCounter-BV32zXDQ.mjs";const ft=["ownerState"],ht=["variants"],xt=["name","slot","skipVariantsResolver","skipSx","overridesResolver"];function gt(e){return Object.keys(e).length===0}function yt(e){return typeof e=="string"&&e.charCodeAt(0)>96}function ce(e){return e!=="ownerState"&&e!=="theme"&&e!=="sx"&&e!=="as"}const vt=$e(),bt=e=>e&&e.charAt(0).toLowerCase()+e.slice(1);function X({defaultTheme:e,theme:t,themeId:r}){return gt(t)?e:t[r]||t}function wt(e){return e?(t,r)=>r[e]:null}function J(e,t){let{ownerState:r}=t,n=H(t,ft);const o=typeof e=="function"?e($({ownerState:r},n)):e;if(Array.isArray(o))return o.flatMap(l=>J(l,$({ownerState:r},n)));if(o&&typeof o=="object"&&Array.isArray(o.variants)){const{variants:l=[]}=o;let a=H(o,ht);return l.forEach(s=>{let c=!0;typeof s.props=="function"?c=s.props($({ownerState:r},n,r)):Object.keys(s.props).forEach(d=>{r?.[d]!==s.props[d]&&n[d]!==s.props[d]&&(c=!1)}),c&&(Array.isArray(a)||(a=[a]),a.push(typeof s.style=="function"?s.style($({ownerState:r},n,r)):s.style))}),a}return o}function jt(e={}){const{themeId:t,defaultTheme:r=vt,rootShouldForwardProp:n=ce,slotShouldForwardProp:o=ce}=e,l=a=>tt($({},a,{theme:X($({},a,{defaultTheme:r,themeId:t}))}));return l.__mui_systemSx=!0,(a,s={})=>{Qe(a,g=>g.filter(k=>!(k!=null&&k.__mui_systemSx)));const{name:c,slot:d,skipVariantsResolver:m,skipSx:x,overridesResolver:p=wt(bt(d))}=s,f=H(s,xt),S=m!==void 0?m:d&&d!=="Root"&&d!=="root"||!1,y=x||!1;let w,v=ce;d==="Root"||d==="root"?v=n:d?v=o:yt(a)&&(v=void 0);const b=et(a,$({shouldForwardProp:v,label:w},f)),j=g=>typeof g=="function"&&g.__emotion_real!==g||rt(g)?k=>J(g,$({},k,{theme:X({theme:k.theme,defaultTheme:r,themeId:t})})):g,A=(g,...k)=>{let L=j(g);const T=k?k.map(j):[];c&&p&&T.push(u=>{const h=X($({},u,{defaultTheme:r,themeId:t}));if(!h.components||!h.components[c]||!h.components[c].styleOverrides)return null;const O=h.components[c].styleOverrides,M={};return Object.entries(O).forEach(([_,C])=>{M[_]=J(C,$({},u,{theme:h}))}),p(u,M)}),c&&!S&&T.push(u=>{var h;const O=X($({},u,{defaultTheme:r,themeId:t})),M=O==null||(h=O.components)==null||(h=h[c])==null?void 0:h.variants;return J({variants:M},$({},u,{theme:O}))}),y||T.push(l);const E=T.length-k.length;if(Array.isArray(g)&&E>0){const u=new Array(E).fill("");L=[...g,...u],L.raw=[...g.raw,...u]}const R=b(L,...T);return a.muiName&&(R.muiName=a.muiName),R};return b.withConfig&&(A.withConfig=b.withConfig),A}}const kt=jt(),Ot=(e,t)=>e.filter(r=>t.includes(r)),V=(e,t,r)=>{const n=e.keys[0];Array.isArray(t)?t.forEach((o,l)=>{r((a,s)=>{l<=e.keys.length-1&&(l===0?Object.assign(a,s):a[e.up(e.keys[l])]=s)},o)}):t&&typeof t=="object"?(Object.keys(t).length>e.keys.length?e.keys:Ot(e.keys,Object.keys(t))).forEach(o=>{if(e.keys.indexOf(o)!==-1){const l=t[o];l!==void 0&&r((a,s)=>{n===o?Object.assign(a,s):a[e.up(o)]=s},l)}}):(typeof t=="number"||typeof t=="string")&&r((o,l)=>{Object.assign(o,l)},t)};function G(e){return e?`Level${e}`:""}function q(e){return e.unstable_level>0&&e.container}function Te(e){return function(t){return`var(--Grid-${t}Spacing${G(e.unstable_level)})`}}function ue(e){return function(t){return e.unstable_level===0?`var(--Grid-${t}Spacing)`:`var(--Grid-${t}Spacing${G(e.unstable_level-1)})`}}function de(e){return e.unstable_level===0?"var(--Grid-columns)":`var(--Grid-columns${G(e.unstable_level-1)})`}const St=({theme:e,ownerState:t})=>{const r=Te(t),n={};return V(e.breakpoints,t.gridSize,(o,l)=>{let a={};l===!0&&(a={flexBasis:0,flexGrow:1,maxWidth:"100%"}),l==="auto"&&(a={flexBasis:"auto",flexGrow:0,flexShrink:0,maxWidth:"none",width:"auto"}),typeof l=="number"&&(a={flexGrow:0,flexBasis:"auto",width:`calc(100% * ${l} / ${de(t)}${q(t)?` + ${r("column")}`:""})`}),o(n,a)}),n},$t=({theme:e,ownerState:t})=>{const r={};return V(e.breakpoints,t.gridOffset,(n,o)=>{let l={};o==="auto"&&(l={marginLeft:"auto"}),typeof o=="number"&&(l={marginLeft:o===0?"0px":`calc(100% * ${o} / ${de(t)})`}),n(r,l)}),r},Tt=({theme:e,ownerState:t})=>{if(!t.container)return{};const r=q(t)?{[`--Grid-columns${G(t.unstable_level)}`]:de(t)}:{"--Grid-columns":12};return V(e.breakpoints,t.columns,(n,o)=>{n(r,{[`--Grid-columns${G(t.unstable_level)}`]:o})}),r},At=({theme:e,ownerState:t})=>{if(!t.container)return{};const r=ue(t),n=q(t)?{[`--Grid-rowSpacing${G(t.unstable_level)}`]:r("row")}:{};return V(e.breakpoints,t.rowSpacing,(o,l)=>{var a;o(n,{[`--Grid-rowSpacing${G(t.unstable_level)}`]:typeof l=="string"?l:(a=e.spacing)==null?void 0:a.call(e,l)})}),n},Rt=({theme:e,ownerState:t})=>{if(!t.container)return{};const r=ue(t),n=q(t)?{[`--Grid-columnSpacing${G(t.unstable_level)}`]:r("column")}:{};return V(e.breakpoints,t.columnSpacing,(o,l)=>{var a;o(n,{[`--Grid-columnSpacing${G(t.unstable_level)}`]:typeof l=="string"?l:(a=e.spacing)==null?void 0:a.call(e,l)})}),n},Et=({theme:e,ownerState:t})=>{if(!t.container)return{};const r={};return V(e.breakpoints,t.direction,(n,o)=>{n(r,{flexDirection:o})}),r},Ct=({ownerState:e})=>{const t=Te(e),r=ue(e);return $({minWidth:0,boxSizing:"border-box"},e.container&&$({display:"flex",flexWrap:"wrap"},e.wrap&&e.wrap!=="wrap"&&{flexWrap:e.wrap},{margin:`calc(${t("row")} / -2) calc(${t("column")} / -2)`},e.disableEqualOverflow&&{margin:`calc(${t("row")} * -1) 0px 0px calc(${t("column")} * -1)`}),(!e.container||q(e))&&$({padding:`calc(${r("row")} / 2) calc(${r("column")} / 2)`},(e.disableEqualOverflow||e.parentDisableEqualOverflow)&&{padding:`${r("row")} 0px 0px ${r("column")}`}))},Nt=e=>{const t=[];return Object.entries(e).forEach(([r,n])=>{n!==!1&&n!==void 0&&t.push(`grid-${r}-${String(n)}`)}),t},Lt=(e,t="xs")=>{function r(n){return n===void 0?!1:typeof n=="string"&&!Number.isNaN(Number(n))||typeof n=="number"&&n>0}if(r(e))return[`spacing-${t}-${String(e)}`];if(typeof e=="object"&&!Array.isArray(e)){const n=[];return Object.entries(e).forEach(([o,l])=>{r(l)&&n.push(`spacing-${o}-${String(l)}`)}),n}return[]},_t=e=>e===void 0?[]:typeof e=="object"?Object.entries(e).map(([t,r])=>`direction-${t}-${r}`):[`direction-xs-${String(e)}`],Dt=["className","children","columns","container","component","direction","wrap","spacing","rowSpacing","columnSpacing","disableEqualOverflow","unstable_level"],Mt=$e(),Gt=kt("div",{name:"MuiGrid",slot:"Root",overridesResolver:(e,t)=>t.root});function Ft(e){return lt({props:e,name:"MuiGrid",defaultTheme:Mt})}function It(e={}){const{createStyledComponent:t=Gt,useThemeProps:r=Ft,componentName:n="MuiGrid"}=e,o=P.createContext(void 0),l=(c,d)=>{const{container:m,direction:x,spacing:p,wrap:f,gridSize:S}=c,y={root:["root",m&&"container",f!=="wrap"&&`wrap-xs-${String(f)}`,..._t(x),...Nt(S),...m?Lt(p,d.breakpoints.keys[0]):[]]};return st(y,w=>ct(n,w),{})},a=t(Tt,Rt,At,St,Et,Ct,$t),s=P.forwardRef(function(c,d){var m,x,p,f,S,y,w,v;const b=nt(),j=r(c),A=at(j),g=P.useContext(o),{className:k,children:L,columns:T=12,container:E=!1,component:R="div",direction:u="row",wrap:h="wrap",spacing:O=0,rowSpacing:M=O,columnSpacing:_=O,disableEqualOverflow:C,unstable_level:N=0}=A,Q=H(A,Dt);let B=C;N&&C!==void 0&&(B=c.disableEqualOverflow);const me={},fe={},he={};Object.entries(Q).forEach(([D,I])=>{b.breakpoints.values[D]!==void 0?me[D]=I:b.breakpoints.values[D.replace("Offset","")]!==void 0?fe[D.replace("Offset","")]=I:he[D]=I});const Le=(m=c.columns)!=null?m:N?void 0:T,_e=(x=c.spacing)!=null?x:N?void 0:O,De=(p=(f=c.rowSpacing)!=null?f:c.spacing)!=null?p:N?void 0:M,Me=(S=(y=c.columnSpacing)!=null?y:c.spacing)!=null?S:N?void 0:_,xe=$({},A,{level:N,columns:Le,container:E,direction:u,wrap:h,spacing:_e,rowSpacing:De,columnSpacing:Me,gridSize:me,gridOffset:fe,disableEqualOverflow:(w=(v=B)!=null?v:g)!=null?w:!1,parentDisableEqualOverflow:g}),Ge=l(xe,b);let ee=i.jsx(a,$({ref:d,as:R,ownerState:xe,className:ot(Ge.root,k)},he,{children:P.Children.map(L,D=>{if(P.isValidElement(D)&&it(D,["Grid"])){var I;return P.cloneElement(D,{unstable_level:(I=D.props.unstable_level)!=null?I:N+1})}return D})}));return B!==void 0&&B!==(g??!1)&&(ee=i.jsx(o.Provider,{value:B,children:ee})),ee});return s.muiName="Grid",s}const Ae=It({createStyledComponent:ut("div",{name:"MuiGrid2",slot:"Root",overridesResolver:(e,t)=>t.root}),componentName:"MuiGrid2",useThemeProps:e=>dt({props:e,name:"MuiGrid2"})});function Pt({entry:e,payload:t}){const r=te(x=>{var p,f,S;return(S=(f=(p=x.payload)==null?void 0:p.data)==null?void 0:f.reduce)==null?void 0:S.call(f,(y,w)=>y+w.value,0)},[]),n=te(x=>{const p=new le(r(x)||0),f=t?.reduce((w,v)=>w+r(v),0)||0,S=new le(f),y=Number(p.div(S).times(100).toFixed(2,le.ROUND_DOWN));return isNaN(y)||!isFinite(y)?0:y},[r,t]),o=re(()=>r(e),[e,r]),l=se(o),a=re(()=>Number(n(e)),[e,n]),s=se(a),c=te(x=>Math.floor(x).toLocaleString(),[]),d=Xe({type:"text/plain"}),m=pt();return i.jsxs(Je,{component:"li",direction:"row",spacing:1,sx:{color:e.color},layout:"position",initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},children:[i.jsx(z,{sx:{width:"3px",height:"100%",backgroundColor:e.color,borderRadius:3}}),i.jsxs(U,{children:[i.jsxs(W,{component:"p",variant:"caption",children:[i.jsx(U,{component:"span",display:"inline-flex",mr:.5,children:i.jsx(Se,{from:l??0,to:o,map:c,children:"0"})}),i.jsxs(U,{component:"span",direction:"row",display:"inline-flex",children:["(",i.jsx(Se,{from:s??0,to:a,map:c,children:"0"}),"%)"]})]}),i.jsx(W,{variant:"body1",children:e.value}),e.payload.uuid&&i.jsxs(W,{variant:"body2",sx:{cursor:"pointer","&:hover":{textDecoration:"underline"}},onClick:()=>{d.copy(e.payload.uuid).catch(()=>{}),m.enqueueSnackbar("UUID copied to clipboard","success")},children:[e.payload.uuid.slice(0,5),"..."]})]})]})}function Re(e){const{payload:t}=e;return i.jsx(Ae,{container:!0,direction:"row",component:"ul",gap:2,sx:{mt:2,justifyContent:"flex-start",alignItem:"center",flexWrap:"wrap"},children:i.jsx(He,{children:t?.map(r=>i.jsx(Ae,{children:i.jsx(Pt,{entry:r,payload:t})},`item-${r.value}`))})})}function zt(e){const t=F();return i.jsx(z,{sx:{width:"100%",height:"100%",...e.sx},children:i.jsx(Z,{children:i.jsxs(ze,{width:500,height:300,margin:{top:5,right:60,left:20,bottom:5},children:[i.jsx(ne,{vertical:!1}),i.jsx(ae,{dataKey:"date",type:"number",domain:["dataMin","dataMax"],tickFormatter:r=>ke(r,{timeZone:e.filter.timezone,hour12:!1,hour:"numeric"}),allowDuplicatedCategory:!1,tickLine:!1,fontSize:12,tickMargin:12}),i.jsx(oe,{textAnchor:"end",dataKey:"value",tickLine:!1,tickFormatter:r=>Number(r).toLocaleString(),allowDecimals:!1,domain:[1,"dataMax"],children:e.label&&i.jsx(ye,{value:e.label,angle:-90,position:"insideLeft",style:{textAnchor:"middle"}})}),i.jsx(ie,{cursor:{stroke:t.palette.neutral.main,strokeWidth:1},formatter:r=>Number(r).toLocaleString(),labelFormatter:r=>Oe(r,{timeZone:e.filter.timezone,hour12:!1})}),i.jsx(ve,{content:i.jsx(Re,{})}),e.data.map(r=>Fe(Ve,{uuid:r.uuid,key:r.uuid,name:r.name,dataKey:"value",data:r.chartData,type:"monotone",stroke:r.color,strokeWidth:2}))]})})})}const Vt=(e,t)=>{const r=new Map;return e.forEach(n=>{n.chartData.forEach(o=>{const l=new Date(o.date).getTime().toString();if(!r.has(l)){const a={date:l,total:0,diff:0,totalKey:"",originalTotal:0};t.forEach(({key:s})=>{a[s]=0,a[`${s}_absolute`]=0}),r.set(l,a)}t.forEach(({key:a})=>{const s=r.get(l),c=o[a],d=typeof c=="string"?c.trim()===""?0:parseInt(c,10):typeof c=="number"?c:0;s[`${a}_absolute`]=d,s[a]=0})})}),Array.from(r.values()).map(n=>{var o;const l=(o=t.find(c=>c.isTotal))==null?void 0:o.key,a=t.filter(c=>!c.isTotal).map(c=>c.key);if(!l||a.length===0)return n;const s=n[`${l}_absolute`];return n.originalTotal=s,n.total=s,n[l]=100,a.forEach(c=>{const d=n[`${c}_absolute`],m=s>0?new Y(d.toString()).div(s).mul(100).toFixed(2,Y.ROUND_DOWN):"0.00";n[c]=parseFloat(m)}),{...n,totalKey:l}}).sort((n,o)=>parseInt(n.date)-parseInt(o.date))};function Bt(e){const t=F(),r=re(()=>e.data?Vt(e.data,e.keyValues):[],[e.data,e.keyValues]);return i.jsx(z,{sx:{width:"100%",height:"100%",...e.sx},children:i.jsx(Z,{width:"100%",height:"100%",children:i.jsxs(Be,{data:r,width:500,height:300,margin:{top:5,right:60,left:20,bottom:5},children:[i.jsx(ne,{strokeDasharray:"3 3"}),i.jsx(ae,{dataKey:"date",type:"number",domain:["dataMin","dataMax"],tickFormatter:n=>ke(n,{timeZone:e.filter.timezone,hour12:!1,hour:"numeric"}),allowDuplicatedCategory:!1,tickLine:!1,fontSize:12,tickMargin:12}),i.jsx(oe,{textAnchor:"end",tickLine:!1,tickFormatter:n=>`${n.toFixed(2)}%`}),i.jsx(ie,{cursor:{stroke:t.palette.neutral.main,strokeWidth:1},labelFormatter:n=>Oe(n,{timeZone:e.filter.timezone,hour12:!1}),formatter:(n,o,l)=>{const a=l.payload.totalKey,s=l.dataKey,c=s===a,d=l.payload[`${s}_absolute`],m=l.payload.originalTotal,x=c?null:m===0?"0.00":new Y(d.toString()).div(m).mul(100).toFixed(2,Y.ROUND_DOWN);return[x?`${d.toLocaleString()} (${x}%)`:`${d.toLocaleString()} (TOTAL)`,o]}}),e.keyValues.sort((n,o)=>n.isTotal?-1:o.isTotal?1:0).map(n=>i.jsx(We,{type:"monotone",dataKey:n.key,name:n.name,stroke:n.color,fill:n.color,strokeWidth:2,fillOpacity:.6},n.key))]})})})}function Wt(e){const t=se(e.value),{ref:r}=mt({from:t??0,to:e.value,duration:1,map:e.map});return i.jsx(Pe,{sx:{p:3,flex:1,...e.sx},children:i.jsxs(U,{spacing:1,alignItems:"center",children:[i.jsx(W,{ref:r,variant:"h4",fontWeight:"bold",children:e.initialValue}),i.jsx(W,{color:"text.secondary",children:e.label})]})})}const Ee={margin:{top:5,right:30,left:20,bottom:5}},qt={tickLine:!1,fontSize:12,tickMargin:12},Kt={textAnchor:"end",tickLine:!1};function pe({data:e,series:t,xAxis:r,yAxis:n,tooltip:o,bar:l,referenceLines:a,referenceAreas:s,sx:c}){const d=F(),m=p=>!p.isFront,x=p=>!!p.isFront;return i.jsx(z,{sx:{width:"100%",height:"100%",...c},children:i.jsx(Z,{children:i.jsxs(qe,{data:e,...Ee,children:[i.jsx(ne,{strokeDasharray:"3 3",vertical:!1}),i.jsx(ae,{...qt,...r}),i.jsx(oe,{...Kt,...n}),i.jsx(ie,{cursor:{stroke:d.palette.neutral.main,strokeWidth:1},...o}),a?.filter(m).map((p,f)=>i.jsx(be,{...p},p.label??f)),s?.filter(m).map((p,f)=>i.jsx(we,{...p},p.label??f)),t.map(p=>i.jsx(Ke,{name:p.key,dataKey:p.dataKey,fill:p.color,stackId:"stack",isAnimationActive:!1,...l},p.key)),a?.filter(x).map((p,f)=>i.jsx(be,{...p},p.label??f)),s?.filter(x).map((p,f)=>i.jsx(we,{...p},p.label??f))]})})})}function Ut({data:e,threshold:t=100,sx:r}){const n=F(),o=Object.entries(e??{}).map(([a,s])=>({key:a,[a]:s})),l=o.map(({key:a})=>({key:a,dataKey:a,color:n.palette.error.light}));return i.jsx(pe,{sx:r,data:o,series:l,xAxis:{tickLine:!1,dataKey:"key"},yAxis:{tickLine:!1,domain:[0,`dataMax + ${t}`]},tooltip:{labelFormatter:a=>"Total"},referenceLines:[{y:t,stroke:n.palette.error.dark,strokeDasharray:"3 3",label:i.jsx(ye,{value:"Unhealthy threshold",position:"insideBottomRight"}),isFront:!0}]})}function Ce({payload:e=[],hiddenItems:t,onToggle:r,legendLabel:n}){return i.jsx(z,{sx:{display:"flex",justifyContent:"center",gap:"20px",paddingTop:"20px"},children:e.map((o,l)=>{const a=t.has(o.payload.name);return i.jsxs("div",{style:{display:"flex",alignItems:"center",cursor:"pointer",opacity:a?.4:1},onClick:()=>{r?.(o.payload)},children:[i.jsx("div",{style:{width:"12px",height:"12px",backgroundColor:o.color,marginRight:"8px",borderRadius:"2px"}}),i.jsx("span",{style:{color:o.color},children:n?`${n}: ${o.value}`:o.value})]},`legend-${l}`)})})}const Zt=e=>{const t=Math.PI/180,{cx:r,cy:n,midAngle:o,innerRadius:l,outerRadius:a,startAngle:s,endAngle:c,fill:d,payload:m,percent:x,value:p,valueText:f,valuePercentage:S,needleVisible:y,customText:w,allActive:v}=e,b=Math.sin(-t*o),j=Math.cos(-t*o),A=r+(a+5)*j,g=n+(a+5)*b,k=r+(a+15)*j,L=n+(a+15)*b,T=k+(j>=0?1:-1)*22,E=L,R=j>=0?"start":"end",u=p.toLocaleString(void 0,{minimumFractionDigits:0,maximumFractionDigits:0}),h=()=>y||v?null:i.jsx("text",{x:r,y:n,dy:8,textAnchor:"middle",fill:"#333",fontSize:14,children:m.name});return i.jsxs("g",{children:[h(),i.jsx(je,{cx:r,cy:n,innerRadius:l,outerRadius:a,startAngle:s,endAngle:c,fill:d}),i.jsx(je,{cx:r,cy:n,startAngle:s,endAngle:c,innerRadius:a+2,outerRadius:a+6,fill:d}),i.jsx("path",{d:`M${A},${g}L${k},${L}L${T},${E}`,stroke:d,fill:"none"}),i.jsx("circle",{cx:T,cy:E,r:2,fill:d,stroke:"none"}),i.jsx("text",{x:T+(j>=0?1:-1)*12,y:E,textAnchor:R,fill:"#333",fontSize:12,children:w||(f?`${f} ${u}`:u)}),S&&i.jsxs("text",{x:T+(j>=0?1:-1)*12,y:E,dy:16,textAnchor:R,fill:"#999",fontSize:11,children:[`${(x*100).toFixed(2)}%`," (",u,")"]})]})},Yt=e=>{const{value:t,data:r,color:n,innerRadius:o,outerRadius:l,boxDimensions:a,legendDimensions:s,valueText:c}=e,d=Math.PI/180;let m=0;r.forEach(h=>{m+=h.value});const x=a?a.width/2:150,p=(a?a.height/2:200)-s.height/2,f=180*(1-Math.max(0,Math.min(1,t/m))),S=(Number(o)+2*Number(l))/3,y=Math.sin(-d*f),w=Math.cos(-d*f),v=5,b=x-v,j=p,A=b+v*y,g=j-v*w,k=b-v*y,L=j+v*w,T=b+S*w,E=j+S*y,R=t.toLocaleString(void 0,{minimumFractionDigits:0,maximumFractionDigits:0}),u=c??R;return i.jsxs(i.Fragment,{children:[i.jsx("circle",{cx:b,cy:j,r:v,fill:n,stroke:"none",style:{pointerEvents:"none"}},"needle-circle"),i.jsx("path",{d:`M${A} ${g}L${k} ${L} L${T} ${E} L${A} ${g}`,stroke:"none",fill:n,style:{pointerEvents:"none"}},"needle-path"),i.jsx("text",{x:b+v,y:j+26,textAnchor:"middle",fill:"#333",fontSize:12,children:u},"needle-value")]})},Ht=(e,t)=>({Allow:t.palette.success.main,Flag:t.palette.warning.main,Block:t.palette.error.main})[e]??t.palette.primary.main;function Ne({data:e,sx:t,legendLabel:r,legendToggle:n=!1,valueText:o="",valuePercentage:l=!0,pie:a,needleVisible:s=!1,needleValue:c,needleColor:d="#aaa",allActive:m=!1}){const{innerRadius:x=60,outerRadius:p=100}=a??{},f=F(),[S,y]=K(void 0),[w,v]=K(new Set),b=Ie(null),[j,A]=K(null),[g,k]=K(null),L=(u,h)=>{m||y(h)},T=()=>{m||y(void 0)},E=u=>{n&&u&&v(h=>{const O=new Set(h);return O.has(u.name)?O.delete(u.name):O.size<e.length-1&&O.add(u.name),O})},R=e.map((u,h)=>({...u,index:h,value:w.has(u.name)?0:u.value}));return ge(()=>{const u=b.current;if(!u)return;const h=new ResizeObserver(M=>{var _;const C=(_=M[0])==null?void 0:_.contentRect;C&&A(C)});h.observe(u);const O=u.getBoundingClientRect();return A(O),()=>{h.disconnect()}},[]),ge(()=>{var u;const h=(u=b.current)==null?void 0:u.querySelector(".recharts-legend-wrapper");if(!h){const _=setInterval(()=>{var C;const N=(C=b.current)==null?void 0:C.querySelector(".recharts-legend-wrapper");if(N){const Q=N.getBoundingClientRect();k(Q),clearInterval(_)}},100);return()=>{clearInterval(_)}}const O=new ResizeObserver(_=>{var C;const N=(C=_[0])==null?void 0:C.contentRect;N&&k(N)});O.observe(h);const M=h.getBoundingClientRect();return k(M),()=>{O.disconnect()}},[]),i.jsx(z,{ref:b,sx:{width:"100%",height:"100%","& g":{outline:"none"},...t},children:i.jsx(Z,{children:i.jsxs(Ue,{...Ee,children:[i.jsx(Ze,{data:R,nameKey:"name",dataKey:"value",innerRadius:x,outerRadius:p,activeIndex:m?R.filter(u=>u.value>0).map(u=>u.index):S,activeShape:u=>Zt({...u,valueText:o,valuePercentage:l,needleVisible:s,allActive:m}),paddingAngle:0,onMouseEnter:L,onMouseLeave:T,...a,children:R.map(u=>i.jsx(Ye,{fill:u.color??Ht(u.name,f),opacity:w.has(u.name)?.5:1,stroke:"none"},u.name))}),i.jsx(ve,{content:i.jsx(Ce,{legendLabel:r,hiddenItems:w,onToggle:E})}),s&&c!==void 0&&j&&g&&Yt({data:R,value:c,color:d,innerRadius:x,outerRadius:p,boxDimensions:j,legendDimensions:g,valueText:o})]})})})}function Xt({sx:e,data:t,score:r=200,legendLabel:n}){const o=F(),l=[{name:"Allow",customText:"0-299",value:t[0].value,color:o.palette.primary.main},{name:"Flag",customText:"300-599",value:t[1].value,color:o.palette.warning.main},{name:"Block",customText:"Over 600",value:t[2].value,color:o.palette.error.main}];return i.jsx(Ne,{data:l,legendToggle:!0,needleValue:r,legendLabel:n,allActive:!0,sx:e})}function Jt({data:e,sx:t}){const r=F(),n=(l=>{const a={};return l.forEach(s=>{Object.entries(s).forEach(([c,d])=>{const m=parseInt(c);m<=1e3&&(a[m]=(a[m]||0)+d)})}),Array.from({length:1001},(s,c)=>({key:c.toString(),value:a[c]||0}))})(e),o=[{key:"Risk Score",dataKey:"value",color:r.palette.error.main}];return i.jsx(pe,{data:n,series:o,sx:t,yAxis:{label:{value:"Count",angle:-90,position:"insideLeft"},domain:[0,"dataMax + 10"]},xAxis:{domain:[0,"dataMax"],interval:"preserveStartEnd"},tooltip:{labelFormatter:()=>"Risk Score",formatter:(l,a,s)=>[l,s.payload.key]},referenceAreas:[{x1:0,x2:299,fill:"#ffffff00",isFront:!1,label:"Allow"},{x1:300,x2:600,fill:r.palette.warning.light,isFront:!1,label:"Flag"},{x1:600,fill:r.palette.error.light,isFront:!1,label:"Block"}]})}export{Wt as BigNumber,Ut as ErrorCodesChart,Ne as PieChart,Jt as RiskScoreBarChart,Xt as RiskScorePieChart,zt as SeriesChart,Re as SeriesChartLegend,Bt as SeriesPercentageChart,pe as SimpleBarChart,Ce as SimpleLegend};
|