1import{r as l,J as V,j as e,x as H,H as w,B as K,bP as G,y as M,aa as X,ab as Y,ac as q,ad as J,ae as g,af as P,ag as U,ah as Q,ai as Z,am as ee,bB as te,aP as A,a9 as ae,aX as p,aj as oe,bD as re,bE as R,bn as ie,a1 as se}from"./index-BACUqBz4.js";import{E as ne,D as le}from"./EmptyState-Bfv-WZ-b.js";import{E as de}from"./ExportMenu-D8Z6Rm_7.js";import{O as ce}from"./OpenInAskYourData-wBi-dzNc.js";import{P as me}from"./PinToDashboard-DnNSHhVa.js";import{N as ue}from"./NextStepChips-u7Xcd5Pc.js";import"./ExplainThis-BeAxgNI8.js";import{A as pe}from"./AiTrio-CvYhPv-6.js";import{C as he}from"./ChartAnnotations-qRF2igM2.js";import{n as xe,d as ve,b as ge,f as fe,p as ye}from"./series-6vDvXsE1.js";import{u as je}from"./useDrilldown-DTq53-bE.js";import"./EmptyState-CRi2jFBw.js";import"./Pill-DScCZ4qx.js";import"./send-C8h3E7md.js";import"./trash-2-BnqHyW3k.js";function ze(){const[I,$]=l.useState([]),[d,T]=l.useState(""),[h,k]=l.useState([]),[c,B]=l.useState([]),[i,F]=l.useState(""),[o,D]=l.useState(""),[a,f]=l.useState(null),y=l.useRef(null),m=je(),E=t=>{!(t!=null&&t.name)||!i||m.addFilter({column:i,op:"eq",value:t.name})};l.useEffect(()=>{V.list().then(t=>$(t.data||[])).catch(()=>{})},[]);function z(t){T(t),f(null),t&&se.preview(t).then(s=>{k(s.data.headers||[]),B(s.data.rows||[])}).catch(()=>{})}function W(){if(!i||!o||!c.length)return;const t={};
1c.forEach(r=>{const n=r[i]||"(blank)",_=ye(r[o])||0;t[n]=(t[n]||0)+_});const s=Object.entries(t).sort((r,n)=>n[1]-r[1]),u=s.reduce((r,[,n])=>r+n,0);let b=0;const x=s.map(([r,n])=>(b+=n/u*100,{name:r.length>14?r.slice(0,14)+"â¦":r,value:parseFloat(n.toFixed(2)),cumPct:parseFloat(b.toFixed(1))})),C=x.filter(r=>r.cumPct<=80),v=x.slice(0,20),S=v.findIndex(r=>r.cumPct>=80),O=S>=0?v[S]:null;f({data:v,total:u,vital:C.length,trivial:x.length-C.length,cross:O})}const L=xe(c,h),N=ve(c,h),j=ge(c,N);return e.jsxs(H,{children:[e.jsx(w,{title:e.jsxs(e.Fragment,{children:["Pareto Analysis ",e.jsx(w.Accent,{children:"(80/20)"})]}),description:"Find the 20% of categories that drive 80% of your results"}),e.jsxs("div",{style:{background:"var(--bg-raised)",borderRadius:12,padding:20,boxShadow:"var(--elev-1)",marginBottom:24},children:[e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))",gap:12,marginBottom:12},children:[["File",e.jsxs("select",{value:d,onChange:t=>z(t.target.value),style:{width:"100%",padding:"9px 12px",border:"1px solid var(--border-default)",borderRadius:8,fontSize:"0.9rem"},children:[e.jsx("option",{value:"",children:"-- Choose --"}),I.map(t=>e.jsx("option",{value:t.id,children:t.filename},t.id))]})],["Category Column",e.jsxs("select",{value:i,onChange:t=>F(t.target.value),style:{width:"100%",padding:"9px 12px",border:"1px solid var(--border-default)",borderRadius:8,fontSize:"0.9rem"},children:[e.jsx("option",{value:"",children:"-- Column --"}),h.map(t=>e.jsx("option",{value:t,children:t},t))]})],["Value Column",e.jsxs("select",{value:o,onChange:t=>D(t.target.value),style:{width:"100%",padding:"9px 12px",border:"1px solid var(--border-default)",borderRadius:8,fontSize:"0.9rem"},children:[e.jsx("option",{value:"",children:"-- Numeric --"}),L.map(t=>e.jsx("option",{value:t,children:t},t))]})]].map(([t,s])=>e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:"0.8rem",fontWeight:600,color:"var(--fg-secondary)",marginBottom:5},children:t}),s]},t))}),e.jsx(K,{onClick:W,disabled:!i||!o,children:"Run Pareto"})]}),a&&e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginBottom:12},children:[e.jsx(ce,{fileId:d,prompt:`In a Pareto on ${o} by ${i}, ${a.vital} categories drive 80% of total. Tell me how concentration is changing over time and which categories are climbing fastest.`}),e.jsx(me,{widget:{type:"bar",col:o,label:`Pareto: ${o} by ${i}`,file_id:d,extra:{catCol:i,vital:a.vital,total:a.total}}}),e.jsx(de,{data:a.data,filename:`pareto-${i}-${o}`,containerRef:y,title:`Pareto: ${o} by ${i}`})]}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:16,marginBottom:24},children:[["Total Value",Number(a.total).toLocaleString(void 0,{maximumFractionDigits:0}),"#0c1446"],["Vital Few (â¤80%)",`${a.vital} categories`,"#e91e8c"],["Trivial Many (>80%)",`${a.trivial} categories`,"#6b7280"]].map(([t,s,u])=>e.jsxs("div",{style:{background:"var(--bg-raised)",borderRadius:12,padding:16,boxShadow:"var(--elev-1)",borderLeft:`4px solid ${u}`},children:[e.jsx("div",{style:{fontSize:"0.75rem",color:"var(--fg-tertiary)",marginBottom:4},children:t}),e.jsx("div",{style:{fontSize:"1.3rem",fontWeight:800,color:u},children:s})]},t))}),m.hasFilters&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:8,marginBottom:14,alignItems:"center"},children:[e.jsx("span",{style:{fontSize:11,fontWeight:700,color:"var(--fg-tertiary)",textTransform:"uppercase",letterSpacing:"0.08em"},children:"Drill-down"}),m.filters.map((t,s)=>e.jsxs(G,{tone:"cyan",onRemove:()=>m.removeFilter(t),children:[t.column," = ",t.value]},`${t.column}-${t.value}-${s}`)),e.jsx("button",{onClick:m.clearAll,style:{background:"transparent",border:"none",color:"var(--color-violet-600)",fontSize:11.5,fontWeight:700,cursor:"pointer",padding:"4px 8px"},children:"Clear all"})]}),e.jsxs("div",{ref:y,style:{background:"var(--bg-raised)",borderRadius:12,padding:20,boxShadow:"var(--elev-1)"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:16},children:[e.jsxs("div",{children:[e.jsxs("div",{style:{fontWeight:700,color:"var(--fg-primary)"},children:["Pareto Chart â Top ",a.data.length," categories"]}),j&&e.jsx("div",{style:{fontSize:"0.68rem",color:"var(--fg-tertiary)",fontWeight:600,marginBottom:8},children:j})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx(pe,{fileId:d,what:`Pareto 80/20 analysis on ${o}`,pivot:`the top ${a.vital} categories`,context:{value_column:o,total:a.total,vital_few:a.vital,trivial_many:a.trivial,top_5:(a.data||[]).slice(0,5).map(t=>({name:t.name,value:t.value,cum_pct:t.cumPct}))}}),e.jsx(he,{fileId:d,chartKey:`pareto:${i}:${o}`,xValue:`${i} à ${o}`})]})]}),e.jsx(M,{width:"100%",height:320,children:e.jsxs(X,{data:a.data,children:[e.jsx(Y,{...q}),e.jsx(J,{...g,dataKey:"name",angle:-30,textAnchor:"end",height:60}),e.jsx(P,{...g,yAxisId:"left",tickFormatter:fe}),e.jsx(P,{...g,yAxisId:"right",orientation:"right",domain:[0,100],unit:"%"}),e.jsx(U,{...Z,cursor:Q}),e.jsx(ee,{yAxisId:"left",dataKey:"value",fill:te,radius:[4,4,0,0],maxBarSize:22,name:o,onClick:E,style:{cursor:"pointer"},...A(0)}),e.jsx(ae,{yAxisId:"right",type:"monotone",dataKey:"cumPct",stroke:p,strokeWidth:2.5,dot:{r:3,fill:p},name:"Cumulative %",...A(1)}),e.jsx(oe,{yAxisId:"right",y:80,stroke:p,strokeWidth:1.6,strokeDasharray:"5 4",label:{value:"â 80% · Pareto threshold",position:"left",fontSize:10.5,fontWeight:700,fill:p,letterSpacing:"0.02em"}}),a.cross&&e.jsx(re,{yAxisId:"right",x:a.cross.name,y:a.cross.cumPct,...R.dot,children:e.jsx(ie,{...R.label,value:`Vital few cutoff (${a.vital})`,position:"top"})})]})})]}),e.jsx(ue,{fileId:d,suggestions:[{label:'Segment your "vital few"',path:"/rfm",icon:"ð¯",description:"Build RFM scores for the top contributors"},{label:"Predict churn for top segment",path:"/churn-risk",icon:"ðª",description:"Protect revenue concentrated in a small group"},{label:"Cohort behaviour over time",path:"/cohort-analysis",icon:"ð¥",description:"How does the leader cohort retain vs others?"},{label:"Anomalies in top performers",path:"/anomaly-detection",icon:"â ï¸",description:"Spot unusual movements in the contributors that matter"}]})]}),!a&&e.jsx(ne,{icon:"ð",title:"Pick category and value columns",body:"The Pareto chart shows the 20% of categories that drive 80% of your total â surfaced as 'vital few' vs 'trivial many'.",tone
1:"info",teaser:e.jsx(le,{variant:"bar",accent:"#10b981"})})]})}export{ze as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.