@jacshuo/onyx 1.4.1 → 2.0.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.
Files changed (71) hide show
  1. package/dist/Chart/BarChart.cjs +1 -0
  2. package/dist/Chart/BarChart.css +1 -0
  3. package/dist/Chart/BarChart.d.cts +2 -0
  4. package/dist/Chart/BarChart.d.ts +2 -0
  5. package/dist/Chart/BarChart.js +1 -0
  6. package/dist/Chart/LineChart.cjs +1 -0
  7. package/dist/Chart/LineChart.css +1 -0
  8. package/dist/Chart/LineChart.d.cts +2 -0
  9. package/dist/Chart/LineChart.d.ts +2 -0
  10. package/dist/Chart/LineChart.js +1 -0
  11. package/dist/Chart/PieChart.cjs +1 -0
  12. package/dist/Chart/PieChart.css +1 -0
  13. package/dist/Chart/PieChart.d.cts +2 -0
  14. package/dist/Chart/PieChart.d.ts +2 -0
  15. package/dist/Chart/PieChart.js +1 -0
  16. package/dist/Chart/ScatterChart.cjs +1 -0
  17. package/dist/Chart/ScatterChart.css +1 -0
  18. package/dist/Chart/ScatterChart.d.cts +2 -0
  19. package/dist/Chart/ScatterChart.d.ts +2 -0
  20. package/dist/Chart/ScatterChart.js +1 -0
  21. package/dist/Chart/index.cjs +1 -0
  22. package/dist/Chart/index.css +1 -0
  23. package/dist/Chart/index.d.cts +12 -0
  24. package/dist/Chart/index.d.ts +12 -0
  25. package/dist/Chart/index.js +1 -0
  26. package/dist/DataDisplay/index.d.cts +1 -1
  27. package/dist/DataDisplay/index.d.ts +1 -1
  28. package/dist/Disclosure/index.d.cts +1 -1
  29. package/dist/Disclosure/index.d.ts +1 -1
  30. package/dist/Extras/TypewriterText.cjs +1 -0
  31. package/dist/Extras/TypewriterText.css +1 -0
  32. package/dist/Extras/TypewriterText.d.cts +2 -0
  33. package/dist/Extras/TypewriterText.d.ts +2 -0
  34. package/dist/Extras/TypewriterText.js +1 -0
  35. package/dist/Extras/index.cjs +4 -4
  36. package/dist/Extras/index.css +1 -0
  37. package/dist/Extras/index.d.cts +3 -1
  38. package/dist/Extras/index.d.ts +3 -1
  39. package/dist/Extras/index.js +4 -4
  40. package/dist/Feedback/index.d.cts +1 -1
  41. package/dist/Feedback/index.d.ts +1 -1
  42. package/dist/Forms/index.d.cts +1 -1
  43. package/dist/Forms/index.d.ts +1 -1
  44. package/dist/Layout/index.d.cts +1 -1
  45. package/dist/Layout/index.d.ts +1 -1
  46. package/dist/Navigation/index.d.cts +1 -1
  47. package/dist/Navigation/index.d.ts +1 -1
  48. package/dist/Overlay/index.d.cts +1 -1
  49. package/dist/Overlay/index.d.ts +1 -1
  50. package/dist/Primitives/index.d.cts +1 -1
  51. package/dist/Primitives/index.d.ts +1 -1
  52. package/dist/_tsup-dts-rollup.d.cts +481 -11
  53. package/dist/_tsup-dts-rollup.d.ts +481 -11
  54. package/dist/index.cjs +5 -5
  55. package/dist/index.css +1 -0
  56. package/dist/index.d.cts +20 -0
  57. package/dist/index.d.ts +20 -0
  58. package/dist/index.js +5 -5
  59. package/dist/styles/Chart/BarChart.css +44 -0
  60. package/dist/styles/Chart/LineChart.css +72 -0
  61. package/dist/styles/Chart/PieChart.css +56 -0
  62. package/dist/styles/Chart/ScatterChart.css +45 -0
  63. package/dist/styles/Extras/TypewriterText.css +55 -0
  64. package/dist/styles/base.css +140 -0
  65. package/dist/styles/tokens/core.css +10 -0
  66. package/dist/styles.css +344 -0
  67. package/dist/theme.cjs +1 -1
  68. package/dist/theme.d.cts +3 -0
  69. package/dist/theme.d.ts +3 -0
  70. package/dist/theme.js +1 -1
  71. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ 'use strict';var react=require('react'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),classVarianceAuthority=require('class-variance-authority'),jsxRuntime=require('react/jsx-runtime');function G(...t){return tailwindMerge.twMerge(clsx.clsx(t))}var O=classVarianceAuthority.cva("relative w-full font-sans select-none",{variants:{size:{sm:"text-xs",md:"text-sm",lg:"text-base"}},defaultVariants:{size:"md"}}),P=classVarianceAuthority.cva("flex flex-wrap gap-3 items-center justify-center",{variants:{position:{top:"mb-3",bottom:"mt-3",left:"flex-col mr-4",right:"flex-col ml-4"}},defaultVariants:{position:"bottom"}}),K=classVarianceAuthority.cva("absolute z-50 pointer-events-none px-3 py-2 rounded-lg text-xs shadow-lg border transition-opacity duration-150 bg-primary-900 text-primary-50 border-primary-700 dark:bg-primary-950 dark:border-primary-800");function et(t){let[o,r]=react.useState(()=>new Set(t)),i=react.useCallback(s=>{r(h=>{let d=new Set(h);return d.has(s)?d.delete(s):d.add(s),d});},[]),a=react.useCallback(s=>o.has(s),[o]),m=react.useCallback(()=>{r(new Set(t));},[t]);return {visible:o,toggle:i,isVisible:a,showAll:m}}function nt(t){let o=["var(--color-chart-1)","var(--color-chart-2)","var(--color-chart-3)","var(--color-chart-4)","var(--color-chart-5)","var(--color-chart-6)","var(--color-chart-7)","var(--color-chart-8)"];return Array.from({length:t},(r,i)=>o[i%o.length])}function q(t,o,r=.1){if(t===o)return [t-1,o+1];let a=(o-t)*r;return [Math.floor(t-a),Math.ceil(o+a)]}function ot(t,o,r){if(r<=1)return [t];let i=(o-t)/(r-1);return Array.from({length:r},(a,m)=>+(t+m*i).toFixed(10))}function Y(t,o){return o?o(t):typeof t=="number"?Math.abs(t)>=1e6?`${(t/1e6).toFixed(1)}M`:Math.abs(t)>=1e3?`${(t/1e3).toFixed(1)}K`:Number.isInteger(t)?t.toString():t.toFixed(2):String(t)}function J(t,o,r){return {top:20,right:r?65:20,bottom:t?52:36,left:o?65:52}}function Q(t,o,r){let i=Math.max(t,120);return {width:i,height:o,margins:r,plotLeft:r.left,plotTop:r.top,plotRight:i-r.right,plotBottom:o-r.bottom,plotWidth:Math.max(i-r.left-r.right,10),plotHeight:Math.max(o-r.top-r.bottom,10)}}function at(t,o){let r=new Set,i=[];for(let a of t)if(o.has(a.id))for(let m of a.data){let s=String(m.x);r.has(s)||(r.add(s),i.push(s));}return i}function it(t,o,r,i){if(r){let a=0;for(let s of t)if(o.has(s.id))for(let h of s.data)h.y>a&&(a=h.y);a===0&&(a=1);let[,m]=q(0,a,.05);return [i?.min??0,i?.max??m]}else {let a=new Map;for(let h of t)if(o.has(h.id))for(let d of h.data){let C=String(d.x);a.set(C,(a.get(C)??0)+d.y);}let m=Math.max(0,...a.values()),[,s]=q(0,m===0?1:m,.05);return [i?.min??0,i?.max??s]}}function st(t,o){let[r,i]=t,[a,m]=o;return i===r?()=>(a+m)/2:s=>a+(s-r)/(i-r)*(m-a)}function ct(t,o=5){return ot(t[0],t[1],o)}function lt(t,o,r,i,a,m,s,h,d,C,S){let v=t.filter(y=>o.has(y.id)),f=r.length,b=v.length;if(f===0||b===0)return [];let u=m/f,p=u*(1-C),k=b>0?p*(1-S)/b:0,x=[];for(let y=0;y<r.length;y++){let M=r[y],V=a+y*u+(u-p)/2;for(let B=0;B<v.length;B++){let g=v[B],F=g.data.find(H=>String(H.x)===M);if(!F)continue;let W=V+B*(k+p*S/b),$=d(F.y);x.push({seriesId:g.id,category:M,x:W,y:$,width:Math.max(k,1),height:Math.max(s-$,0),stackBase:s,value:F.y,color:i.get(g.id)??"var(--color-chart-1)"});}}return x}function ut(t,o,r,i,a,m,s,h,d,C){let S=t.filter(x=>o.has(x.id)),v=r.length,f=S.length;if(v===0||f===0)return [];let b=s/v,u=b*(1-d),p=f>0?u*(1-C)/f:0,k=[];for(let x=0;x<r.length;x++){let y=r[x],M=m+x*b+(b-u)/2;for(let V=0;V<S.length;V++){let B=S[V],g=B.data.find($=>String($.x)===y);if(!g)continue;let F=M+V*(p+u*C/Math.max(f,1)),W=h(g.y);k.push({seriesId:B.id,category:y,x:a,y:F,width:Math.max(W-a,0),height:Math.max(p,1),stackBase:a,value:g.y,color:i.get(B.id)??"var(--color-chart-1)"});}}return k}function mt(t,o,r,i,a,m,s,h,d){let C=t.filter(u=>o.has(u.id)),S=r.length;if(S===0)return [];let v=s/S*(1-d),f=[],b=new Map;r.forEach(u=>b.set(u,a));for(let u of C)for(let p of r){let k=u.data.find(B=>String(B.x)===p);if(!k)continue;let x=b.get(p)??a,y=Math.max(h(k.y)-a,0),M=r.indexOf(p),V=m+(M+.5)*(s/S);f.push({seriesId:u.id,category:p,x,y:V-v/2,width:y,height:Math.max(v,1),stackBase:x,value:k.y,color:i.get(u.id)??"var(--color-chart-1)"}),b.set(p,x+y);}return f}function pt(t,o,r,i,a,m,s,h,d){let C=t.filter(u=>o.has(u.id)),S=r.length;if(S===0)return [];let v=m/S*(1-d),f=[],b=new Map;r.forEach(u=>b.set(u,s));for(let u of C)for(let p of r){let k=u.data.find(g=>String(g.x)===p);if(!k)continue;let x=b.get(p)??s,y=Math.max(s-h(k.y),0),M=x-y,V=r.indexOf(p),B=a+(V+.5)*(m/S);f.push({seriesId:u.id,category:p,x:B-v/2,y:M,width:Math.max(v,1),height:y,stackBase:x,value:k.y,color:i.get(u.id)??"var(--color-chart-1)"}),b.set(p,M);}return f}function j({items:t,position:o,onToggle:r}){return jsxRuntime.jsx("div",{className:P({position:o}),children:t.map(i=>jsxRuntime.jsxs("button",{onClick:()=>r(i.id),className:G("flex items-center gap-1.5 cursor-pointer rounded px-1.5 py-1 text-xs text-primary-700 transition-opacity hover:bg-primary-100 dark:text-primary-300 dark:hover:bg-primary-800",!i.visible&&"opacity-40"),"aria-pressed":i.visible,children:[jsxRuntime.jsx("span",{className:"h-2.5 w-5 rounded-sm shrink-0",style:{background:i.color}}),i.label]},i.id))})}function Jt({series:t,xAxis:o,yAxis:r,orientation:i="vertical",grouped:a=true,barRadius:m=4,barPadding:s=.2,groupPadding:h=.3,title:d,height:C=300,className:S,legend:v=true,legendPosition:f="bottom",animateOnMount:b=true,emptyText:u="No data to display"}){let p=react.useRef(null),k=react.useRef(null),[x,y]=react.useState(600),[M,V]=react.useState(null);react.useEffect(()=>{let e=k.current;if(!e)return;let c=e.getBoundingClientRect().width;c>0&&y(c);let T=new ResizeObserver(R=>{let D=R[0]?.contentRect.width;D&&D>0&&y(D);});return T.observe(e),()=>T.disconnect()},[]);let B=react.useMemo(()=>t.map(e=>e.id),[t]),{visible:g,toggle:F,isVisible:W}=et(B),$=react.useMemo(()=>nt(t.length),[t.length]),H=react.useMemo(()=>new Map(t.map((e,c)=>[e.id,e.color??$[c]])),[t,$]),w=i==="horizontal",U=react.useMemo(()=>J(!!o?.label,!!r?.label,false),[o?.label,r?.label]),n=react.useMemo(()=>Q(x,C,U),[x,C,U]),N=react.useMemo(()=>at(t,g),[t,g]),_=react.useMemo(()=>it(t,g,a,w?o:r),[t,g,a,w,o,r]),I=react.useMemo(()=>st(_,w?[n.plotLeft,n.plotRight]:[n.plotBottom,n.plotTop]),[_,n,w]),A=react.useMemo(()=>ct(_,(w?o:r)?.tickCount??5),[_,w,o,r]),dt=react.useMemo(()=>w?a?ut(t,g,N,H,n.plotLeft,n.plotTop,n.plotHeight,I,h,s):mt(t,g,N,H,n.plotLeft,n.plotTop,n.plotHeight,I,h):a?lt(t,g,N,H,n.plotLeft,n.plotWidth,n.plotBottom,n.plotTop,I,h,s):pt(t,g,N,H,n.plotLeft,n.plotWidth,n.plotBottom,I,h),[t,g,N,H,n,I,a,w,h,s]),bt=N.length>0?n.plotWidth/N.length:1,xt=N.length>0?n.plotHeight/N.length:1,tt=react.useCallback((e,c)=>{let T=p.current?.getBoundingClientRect();if(!T)return;let R=t.filter(D=>W(D.id)).map(D=>{let rt=D.data.find(St=>String(St.x)===c);return {name:D.name,value:rt?Y(rt.y,r?.format):"\u2014",color:H.get(D.id)??"var(--color-chart-1)"}});V({x:e.clientX-T.left+12,y:e.clientY-T.top-10,category:c,items:R});},[t,W,H,r?.format]),E=react.useMemo(()=>t.map((e,c)=>({id:e.id,label:e.name,color:e.color??$[c],visible:W(e.id)})),[t,$,W]),gt=t.some(e=>e.data.length>0),yt=f==="left"||f==="right",vt=jsxRuntime.jsxs("svg",{role:"img","aria-label":d??"Bar chart",width:n.width,height:n.height,viewBox:`0 0 ${n.width} ${n.height}`,shapeRendering:"geometricPrecision",children:[A.map(e=>{let c=I(e);return w?jsxRuntime.jsx("line",{x1:c,x2:c,y1:n.plotTop,y2:n.plotBottom,stroke:"currentColor",strokeWidth:.5,strokeDasharray:"4 4",className:"text-secondary-200 dark:text-secondary-700"},e):jsxRuntime.jsx("line",{x1:n.plotLeft,x2:n.plotRight,y1:c,y2:c,stroke:"currentColor",strokeWidth:.5,strokeDasharray:"4 4",className:"text-secondary-200 dark:text-secondary-700"},e)}),dt.map(e=>{let c=Math.min(m,e.width/2,e.height/2),T=`${e.seriesId}-${e.category}`;return w?jsxRuntime.jsx("rect",{x:e.x,y:e.y,width:e.width,height:e.height,rx:c,fill:e.color,className:G("chart-bar-h",b&&"chart-bar-animate"),onMouseMove:R=>tt(R,e.category),onMouseLeave:()=>V(null)},T):jsxRuntime.jsx("rect",{x:e.x,y:e.y,width:e.width,height:e.height,rx:c,fill:e.color,className:G("chart-bar-v",b&&"chart-bar-animate"),onMouseMove:R=>tt(R,e.category),onMouseLeave:()=>V(null)},T)}),jsxRuntime.jsx("line",{x1:n.plotLeft,x2:n.plotLeft,y1:n.plotTop,y2:n.plotBottom,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsxRuntime.jsx("line",{x1:n.plotLeft,x2:n.plotRight,y1:n.plotBottom,y2:n.plotBottom,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),!w&&A.map(e=>{let c=I(e);return jsxRuntime.jsxs("g",{children:[jsxRuntime.jsx("line",{x1:n.plotLeft-4,x2:n.plotLeft,y1:c,y2:c,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsxRuntime.jsx("text",{x:n.plotLeft-6,y:c,textAnchor:"end",dominantBaseline:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:Y(e,r?.format)})]},e)}),w&&A.map(e=>{let c=I(e);return jsxRuntime.jsxs("g",{children:[jsxRuntime.jsx("line",{x1:c,x2:c,y1:n.plotBottom,y2:n.plotBottom+4,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsxRuntime.jsx("text",{x:c,y:n.plotBottom+14,textAnchor:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:Y(e,o?.format)})]},e)}),N.map((e,c)=>{if(w){let R=n.plotTop+(c+.5)*xt;return jsxRuntime.jsx("text",{x:n.plotLeft-6,y:R,textAnchor:"end",dominantBaseline:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:e},e)}let T=n.plotLeft+(c+.5)*bt;return jsxRuntime.jsx("text",{x:T,y:n.plotBottom+14,textAnchor:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:e},e)}),r?.label&&!w&&jsxRuntime.jsx("text",{x:-(n.plotTop+n.plotHeight/2),y:14,textAnchor:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-600 dark:text-secondary-400",transform:"rotate(-90)",children:r.label}),o?.label&&jsxRuntime.jsx("text",{x:n.plotLeft+n.plotWidth/2,y:n.height-4,textAnchor:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-600 dark:text-secondary-400",children:o.label})]});return jsxRuntime.jsxs("div",{ref:p,className:G(O(),S),children:[d&&jsxRuntime.jsx("h3",{className:"mb-2 text-sm font-semibold text-primary-700 dark:text-primary-200",children:d}),v&&f==="top"&&jsxRuntime.jsx(j,{items:E,position:"top",onToggle:F}),jsxRuntime.jsxs("div",{className:G("flex items-start",yt&&"gap-0"),children:[v&&f==="left"&&jsxRuntime.jsx(j,{items:E,position:"left",onToggle:F}),jsxRuntime.jsx("div",{ref:k,className:"flex-1 min-w-0 overflow-hidden",children:gt?vt:jsxRuntime.jsx("div",{className:"flex items-center justify-center text-secondary-400 dark:text-secondary-500",style:{height:C},children:u})}),v&&f==="right"&&jsxRuntime.jsx(j,{items:E,position:"right",onToggle:F})]}),v&&f==="bottom"&&jsxRuntime.jsx(j,{items:E,position:"bottom",onToggle:F}),M&&jsxRuntime.jsxs("div",{className:K(),style:{left:M.x,top:M.y},role:"tooltip",children:[jsxRuntime.jsx("div",{className:"mb-1 font-medium text-primary-200",children:M.category}),M.items.map((e,c)=>jsxRuntime.jsxs("div",{className:"flex items-center gap-1.5",children:[jsxRuntime.jsx("span",{className:"h-2 w-2 rounded-full shrink-0",style:{background:e.color}}),jsxRuntime.jsxs("span",{className:"text-primary-300",children:[e.name,":"]}),jsxRuntime.jsx("span",{className:"font-medium",children:e.value})]},c))]})]})}exports.BarChart=Jt;
@@ -0,0 +1 @@
1
+ @keyframes chart-bar-rise{0%{clip-path:inset(100% 0 0 0);opacity:.5}to{clip-path:inset(0% 0 0 0);opacity:1}}@keyframes chart-bar-extend{0%{clip-path:inset(0 100% 0 0);opacity:.5}to{clip-path:inset(0 0% 0 0);opacity:1}}.chart-bar-v{transition:filter .18s ease}.chart-bar-v.chart-bar-animate{animation:chart-bar-rise .6s cubic-bezier(.22,1,.36,1) both}.chart-bar-h{transition:filter .18s ease}.chart-bar-h.chart-bar-animate{animation:chart-bar-extend .6s cubic-bezier(.22,1,.36,1) both}.chart-bar-v:hover,.chart-bar-h:hover{filter:brightness(1.18);cursor:pointer}.chart-bar-hidden{opacity:0;pointer-events:none}
@@ -0,0 +1,2 @@
1
+ export { BarChart_alias_3 as BarChart } from '../_tsup-dts-rollup.cjs';
2
+ export { BarChartProps_alias_1 as BarChartProps } from '../_tsup-dts-rollup.cjs';
@@ -0,0 +1,2 @@
1
+ export { BarChart_alias_3 as BarChart } from '../_tsup-dts-rollup.js';
2
+ export { BarChartProps_alias_1 as BarChartProps } from '../_tsup-dts-rollup.js';
@@ -0,0 +1 @@
1
+ import {useRef,useState,useEffect,useMemo,useCallback}from'react';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {cva}from'class-variance-authority';import {jsxs,jsx}from'react/jsx-runtime';function G(...t){return twMerge(clsx(t))}var O=cva("relative w-full font-sans select-none",{variants:{size:{sm:"text-xs",md:"text-sm",lg:"text-base"}},defaultVariants:{size:"md"}}),P=cva("flex flex-wrap gap-3 items-center justify-center",{variants:{position:{top:"mb-3",bottom:"mt-3",left:"flex-col mr-4",right:"flex-col ml-4"}},defaultVariants:{position:"bottom"}}),K=cva("absolute z-50 pointer-events-none px-3 py-2 rounded-lg text-xs shadow-lg border transition-opacity duration-150 bg-primary-900 text-primary-50 border-primary-700 dark:bg-primary-950 dark:border-primary-800");function et(t){let[o,r]=useState(()=>new Set(t)),i=useCallback(s=>{r(h=>{let d=new Set(h);return d.has(s)?d.delete(s):d.add(s),d});},[]),a=useCallback(s=>o.has(s),[o]),m=useCallback(()=>{r(new Set(t));},[t]);return {visible:o,toggle:i,isVisible:a,showAll:m}}function nt(t){let o=["var(--color-chart-1)","var(--color-chart-2)","var(--color-chart-3)","var(--color-chart-4)","var(--color-chart-5)","var(--color-chart-6)","var(--color-chart-7)","var(--color-chart-8)"];return Array.from({length:t},(r,i)=>o[i%o.length])}function q(t,o,r=.1){if(t===o)return [t-1,o+1];let a=(o-t)*r;return [Math.floor(t-a),Math.ceil(o+a)]}function ot(t,o,r){if(r<=1)return [t];let i=(o-t)/(r-1);return Array.from({length:r},(a,m)=>+(t+m*i).toFixed(10))}function Y(t,o){return o?o(t):typeof t=="number"?Math.abs(t)>=1e6?`${(t/1e6).toFixed(1)}M`:Math.abs(t)>=1e3?`${(t/1e3).toFixed(1)}K`:Number.isInteger(t)?t.toString():t.toFixed(2):String(t)}function J(t,o,r){return {top:20,right:r?65:20,bottom:t?52:36,left:o?65:52}}function Q(t,o,r){let i=Math.max(t,120);return {width:i,height:o,margins:r,plotLeft:r.left,plotTop:r.top,plotRight:i-r.right,plotBottom:o-r.bottom,plotWidth:Math.max(i-r.left-r.right,10),plotHeight:Math.max(o-r.top-r.bottom,10)}}function at(t,o){let r=new Set,i=[];for(let a of t)if(o.has(a.id))for(let m of a.data){let s=String(m.x);r.has(s)||(r.add(s),i.push(s));}return i}function it(t,o,r,i){if(r){let a=0;for(let s of t)if(o.has(s.id))for(let h of s.data)h.y>a&&(a=h.y);a===0&&(a=1);let[,m]=q(0,a,.05);return [i?.min??0,i?.max??m]}else {let a=new Map;for(let h of t)if(o.has(h.id))for(let d of h.data){let C=String(d.x);a.set(C,(a.get(C)??0)+d.y);}let m=Math.max(0,...a.values()),[,s]=q(0,m===0?1:m,.05);return [i?.min??0,i?.max??s]}}function st(t,o){let[r,i]=t,[a,m]=o;return i===r?()=>(a+m)/2:s=>a+(s-r)/(i-r)*(m-a)}function ct(t,o=5){return ot(t[0],t[1],o)}function lt(t,o,r,i,a,m,s,h,d,C,S){let v=t.filter(y=>o.has(y.id)),f=r.length,b=v.length;if(f===0||b===0)return [];let u=m/f,p=u*(1-C),k=b>0?p*(1-S)/b:0,x=[];for(let y=0;y<r.length;y++){let M=r[y],V=a+y*u+(u-p)/2;for(let B=0;B<v.length;B++){let g=v[B],F=g.data.find(H=>String(H.x)===M);if(!F)continue;let W=V+B*(k+p*S/b),$=d(F.y);x.push({seriesId:g.id,category:M,x:W,y:$,width:Math.max(k,1),height:Math.max(s-$,0),stackBase:s,value:F.y,color:i.get(g.id)??"var(--color-chart-1)"});}}return x}function ut(t,o,r,i,a,m,s,h,d,C){let S=t.filter(x=>o.has(x.id)),v=r.length,f=S.length;if(v===0||f===0)return [];let b=s/v,u=b*(1-d),p=f>0?u*(1-C)/f:0,k=[];for(let x=0;x<r.length;x++){let y=r[x],M=m+x*b+(b-u)/2;for(let V=0;V<S.length;V++){let B=S[V],g=B.data.find($=>String($.x)===y);if(!g)continue;let F=M+V*(p+u*C/Math.max(f,1)),W=h(g.y);k.push({seriesId:B.id,category:y,x:a,y:F,width:Math.max(W-a,0),height:Math.max(p,1),stackBase:a,value:g.y,color:i.get(B.id)??"var(--color-chart-1)"});}}return k}function mt(t,o,r,i,a,m,s,h,d){let C=t.filter(u=>o.has(u.id)),S=r.length;if(S===0)return [];let v=s/S*(1-d),f=[],b=new Map;r.forEach(u=>b.set(u,a));for(let u of C)for(let p of r){let k=u.data.find(B=>String(B.x)===p);if(!k)continue;let x=b.get(p)??a,y=Math.max(h(k.y)-a,0),M=r.indexOf(p),V=m+(M+.5)*(s/S);f.push({seriesId:u.id,category:p,x,y:V-v/2,width:y,height:Math.max(v,1),stackBase:x,value:k.y,color:i.get(u.id)??"var(--color-chart-1)"}),b.set(p,x+y);}return f}function pt(t,o,r,i,a,m,s,h,d){let C=t.filter(u=>o.has(u.id)),S=r.length;if(S===0)return [];let v=m/S*(1-d),f=[],b=new Map;r.forEach(u=>b.set(u,s));for(let u of C)for(let p of r){let k=u.data.find(g=>String(g.x)===p);if(!k)continue;let x=b.get(p)??s,y=Math.max(s-h(k.y),0),M=x-y,V=r.indexOf(p),B=a+(V+.5)*(m/S);f.push({seriesId:u.id,category:p,x:B-v/2,y:M,width:Math.max(v,1),height:y,stackBase:x,value:k.y,color:i.get(u.id)??"var(--color-chart-1)"}),b.set(p,M);}return f}function j({items:t,position:o,onToggle:r}){return jsx("div",{className:P({position:o}),children:t.map(i=>jsxs("button",{onClick:()=>r(i.id),className:G("flex items-center gap-1.5 cursor-pointer rounded px-1.5 py-1 text-xs text-primary-700 transition-opacity hover:bg-primary-100 dark:text-primary-300 dark:hover:bg-primary-800",!i.visible&&"opacity-40"),"aria-pressed":i.visible,children:[jsx("span",{className:"h-2.5 w-5 rounded-sm shrink-0",style:{background:i.color}}),i.label]},i.id))})}function Jt({series:t,xAxis:o,yAxis:r,orientation:i="vertical",grouped:a=true,barRadius:m=4,barPadding:s=.2,groupPadding:h=.3,title:d,height:C=300,className:S,legend:v=true,legendPosition:f="bottom",animateOnMount:b=true,emptyText:u="No data to display"}){let p=useRef(null),k=useRef(null),[x,y]=useState(600),[M,V]=useState(null);useEffect(()=>{let e=k.current;if(!e)return;let c=e.getBoundingClientRect().width;c>0&&y(c);let T=new ResizeObserver(R=>{let D=R[0]?.contentRect.width;D&&D>0&&y(D);});return T.observe(e),()=>T.disconnect()},[]);let B=useMemo(()=>t.map(e=>e.id),[t]),{visible:g,toggle:F,isVisible:W}=et(B),$=useMemo(()=>nt(t.length),[t.length]),H=useMemo(()=>new Map(t.map((e,c)=>[e.id,e.color??$[c]])),[t,$]),w=i==="horizontal",U=useMemo(()=>J(!!o?.label,!!r?.label,false),[o?.label,r?.label]),n=useMemo(()=>Q(x,C,U),[x,C,U]),N=useMemo(()=>at(t,g),[t,g]),_=useMemo(()=>it(t,g,a,w?o:r),[t,g,a,w,o,r]),I=useMemo(()=>st(_,w?[n.plotLeft,n.plotRight]:[n.plotBottom,n.plotTop]),[_,n,w]),A=useMemo(()=>ct(_,(w?o:r)?.tickCount??5),[_,w,o,r]),dt=useMemo(()=>w?a?ut(t,g,N,H,n.plotLeft,n.plotTop,n.plotHeight,I,h,s):mt(t,g,N,H,n.plotLeft,n.plotTop,n.plotHeight,I,h):a?lt(t,g,N,H,n.plotLeft,n.plotWidth,n.plotBottom,n.plotTop,I,h,s):pt(t,g,N,H,n.plotLeft,n.plotWidth,n.plotBottom,I,h),[t,g,N,H,n,I,a,w,h,s]),bt=N.length>0?n.plotWidth/N.length:1,xt=N.length>0?n.plotHeight/N.length:1,tt=useCallback((e,c)=>{let T=p.current?.getBoundingClientRect();if(!T)return;let R=t.filter(D=>W(D.id)).map(D=>{let rt=D.data.find(St=>String(St.x)===c);return {name:D.name,value:rt?Y(rt.y,r?.format):"\u2014",color:H.get(D.id)??"var(--color-chart-1)"}});V({x:e.clientX-T.left+12,y:e.clientY-T.top-10,category:c,items:R});},[t,W,H,r?.format]),E=useMemo(()=>t.map((e,c)=>({id:e.id,label:e.name,color:e.color??$[c],visible:W(e.id)})),[t,$,W]),gt=t.some(e=>e.data.length>0),yt=f==="left"||f==="right",vt=jsxs("svg",{role:"img","aria-label":d??"Bar chart",width:n.width,height:n.height,viewBox:`0 0 ${n.width} ${n.height}`,shapeRendering:"geometricPrecision",children:[A.map(e=>{let c=I(e);return w?jsx("line",{x1:c,x2:c,y1:n.plotTop,y2:n.plotBottom,stroke:"currentColor",strokeWidth:.5,strokeDasharray:"4 4",className:"text-secondary-200 dark:text-secondary-700"},e):jsx("line",{x1:n.plotLeft,x2:n.plotRight,y1:c,y2:c,stroke:"currentColor",strokeWidth:.5,strokeDasharray:"4 4",className:"text-secondary-200 dark:text-secondary-700"},e)}),dt.map(e=>{let c=Math.min(m,e.width/2,e.height/2),T=`${e.seriesId}-${e.category}`;return w?jsx("rect",{x:e.x,y:e.y,width:e.width,height:e.height,rx:c,fill:e.color,className:G("chart-bar-h",b&&"chart-bar-animate"),onMouseMove:R=>tt(R,e.category),onMouseLeave:()=>V(null)},T):jsx("rect",{x:e.x,y:e.y,width:e.width,height:e.height,rx:c,fill:e.color,className:G("chart-bar-v",b&&"chart-bar-animate"),onMouseMove:R=>tt(R,e.category),onMouseLeave:()=>V(null)},T)}),jsx("line",{x1:n.plotLeft,x2:n.plotLeft,y1:n.plotTop,y2:n.plotBottom,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsx("line",{x1:n.plotLeft,x2:n.plotRight,y1:n.plotBottom,y2:n.plotBottom,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),!w&&A.map(e=>{let c=I(e);return jsxs("g",{children:[jsx("line",{x1:n.plotLeft-4,x2:n.plotLeft,y1:c,y2:c,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsx("text",{x:n.plotLeft-6,y:c,textAnchor:"end",dominantBaseline:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:Y(e,r?.format)})]},e)}),w&&A.map(e=>{let c=I(e);return jsxs("g",{children:[jsx("line",{x1:c,x2:c,y1:n.plotBottom,y2:n.plotBottom+4,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsx("text",{x:c,y:n.plotBottom+14,textAnchor:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:Y(e,o?.format)})]},e)}),N.map((e,c)=>{if(w){let R=n.plotTop+(c+.5)*xt;return jsx("text",{x:n.plotLeft-6,y:R,textAnchor:"end",dominantBaseline:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:e},e)}let T=n.plotLeft+(c+.5)*bt;return jsx("text",{x:T,y:n.plotBottom+14,textAnchor:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:e},e)}),r?.label&&!w&&jsx("text",{x:-(n.plotTop+n.plotHeight/2),y:14,textAnchor:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-600 dark:text-secondary-400",transform:"rotate(-90)",children:r.label}),o?.label&&jsx("text",{x:n.plotLeft+n.plotWidth/2,y:n.height-4,textAnchor:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-600 dark:text-secondary-400",children:o.label})]});return jsxs("div",{ref:p,className:G(O(),S),children:[d&&jsx("h3",{className:"mb-2 text-sm font-semibold text-primary-700 dark:text-primary-200",children:d}),v&&f==="top"&&jsx(j,{items:E,position:"top",onToggle:F}),jsxs("div",{className:G("flex items-start",yt&&"gap-0"),children:[v&&f==="left"&&jsx(j,{items:E,position:"left",onToggle:F}),jsx("div",{ref:k,className:"flex-1 min-w-0 overflow-hidden",children:gt?vt:jsx("div",{className:"flex items-center justify-center text-secondary-400 dark:text-secondary-500",style:{height:C},children:u})}),v&&f==="right"&&jsx(j,{items:E,position:"right",onToggle:F})]}),v&&f==="bottom"&&jsx(j,{items:E,position:"bottom",onToggle:F}),M&&jsxs("div",{className:K(),style:{left:M.x,top:M.y},role:"tooltip",children:[jsx("div",{className:"mb-1 font-medium text-primary-200",children:M.category}),M.items.map((e,c)=>jsxs("div",{className:"flex items-center gap-1.5",children:[jsx("span",{className:"h-2 w-2 rounded-full shrink-0",style:{background:e.color}}),jsxs("span",{className:"text-primary-300",children:[e.name,":"]}),jsx("span",{className:"font-medium",children:e.value})]},c))]})]})}export{Jt as BarChart};
@@ -0,0 +1 @@
1
+ 'use strict';var react=require('react'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),classVarianceAuthority=require('class-variance-authority'),jsxRuntime=require('react/jsx-runtime');function P(...t){return tailwindMerge.twMerge(clsx.clsx(t))}var rt=classVarianceAuthority.cva("relative w-full font-sans select-none",{variants:{size:{sm:"text-xs",md:"text-sm",lg:"text-base"}},defaultVariants:{size:"md"}}),nt=classVarianceAuthority.cva("flex flex-wrap gap-3 items-center justify-center",{variants:{position:{top:"mb-3",bottom:"mt-3",left:"flex-col mr-4",right:"flex-col ml-4"}},defaultVariants:{position:"bottom"}}),at=classVarianceAuthority.cva("absolute z-50 pointer-events-none px-3 py-2 rounded-lg text-xs shadow-lg border transition-opacity duration-150 bg-primary-900 text-primary-50 border-primary-700 dark:bg-primary-950 dark:border-primary-800");function Mt(t){let[r,a]=react.useState(()=>new Set(t)),e=react.useCallback(s=>{a(k=>{let p=new Set(k);return p.has(s)?p.delete(s):p.add(s),p});},[]),l=react.useCallback(s=>r.has(s),[r]),m=react.useCallback(()=>{a(new Set(t));},[t]);return {visible:r,toggle:e,isVisible:l,showAll:m}}function Tt(t){let r=["var(--color-chart-1)","var(--color-chart-2)","var(--color-chart-3)","var(--color-chart-4)","var(--color-chart-5)","var(--color-chart-6)","var(--color-chart-7)","var(--color-chart-8)"];return Array.from({length:t},(a,e)=>r[e%r.length])}function wt(t,r,a=.1){if(t===r)return [t-1,r+1];let l=(r-t)*a;return [Math.floor(t-l),Math.ceil(r+l)]}function Rt(t,r,a){if(a<=1)return [t];let e=(r-t)/(a-1);return Array.from({length:a},(l,m)=>+(t+m*e).toFixed(10))}function $(t,r){return r?r(t):typeof t=="number"?Math.abs(t)>=1e6?`${(t/1e6).toFixed(1)}M`:Math.abs(t)>=1e3?`${(t/1e3).toFixed(1)}K`:Number.isInteger(t)?t.toString():t.toFixed(2):String(t)}function Nt(t,r,a){return {top:20,right:a?65:20,bottom:t?52:36,left:r?65:52}}function St(t,r,a){let e=Math.max(t,120);return {width:e,height:r,margins:a,plotLeft:a.left,plotTop:a.top,plotRight:e-a.right,plotBottom:r-a.bottom,plotWidth:Math.max(e-a.left-a.right,10),plotHeight:Math.max(r-a.top-a.bottom,10)}}function Ft(t,r){let a=new Set,e=[];for(let l of t)if(r.has(l.id))for(let m of l.data){let s=String(m.x);a.has(s)||(a.add(s),e.push(s));}return e}function lt(t,r,a){let e=1/0,l=-1/0;for(let k of t)if(r.has(k.id))for(let p of k.data)p.y<e&&(e=p.y),p.y>l&&(l=p.y);if(!isFinite(e))return [0,1];let[m,s]=wt(e,l);return [a?.min??m,a?.max??s]}function G(t,r){let[a,e]=t,[l,m]=r;return e===a?()=>(l+m)/2:s=>l+(s-a)/(e-a)*(m-l)}function K(t,r){let a=t.length;if(a===0)return ()=>(r[0]+r[1])/2;let e=(r[1]-r[0])/a;return l=>{let m=t.indexOf(l);return m<0?(r[0]+r[1])/2:r[0]+m*e+e/2}}function $t(t,r,a){return t.map(e=>`${r(e.x).toFixed(2)},${a(e.y).toFixed(2)}`).join(" ")}function st(t,r,a){if(t.length===0)return "";let e=t.map(s=>({x:r(s.x),y:a(s.y)}));if(e.length===1)return `M ${e[0].x.toFixed(2)} ${e[0].y.toFixed(2)}`;let l=.5,m=`M ${e[0].x.toFixed(2)} ${e[0].y.toFixed(2)}`;for(let s=0;s<e.length-1;s++){let k=s===0?{x:2*e[0].x-e[1].x,y:2*e[0].y-e[1].y}:e[s-1],p=e[s],V=e[s+1],D=s+2<e.length?e[s+2]:{x:2*e[e.length-1].x-e[e.length-2].x,y:2*e[e.length-1].y-e[e.length-2].y},J=p.x+(V.x-k.x)*l/3,B=p.y+(V.y-k.y)*l/3,w=V.x-(D.x-p.x)*l/3,W=V.y-(D.y-p.y)*l/3;m+=` C ${J.toFixed(2)} ${B.toFixed(2)}, ${w.toFixed(2)} ${W.toFixed(2)}, ${V.x.toFixed(2)} ${V.y.toFixed(2)}`;}return m}function Dt(t,r,a,e,l){if(t.length===0)return "";let m=e?st(t,r,a):`M ${t.map(p=>`${r(p.x).toFixed(2)},${a(p.y).toFixed(2)}`).join(" L ")}`,s=r(t[t.length-1].x).toFixed(2),k=r(t[0].x).toFixed(2);return `${m} L ${s},${l.toFixed(2)} L ${k},${l.toFixed(2)} Z`}function Z(t,r=5){return Rt(t[0],t[1],r)}function ct(t,r,a){if(r.length===0)return -1;let e=1/0,l=0;for(let m=0;m<r.length;m++){let s=Math.abs(a(r[m])-t);s<e&&(e=s,l=m);}return l}function mt(t,r){return t.data.find(a=>String(a.x)===r)?.y}function Bt(t){for(let r of t)for(let a of r.data)if(typeof a.x=="string")return true;return false}function q({items:t,position:r,onToggle:a}){return jsxRuntime.jsx("div",{className:nt({position:r}),children:t.map(e=>jsxRuntime.jsxs("button",{onClick:()=>a(e.id),className:P("flex items-center gap-1.5 cursor-pointer rounded px-1.5 py-1 text-xs text-primary-700 transition-opacity hover:bg-primary-100 dark:text-primary-300 dark:hover:bg-primary-800",!e.visible&&"opacity-40"),"aria-pressed":e.visible,children:[jsxRuntime.jsx("span",{className:"h-2.5 w-5 rounded-sm shrink-0",style:{background:e.color}}),e.label]},e.id))})}function ye({series:t,xAxis:r,yAxis:a,y2Axis:e,y2Series:l=[],smooth:m=false,showDots:s=true,area:k=false,strokeWidth:p=2,title:V,height:D=300,className:J,legend:B=true,legendPosition:w="bottom",animateOnMount:W=true,emptyText:Xt="No data to display"}){let O=react.useRef(null),pt=react.useRef(null),[ft,ht]=react.useState(600),[X,Q]=react.useState(null),[U,A]=react.useState(null);react.useEffect(()=>{let o=pt.current;if(!o)return;let i=o.getBoundingClientRect().width;i>0&&ht(i);let d=new ResizeObserver(f=>{let u=f[0]?.contentRect.width;u&&u>0&&ht(u);});return d.observe(o),()=>d.disconnect()},[]);let Yt=react.useMemo(()=>t.map(o=>o.id),[t]),{visible:Y,toggle:z,isVisible:T}=Mt(Yt),E=react.useMemo(()=>Tt(t.length),[t.length]),R=react.useMemo(()=>new Map(t.map((o,i)=>[o.id,o.color??E[i]])),[t,E]),gt=react.useMemo(()=>Nt(!!r?.label,!!a?.label,!!e),[r?.label,a?.label,e]),n=react.useMemo(()=>St(ft,D,gt),[ft,D,gt]),b=react.useMemo(()=>Bt(t),[t]),x=react.useMemo(()=>b?Ft(t,Y):[],[t,Y,b]),N=react.useMemo(()=>{if(b){let u=K(x,[n.plotLeft,n.plotRight]);return y=>u(y)}let o=t.flatMap(u=>u.data.map(y=>y.x));if(o.length===0)return ()=>n.plotLeft;let i=Math.min(...o),d=Math.max(...o),f=G([i,d],[n.plotLeft,n.plotRight]);return u=>f(u)},[t,b,x,n]),_=react.useMemo(()=>lt(t,Y,a),[t,Y,a]),S=react.useMemo(()=>G(_,[n.plotBottom,n.plotTop]),[_,n]),xt=react.useMemo(()=>Z(_,a?.tickCount??5),[_,a?.tickCount]),I=react.useMemo(()=>{if(!e)return null;let o=t.filter(i=>l.includes(i.id));return lt(o,Y,e)},[e,t,l,Y]),v=react.useMemo(()=>I?G(I,[n.plotBottom,n.plotTop]):null,[I,n]),It=react.useMemo(()=>I?Z(I,e?.tickCount??5):[],[I,e?.tickCount]),tt=react.useMemo(()=>{if(b)return x;let o=t.flatMap(f=>f.data.map(u=>Number(u.x)));if(o.length===0)return [];let i=Math.min(...o),d=Math.max(...o);return Z([i,d],r?.tickCount??6)},[b,x,t,r?.tickCount]),Pt=react.useCallback(o=>{let i=o.currentTarget.closest("svg");if(!i)return;let d=i.getBoundingClientRect(),f=o.clientX-d.left,u=O.current?.getBoundingClientRect();if(!u)return;let y="",L=f;if(b&&x.length>0){let h=K(x,[n.plotLeft,n.plotRight]),kt=ct(f,x,h);y=x[kt]??"",L=h(y);}else if(!b){let h=tt;y=$((f-n.plotLeft)/n.plotWidth*(h[h.length-1]-h[0])+h[0],r?.format),L=f;}let F=t.filter(h=>T(h.id)).map(h=>{l.includes(h.id)&&v!=null?v:S;let j;if(b)j=mt(h,y);else {let Ht=f,vt=1/0,Ct;for(let Vt of h.data){let jt=N(Vt.x),Lt=Math.abs(jt-Ht);Lt<vt&&(vt=Lt,Ct=Vt.y);}j=Ct;}return {name:h.name,value:j!==void 0?$(j,a?.format):"\u2014",color:R.get(h.id)??"var(--color-chart-1)"}});L>=n.plotLeft&&L<=n.plotRight&&A(L);let et=o.clientX-u.left+12,M=o.clientY-u.top-10;Q({x:et,y:M,label:y,items:F});},[b,x,n,t,T,l,v,S,N,tt,r?.format,a?.format,R]),bt=react.useCallback(()=>{Q(null),A(null);},[]),yt=react.useCallback(o=>{o.preventDefault();let i=o.touches[0];if(!i)return;let d=o.currentTarget.closest("svg");if(!d)return;let f=d.getBoundingClientRect(),u=O.current?.getBoundingClientRect();if(!u)return;let y=i.clientX-f.left,L=y,F="";if(b&&x.length>0){let M=K(x,[n.plotLeft,n.plotRight]),h=ct(y,x,M);F=x[h]??"",L=M(F);}L>=n.plotLeft&&L<=n.plotRight&&A(L);let et=t.filter(M=>T(M.id)).map(M=>({name:M.name,value:b&&F?$(mt(M,F)??0,a?.format):"\u2014",color:R.get(M.id)??"var(--color-chart-1)"}));Q({x:i.clientX-u.left+12,y:i.clientY-u.top-10,label:F,items:et});},[b,x,n,t,T,a?.format,R]),H=react.useMemo(()=>t.map((o,i)=>({id:o.id,label:o.name,color:o.color??E[i],visible:T(o.id)})),[t,E,T]),zt=t.some(o=>o.data.length>0),Et=jsxRuntime.jsxs("svg",{role:"img","aria-label":V??"Line chart",width:n.width,height:n.height,viewBox:`0 0 ${n.width} ${n.height}`,shapeRendering:"geometricPrecision",children:[a?.gridLines!==false&&xt.map(o=>{let i=S(o);return jsxRuntime.jsx("line",{x1:n.plotLeft,x2:n.plotRight,y1:i,y2:i,stroke:"currentColor",strokeWidth:.5,strokeDasharray:"4 4",className:"text-secondary-200 dark:text-secondary-700"},o)}),k&&t.map(o=>{if(!T(o.id)||o.data.length===0)return null;let d=l.includes(o.id)&&v!=null?v:S,f=R.get(o.id)??"var(--color-chart-1)",u=Dt(o.data,N,d,m,n.plotBottom);return jsxRuntime.jsx("path",{d:u,fill:f,fillOpacity:.15,stroke:"none",className:W?"chart-area-animate":""},`area-${o.id}`)}),t.map(o=>{if(!T(o.id)||o.data.length===0)return null;let d=l.includes(o.id)&&v!=null?v:S,f=R.get(o.id)??"var(--color-chart-1)";return m?jsxRuntime.jsx("path",{d:st(o.data,N,d),fill:"none",stroke:f,strokeWidth:p,strokeLinecap:"round",strokeLinejoin:"round",className:W?"chart-line-animate":""},o.id):jsxRuntime.jsx("polyline",{points:$t(o.data,N,d),fill:"none",stroke:f,strokeWidth:p,strokeLinecap:"round",strokeLinejoin:"round",className:W?"chart-line-animate":""},o.id)}),s&&t.map(o=>{if(!T(o.id))return null;let d=l.includes(o.id)&&v!=null?v:S,f=R.get(o.id)??"var(--color-chart-1)";return o.data.map((u,y)=>jsxRuntime.jsx("circle",{cx:N(u.x),cy:d(u.y),r:3,fill:f,stroke:"white",strokeWidth:1.5,className:P("chart-dot",W?"chart-dot-animate":"")},`${o.id}-${y}`))}),U!=null&&jsxRuntime.jsx("line",{className:"chart-crosshair",x1:U,x2:U,y1:n.plotTop,y2:n.plotBottom,stroke:"currentColor",strokeWidth:1,strokeDasharray:"4 4",opacity:.5,style:{color:"var(--color-secondary-400)"}}),jsxRuntime.jsx("line",{x1:n.plotLeft,x2:n.plotLeft,y1:n.plotTop,y2:n.plotBottom,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),xt.map(o=>{let i=S(o);return jsxRuntime.jsxs("g",{children:[jsxRuntime.jsx("line",{x1:n.plotLeft-4,x2:n.plotLeft,y1:i,y2:i,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsxRuntime.jsx("text",{x:n.plotLeft-6,y:i,textAnchor:"end",dominantBaseline:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:$(o,a?.format)})]},o)}),a?.label&&jsxRuntime.jsx("text",{x:-(n.plotTop+n.plotHeight/2),y:14,textAnchor:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-600 dark:text-secondary-400",transform:"rotate(-90)",children:a.label}),e&&v&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("line",{x1:n.plotRight,x2:n.plotRight,y1:n.plotTop,y2:n.plotBottom,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),It.map(o=>{let i=v(o);return jsxRuntime.jsxs("g",{children:[jsxRuntime.jsx("line",{x1:n.plotRight,x2:n.plotRight+4,y1:i,y2:i,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsxRuntime.jsx("text",{x:n.plotRight+6,y:i,textAnchor:"start",dominantBaseline:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:$(o,e?.format)})]},o)}),e?.label&&jsxRuntime.jsx("text",{x:n.plotTop+n.plotHeight/2,y:-(n.width-14),textAnchor:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-600 dark:text-secondary-400",transform:"rotate(90)",children:e.label})]}),jsxRuntime.jsx("line",{x1:n.plotLeft,x2:n.plotRight,y1:n.plotBottom,y2:n.plotBottom,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),(b?x:tt).map((o,i)=>{let d=N(o);return jsxRuntime.jsxs("g",{children:[jsxRuntime.jsx("line",{x1:d,x2:d,y1:n.plotBottom,y2:n.plotBottom+4,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsxRuntime.jsx("text",{x:d,y:n.plotBottom+14,textAnchor:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:$(o,r?.format)})]},i)}),r?.label&&jsxRuntime.jsx("text",{x:n.plotLeft+n.plotWidth/2,y:n.height-4,textAnchor:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-600 dark:text-secondary-400",children:r.label}),jsxRuntime.jsx("rect",{x:n.plotLeft,y:n.plotTop,width:n.plotWidth,height:n.plotHeight,fill:"transparent",onMouseMove:Pt,onMouseLeave:bt,onTouchStart:yt,onTouchMove:yt,onTouchEnd:bt,style:{cursor:"crosshair"}})]}),_t=w==="left"||w==="right";return jsxRuntime.jsxs("div",{ref:O,className:P(rt(),J),children:[V&&jsxRuntime.jsx("h3",{className:"mb-2 text-sm font-semibold text-primary-700 dark:text-primary-200",children:V}),B&&w==="top"&&jsxRuntime.jsx(q,{items:H,position:"top",onToggle:z}),jsxRuntime.jsxs("div",{className:P("flex items-start",_t&&"gap-0"),children:[B&&w==="left"&&jsxRuntime.jsx(q,{items:H,position:"left",onToggle:z}),jsxRuntime.jsx("div",{ref:pt,className:"flex-1 min-w-0 overflow-hidden",children:zt?Et:jsxRuntime.jsx("div",{className:"flex items-center justify-center text-secondary-400 dark:text-secondary-500",style:{height:D},children:Xt})}),B&&w==="right"&&jsxRuntime.jsx(q,{items:H,position:"right",onToggle:z})]}),B&&w==="bottom"&&jsxRuntime.jsx(q,{items:H,position:"bottom",onToggle:z}),X&&jsxRuntime.jsxs("div",{className:at(),style:{left:X.x,top:X.y},role:"tooltip",children:[X.label&&jsxRuntime.jsx("div",{className:"mb-1 font-medium text-primary-200",children:X.label}),X.items.map((o,i)=>jsxRuntime.jsxs("div",{className:"flex items-center gap-1.5",children:[jsxRuntime.jsx("span",{className:"h-2 w-2 rounded-full shrink-0",style:{background:o.color}}),jsxRuntime.jsxs("span",{className:"text-primary-300",children:[o.name,":"]}),jsxRuntime.jsx("span",{className:"font-medium",children:o.value})]},i))]})]})}exports.LineChart=ye;
@@ -0,0 +1 @@
1
+ @keyframes chart-line-draw{0%{stroke-dashoffset:3000}to{stroke-dashoffset:0}}@keyframes chart-dot-pop{0%{r:0;opacity:0}to{opacity:1}}@keyframes chart-area-fade{0%{opacity:0}to{opacity:1}}.chart-line-animate{stroke-dasharray:3000;stroke-dashoffset:3000;animation:chart-line-draw 1s ease-out forwards}.chart-line-animate:nth-child(2){animation-delay:.1s}.chart-line-animate:nth-child(3){animation-delay:.2s}.chart-line-animate:nth-child(4){animation-delay:.3s}.chart-line-animate:nth-child(5){animation-delay:.4s}.chart-area-animate{animation:chart-area-fade .8s ease-out forwards;opacity:0}.chart-dot-animate{animation:chart-dot-pop .4s ease-out forwards;animation-delay:.8s;opacity:0}circle.chart-dot{transition:r .15s ease,filter .15s ease;cursor:crosshair}circle.chart-dot:hover,circle.chart-dot.chart-dot--active{filter:drop-shadow(0 0 4px currentColor)}.chart-crosshair{pointer-events:none;transition:opacity .1s ease}
@@ -0,0 +1,2 @@
1
+ export { LineChart_alias_3 as LineChart } from '../_tsup-dts-rollup.cjs';
2
+ export { LineChartProps_alias_1 as LineChartProps } from '../_tsup-dts-rollup.cjs';
@@ -0,0 +1,2 @@
1
+ export { LineChart_alias_3 as LineChart } from '../_tsup-dts-rollup.js';
2
+ export { LineChartProps_alias_1 as LineChartProps } from '../_tsup-dts-rollup.js';
@@ -0,0 +1 @@
1
+ import {useRef,useState,useEffect,useMemo,useCallback}from'react';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {cva}from'class-variance-authority';import {jsxs,jsx,Fragment}from'react/jsx-runtime';function P(...t){return twMerge(clsx(t))}var rt=cva("relative w-full font-sans select-none",{variants:{size:{sm:"text-xs",md:"text-sm",lg:"text-base"}},defaultVariants:{size:"md"}}),nt=cva("flex flex-wrap gap-3 items-center justify-center",{variants:{position:{top:"mb-3",bottom:"mt-3",left:"flex-col mr-4",right:"flex-col ml-4"}},defaultVariants:{position:"bottom"}}),at=cva("absolute z-50 pointer-events-none px-3 py-2 rounded-lg text-xs shadow-lg border transition-opacity duration-150 bg-primary-900 text-primary-50 border-primary-700 dark:bg-primary-950 dark:border-primary-800");function Mt(t){let[r,a]=useState(()=>new Set(t)),e=useCallback(s=>{a(k=>{let p=new Set(k);return p.has(s)?p.delete(s):p.add(s),p});},[]),l=useCallback(s=>r.has(s),[r]),m=useCallback(()=>{a(new Set(t));},[t]);return {visible:r,toggle:e,isVisible:l,showAll:m}}function Tt(t){let r=["var(--color-chart-1)","var(--color-chart-2)","var(--color-chart-3)","var(--color-chart-4)","var(--color-chart-5)","var(--color-chart-6)","var(--color-chart-7)","var(--color-chart-8)"];return Array.from({length:t},(a,e)=>r[e%r.length])}function wt(t,r,a=.1){if(t===r)return [t-1,r+1];let l=(r-t)*a;return [Math.floor(t-l),Math.ceil(r+l)]}function Rt(t,r,a){if(a<=1)return [t];let e=(r-t)/(a-1);return Array.from({length:a},(l,m)=>+(t+m*e).toFixed(10))}function $(t,r){return r?r(t):typeof t=="number"?Math.abs(t)>=1e6?`${(t/1e6).toFixed(1)}M`:Math.abs(t)>=1e3?`${(t/1e3).toFixed(1)}K`:Number.isInteger(t)?t.toString():t.toFixed(2):String(t)}function Nt(t,r,a){return {top:20,right:a?65:20,bottom:t?52:36,left:r?65:52}}function St(t,r,a){let e=Math.max(t,120);return {width:e,height:r,margins:a,plotLeft:a.left,plotTop:a.top,plotRight:e-a.right,plotBottom:r-a.bottom,plotWidth:Math.max(e-a.left-a.right,10),plotHeight:Math.max(r-a.top-a.bottom,10)}}function Ft(t,r){let a=new Set,e=[];for(let l of t)if(r.has(l.id))for(let m of l.data){let s=String(m.x);a.has(s)||(a.add(s),e.push(s));}return e}function lt(t,r,a){let e=1/0,l=-1/0;for(let k of t)if(r.has(k.id))for(let p of k.data)p.y<e&&(e=p.y),p.y>l&&(l=p.y);if(!isFinite(e))return [0,1];let[m,s]=wt(e,l);return [a?.min??m,a?.max??s]}function G(t,r){let[a,e]=t,[l,m]=r;return e===a?()=>(l+m)/2:s=>l+(s-a)/(e-a)*(m-l)}function K(t,r){let a=t.length;if(a===0)return ()=>(r[0]+r[1])/2;let e=(r[1]-r[0])/a;return l=>{let m=t.indexOf(l);return m<0?(r[0]+r[1])/2:r[0]+m*e+e/2}}function $t(t,r,a){return t.map(e=>`${r(e.x).toFixed(2)},${a(e.y).toFixed(2)}`).join(" ")}function st(t,r,a){if(t.length===0)return "";let e=t.map(s=>({x:r(s.x),y:a(s.y)}));if(e.length===1)return `M ${e[0].x.toFixed(2)} ${e[0].y.toFixed(2)}`;let l=.5,m=`M ${e[0].x.toFixed(2)} ${e[0].y.toFixed(2)}`;for(let s=0;s<e.length-1;s++){let k=s===0?{x:2*e[0].x-e[1].x,y:2*e[0].y-e[1].y}:e[s-1],p=e[s],V=e[s+1],D=s+2<e.length?e[s+2]:{x:2*e[e.length-1].x-e[e.length-2].x,y:2*e[e.length-1].y-e[e.length-2].y},J=p.x+(V.x-k.x)*l/3,B=p.y+(V.y-k.y)*l/3,w=V.x-(D.x-p.x)*l/3,W=V.y-(D.y-p.y)*l/3;m+=` C ${J.toFixed(2)} ${B.toFixed(2)}, ${w.toFixed(2)} ${W.toFixed(2)}, ${V.x.toFixed(2)} ${V.y.toFixed(2)}`;}return m}function Dt(t,r,a,e,l){if(t.length===0)return "";let m=e?st(t,r,a):`M ${t.map(p=>`${r(p.x).toFixed(2)},${a(p.y).toFixed(2)}`).join(" L ")}`,s=r(t[t.length-1].x).toFixed(2),k=r(t[0].x).toFixed(2);return `${m} L ${s},${l.toFixed(2)} L ${k},${l.toFixed(2)} Z`}function Z(t,r=5){return Rt(t[0],t[1],r)}function ct(t,r,a){if(r.length===0)return -1;let e=1/0,l=0;for(let m=0;m<r.length;m++){let s=Math.abs(a(r[m])-t);s<e&&(e=s,l=m);}return l}function mt(t,r){return t.data.find(a=>String(a.x)===r)?.y}function Bt(t){for(let r of t)for(let a of r.data)if(typeof a.x=="string")return true;return false}function q({items:t,position:r,onToggle:a}){return jsx("div",{className:nt({position:r}),children:t.map(e=>jsxs("button",{onClick:()=>a(e.id),className:P("flex items-center gap-1.5 cursor-pointer rounded px-1.5 py-1 text-xs text-primary-700 transition-opacity hover:bg-primary-100 dark:text-primary-300 dark:hover:bg-primary-800",!e.visible&&"opacity-40"),"aria-pressed":e.visible,children:[jsx("span",{className:"h-2.5 w-5 rounded-sm shrink-0",style:{background:e.color}}),e.label]},e.id))})}function ye({series:t,xAxis:r,yAxis:a,y2Axis:e,y2Series:l=[],smooth:m=false,showDots:s=true,area:k=false,strokeWidth:p=2,title:V,height:D=300,className:J,legend:B=true,legendPosition:w="bottom",animateOnMount:W=true,emptyText:Xt="No data to display"}){let O=useRef(null),pt=useRef(null),[ft,ht]=useState(600),[X,Q]=useState(null),[U,A]=useState(null);useEffect(()=>{let o=pt.current;if(!o)return;let i=o.getBoundingClientRect().width;i>0&&ht(i);let d=new ResizeObserver(f=>{let u=f[0]?.contentRect.width;u&&u>0&&ht(u);});return d.observe(o),()=>d.disconnect()},[]);let Yt=useMemo(()=>t.map(o=>o.id),[t]),{visible:Y,toggle:z,isVisible:T}=Mt(Yt),E=useMemo(()=>Tt(t.length),[t.length]),R=useMemo(()=>new Map(t.map((o,i)=>[o.id,o.color??E[i]])),[t,E]),gt=useMemo(()=>Nt(!!r?.label,!!a?.label,!!e),[r?.label,a?.label,e]),n=useMemo(()=>St(ft,D,gt),[ft,D,gt]),b=useMemo(()=>Bt(t),[t]),x=useMemo(()=>b?Ft(t,Y):[],[t,Y,b]),N=useMemo(()=>{if(b){let u=K(x,[n.plotLeft,n.plotRight]);return y=>u(y)}let o=t.flatMap(u=>u.data.map(y=>y.x));if(o.length===0)return ()=>n.plotLeft;let i=Math.min(...o),d=Math.max(...o),f=G([i,d],[n.plotLeft,n.plotRight]);return u=>f(u)},[t,b,x,n]),_=useMemo(()=>lt(t,Y,a),[t,Y,a]),S=useMemo(()=>G(_,[n.plotBottom,n.plotTop]),[_,n]),xt=useMemo(()=>Z(_,a?.tickCount??5),[_,a?.tickCount]),I=useMemo(()=>{if(!e)return null;let o=t.filter(i=>l.includes(i.id));return lt(o,Y,e)},[e,t,l,Y]),v=useMemo(()=>I?G(I,[n.plotBottom,n.plotTop]):null,[I,n]),It=useMemo(()=>I?Z(I,e?.tickCount??5):[],[I,e?.tickCount]),tt=useMemo(()=>{if(b)return x;let o=t.flatMap(f=>f.data.map(u=>Number(u.x)));if(o.length===0)return [];let i=Math.min(...o),d=Math.max(...o);return Z([i,d],r?.tickCount??6)},[b,x,t,r?.tickCount]),Pt=useCallback(o=>{let i=o.currentTarget.closest("svg");if(!i)return;let d=i.getBoundingClientRect(),f=o.clientX-d.left,u=O.current?.getBoundingClientRect();if(!u)return;let y="",L=f;if(b&&x.length>0){let h=K(x,[n.plotLeft,n.plotRight]),kt=ct(f,x,h);y=x[kt]??"",L=h(y);}else if(!b){let h=tt;y=$((f-n.plotLeft)/n.plotWidth*(h[h.length-1]-h[0])+h[0],r?.format),L=f;}let F=t.filter(h=>T(h.id)).map(h=>{l.includes(h.id)&&v!=null?v:S;let j;if(b)j=mt(h,y);else {let Ht=f,vt=1/0,Ct;for(let Vt of h.data){let jt=N(Vt.x),Lt=Math.abs(jt-Ht);Lt<vt&&(vt=Lt,Ct=Vt.y);}j=Ct;}return {name:h.name,value:j!==void 0?$(j,a?.format):"\u2014",color:R.get(h.id)??"var(--color-chart-1)"}});L>=n.plotLeft&&L<=n.plotRight&&A(L);let et=o.clientX-u.left+12,M=o.clientY-u.top-10;Q({x:et,y:M,label:y,items:F});},[b,x,n,t,T,l,v,S,N,tt,r?.format,a?.format,R]),bt=useCallback(()=>{Q(null),A(null);},[]),yt=useCallback(o=>{o.preventDefault();let i=o.touches[0];if(!i)return;let d=o.currentTarget.closest("svg");if(!d)return;let f=d.getBoundingClientRect(),u=O.current?.getBoundingClientRect();if(!u)return;let y=i.clientX-f.left,L=y,F="";if(b&&x.length>0){let M=K(x,[n.plotLeft,n.plotRight]),h=ct(y,x,M);F=x[h]??"",L=M(F);}L>=n.plotLeft&&L<=n.plotRight&&A(L);let et=t.filter(M=>T(M.id)).map(M=>({name:M.name,value:b&&F?$(mt(M,F)??0,a?.format):"\u2014",color:R.get(M.id)??"var(--color-chart-1)"}));Q({x:i.clientX-u.left+12,y:i.clientY-u.top-10,label:F,items:et});},[b,x,n,t,T,a?.format,R]),H=useMemo(()=>t.map((o,i)=>({id:o.id,label:o.name,color:o.color??E[i],visible:T(o.id)})),[t,E,T]),zt=t.some(o=>o.data.length>0),Et=jsxs("svg",{role:"img","aria-label":V??"Line chart",width:n.width,height:n.height,viewBox:`0 0 ${n.width} ${n.height}`,shapeRendering:"geometricPrecision",children:[a?.gridLines!==false&&xt.map(o=>{let i=S(o);return jsx("line",{x1:n.plotLeft,x2:n.plotRight,y1:i,y2:i,stroke:"currentColor",strokeWidth:.5,strokeDasharray:"4 4",className:"text-secondary-200 dark:text-secondary-700"},o)}),k&&t.map(o=>{if(!T(o.id)||o.data.length===0)return null;let d=l.includes(o.id)&&v!=null?v:S,f=R.get(o.id)??"var(--color-chart-1)",u=Dt(o.data,N,d,m,n.plotBottom);return jsx("path",{d:u,fill:f,fillOpacity:.15,stroke:"none",className:W?"chart-area-animate":""},`area-${o.id}`)}),t.map(o=>{if(!T(o.id)||o.data.length===0)return null;let d=l.includes(o.id)&&v!=null?v:S,f=R.get(o.id)??"var(--color-chart-1)";return m?jsx("path",{d:st(o.data,N,d),fill:"none",stroke:f,strokeWidth:p,strokeLinecap:"round",strokeLinejoin:"round",className:W?"chart-line-animate":""},o.id):jsx("polyline",{points:$t(o.data,N,d),fill:"none",stroke:f,strokeWidth:p,strokeLinecap:"round",strokeLinejoin:"round",className:W?"chart-line-animate":""},o.id)}),s&&t.map(o=>{if(!T(o.id))return null;let d=l.includes(o.id)&&v!=null?v:S,f=R.get(o.id)??"var(--color-chart-1)";return o.data.map((u,y)=>jsx("circle",{cx:N(u.x),cy:d(u.y),r:3,fill:f,stroke:"white",strokeWidth:1.5,className:P("chart-dot",W?"chart-dot-animate":"")},`${o.id}-${y}`))}),U!=null&&jsx("line",{className:"chart-crosshair",x1:U,x2:U,y1:n.plotTop,y2:n.plotBottom,stroke:"currentColor",strokeWidth:1,strokeDasharray:"4 4",opacity:.5,style:{color:"var(--color-secondary-400)"}}),jsx("line",{x1:n.plotLeft,x2:n.plotLeft,y1:n.plotTop,y2:n.plotBottom,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),xt.map(o=>{let i=S(o);return jsxs("g",{children:[jsx("line",{x1:n.plotLeft-4,x2:n.plotLeft,y1:i,y2:i,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsx("text",{x:n.plotLeft-6,y:i,textAnchor:"end",dominantBaseline:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:$(o,a?.format)})]},o)}),a?.label&&jsx("text",{x:-(n.plotTop+n.plotHeight/2),y:14,textAnchor:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-600 dark:text-secondary-400",transform:"rotate(-90)",children:a.label}),e&&v&&jsxs(Fragment,{children:[jsx("line",{x1:n.plotRight,x2:n.plotRight,y1:n.plotTop,y2:n.plotBottom,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),It.map(o=>{let i=v(o);return jsxs("g",{children:[jsx("line",{x1:n.plotRight,x2:n.plotRight+4,y1:i,y2:i,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsx("text",{x:n.plotRight+6,y:i,textAnchor:"start",dominantBaseline:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:$(o,e?.format)})]},o)}),e?.label&&jsx("text",{x:n.plotTop+n.plotHeight/2,y:-(n.width-14),textAnchor:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-600 dark:text-secondary-400",transform:"rotate(90)",children:e.label})]}),jsx("line",{x1:n.plotLeft,x2:n.plotRight,y1:n.plotBottom,y2:n.plotBottom,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),(b?x:tt).map((o,i)=>{let d=N(o);return jsxs("g",{children:[jsx("line",{x1:d,x2:d,y1:n.plotBottom,y2:n.plotBottom+4,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsx("text",{x:d,y:n.plotBottom+14,textAnchor:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:$(o,r?.format)})]},i)}),r?.label&&jsx("text",{x:n.plotLeft+n.plotWidth/2,y:n.height-4,textAnchor:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-600 dark:text-secondary-400",children:r.label}),jsx("rect",{x:n.plotLeft,y:n.plotTop,width:n.plotWidth,height:n.plotHeight,fill:"transparent",onMouseMove:Pt,onMouseLeave:bt,onTouchStart:yt,onTouchMove:yt,onTouchEnd:bt,style:{cursor:"crosshair"}})]}),_t=w==="left"||w==="right";return jsxs("div",{ref:O,className:P(rt(),J),children:[V&&jsx("h3",{className:"mb-2 text-sm font-semibold text-primary-700 dark:text-primary-200",children:V}),B&&w==="top"&&jsx(q,{items:H,position:"top",onToggle:z}),jsxs("div",{className:P("flex items-start",_t&&"gap-0"),children:[B&&w==="left"&&jsx(q,{items:H,position:"left",onToggle:z}),jsx("div",{ref:pt,className:"flex-1 min-w-0 overflow-hidden",children:zt?Et:jsx("div",{className:"flex items-center justify-center text-secondary-400 dark:text-secondary-500",style:{height:D},children:Xt})}),B&&w==="right"&&jsx(q,{items:H,position:"right",onToggle:z})]}),B&&w==="bottom"&&jsx(q,{items:H,position:"bottom",onToggle:z}),X&&jsxs("div",{className:at(),style:{left:X.x,top:X.y},role:"tooltip",children:[X.label&&jsx("div",{className:"mb-1 font-medium text-primary-200",children:X.label}),X.items.map((o,i)=>jsxs("div",{className:"flex items-center gap-1.5",children:[jsx("span",{className:"h-2 w-2 rounded-full shrink-0",style:{background:o.color}}),jsxs("span",{className:"text-primary-300",children:[o.name,":"]}),jsx("span",{className:"font-medium",children:o.value})]},i))]})]})}export{ye as LineChart};
@@ -0,0 +1 @@
1
+ 'use strict';var react=require('react'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),classVarianceAuthority=require('class-variance-authority'),jsxRuntime=require('react/jsx-runtime');function B(...n){return tailwindMerge.twMerge(clsx.clsx(n))}var lt=classVarianceAuthority.cva("relative w-full font-sans select-none",{variants:{size:{sm:"text-xs",md:"text-sm",lg:"text-base"}},defaultVariants:{size:"md"}}),dt=classVarianceAuthority.cva("flex flex-wrap gap-3 items-center justify-center",{variants:{position:{top:"mb-3",bottom:"mt-3",left:"flex-col mr-4",right:"flex-col ml-4"}},defaultVariants:{position:"bottom"}}),mt=classVarianceAuthority.cva("absolute z-50 pointer-events-none px-3 py-2 rounded-lg text-xs shadow-lg border transition-opacity duration-150 bg-primary-900 text-primary-50 border-primary-700 dark:bg-primary-950 dark:border-primary-800");function Vt(n){let[l,h]=react.useState(()=>new Set(n)),a=react.useCallback(u=>{h(C=>{let A=new Set(C);return A.has(u)?A.delete(u):A.add(u),A});},[]),g=react.useCallback(u=>l.has(u),[l]),p=react.useCallback(()=>{h(new Set(n));},[n]);return {visible:l,toggle:a,isVisible:g,showAll:p}}function wt(n){let l=["var(--color-chart-1)","var(--color-chart-2)","var(--color-chart-3)","var(--color-chart-4)","var(--color-chart-5)","var(--color-chart-6)","var(--color-chart-7)","var(--color-chart-8)"];return Array.from({length:n},(h,a)=>l[a%l.length])}function tt(n,l){return l?l(n):typeof n=="number"?Math.abs(n)>=1e6?`${(n/1e6).toFixed(1)}M`:Math.abs(n)>=1e3?`${(n/1e3).toFixed(1)}K`:Number.isInteger(n)?n.toString():n.toFixed(2):String(n)}function k(n,l,h,a){let g=(a-90)*Math.PI/180;return {x:n+h*Math.cos(g),y:l+h*Math.sin(g)}}function kt(n,l,h,a,g,p,u,C,A){let z=n.filter(m=>l.has(m.id)),L=z.reduce((m,F)=>m+F.value,0);if(L===0)return [];let H=new Map(n.map((m,F)=>[m.id,m.color??h[F%h.length]])),j=[],E=C;for(let m of z){let F=m.value/L*360,G=A/2,b=E+G,M=E+F-G,ot=(b+M)/2,T;if(Math.abs(M-b)>=359.9){let f=k(p,u,a,b),$=k(p,u,a,b+180);T=`M ${f.x.toFixed(3)} ${f.y.toFixed(3)} A ${a} ${a} 0 1 1 ${$.x.toFixed(3)} ${$.y.toFixed(3)} A ${a} ${a} 0 1 1 ${f.x.toFixed(3)} ${f.y.toFixed(3)} Z`;}else if(g>0){let f=k(p,u,a,b),$=k(p,u,a,M),S=k(p,u,g,M),R=k(p,u,g,b),P=M-b>180?1:0;T=`M ${f.x.toFixed(3)} ${f.y.toFixed(3)} A ${a} ${a} 0 ${P} 1 ${$.x.toFixed(3)} ${$.y.toFixed(3)} L ${S.x.toFixed(3)} ${S.y.toFixed(3)} A ${g} ${g} 0 ${P} 0 ${R.x.toFixed(3)} ${R.y.toFixed(3)} Z`;}else {let f=k(p,u,a,b),$=k(p,u,a,M),S=M-b>180?1:0;T=`M ${p.toFixed(3)} ${u.toFixed(3)} L ${f.x.toFixed(3)} ${f.y.toFixed(3)} A ${a} ${a} 0 ${S} 1 ${$.x.toFixed(3)} ${$.y.toFixed(3)} Z`;}j.push({id:m.id,label:m.label,value:m.value,percent:Math.round(m.value/L*1e3)/10,color:H.get(m.id)??"var(--color-chart-1)",startAngle:b,endAngle:M,midAngle:ot,path:T,outerR:a,innerR:g,cx:p,cy:u}),E+=F;}return j}function Mt(n,l){let h=(n-90)*Math.PI/180;return {dx:Math.cos(h)*l,dy:Math.sin(h)*l}}function rt({items:n,position:l,onToggle:h}){return jsxRuntime.jsx("div",{className:dt({position:l}),children:n.map(a=>jsxRuntime.jsxs("button",{onClick:()=>h(a.id),className:B("flex items-center gap-1.5 cursor-pointer rounded px-1.5 py-1 text-xs text-primary-700 transition-opacity hover:bg-primary-100 dark:text-primary-300 dark:hover:bg-primary-800",!a.visible&&"opacity-40"),"aria-pressed":a.visible,children:[jsxRuntime.jsx("span",{className:"h-2.5 w-2.5 rounded-full shrink-0",style:{background:a.color}}),jsxRuntime.jsx("span",{children:a.label}),jsxRuntime.jsxs("span",{className:"text-secondary-400",children:["(",a.percent,"%)"]})]},a.id))})}function ce({data:n,donut:l=false,donutThickness:h=.5,startAngle:a=-90,padAngle:g=0,labelType:p="percent",centerLabel:u,centerSubLabel:C,explodeOnHover:A=true,explodeOffset:z=8,title:L,height:H=300,className:j,legend:E=true,legendPosition:m="bottom",animateOnMount:F=true,emptyText:G="No data to display"}){let b=react.useRef(null),M=react.useRef(null),[ot,T]=react.useState(400),[f,$]=react.useState(null),[S,R]=react.useState(null),[P,ft]=react.useState({}),O=react.useRef(null);react.useEffect(()=>{let t=M.current;if(!t)return;let o=t.getBoundingClientRect().width;o>0&&T(o);let r=new ResizeObserver(i=>{let c=i[0]?.contentRect.width;c&&c>0&&T(c);});return r.observe(t),()=>r.disconnect()},[]),react.useEffect(()=>{function t(r){let i=O.current;if(!i)return;"touches"in r&&r.cancelable&&r.preventDefault();let c="touches"in r?r.touches[0]?.clientX??i.startX:r.clientX,w="touches"in r?r.touches[0]?.clientY??i.startY:r.clientY;ft(X=>({...X,[i.id]:{dx:i.origDx+c-i.startX,dy:i.origDy+w-i.startY}}));}function o(){O.current=null;}return window.addEventListener("mousemove",t),window.addEventListener("mouseup",o),window.addEventListener("touchmove",t,{passive:false}),window.addEventListener("touchend",o),()=>{window.removeEventListener("mousemove",t),window.removeEventListener("mouseup",o),window.removeEventListener("touchmove",t),window.removeEventListener("touchend",o);}},[]);let St=react.useMemo(()=>n.map(t=>t.id),[n]),{visible:xt,toggle:Z,isVisible:gt}=Vt(St),K=react.useMemo(()=>wt(n.length),[n.length]),I=10,At=6.4,bt=18,it=14,U=6,at=ot,_=H,N=at/2,D=_/2,Et=p!=="none"?bt+U+4:U+4,st=Math.max(Math.min(N,D)-Et,20),yt=l?st*h:0,V=react.useMemo(()=>kt(n,xt,K,st,yt,N,D,a,g),[n,xt,K,st,yt,N,D,a,g]),Ct=react.useMemo(()=>V.map(t=>t.id).join(","),[V]);react.useEffect(()=>{ft({});},[Ct]);let Lt=react.useCallback((t,o)=>{if(O.current)return;let r=b.current?.getBoundingClientRect();if(!r)return;$(o);let i=V.find(c=>c.id===o);i&&R({x:t.clientX-r.left+12,y:t.clientY-r.top-10,items:[{label:i.label,value:tt(i.value),percent:`${i.percent}%`,color:i.color}]});},[V]),vt=react.useCallback(()=>{$(null),R(null);},[]),$t=react.useCallback((t,o,r)=>{let i=P[t]??{dx:0,dy:0};O.current={id:t,startX:o,startY:r,origDx:i.dx,origDy:i.dy};},[P]),Tt=react.useCallback((t,o)=>{t.preventDefault(),$(o);let r=b.current?.getBoundingClientRect();if(!r)return;let i=t.touches[0];if(!i)return;let c=V.find(w=>w.id===o);c&&R({x:i.clientX-r.left+12,y:i.clientY-r.top-10,items:[{label:c.label,value:tt(c.value),percent:`${c.percent}%`,color:c.color}]});},[V]),q=react.useMemo(()=>{let t=n.reduce((o,r)=>o+r.value,0);return n.map((o,r)=>({id:o.id,label:o.label,color:o.color??K[r],visible:gt(o.id),percent:t>0?Math.round(o.value/t*1e3)/10:0}))},[n,K,gt]),Nt=n.length>0&&n.some(t=>t.value>0),Dt=m==="left"||m==="right",Xt=react.useMemo(()=>{if(p==="none")return [];let t=I+3,o=U+I*.5,r=_-U-I*.5,i=V.filter(e=>e.percent>=3).map(e=>{let x="";switch(p){case "percent":x=`${e.percent}%`;break;case "value":x=tt(e.value);break;case "label":x=e.label;break;case "label+percent":x=`${e.label} ${e.percent}%`;break}let Y=k(e.cx,e.cy,e.outerR+2,e.midAngle),y=k(e.cx,e.cy,e.outerR+bt,e.midAngle),s=(e.midAngle-90)*Math.PI/180,J=Math.cos(s)>=0,Q=Math.ceil(x.length*At);return {id:e.id,color:e.color,text:x,textW:Q,p1:Y,elbowX:y.x,y:y.y,isRight:J}}),c=i.filter(e=>e.isRight).sort((e,x)=>e.y-x.y),w=i.filter(e=>!e.isRight).sort((e,x)=>e.y-x.y);function X(e){if(e.length!==0)for(let x=0;x<20;x++){let Y=false;for(let s=1;s<e.length;s++){let J=e[s].y-e[s-1].y;if(J<t){let Q=(t-J)/2;e[s-1].y-=Q,e[s].y+=Q,Y=true;}}e[0].y<o&&(e[0].y=o);for(let s=1;s<e.length;s++)e[s].y<e[s-1].y+t&&(e[s].y=e[s-1].y+t);let y=e.length-1;e[y].y>r&&(e[y].y=r);for(let s=y-1;s>=0;s--)e[s].y>e[s+1].y-t&&(e[s].y=e[s+1].y-t);for(let s of e)s.y=Math.max(o,Math.min(r,s.y));if(!Y)break}}return X(c),X(w),[...w,...c]},[V,p,_]),Rt=jsxRuntime.jsxs("svg",{role:"img","aria-label":L??"Pie chart",width:at,height:_,viewBox:`0 0 ${at} ${_}`,shapeRendering:"geometricPrecision",children:[jsxRuntime.jsxs("g",{className:F?"chart-pie-animate":"",children:[V.map((t,o)=>{let r=f===t.id,i=A&&r,c=Mt(t.midAngle,i?z:0);return jsxRuntime.jsx("path",{d:t.path,fill:t.color,transform:i?`translate(${c.dx}, ${c.dy})`:void 0,className:B("chart-slice",F&&`chart-slice-animate-${Math.min(o,7)}`,r&&"chart-slice--exploded"),stroke:t.color,strokeWidth:.6,onMouseMove:w=>Lt(w,t.id),onMouseLeave:vt,onTouchStart:w=>Tt(w,t.id),onTouchEnd:vt,"aria-label":`${t.label}: ${t.percent}%`},t.id)}),Xt.map(t=>{let o=P[t.id]??{dx:0,dy:0},r=t.elbowX+o.dx,i=t.y+o.dy,c=r+(t.isRight?it:-it),w=t.isRight?c+3:c-3,X=it+3+t.textW+6,e=t.isRight?r:r-X,x=i-I-2,Y=I*2+4;return jsxRuntime.jsxs("g",{style:{userSelect:"none"},children:[jsxRuntime.jsx("polyline",{points:[`${t.p1.x.toFixed(2)},${t.p1.y.toFixed(2)}`,`${r.toFixed(2)},${i.toFixed(2)}`,`${c.toFixed(2)},${i.toFixed(2)}`].join(" "),fill:"none",stroke:t.color,strokeWidth:1.2,opacity:.85,strokeLinejoin:"round",strokeLinecap:"round",style:{pointerEvents:"none"}}),jsxRuntime.jsx("text",{x:w.toFixed(2),y:i.toFixed(2),textAnchor:t.isRight?"start":"end",dominantBaseline:"middle",fontSize:I,fill:"currentColor",className:"text-primary-700 dark:text-primary-300",style:{pointerEvents:"none"},children:t.text}),jsxRuntime.jsx("rect",{x:e,y:x,width:X,height:Y,fill:"transparent",style:{cursor:"grab",touchAction:"none"},onMouseDown:y=>{y.stopPropagation(),$t(t.id,y.clientX,y.clientY);},onTouchStart:y=>{y.stopPropagation();let s=y.touches[0];s&&$t(t.id,s.clientX,s.clientY);}})]},`label-${t.id}`)})]}),l&&jsxRuntime.jsx("g",{style:{pointerEvents:"none"},children:f&&V.find(t=>t.id===f)?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("text",{x:N,y:D-8,textAnchor:"middle",dominantBaseline:"middle",fontSize:18,fontWeight:600,fill:"currentColor",className:"text-primary-800 dark:text-primary-100",children:[V.find(t=>t.id===f)?.percent,"%"]}),jsxRuntime.jsx("text",{x:N,y:D+12,textAnchor:"middle",dominantBaseline:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:V.find(t=>t.id===f)?.label})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[u&&jsxRuntime.jsx("text",{x:N,y:D-(C?8:0),textAnchor:"middle",dominantBaseline:"middle",fontSize:16,fontWeight:600,fill:"currentColor",className:"text-primary-800 dark:text-primary-100",children:u}),C&&jsxRuntime.jsx("text",{x:N,y:D+14,textAnchor:"middle",dominantBaseline:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:C})]})})]});return jsxRuntime.jsxs("div",{ref:b,className:B(lt(),j),children:[L&&jsxRuntime.jsx("h3",{className:"mb-2 text-sm font-semibold text-primary-700 dark:text-primary-200",children:L}),E&&m==="top"&&jsxRuntime.jsx(rt,{items:q,position:"top",onToggle:Z}),jsxRuntime.jsxs("div",{className:B("flex items-start justify-center",Dt&&"gap-0"),children:[E&&m==="left"&&jsxRuntime.jsx(rt,{items:q,position:"left",onToggle:Z}),jsxRuntime.jsx("div",{ref:M,className:"flex-1 min-w-0 overflow-hidden",children:Nt?Rt:jsxRuntime.jsx("div",{className:"flex items-center justify-center text-secondary-400 dark:text-secondary-500",style:{height:H},children:G})}),E&&m==="right"&&jsxRuntime.jsx(rt,{items:q,position:"right",onToggle:Z})]}),E&&m==="bottom"&&jsxRuntime.jsx(rt,{items:q,position:"bottom",onToggle:Z}),S&&jsxRuntime.jsx("div",{className:mt(),style:{left:S.x,top:S.y},role:"tooltip",children:S.items.map((t,o)=>jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{className:"h-2.5 w-2.5 rounded-full shrink-0",style:{background:t.color}}),jsxRuntime.jsxs("span",{className:"font-medium",children:[t.label,":"]}),jsxRuntime.jsx("span",{children:t.value}),jsxRuntime.jsxs("span",{className:"text-primary-300",children:["(",t.percent,")"]})]},o))})]})}exports.PieChart=ce;
@@ -0,0 +1 @@
1
+ @keyframes chart-pie-scale-in{0%{transform:scale(0);opacity:0}to{transform:scale(1);opacity:1}}@keyframes chart-pie-slice-appear{0%{opacity:0;transform:scale(.7)}to{opacity:1;transform:scale(1)}}.chart-pie-animate{transform-origin:center;animation:chart-pie-scale-in .6s cubic-bezier(.34,1.56,.64,1) forwards}.chart-slice{transform-origin:center;transition:transform .2s ease,filter .15s ease;cursor:pointer}.chart-slice-animate-0{animation:chart-pie-slice-appear .4s ease-out 0s both}.chart-slice-animate-1{animation:chart-pie-slice-appear .4s ease-out .06s both}.chart-slice-animate-2{animation:chart-pie-slice-appear .4s ease-out .12s both}.chart-slice-animate-3{animation:chart-pie-slice-appear .4s ease-out .18s both}.chart-slice-animate-4{animation:chart-pie-slice-appear .4s ease-out .24s both}.chart-slice-animate-5{animation:chart-pie-slice-appear .4s ease-out .3s both}.chart-slice-animate-6{animation:chart-pie-slice-appear .4s ease-out .36s both}.chart-slice-animate-7{animation:chart-pie-slice-appear .4s ease-out .42s both}.chart-slice--exploded{filter:brightness(1.12) drop-shadow(0 4px 8px rgba(0,0,0,.25))}.chart-slice--hidden{opacity:.12;pointer-events:none}
@@ -0,0 +1,2 @@
1
+ export { PieChart_alias_3 as PieChart } from '../_tsup-dts-rollup.cjs';
2
+ export { PieChartProps_alias_1 as PieChartProps } from '../_tsup-dts-rollup.cjs';
@@ -0,0 +1,2 @@
1
+ export { PieChart_alias_3 as PieChart } from '../_tsup-dts-rollup.js';
2
+ export { PieChartProps_alias_1 as PieChartProps } from '../_tsup-dts-rollup.js';
@@ -0,0 +1 @@
1
+ import {useRef,useState,useEffect,useMemo,useCallback}from'react';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {cva}from'class-variance-authority';import {jsxs,jsx,Fragment}from'react/jsx-runtime';function B(...n){return twMerge(clsx(n))}var lt=cva("relative w-full font-sans select-none",{variants:{size:{sm:"text-xs",md:"text-sm",lg:"text-base"}},defaultVariants:{size:"md"}}),dt=cva("flex flex-wrap gap-3 items-center justify-center",{variants:{position:{top:"mb-3",bottom:"mt-3",left:"flex-col mr-4",right:"flex-col ml-4"}},defaultVariants:{position:"bottom"}}),mt=cva("absolute z-50 pointer-events-none px-3 py-2 rounded-lg text-xs shadow-lg border transition-opacity duration-150 bg-primary-900 text-primary-50 border-primary-700 dark:bg-primary-950 dark:border-primary-800");function Vt(n){let[l,h]=useState(()=>new Set(n)),a=useCallback(u=>{h(C=>{let A=new Set(C);return A.has(u)?A.delete(u):A.add(u),A});},[]),g=useCallback(u=>l.has(u),[l]),p=useCallback(()=>{h(new Set(n));},[n]);return {visible:l,toggle:a,isVisible:g,showAll:p}}function wt(n){let l=["var(--color-chart-1)","var(--color-chart-2)","var(--color-chart-3)","var(--color-chart-4)","var(--color-chart-5)","var(--color-chart-6)","var(--color-chart-7)","var(--color-chart-8)"];return Array.from({length:n},(h,a)=>l[a%l.length])}function tt(n,l){return l?l(n):typeof n=="number"?Math.abs(n)>=1e6?`${(n/1e6).toFixed(1)}M`:Math.abs(n)>=1e3?`${(n/1e3).toFixed(1)}K`:Number.isInteger(n)?n.toString():n.toFixed(2):String(n)}function k(n,l,h,a){let g=(a-90)*Math.PI/180;return {x:n+h*Math.cos(g),y:l+h*Math.sin(g)}}function kt(n,l,h,a,g,p,u,C,A){let z=n.filter(m=>l.has(m.id)),L=z.reduce((m,F)=>m+F.value,0);if(L===0)return [];let H=new Map(n.map((m,F)=>[m.id,m.color??h[F%h.length]])),j=[],E=C;for(let m of z){let F=m.value/L*360,G=A/2,b=E+G,M=E+F-G,ot=(b+M)/2,T;if(Math.abs(M-b)>=359.9){let f=k(p,u,a,b),$=k(p,u,a,b+180);T=`M ${f.x.toFixed(3)} ${f.y.toFixed(3)} A ${a} ${a} 0 1 1 ${$.x.toFixed(3)} ${$.y.toFixed(3)} A ${a} ${a} 0 1 1 ${f.x.toFixed(3)} ${f.y.toFixed(3)} Z`;}else if(g>0){let f=k(p,u,a,b),$=k(p,u,a,M),S=k(p,u,g,M),R=k(p,u,g,b),P=M-b>180?1:0;T=`M ${f.x.toFixed(3)} ${f.y.toFixed(3)} A ${a} ${a} 0 ${P} 1 ${$.x.toFixed(3)} ${$.y.toFixed(3)} L ${S.x.toFixed(3)} ${S.y.toFixed(3)} A ${g} ${g} 0 ${P} 0 ${R.x.toFixed(3)} ${R.y.toFixed(3)} Z`;}else {let f=k(p,u,a,b),$=k(p,u,a,M),S=M-b>180?1:0;T=`M ${p.toFixed(3)} ${u.toFixed(3)} L ${f.x.toFixed(3)} ${f.y.toFixed(3)} A ${a} ${a} 0 ${S} 1 ${$.x.toFixed(3)} ${$.y.toFixed(3)} Z`;}j.push({id:m.id,label:m.label,value:m.value,percent:Math.round(m.value/L*1e3)/10,color:H.get(m.id)??"var(--color-chart-1)",startAngle:b,endAngle:M,midAngle:ot,path:T,outerR:a,innerR:g,cx:p,cy:u}),E+=F;}return j}function Mt(n,l){let h=(n-90)*Math.PI/180;return {dx:Math.cos(h)*l,dy:Math.sin(h)*l}}function rt({items:n,position:l,onToggle:h}){return jsx("div",{className:dt({position:l}),children:n.map(a=>jsxs("button",{onClick:()=>h(a.id),className:B("flex items-center gap-1.5 cursor-pointer rounded px-1.5 py-1 text-xs text-primary-700 transition-opacity hover:bg-primary-100 dark:text-primary-300 dark:hover:bg-primary-800",!a.visible&&"opacity-40"),"aria-pressed":a.visible,children:[jsx("span",{className:"h-2.5 w-2.5 rounded-full shrink-0",style:{background:a.color}}),jsx("span",{children:a.label}),jsxs("span",{className:"text-secondary-400",children:["(",a.percent,"%)"]})]},a.id))})}function ce({data:n,donut:l=false,donutThickness:h=.5,startAngle:a=-90,padAngle:g=0,labelType:p="percent",centerLabel:u,centerSubLabel:C,explodeOnHover:A=true,explodeOffset:z=8,title:L,height:H=300,className:j,legend:E=true,legendPosition:m="bottom",animateOnMount:F=true,emptyText:G="No data to display"}){let b=useRef(null),M=useRef(null),[ot,T]=useState(400),[f,$]=useState(null),[S,R]=useState(null),[P,ft]=useState({}),O=useRef(null);useEffect(()=>{let t=M.current;if(!t)return;let o=t.getBoundingClientRect().width;o>0&&T(o);let r=new ResizeObserver(i=>{let c=i[0]?.contentRect.width;c&&c>0&&T(c);});return r.observe(t),()=>r.disconnect()},[]),useEffect(()=>{function t(r){let i=O.current;if(!i)return;"touches"in r&&r.cancelable&&r.preventDefault();let c="touches"in r?r.touches[0]?.clientX??i.startX:r.clientX,w="touches"in r?r.touches[0]?.clientY??i.startY:r.clientY;ft(X=>({...X,[i.id]:{dx:i.origDx+c-i.startX,dy:i.origDy+w-i.startY}}));}function o(){O.current=null;}return window.addEventListener("mousemove",t),window.addEventListener("mouseup",o),window.addEventListener("touchmove",t,{passive:false}),window.addEventListener("touchend",o),()=>{window.removeEventListener("mousemove",t),window.removeEventListener("mouseup",o),window.removeEventListener("touchmove",t),window.removeEventListener("touchend",o);}},[]);let St=useMemo(()=>n.map(t=>t.id),[n]),{visible:xt,toggle:Z,isVisible:gt}=Vt(St),K=useMemo(()=>wt(n.length),[n.length]),I=10,At=6.4,bt=18,it=14,U=6,at=ot,_=H,N=at/2,D=_/2,Et=p!=="none"?bt+U+4:U+4,st=Math.max(Math.min(N,D)-Et,20),yt=l?st*h:0,V=useMemo(()=>kt(n,xt,K,st,yt,N,D,a,g),[n,xt,K,st,yt,N,D,a,g]),Ct=useMemo(()=>V.map(t=>t.id).join(","),[V]);useEffect(()=>{ft({});},[Ct]);let Lt=useCallback((t,o)=>{if(O.current)return;let r=b.current?.getBoundingClientRect();if(!r)return;$(o);let i=V.find(c=>c.id===o);i&&R({x:t.clientX-r.left+12,y:t.clientY-r.top-10,items:[{label:i.label,value:tt(i.value),percent:`${i.percent}%`,color:i.color}]});},[V]),vt=useCallback(()=>{$(null),R(null);},[]),$t=useCallback((t,o,r)=>{let i=P[t]??{dx:0,dy:0};O.current={id:t,startX:o,startY:r,origDx:i.dx,origDy:i.dy};},[P]),Tt=useCallback((t,o)=>{t.preventDefault(),$(o);let r=b.current?.getBoundingClientRect();if(!r)return;let i=t.touches[0];if(!i)return;let c=V.find(w=>w.id===o);c&&R({x:i.clientX-r.left+12,y:i.clientY-r.top-10,items:[{label:c.label,value:tt(c.value),percent:`${c.percent}%`,color:c.color}]});},[V]),q=useMemo(()=>{let t=n.reduce((o,r)=>o+r.value,0);return n.map((o,r)=>({id:o.id,label:o.label,color:o.color??K[r],visible:gt(o.id),percent:t>0?Math.round(o.value/t*1e3)/10:0}))},[n,K,gt]),Nt=n.length>0&&n.some(t=>t.value>0),Dt=m==="left"||m==="right",Xt=useMemo(()=>{if(p==="none")return [];let t=I+3,o=U+I*.5,r=_-U-I*.5,i=V.filter(e=>e.percent>=3).map(e=>{let x="";switch(p){case "percent":x=`${e.percent}%`;break;case "value":x=tt(e.value);break;case "label":x=e.label;break;case "label+percent":x=`${e.label} ${e.percent}%`;break}let Y=k(e.cx,e.cy,e.outerR+2,e.midAngle),y=k(e.cx,e.cy,e.outerR+bt,e.midAngle),s=(e.midAngle-90)*Math.PI/180,J=Math.cos(s)>=0,Q=Math.ceil(x.length*At);return {id:e.id,color:e.color,text:x,textW:Q,p1:Y,elbowX:y.x,y:y.y,isRight:J}}),c=i.filter(e=>e.isRight).sort((e,x)=>e.y-x.y),w=i.filter(e=>!e.isRight).sort((e,x)=>e.y-x.y);function X(e){if(e.length!==0)for(let x=0;x<20;x++){let Y=false;for(let s=1;s<e.length;s++){let J=e[s].y-e[s-1].y;if(J<t){let Q=(t-J)/2;e[s-1].y-=Q,e[s].y+=Q,Y=true;}}e[0].y<o&&(e[0].y=o);for(let s=1;s<e.length;s++)e[s].y<e[s-1].y+t&&(e[s].y=e[s-1].y+t);let y=e.length-1;e[y].y>r&&(e[y].y=r);for(let s=y-1;s>=0;s--)e[s].y>e[s+1].y-t&&(e[s].y=e[s+1].y-t);for(let s of e)s.y=Math.max(o,Math.min(r,s.y));if(!Y)break}}return X(c),X(w),[...w,...c]},[V,p,_]),Rt=jsxs("svg",{role:"img","aria-label":L??"Pie chart",width:at,height:_,viewBox:`0 0 ${at} ${_}`,shapeRendering:"geometricPrecision",children:[jsxs("g",{className:F?"chart-pie-animate":"",children:[V.map((t,o)=>{let r=f===t.id,i=A&&r,c=Mt(t.midAngle,i?z:0);return jsx("path",{d:t.path,fill:t.color,transform:i?`translate(${c.dx}, ${c.dy})`:void 0,className:B("chart-slice",F&&`chart-slice-animate-${Math.min(o,7)}`,r&&"chart-slice--exploded"),stroke:t.color,strokeWidth:.6,onMouseMove:w=>Lt(w,t.id),onMouseLeave:vt,onTouchStart:w=>Tt(w,t.id),onTouchEnd:vt,"aria-label":`${t.label}: ${t.percent}%`},t.id)}),Xt.map(t=>{let o=P[t.id]??{dx:0,dy:0},r=t.elbowX+o.dx,i=t.y+o.dy,c=r+(t.isRight?it:-it),w=t.isRight?c+3:c-3,X=it+3+t.textW+6,e=t.isRight?r:r-X,x=i-I-2,Y=I*2+4;return jsxs("g",{style:{userSelect:"none"},children:[jsx("polyline",{points:[`${t.p1.x.toFixed(2)},${t.p1.y.toFixed(2)}`,`${r.toFixed(2)},${i.toFixed(2)}`,`${c.toFixed(2)},${i.toFixed(2)}`].join(" "),fill:"none",stroke:t.color,strokeWidth:1.2,opacity:.85,strokeLinejoin:"round",strokeLinecap:"round",style:{pointerEvents:"none"}}),jsx("text",{x:w.toFixed(2),y:i.toFixed(2),textAnchor:t.isRight?"start":"end",dominantBaseline:"middle",fontSize:I,fill:"currentColor",className:"text-primary-700 dark:text-primary-300",style:{pointerEvents:"none"},children:t.text}),jsx("rect",{x:e,y:x,width:X,height:Y,fill:"transparent",style:{cursor:"grab",touchAction:"none"},onMouseDown:y=>{y.stopPropagation(),$t(t.id,y.clientX,y.clientY);},onTouchStart:y=>{y.stopPropagation();let s=y.touches[0];s&&$t(t.id,s.clientX,s.clientY);}})]},`label-${t.id}`)})]}),l&&jsx("g",{style:{pointerEvents:"none"},children:f&&V.find(t=>t.id===f)?jsxs(Fragment,{children:[jsxs("text",{x:N,y:D-8,textAnchor:"middle",dominantBaseline:"middle",fontSize:18,fontWeight:600,fill:"currentColor",className:"text-primary-800 dark:text-primary-100",children:[V.find(t=>t.id===f)?.percent,"%"]}),jsx("text",{x:N,y:D+12,textAnchor:"middle",dominantBaseline:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:V.find(t=>t.id===f)?.label})]}):jsxs(Fragment,{children:[u&&jsx("text",{x:N,y:D-(C?8:0),textAnchor:"middle",dominantBaseline:"middle",fontSize:16,fontWeight:600,fill:"currentColor",className:"text-primary-800 dark:text-primary-100",children:u}),C&&jsx("text",{x:N,y:D+14,textAnchor:"middle",dominantBaseline:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:C})]})})]});return jsxs("div",{ref:b,className:B(lt(),j),children:[L&&jsx("h3",{className:"mb-2 text-sm font-semibold text-primary-700 dark:text-primary-200",children:L}),E&&m==="top"&&jsx(rt,{items:q,position:"top",onToggle:Z}),jsxs("div",{className:B("flex items-start justify-center",Dt&&"gap-0"),children:[E&&m==="left"&&jsx(rt,{items:q,position:"left",onToggle:Z}),jsx("div",{ref:M,className:"flex-1 min-w-0 overflow-hidden",children:Nt?Rt:jsx("div",{className:"flex items-center justify-center text-secondary-400 dark:text-secondary-500",style:{height:H},children:G})}),E&&m==="right"&&jsx(rt,{items:q,position:"right",onToggle:Z})]}),E&&m==="bottom"&&jsx(rt,{items:q,position:"bottom",onToggle:Z}),S&&jsx("div",{className:mt(),style:{left:S.x,top:S.y},role:"tooltip",children:S.items.map((t,o)=>jsxs("div",{className:"flex items-center gap-2",children:[jsx("span",{className:"h-2.5 w-2.5 rounded-full shrink-0",style:{background:t.color}}),jsxs("span",{className:"font-medium",children:[t.label,":"]}),jsx("span",{children:t.value}),jsxs("span",{className:"text-primary-300",children:["(",t.percent,")"]})]},o))})]})}export{ce as PieChart};
@@ -0,0 +1 @@
1
+ 'use strict';var react=require('react'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),classVarianceAuthority=require('class-variance-authority'),jsxRuntime=require('react/jsx-runtime');function M(...t){return tailwindMerge.twMerge(clsx.clsx(t))}var _=classVarianceAuthority.cva("relative w-full font-sans select-none",{variants:{size:{sm:"text-xs",md:"text-sm",lg:"text-base"}},defaultVariants:{size:"md"}}),j=classVarianceAuthority.cva("flex flex-wrap gap-3 items-center justify-center",{variants:{position:{top:"mb-3",bottom:"mt-3",left:"flex-col mr-4",right:"flex-col ml-4"}},defaultVariants:{position:"bottom"}}),H=classVarianceAuthority.cva("absolute z-50 pointer-events-none px-3 py-2 rounded-lg text-xs shadow-lg border transition-opacity duration-150 bg-primary-900 text-primary-50 border-primary-700 dark:bg-primary-950 dark:border-primary-800");function ot(t){let[o,e]=react.useState(()=>new Set(t)),n=react.useCallback(l=>{e(b=>{let h=new Set(b);return h.has(l)?h.delete(l):h.add(l),h});},[]),s=react.useCallback(l=>o.has(l),[o]),m=react.useCallback(()=>{e(new Set(t));},[t]);return {visible:o,toggle:n,isVisible:s,showAll:m}}function nt(t){let o=["var(--color-chart-1)","var(--color-chart-2)","var(--color-chart-3)","var(--color-chart-4)","var(--color-chart-5)","var(--color-chart-6)","var(--color-chart-7)","var(--color-chart-8)"];return Array.from({length:t},(e,n)=>o[n%o.length])}function G(t,o,e=.1){if(t===o)return [t-1,o+1];let s=(o-t)*e;return [Math.floor(t-s),Math.ceil(o+s)]}function at(t,o,e){if(e<=1)return [t];let n=(o-t)/(e-1);return Array.from({length:e},(s,m)=>+(t+m*n).toFixed(10))}function v(t,o){return o?o(t):typeof t=="number"?Math.abs(t)>=1e6?`${(t/1e6).toFixed(1)}M`:Math.abs(t)>=1e3?`${(t/1e3).toFixed(1)}K`:Number.isInteger(t)?t.toString():t.toFixed(2):String(t)}function J(t,o,e){return {top:20,right:e?65:20,bottom:t?52:36,left:o?65:52}}function K(t,o,e){let n=Math.max(t,120);return {width:n,height:o,margins:e,plotLeft:e.left,plotTop:e.top,plotRight:n-e.right,plotBottom:o-e.bottom,plotWidth:Math.max(n-e.left-e.right,10),plotHeight:Math.max(o-e.top-e.bottom,10)}}function it(t,o,e){let n=1/0,s=-1/0;for(let b of t)if(o.has(b.id))for(let h of b.data){let k=Number(h.x);k<n&&(n=k),k>s&&(s=k);}if(!isFinite(n))return [0,1];let[m,l]=G(n,s);return [e?.min??m,e?.max??l]}function st(t,o,e){let n=1/0,s=-1/0;for(let b of t)if(o.has(b.id))for(let h of b.data)h.y<n&&(n=h.y),h.y>s&&(s=h.y);if(!isFinite(n))return [0,1];let[m,l]=G(n,s);return [e?.min??m,e?.max??l]}function Z(t,o){let[e,n]=t,[s,m]=o;return n===e?()=>(s+m)/2:l=>s+(l-e)/(n-e)*(m-s)}function q(t,o=5){return at(t[0],t[1],o)}function ct(t,o,e){let n=1.618033988749895,s=t*137+o,m=s*n%1*2-1,l=s*n*n%1*2-1;return [m*e,l*e]}function lt(t,o,e=12){if(t.length<2)return null;let n=Math.min(...t),s=Math.max(...t),m=Math.min(...o),l=Math.max(...o);return {cx:(n+s)/2,cy:(m+l)/2,rx:(s-n)/2+e,ry:(l-m)/2+e}}function W({items:t,position:o,onToggle:e}){return jsxRuntime.jsx("div",{className:j({position:o}),children:t.map(n=>jsxRuntime.jsxs("button",{onClick:()=>e(n.id),className:M("flex items-center gap-1.5 cursor-pointer rounded px-1.5 py-1 text-xs text-primary-700 transition-opacity hover:bg-primary-100 dark:text-primary-300 dark:hover:bg-primary-800",!n.visible&&"opacity-40"),"aria-pressed":n.visible,children:[jsxRuntime.jsx("span",{className:"h-2.5 w-2.5 rounded-full shrink-0",style:{background:n.color}}),n.label]},n.id))})}function Ut({series:t,xAxis:o,yAxis:e,dotRadius:n=5,dotOpacity:s=.75,clusters:m=false,jitter:l=false,jitterAmount:b=12,linkedLines:h=false,title:k,height:E=300,className:dt,legend:F=true,legendPosition:V="bottom",animateOnMount:Q=true,emptyText:ft="No data to display"}){let P=react.useRef(null),U=react.useRef(null),[A,tt]=react.useState(600),[C,T]=react.useState(null);react.useEffect(()=>{let r=U.current;if(!r)return;let c=r.getBoundingClientRect().width;c>0&&tt(c);let d=new ResizeObserver(f=>{let u=f[0]?.contentRect.width;u&&u>0&&tt(u);});return d.observe(r),()=>d.disconnect()},[]);let ht=react.useMemo(()=>t.map(r=>r.id),[t]),{visible:w,toggle:L,isVisible:N}=ot(ht),$=react.useMemo(()=>nt(t.length),[t.length]),X=react.useMemo(()=>new Map(t.map((r,c)=>[r.id,r.color??$[c]])),[t,$]),et=react.useMemo(()=>J(!!o?.label,!!e?.label,false),[o?.label,e?.label]),a=react.useMemo(()=>K(A,E,et),[A,E,et]),D=react.useMemo(()=>it(t,w,o),[t,w,o]),R=react.useMemo(()=>st(t,w,e),[t,w,e]),B=react.useMemo(()=>Z(D,[a.plotLeft,a.plotRight]),[D,a]),S=react.useMemo(()=>Z(R,[a.plotBottom,a.plotTop]),[R,a]),xt=react.useMemo(()=>q(D,o?.tickCount??6),[D,o?.tickCount]),rt=react.useMemo(()=>q(R,e?.tickCount??5),[R,e?.tickCount]),bt=react.useCallback((r,c,d,f,u)=>{let p=P.current?.getBoundingClientRect();p&&T({x:r.clientX-p.left+12,y:r.clientY-p.top-10,seriesName:c,xVal:v(d,o?.format),yVal:v(f,e?.format),color:u});},[o?.format,e?.format]),gt=react.useCallback((r,c,d,f,u)=>{r.preventDefault();let p=P.current?.getBoundingClientRect();if(!p)return;let g=r.touches[0];g&&T({x:g.clientX-p.left+12,y:g.clientY-p.top-10,seriesName:c,xVal:v(d,o?.format),yVal:v(f,e?.format),color:u});},[o?.format,e?.format]),I=react.useMemo(()=>t.map((r,c)=>({id:r.id,label:r.name,color:r.color??$[c],visible:N(r.id)})),[t,$,N]),yt=t.some(r=>r.data.length>0),kt=V==="left"||V==="right",Ct=jsxRuntime.jsxs("svg",{role:"img","aria-label":k??"Scatter chart",width:a.width,height:a.height,viewBox:`0 0 ${a.width} ${a.height}`,shapeRendering:"geometricPrecision",children:[rt.map(r=>jsxRuntime.jsx("line",{x1:a.plotLeft,x2:a.plotRight,y1:S(r),y2:S(r),stroke:"currentColor",strokeWidth:.5,strokeDasharray:"4 4",className:"text-secondary-200 dark:text-secondary-700"},r)),m&&t.map((r,c)=>{if(!N(r.id)||r.data.length<2)return null;let d=X.get(r.id)??"var(--color-chart-1)",f=r.data.map(g=>B(Number(g.x))),u=r.data.map(g=>S(g.y)),p=lt(f,u,16);return p?jsxRuntime.jsx("ellipse",{cx:p.cx,cy:p.cy,rx:p.rx,ry:p.ry,fill:d,fillOpacity:.06,stroke:d,strokeOpacity:.3,strokeWidth:1.5,strokeDasharray:"5 3",className:Q?"chart-cluster-ellipse":"",style:{animationDelay:`${c*.1}s`}},`cluster-${r.id}`):null}),h&&t.map(r=>{if(!N(r.id)||r.data.length<2)return null;let c=X.get(r.id)??"var(--color-chart-1)",f=[...r.data].sort((u,p)=>Number(u.x)-Number(p.x)).map(u=>`${B(Number(u.x)).toFixed(2)},${S(u.y).toFixed(2)}`).join(" ");return jsxRuntime.jsx("polyline",{points:f,fill:"none",stroke:c,strokeWidth:1.5,className:"chart-scatter-link"},`link-${r.id}`)}),t.map((r,c)=>{if(!N(r.id))return null;let d=X.get(r.id)??"var(--color-chart-1)";return jsxRuntime.jsx("g",{className:"chart-scatter-group",children:r.data.map((f,u)=>{let[p,g]=l?ct(c,u,b):[0,0],vt=B(Number(f.x))+p,Vt=S(f.y)+g;return jsxRuntime.jsx("circle",{cx:vt,cy:Vt,r:n,fill:d,fillOpacity:s,stroke:d,strokeWidth:1,strokeOpacity:.5,className:M("chart-scatter-dot",Q&&"chart-scatter-dot--animate"),style:{color:d},onMouseMove:Y=>bt(Y,r.name,f.x,f.y,d),onMouseLeave:()=>T(null),onTouchStart:Y=>gt(Y,r.name,f.x,f.y,d),onTouchEnd:()=>T(null)},u)})},r.id)}),jsxRuntime.jsx("line",{x1:a.plotLeft,x2:a.plotLeft,y1:a.plotTop,y2:a.plotBottom,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsxRuntime.jsx("line",{x1:a.plotLeft,x2:a.plotRight,y1:a.plotBottom,y2:a.plotBottom,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),rt.map(r=>{let c=S(r);return jsxRuntime.jsxs("g",{children:[jsxRuntime.jsx("line",{x1:a.plotLeft-4,x2:a.plotLeft,y1:c,y2:c,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsxRuntime.jsx("text",{x:a.plotLeft-6,y:c,textAnchor:"end",dominantBaseline:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:v(r,e?.format)})]},r)}),xt.map(r=>{let c=B(r);return jsxRuntime.jsxs("g",{children:[jsxRuntime.jsx("line",{x1:c,x2:c,y1:a.plotBottom,y2:a.plotBottom+4,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsxRuntime.jsx("text",{x:c,y:a.plotBottom+14,textAnchor:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:v(r,o?.format)})]},r)}),e?.label&&jsxRuntime.jsx("text",{x:-(a.plotTop+a.plotHeight/2),y:14,textAnchor:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-600 dark:text-secondary-400",transform:"rotate(-90)",children:e.label}),o?.label&&jsxRuntime.jsx("text",{x:a.plotLeft+a.plotWidth/2,y:a.height-4,textAnchor:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-600 dark:text-secondary-400",children:o.label})]});return jsxRuntime.jsxs("div",{ref:P,className:M(_(),dt),children:[k&&jsxRuntime.jsx("h3",{className:"mb-2 text-sm font-semibold text-primary-700 dark:text-primary-200",children:k}),F&&V==="top"&&jsxRuntime.jsx(W,{items:I,position:"top",onToggle:L}),jsxRuntime.jsxs("div",{className:M("flex items-start",kt&&"gap-0"),children:[F&&V==="left"&&jsxRuntime.jsx(W,{items:I,position:"left",onToggle:L}),jsxRuntime.jsx("div",{ref:U,className:"flex-1 min-w-0 overflow-hidden",children:yt?Ct:jsxRuntime.jsx("div",{className:"flex items-center justify-center text-secondary-400 dark:text-secondary-500",style:{height:E},children:ft})}),F&&V==="right"&&jsxRuntime.jsx(W,{items:I,position:"right",onToggle:L})]}),F&&V==="bottom"&&jsxRuntime.jsx(W,{items:I,position:"bottom",onToggle:L}),C&&jsxRuntime.jsxs("div",{className:H(),style:{left:C.x,top:C.y},role:"tooltip",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[jsxRuntime.jsx("span",{className:"h-2 w-2 rounded-full",style:{background:C.color}}),jsxRuntime.jsx("span",{className:"font-medium",children:C.seriesName})]}),jsxRuntime.jsxs("div",{className:"text-primary-300",children:["X: ",jsxRuntime.jsx("span",{className:"font-medium text-primary-50",children:C.xVal})," ","Y: ",jsxRuntime.jsx("span",{className:"font-medium text-primary-50",children:C.yVal})]})]})]})}exports.ScatterChart=Ut;
@@ -0,0 +1 @@
1
+ @keyframes chart-dot-fade-in{0%{opacity:0;transform:scale(0)}to{opacity:1;transform:scale(1)}}.chart-scatter-dot{transition:r .15s ease,filter .15s ease;cursor:crosshair}.chart-scatter-dot.chart-scatter-dot--animate{animation:chart-dot-fade-in .35s ease-out forwards;opacity:0}.chart-scatter-group:nth-child(1) .chart-scatter-dot{animation-delay:.05s}.chart-scatter-group:nth-child(2) .chart-scatter-dot{animation-delay:.15s}.chart-scatter-group:nth-child(3) .chart-scatter-dot{animation-delay:.25s}.chart-scatter-group:nth-child(4) .chart-scatter-dot{animation-delay:.35s}.chart-scatter-dot:hover{filter:drop-shadow(0 0 5px currentColor)}.chart-cluster-ellipse{pointer-events:none;animation:chart-dot-fade-in .4s ease-out forwards;opacity:0}.chart-scatter-link{pointer-events:none;opacity:.4}
@@ -0,0 +1,2 @@
1
+ export { ScatterChart_alias_3 as ScatterChart } from '../_tsup-dts-rollup.cjs';
2
+ export { ScatterChartProps_alias_1 as ScatterChartProps } from '../_tsup-dts-rollup.cjs';
@@ -0,0 +1,2 @@
1
+ export { ScatterChart_alias_3 as ScatterChart } from '../_tsup-dts-rollup.js';
2
+ export { ScatterChartProps_alias_1 as ScatterChartProps } from '../_tsup-dts-rollup.js';
@@ -0,0 +1 @@
1
+ import {useRef,useState,useEffect,useMemo,useCallback}from'react';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {cva}from'class-variance-authority';import {jsxs,jsx}from'react/jsx-runtime';function M(...t){return twMerge(clsx(t))}var _=cva("relative w-full font-sans select-none",{variants:{size:{sm:"text-xs",md:"text-sm",lg:"text-base"}},defaultVariants:{size:"md"}}),j=cva("flex flex-wrap gap-3 items-center justify-center",{variants:{position:{top:"mb-3",bottom:"mt-3",left:"flex-col mr-4",right:"flex-col ml-4"}},defaultVariants:{position:"bottom"}}),H=cva("absolute z-50 pointer-events-none px-3 py-2 rounded-lg text-xs shadow-lg border transition-opacity duration-150 bg-primary-900 text-primary-50 border-primary-700 dark:bg-primary-950 dark:border-primary-800");function ot(t){let[o,e]=useState(()=>new Set(t)),n=useCallback(l=>{e(b=>{let h=new Set(b);return h.has(l)?h.delete(l):h.add(l),h});},[]),s=useCallback(l=>o.has(l),[o]),m=useCallback(()=>{e(new Set(t));},[t]);return {visible:o,toggle:n,isVisible:s,showAll:m}}function nt(t){let o=["var(--color-chart-1)","var(--color-chart-2)","var(--color-chart-3)","var(--color-chart-4)","var(--color-chart-5)","var(--color-chart-6)","var(--color-chart-7)","var(--color-chart-8)"];return Array.from({length:t},(e,n)=>o[n%o.length])}function G(t,o,e=.1){if(t===o)return [t-1,o+1];let s=(o-t)*e;return [Math.floor(t-s),Math.ceil(o+s)]}function at(t,o,e){if(e<=1)return [t];let n=(o-t)/(e-1);return Array.from({length:e},(s,m)=>+(t+m*n).toFixed(10))}function v(t,o){return o?o(t):typeof t=="number"?Math.abs(t)>=1e6?`${(t/1e6).toFixed(1)}M`:Math.abs(t)>=1e3?`${(t/1e3).toFixed(1)}K`:Number.isInteger(t)?t.toString():t.toFixed(2):String(t)}function J(t,o,e){return {top:20,right:e?65:20,bottom:t?52:36,left:o?65:52}}function K(t,o,e){let n=Math.max(t,120);return {width:n,height:o,margins:e,plotLeft:e.left,plotTop:e.top,plotRight:n-e.right,plotBottom:o-e.bottom,plotWidth:Math.max(n-e.left-e.right,10),plotHeight:Math.max(o-e.top-e.bottom,10)}}function it(t,o,e){let n=1/0,s=-1/0;for(let b of t)if(o.has(b.id))for(let h of b.data){let k=Number(h.x);k<n&&(n=k),k>s&&(s=k);}if(!isFinite(n))return [0,1];let[m,l]=G(n,s);return [e?.min??m,e?.max??l]}function st(t,o,e){let n=1/0,s=-1/0;for(let b of t)if(o.has(b.id))for(let h of b.data)h.y<n&&(n=h.y),h.y>s&&(s=h.y);if(!isFinite(n))return [0,1];let[m,l]=G(n,s);return [e?.min??m,e?.max??l]}function Z(t,o){let[e,n]=t,[s,m]=o;return n===e?()=>(s+m)/2:l=>s+(l-e)/(n-e)*(m-s)}function q(t,o=5){return at(t[0],t[1],o)}function ct(t,o,e){let n=1.618033988749895,s=t*137+o,m=s*n%1*2-1,l=s*n*n%1*2-1;return [m*e,l*e]}function lt(t,o,e=12){if(t.length<2)return null;let n=Math.min(...t),s=Math.max(...t),m=Math.min(...o),l=Math.max(...o);return {cx:(n+s)/2,cy:(m+l)/2,rx:(s-n)/2+e,ry:(l-m)/2+e}}function W({items:t,position:o,onToggle:e}){return jsx("div",{className:j({position:o}),children:t.map(n=>jsxs("button",{onClick:()=>e(n.id),className:M("flex items-center gap-1.5 cursor-pointer rounded px-1.5 py-1 text-xs text-primary-700 transition-opacity hover:bg-primary-100 dark:text-primary-300 dark:hover:bg-primary-800",!n.visible&&"opacity-40"),"aria-pressed":n.visible,children:[jsx("span",{className:"h-2.5 w-2.5 rounded-full shrink-0",style:{background:n.color}}),n.label]},n.id))})}function Ut({series:t,xAxis:o,yAxis:e,dotRadius:n=5,dotOpacity:s=.75,clusters:m=false,jitter:l=false,jitterAmount:b=12,linkedLines:h=false,title:k,height:E=300,className:dt,legend:F=true,legendPosition:V="bottom",animateOnMount:Q=true,emptyText:ft="No data to display"}){let P=useRef(null),U=useRef(null),[A,tt]=useState(600),[C,T]=useState(null);useEffect(()=>{let r=U.current;if(!r)return;let c=r.getBoundingClientRect().width;c>0&&tt(c);let d=new ResizeObserver(f=>{let u=f[0]?.contentRect.width;u&&u>0&&tt(u);});return d.observe(r),()=>d.disconnect()},[]);let ht=useMemo(()=>t.map(r=>r.id),[t]),{visible:w,toggle:L,isVisible:N}=ot(ht),$=useMemo(()=>nt(t.length),[t.length]),X=useMemo(()=>new Map(t.map((r,c)=>[r.id,r.color??$[c]])),[t,$]),et=useMemo(()=>J(!!o?.label,!!e?.label,false),[o?.label,e?.label]),a=useMemo(()=>K(A,E,et),[A,E,et]),D=useMemo(()=>it(t,w,o),[t,w,o]),R=useMemo(()=>st(t,w,e),[t,w,e]),B=useMemo(()=>Z(D,[a.plotLeft,a.plotRight]),[D,a]),S=useMemo(()=>Z(R,[a.plotBottom,a.plotTop]),[R,a]),xt=useMemo(()=>q(D,o?.tickCount??6),[D,o?.tickCount]),rt=useMemo(()=>q(R,e?.tickCount??5),[R,e?.tickCount]),bt=useCallback((r,c,d,f,u)=>{let p=P.current?.getBoundingClientRect();p&&T({x:r.clientX-p.left+12,y:r.clientY-p.top-10,seriesName:c,xVal:v(d,o?.format),yVal:v(f,e?.format),color:u});},[o?.format,e?.format]),gt=useCallback((r,c,d,f,u)=>{r.preventDefault();let p=P.current?.getBoundingClientRect();if(!p)return;let g=r.touches[0];g&&T({x:g.clientX-p.left+12,y:g.clientY-p.top-10,seriesName:c,xVal:v(d,o?.format),yVal:v(f,e?.format),color:u});},[o?.format,e?.format]),I=useMemo(()=>t.map((r,c)=>({id:r.id,label:r.name,color:r.color??$[c],visible:N(r.id)})),[t,$,N]),yt=t.some(r=>r.data.length>0),kt=V==="left"||V==="right",Ct=jsxs("svg",{role:"img","aria-label":k??"Scatter chart",width:a.width,height:a.height,viewBox:`0 0 ${a.width} ${a.height}`,shapeRendering:"geometricPrecision",children:[rt.map(r=>jsx("line",{x1:a.plotLeft,x2:a.plotRight,y1:S(r),y2:S(r),stroke:"currentColor",strokeWidth:.5,strokeDasharray:"4 4",className:"text-secondary-200 dark:text-secondary-700"},r)),m&&t.map((r,c)=>{if(!N(r.id)||r.data.length<2)return null;let d=X.get(r.id)??"var(--color-chart-1)",f=r.data.map(g=>B(Number(g.x))),u=r.data.map(g=>S(g.y)),p=lt(f,u,16);return p?jsx("ellipse",{cx:p.cx,cy:p.cy,rx:p.rx,ry:p.ry,fill:d,fillOpacity:.06,stroke:d,strokeOpacity:.3,strokeWidth:1.5,strokeDasharray:"5 3",className:Q?"chart-cluster-ellipse":"",style:{animationDelay:`${c*.1}s`}},`cluster-${r.id}`):null}),h&&t.map(r=>{if(!N(r.id)||r.data.length<2)return null;let c=X.get(r.id)??"var(--color-chart-1)",f=[...r.data].sort((u,p)=>Number(u.x)-Number(p.x)).map(u=>`${B(Number(u.x)).toFixed(2)},${S(u.y).toFixed(2)}`).join(" ");return jsx("polyline",{points:f,fill:"none",stroke:c,strokeWidth:1.5,className:"chart-scatter-link"},`link-${r.id}`)}),t.map((r,c)=>{if(!N(r.id))return null;let d=X.get(r.id)??"var(--color-chart-1)";return jsx("g",{className:"chart-scatter-group",children:r.data.map((f,u)=>{let[p,g]=l?ct(c,u,b):[0,0],vt=B(Number(f.x))+p,Vt=S(f.y)+g;return jsx("circle",{cx:vt,cy:Vt,r:n,fill:d,fillOpacity:s,stroke:d,strokeWidth:1,strokeOpacity:.5,className:M("chart-scatter-dot",Q&&"chart-scatter-dot--animate"),style:{color:d},onMouseMove:Y=>bt(Y,r.name,f.x,f.y,d),onMouseLeave:()=>T(null),onTouchStart:Y=>gt(Y,r.name,f.x,f.y,d),onTouchEnd:()=>T(null)},u)})},r.id)}),jsx("line",{x1:a.plotLeft,x2:a.plotLeft,y1:a.plotTop,y2:a.plotBottom,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsx("line",{x1:a.plotLeft,x2:a.plotRight,y1:a.plotBottom,y2:a.plotBottom,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),rt.map(r=>{let c=S(r);return jsxs("g",{children:[jsx("line",{x1:a.plotLeft-4,x2:a.plotLeft,y1:c,y2:c,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsx("text",{x:a.plotLeft-6,y:c,textAnchor:"end",dominantBaseline:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:v(r,e?.format)})]},r)}),xt.map(r=>{let c=B(r);return jsxs("g",{children:[jsx("line",{x1:c,x2:c,y1:a.plotBottom,y2:a.plotBottom+4,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsx("text",{x:c,y:a.plotBottom+14,textAnchor:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:v(r,o?.format)})]},r)}),e?.label&&jsx("text",{x:-(a.plotTop+a.plotHeight/2),y:14,textAnchor:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-600 dark:text-secondary-400",transform:"rotate(-90)",children:e.label}),o?.label&&jsx("text",{x:a.plotLeft+a.plotWidth/2,y:a.height-4,textAnchor:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-600 dark:text-secondary-400",children:o.label})]});return jsxs("div",{ref:P,className:M(_(),dt),children:[k&&jsx("h3",{className:"mb-2 text-sm font-semibold text-primary-700 dark:text-primary-200",children:k}),F&&V==="top"&&jsx(W,{items:I,position:"top",onToggle:L}),jsxs("div",{className:M("flex items-start",kt&&"gap-0"),children:[F&&V==="left"&&jsx(W,{items:I,position:"left",onToggle:L}),jsx("div",{ref:U,className:"flex-1 min-w-0 overflow-hidden",children:yt?Ct:jsx("div",{className:"flex items-center justify-center text-secondary-400 dark:text-secondary-500",style:{height:E},children:ft})}),F&&V==="right"&&jsx(W,{items:I,position:"right",onToggle:L})]}),F&&V==="bottom"&&jsx(W,{items:I,position:"bottom",onToggle:L}),C&&jsxs("div",{className:H(),style:{left:C.x,top:C.y},role:"tooltip",children:[jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[jsx("span",{className:"h-2 w-2 rounded-full",style:{background:C.color}}),jsx("span",{className:"font-medium",children:C.seriesName})]}),jsxs("div",{className:"text-primary-300",children:["X: ",jsx("span",{className:"font-medium text-primary-50",children:C.xVal})," ","Y: ",jsx("span",{className:"font-medium text-primary-50",children:C.yVal})]})]})]})}export{Ut as ScatterChart};
@@ -0,0 +1 @@
1
+ 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var react=require('react'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),classVarianceAuthority=require('class-variance-authority'),jsxRuntime=require('react/jsx-runtime');function rt(...t){return tailwindMerge.twMerge(clsx.clsx(t))}var Mt=classVarianceAuthority.cva("relative w-full font-sans select-none",{variants:{size:{sm:"text-xs",md:"text-sm",lg:"text-base"}},defaultVariants:{size:"md"}}),Lt=classVarianceAuthority.cva("flex flex-wrap gap-3 items-center justify-center",{variants:{position:{top:"mb-3",bottom:"mt-3",left:"flex-col mr-4",right:"flex-col ml-4"}},defaultVariants:{position:"bottom"}}),Tt=classVarianceAuthority.cva("absolute z-50 pointer-events-none px-3 py-2 rounded-lg text-xs shadow-lg border transition-opacity duration-150 bg-primary-900 text-primary-50 border-primary-700 dark:bg-primary-950 dark:border-primary-800");function $t(t){let[o,r]=react.useState(()=>new Set(t)),e=react.useCallback(s=>{r(y=>{let x=new Set(y);return x.has(s)?x.delete(s):x.add(s),x});},[]),a=react.useCallback(s=>o.has(s),[o]),d=react.useCallback(()=>{r(new Set(t));},[t]);return {visible:o,toggle:e,isVisible:a,showAll:d}}function Vt(t){let o=["var(--color-chart-1)","var(--color-chart-2)","var(--color-chart-3)","var(--color-chart-4)","var(--color-chart-5)","var(--color-chart-6)","var(--color-chart-7)","var(--color-chart-8)"];return Array.from({length:t},(r,e)=>o[e%o.length])}function Dt(t,o,r=.1){if(t===o)return [t-1,o+1];let a=(o-t)*r;return [Math.floor(t-a),Math.ceil(o+a)]}function Xt(t,o,r){if(r<=1)return [t];let e=(o-t)/(r-1);return Array.from({length:r},(a,d)=>+(t+d*e).toFixed(10))}function tt(t,o){return o?o(t):typeof t=="number"?Math.abs(t)>=1e6?`${(t/1e6).toFixed(1)}M`:Math.abs(t)>=1e3?`${(t/1e3).toFixed(1)}K`:Number.isInteger(t)?t.toString():t.toFixed(2):String(t)}function kt(t,o,r,e){let a=(e-90)*Math.PI/180;return {x:t+r*Math.cos(a),y:o+r*Math.sin(a)}}function Ft(t,o,r){return {top:20,right:r?65:20,bottom:t?52:36,left:o?65:52}}function Et(t,o,r){let e=Math.max(t,120);return {width:e,height:o,margins:r,plotLeft:r.left,plotTop:r.top,plotRight:e-r.right,plotBottom:o-r.bottom,plotWidth:Math.max(e-r.left-r.right,10),plotHeight:Math.max(o-r.top-r.bottom,10)}}function de(t,o){let r=new Set,e=[];for(let a of t)if(o.has(a.id))for(let d of a.data){let s=String(d.x);r.has(s)||(r.add(s),e.push(s));}return e}function Ut(t,o,r){let e=1/0,a=-1/0;for(let y of t)if(o.has(y.id))for(let x of y.data)x.y<e&&(e=x.y),x.y>a&&(a=x.y);if(!isFinite(e))return [0,1];let[d,s]=Dt(e,a);return [r?.min??d,r?.max??s]}function zt(t,o){let[r,e]=t,[a,d]=o;return e===r?()=>(a+d)/2:s=>a+(s-r)/(e-r)*(d-a)}function It(t,o){let r=t.length;if(r===0)return ()=>(o[0]+o[1])/2;let e=(o[1]-o[0])/r;return a=>{let d=t.indexOf(a);return d<0?(o[0]+o[1])/2:o[0]+d*e+e/2}}function ue(t,o,r){return t.map(e=>`${o(e.x).toFixed(2)},${r(e.y).toFixed(2)}`).join(" ")}function qt(t,o,r){if(t.length===0)return "";let e=t.map(s=>({x:o(s.x),y:r(s.y)}));if(e.length===1)return `M ${e[0].x.toFixed(2)} ${e[0].y.toFixed(2)}`;let a=.5,d=`M ${e[0].x.toFixed(2)} ${e[0].y.toFixed(2)}`;for(let s=0;s<e.length-1;s++){let y=s===0?{x:2*e[0].x-e[1].x,y:2*e[0].y-e[1].y}:e[s-1],x=e[s],C=e[s+1],R=s+2<e.length?e[s+2]:{x:2*e[e.length-1].x-e[e.length-2].x,y:2*e[e.length-1].y-e[e.length-2].y},P=x.x+(C.x-y.x)*a/3,L=x.y+(C.y-y.y)*a/3,b=C.x-(R.x-x.x)*a/3,p=C.y-(R.y-x.y)*a/3;d+=` C ${P.toFixed(2)} ${L.toFixed(2)}, ${b.toFixed(2)} ${p.toFixed(2)}, ${C.x.toFixed(2)} ${C.y.toFixed(2)}`;}return d}function pe(t,o,r,e,a){if(t.length===0)return "";let d=e?qt(t,o,r):`M ${t.map(x=>`${o(x.x).toFixed(2)},${r(x.y).toFixed(2)}`).join(" L ")}`,s=o(t[t.length-1].x).toFixed(2),y=o(t[0].x).toFixed(2);return `${d} L ${s},${a.toFixed(2)} L ${y},${a.toFixed(2)} Z`}function Gt(t,o=5){return Xt(t[0],t[1],o)}function Qt(t,o,r){if(o.length===0)return -1;let e=1/0,a=0;for(let d=0;d<o.length;d++){let s=Math.abs(r(o[d])-t);s<e&&(e=s,a=d);}return a}function te(t,o){return t.data.find(r=>String(r.x)===o)?.y}function he(t){for(let o of t)for(let r of o.data)if(typeof r.x=="string")return true;return false}function Pt({items:t,position:o,onToggle:r}){return jsxRuntime.jsx("div",{className:Lt({position:o}),children:t.map(e=>jsxRuntime.jsxs("button",{onClick:()=>r(e.id),className:rt("flex items-center gap-1.5 cursor-pointer rounded px-1.5 py-1 text-xs text-primary-700 transition-opacity hover:bg-primary-100 dark:text-primary-300 dark:hover:bg-primary-800",!e.visible&&"opacity-40"),"aria-pressed":e.visible,children:[jsxRuntime.jsx("span",{className:"h-2.5 w-5 rounded-sm shrink-0",style:{background:e.color}}),e.label]},e.id))})}function oe({series:t,xAxis:o,yAxis:r,y2Axis:e,y2Series:a=[],smooth:d=false,showDots:s=true,area:y=false,strokeWidth:x=2,title:C,height:R=300,className:P,legend:L=true,legendPosition:b="bottom",animateOnMount:p=true,emptyText:$="No data to display"}){let z=react.useRef(null),S=react.useRef(null),[B,K]=react.useState(600),[T,N]=react.useState(null),[w,I]=react.useState(null);react.useEffect(()=>{let l=S.current;if(!l)return;let k=l.getBoundingClientRect().width;k>0&&K(k);let X=new ResizeObserver(Q=>{let j=Q[0]?.contentRect.width;j&&j>0&&K(j);});return X.observe(l),()=>X.disconnect()},[]);let U=react.useMemo(()=>t.map(l=>l.id),[t]),{visible:G,toggle:q,isVisible:D}=$t(U),gt=react.useMemo(()=>Vt(t.length),[t.length]),i=react.useMemo(()=>new Map(t.map((l,k)=>[l.id,l.color??gt[k]])),[t,gt]),A=react.useMemo(()=>Ft(!!o?.label,!!r?.label,!!e),[o?.label,r?.label,e]),c=react.useMemo(()=>Et(B,R,A),[B,R,A]),F=react.useMemo(()=>he(t),[t]),E=react.useMemo(()=>F?de(t,G):[],[t,G,F]),ut=react.useMemo(()=>{if(F){let j=It(E,[c.plotLeft,c.plotRight]);return st=>j(st)}let l=t.flatMap(j=>j.data.map(st=>st.x));if(l.length===0)return ()=>c.plotLeft;let k=Math.min(...l),X=Math.max(...l),Q=zt([k,X],[c.plotLeft,c.plotRight]);return j=>Q(j)},[t,F,E,c]),xt=react.useMemo(()=>Ut(t,G,r),[t,G,r]),mt=react.useMemo(()=>zt(xt,[c.plotBottom,c.plotTop]),[xt,c]),yt=react.useMemo(()=>Gt(xt,r?.tickCount??5),[xt,r?.tickCount]),nt=react.useMemo(()=>{if(!e)return null;let l=t.filter(k=>a.includes(k.id));return Ut(l,G,e)},[e,t,a,G]),et=react.useMemo(()=>nt?zt(nt,[c.plotBottom,c.plotTop]):null,[nt,c]),pt=react.useMemo(()=>nt?Gt(nt,e?.tickCount??5):[],[nt,e?.tickCount]),dt=react.useMemo(()=>{if(F)return E;let l=t.flatMap(Q=>Q.data.map(j=>Number(j.x)));if(l.length===0)return [];let k=Math.min(...l),X=Math.max(...l);return Gt([k,X],o?.tickCount??6)},[F,E,t,o?.tickCount]),n=react.useCallback(l=>{let k=l.currentTarget.closest("svg");if(!k)return;let X=k.getBoundingClientRect(),Q=l.clientX-X.left,j=z.current?.getBoundingClientRect();if(!j)return;let st="",bt=Q;if(F&&E.length>0){let h=It(E,[c.plotLeft,c.plotRight]),_=Qt(Q,E,h);st=E[_]??"",bt=h(st);}else if(!F){let h=dt;st=tt((Q-c.plotLeft)/c.plotWidth*(h[h.length-1]-h[0])+h[0],o?.format),bt=Q;}let m=t.filter(h=>D(h.id)).map(h=>{a.includes(h.id)&&et!=null?et:mt;let vt;if(F)vt=te(h,st);else {let f=Q,at=1/0,wt;for(let ct of h.data){let Y=ut(ct.x),Wt=Math.abs(Y-f);Wt<at&&(at=Wt,wt=ct.y);}vt=wt;}return {name:h.name,value:vt!==void 0?tt(vt,r?.format):"\u2014",color:i.get(h.id)??"var(--color-chart-1)"}});bt>=c.plotLeft&&bt<=c.plotRight&&I(bt);let M=l.clientX-j.left+12,g=l.clientY-j.top-10;N({x:M,y:g,label:st,items:m});},[F,E,c,t,D,a,et,mt,ut,dt,o?.format,r?.format,i]),u=react.useCallback(()=>{N(null),I(null);},[]),V=react.useCallback(l=>{l.preventDefault();let k=l.touches[0];if(!k)return;let X=l.currentTarget.closest("svg");if(!X)return;let Q=X.getBoundingClientRect(),j=z.current?.getBoundingClientRect();if(!j)return;let st=k.clientX-Q.left,bt=st,m="";if(F&&E.length>0){let g=It(E,[c.plotLeft,c.plotRight]),h=Qt(st,E,g);m=E[h]??"",bt=g(m);}bt>=c.plotLeft&&bt<=c.plotRight&&I(bt);let M=t.filter(g=>D(g.id)).map(g=>({name:g.name,value:F&&m?tt(te(g,m)??0,r?.format):"\u2014",color:i.get(g.id)??"var(--color-chart-1)"}));N({x:k.clientX-j.left+12,y:k.clientY-j.top-10,label:m,items:M});},[F,E,c,t,D,r?.format,i]),v=react.useMemo(()=>t.map((l,k)=>({id:l.id,label:l.name,color:l.color??gt[k],visible:D(l.id)})),[t,gt,D]),W=t.some(l=>l.data.length>0),J=jsxRuntime.jsxs("svg",{role:"img","aria-label":C??"Line chart",width:c.width,height:c.height,viewBox:`0 0 ${c.width} ${c.height}`,shapeRendering:"geometricPrecision",children:[r?.gridLines!==false&&yt.map(l=>{let k=mt(l);return jsxRuntime.jsx("line",{x1:c.plotLeft,x2:c.plotRight,y1:k,y2:k,stroke:"currentColor",strokeWidth:.5,strokeDasharray:"4 4",className:"text-secondary-200 dark:text-secondary-700"},l)}),y&&t.map(l=>{if(!D(l.id)||l.data.length===0)return null;let X=a.includes(l.id)&&et!=null?et:mt,Q=i.get(l.id)??"var(--color-chart-1)",j=pe(l.data,ut,X,d,c.plotBottom);return jsxRuntime.jsx("path",{d:j,fill:Q,fillOpacity:.15,stroke:"none",className:p?"chart-area-animate":""},`area-${l.id}`)}),t.map(l=>{if(!D(l.id)||l.data.length===0)return null;let X=a.includes(l.id)&&et!=null?et:mt,Q=i.get(l.id)??"var(--color-chart-1)";return d?jsxRuntime.jsx("path",{d:qt(l.data,ut,X),fill:"none",stroke:Q,strokeWidth:x,strokeLinecap:"round",strokeLinejoin:"round",className:p?"chart-line-animate":""},l.id):jsxRuntime.jsx("polyline",{points:ue(l.data,ut,X),fill:"none",stroke:Q,strokeWidth:x,strokeLinecap:"round",strokeLinejoin:"round",className:p?"chart-line-animate":""},l.id)}),s&&t.map(l=>{if(!D(l.id))return null;let X=a.includes(l.id)&&et!=null?et:mt,Q=i.get(l.id)??"var(--color-chart-1)";return l.data.map((j,st)=>jsxRuntime.jsx("circle",{cx:ut(j.x),cy:X(j.y),r:3,fill:Q,stroke:"white",strokeWidth:1.5,className:rt("chart-dot",p?"chart-dot-animate":"")},`${l.id}-${st}`))}),w!=null&&jsxRuntime.jsx("line",{className:"chart-crosshair",x1:w,x2:w,y1:c.plotTop,y2:c.plotBottom,stroke:"currentColor",strokeWidth:1,strokeDasharray:"4 4",opacity:.5,style:{color:"var(--color-secondary-400)"}}),jsxRuntime.jsx("line",{x1:c.plotLeft,x2:c.plotLeft,y1:c.plotTop,y2:c.plotBottom,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),yt.map(l=>{let k=mt(l);return jsxRuntime.jsxs("g",{children:[jsxRuntime.jsx("line",{x1:c.plotLeft-4,x2:c.plotLeft,y1:k,y2:k,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsxRuntime.jsx("text",{x:c.plotLeft-6,y:k,textAnchor:"end",dominantBaseline:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:tt(l,r?.format)})]},l)}),r?.label&&jsxRuntime.jsx("text",{x:-(c.plotTop+c.plotHeight/2),y:14,textAnchor:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-600 dark:text-secondary-400",transform:"rotate(-90)",children:r.label}),e&&et&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("line",{x1:c.plotRight,x2:c.plotRight,y1:c.plotTop,y2:c.plotBottom,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),pt.map(l=>{let k=et(l);return jsxRuntime.jsxs("g",{children:[jsxRuntime.jsx("line",{x1:c.plotRight,x2:c.plotRight+4,y1:k,y2:k,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsxRuntime.jsx("text",{x:c.plotRight+6,y:k,textAnchor:"start",dominantBaseline:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:tt(l,e?.format)})]},l)}),e?.label&&jsxRuntime.jsx("text",{x:c.plotTop+c.plotHeight/2,y:-(c.width-14),textAnchor:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-600 dark:text-secondary-400",transform:"rotate(90)",children:e.label})]}),jsxRuntime.jsx("line",{x1:c.plotLeft,x2:c.plotRight,y1:c.plotBottom,y2:c.plotBottom,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),(F?E:dt).map((l,k)=>{let X=ut(l);return jsxRuntime.jsxs("g",{children:[jsxRuntime.jsx("line",{x1:X,x2:X,y1:c.plotBottom,y2:c.plotBottom+4,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsxRuntime.jsx("text",{x:X,y:c.plotBottom+14,textAnchor:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:tt(l,o?.format)})]},k)}),o?.label&&jsxRuntime.jsx("text",{x:c.plotLeft+c.plotWidth/2,y:c.height-4,textAnchor:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-600 dark:text-secondary-400",children:o.label}),jsxRuntime.jsx("rect",{x:c.plotLeft,y:c.plotTop,width:c.plotWidth,height:c.plotHeight,fill:"transparent",onMouseMove:n,onMouseLeave:u,onTouchStart:V,onTouchMove:V,onTouchEnd:u,style:{cursor:"crosshair"}})]}),it=b==="left"||b==="right";return jsxRuntime.jsxs("div",{ref:z,className:rt(Mt(),P),children:[C&&jsxRuntime.jsx("h3",{className:"mb-2 text-sm font-semibold text-primary-700 dark:text-primary-200",children:C}),L&&b==="top"&&jsxRuntime.jsx(Pt,{items:v,position:"top",onToggle:q}),jsxRuntime.jsxs("div",{className:rt("flex items-start",it&&"gap-0"),children:[L&&b==="left"&&jsxRuntime.jsx(Pt,{items:v,position:"left",onToggle:q}),jsxRuntime.jsx("div",{ref:S,className:"flex-1 min-w-0 overflow-hidden",children:W?J:jsxRuntime.jsx("div",{className:"flex items-center justify-center text-secondary-400 dark:text-secondary-500",style:{height:R},children:$})}),L&&b==="right"&&jsxRuntime.jsx(Pt,{items:v,position:"right",onToggle:q})]}),L&&b==="bottom"&&jsxRuntime.jsx(Pt,{items:v,position:"bottom",onToggle:q}),T&&jsxRuntime.jsxs("div",{className:Tt(),style:{left:T.x,top:T.y},role:"tooltip",children:[T.label&&jsxRuntime.jsx("div",{className:"mb-1 font-medium text-primary-200",children:T.label}),T.items.map((l,k)=>jsxRuntime.jsxs("div",{className:"flex items-center gap-1.5",children:[jsxRuntime.jsx("span",{className:"h-2 w-2 rounded-full shrink-0",style:{background:l.color}}),jsxRuntime.jsxs("span",{className:"text-primary-300",children:[l.name,":"]}),jsxRuntime.jsx("span",{className:"font-medium",children:l.value})]},k))]})]})}function ge(t,o){let r=new Set,e=[];for(let a of t)if(o.has(a.id))for(let d of a.data){let s=String(d.x);r.has(s)||(r.add(s),e.push(s));}return e}function xe(t,o,r,e){if(r){let a=0;for(let s of t)if(o.has(s.id))for(let y of s.data)y.y>a&&(a=y.y);a===0&&(a=1);let[,d]=Dt(0,a,.05);return [e?.min??0,e?.max??d]}else {let a=new Map;for(let y of t)if(o.has(y.id))for(let x of y.data){let C=String(x.x);a.set(C,(a.get(C)??0)+x.y);}let d=Math.max(0,...a.values()),[,s]=Dt(0,d===0?1:d,.05);return [e?.min??0,e?.max??s]}}function ye(t,o){let[r,e]=t,[a,d]=o;return e===r?()=>(a+d)/2:s=>a+(s-r)/(e-r)*(d-a)}function be(t,o=5){return Xt(t[0],t[1],o)}function ve(t,o,r,e,a,d,s,y,x,C,R){let P=t.filter(B=>o.has(B.id)),L=r.length,b=P.length;if(L===0||b===0)return [];let p=d/L,$=p*(1-C),z=b>0?$*(1-R)/b:0,S=[];for(let B=0;B<r.length;B++){let K=r[B],T=a+B*p+(p-$)/2;for(let N=0;N<P.length;N++){let w=P[N],I=w.data.find(q=>String(q.x)===K);if(!I)continue;let U=T+N*(z+$*R/b),G=x(I.y);S.push({seriesId:w.id,category:K,x:U,y:G,width:Math.max(z,1),height:Math.max(s-G,0),stackBase:s,value:I.y,color:e.get(w.id)??"var(--color-chart-1)"});}}return S}function ke(t,o,r,e,a,d,s,y,x,C){let R=t.filter(S=>o.has(S.id)),P=r.length,L=R.length;if(P===0||L===0)return [];let b=s/P,p=b*(1-x),$=L>0?p*(1-C)/L:0,z=[];for(let S=0;S<r.length;S++){let B=r[S],K=d+S*b+(b-p)/2;for(let T=0;T<R.length;T++){let N=R[T],w=N.data.find(G=>String(G.x)===B);if(!w)continue;let I=K+T*($+p*C/Math.max(L,1)),U=y(w.y);z.push({seriesId:N.id,category:B,x:a,y:I,width:Math.max(U-a,0),height:Math.max($,1),stackBase:a,value:w.y,color:e.get(N.id)??"var(--color-chart-1)"});}}return z}function Ce(t,o,r,e,a,d,s,y,x){let C=t.filter(p=>o.has(p.id)),R=r.length;if(R===0)return [];let P=s/R*(1-x),L=[],b=new Map;r.forEach(p=>b.set(p,a));for(let p of C)for(let $ of r){let z=p.data.find(N=>String(N.x)===$);if(!z)continue;let S=b.get($)??a,B=Math.max(y(z.y)-a,0),K=r.indexOf($),T=d+(K+.5)*(s/R);L.push({seriesId:p.id,category:$,x:S,y:T-P/2,width:B,height:Math.max(P,1),stackBase:S,value:z.y,color:e.get(p.id)??"var(--color-chart-1)"}),b.set($,S+B);}return L}function Se(t,o,r,e,a,d,s,y,x){let C=t.filter(p=>o.has(p.id)),R=r.length;if(R===0)return [];let P=d/R*(1-x),L=[],b=new Map;r.forEach(p=>b.set(p,s));for(let p of C)for(let $ of r){let z=p.data.find(w=>String(w.x)===$);if(!z)continue;let S=b.get($)??s,B=Math.max(s-y(z.y),0),K=S-B,T=r.indexOf($),N=a+(T+.5)*(d/R);L.push({seriesId:p.id,category:$,x:N-P/2,y:K,width:Math.max(P,1),height:B,stackBase:S,value:z.y,color:e.get(p.id)??"var(--color-chart-1)"}),b.set($,K);}return L}function jt({items:t,position:o,onToggle:r}){return jsxRuntime.jsx("div",{className:Lt({position:o}),children:t.map(e=>jsxRuntime.jsxs("button",{onClick:()=>r(e.id),className:rt("flex items-center gap-1.5 cursor-pointer rounded px-1.5 py-1 text-xs text-primary-700 transition-opacity hover:bg-primary-100 dark:text-primary-300 dark:hover:bg-primary-800",!e.visible&&"opacity-40"),"aria-pressed":e.visible,children:[jsxRuntime.jsx("span",{className:"h-2.5 w-5 rounded-sm shrink-0",style:{background:e.color}}),e.label]},e.id))})}function ne({series:t,xAxis:o,yAxis:r,orientation:e="vertical",grouped:a=true,barRadius:d=4,barPadding:s=.2,groupPadding:y=.3,title:x,height:C=300,className:R,legend:P=true,legendPosition:L="bottom",animateOnMount:b=true,emptyText:p="No data to display"}){let $=react.useRef(null),z=react.useRef(null),[S,B]=react.useState(600),[K,T]=react.useState(null);react.useEffect(()=>{let n=z.current;if(!n)return;let u=n.getBoundingClientRect().width;u>0&&B(u);let V=new ResizeObserver(v=>{let W=v[0]?.contentRect.width;W&&W>0&&B(W);});return V.observe(n),()=>V.disconnect()},[]);let N=react.useMemo(()=>t.map(n=>n.id),[t]),{visible:w,toggle:I,isVisible:U}=$t(N),G=react.useMemo(()=>Vt(t.length),[t.length]),q=react.useMemo(()=>new Map(t.map((n,u)=>[n.id,n.color??G[u]])),[t,G]),D=e==="horizontal",gt=react.useMemo(()=>Ft(!!o?.label,!!r?.label,false),[o?.label,r?.label]),i=react.useMemo(()=>Et(S,C,gt),[S,C,gt]),A=react.useMemo(()=>ge(t,w),[t,w]),c=react.useMemo(()=>xe(t,w,a,D?o:r),[t,w,a,D,o,r]),F=react.useMemo(()=>ye(c,D?[i.plotLeft,i.plotRight]:[i.plotBottom,i.plotTop]),[c,i,D]),E=react.useMemo(()=>be(c,(D?o:r)?.tickCount??5),[c,D,o,r]),ut=react.useMemo(()=>D?a?ke(t,w,A,q,i.plotLeft,i.plotTop,i.plotHeight,F,y,s):Ce(t,w,A,q,i.plotLeft,i.plotTop,i.plotHeight,F,y):a?ve(t,w,A,q,i.plotLeft,i.plotWidth,i.plotBottom,i.plotTop,F,y,s):Se(t,w,A,q,i.plotLeft,i.plotWidth,i.plotBottom,F,y),[t,w,A,q,i,F,a,D,y,s]),xt=A.length>0?i.plotWidth/A.length:1,mt=A.length>0?i.plotHeight/A.length:1,yt=react.useCallback((n,u)=>{let V=$.current?.getBoundingClientRect();if(!V)return;let v=t.filter(W=>U(W.id)).map(W=>{let J=W.data.find(it=>String(it.x)===u);return {name:W.name,value:J?tt(J.y,r?.format):"\u2014",color:q.get(W.id)??"var(--color-chart-1)"}});T({x:n.clientX-V.left+12,y:n.clientY-V.top-10,category:u,items:v});},[t,U,q,r?.format]),nt=react.useMemo(()=>t.map((n,u)=>({id:n.id,label:n.name,color:n.color??G[u],visible:U(n.id)})),[t,G,U]),et=t.some(n=>n.data.length>0),pt=L==="left"||L==="right",dt=jsxRuntime.jsxs("svg",{role:"img","aria-label":x??"Bar chart",width:i.width,height:i.height,viewBox:`0 0 ${i.width} ${i.height}`,shapeRendering:"geometricPrecision",children:[E.map(n=>{let u=F(n);return D?jsxRuntime.jsx("line",{x1:u,x2:u,y1:i.plotTop,y2:i.plotBottom,stroke:"currentColor",strokeWidth:.5,strokeDasharray:"4 4",className:"text-secondary-200 dark:text-secondary-700"},n):jsxRuntime.jsx("line",{x1:i.plotLeft,x2:i.plotRight,y1:u,y2:u,stroke:"currentColor",strokeWidth:.5,strokeDasharray:"4 4",className:"text-secondary-200 dark:text-secondary-700"},n)}),ut.map(n=>{let u=Math.min(d,n.width/2,n.height/2),V=`${n.seriesId}-${n.category}`;return D?jsxRuntime.jsx("rect",{x:n.x,y:n.y,width:n.width,height:n.height,rx:u,fill:n.color,className:rt("chart-bar-h",b&&"chart-bar-animate"),onMouseMove:v=>yt(v,n.category),onMouseLeave:()=>T(null)},V):jsxRuntime.jsx("rect",{x:n.x,y:n.y,width:n.width,height:n.height,rx:u,fill:n.color,className:rt("chart-bar-v",b&&"chart-bar-animate"),onMouseMove:v=>yt(v,n.category),onMouseLeave:()=>T(null)},V)}),jsxRuntime.jsx("line",{x1:i.plotLeft,x2:i.plotLeft,y1:i.plotTop,y2:i.plotBottom,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsxRuntime.jsx("line",{x1:i.plotLeft,x2:i.plotRight,y1:i.plotBottom,y2:i.plotBottom,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),!D&&E.map(n=>{let u=F(n);return jsxRuntime.jsxs("g",{children:[jsxRuntime.jsx("line",{x1:i.plotLeft-4,x2:i.plotLeft,y1:u,y2:u,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsxRuntime.jsx("text",{x:i.plotLeft-6,y:u,textAnchor:"end",dominantBaseline:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:tt(n,r?.format)})]},n)}),D&&E.map(n=>{let u=F(n);return jsxRuntime.jsxs("g",{children:[jsxRuntime.jsx("line",{x1:u,x2:u,y1:i.plotBottom,y2:i.plotBottom+4,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsxRuntime.jsx("text",{x:u,y:i.plotBottom+14,textAnchor:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:tt(n,o?.format)})]},n)}),A.map((n,u)=>{if(D){let v=i.plotTop+(u+.5)*mt;return jsxRuntime.jsx("text",{x:i.plotLeft-6,y:v,textAnchor:"end",dominantBaseline:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:n},n)}let V=i.plotLeft+(u+.5)*xt;return jsxRuntime.jsx("text",{x:V,y:i.plotBottom+14,textAnchor:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:n},n)}),r?.label&&!D&&jsxRuntime.jsx("text",{x:-(i.plotTop+i.plotHeight/2),y:14,textAnchor:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-600 dark:text-secondary-400",transform:"rotate(-90)",children:r.label}),o?.label&&jsxRuntime.jsx("text",{x:i.plotLeft+i.plotWidth/2,y:i.height-4,textAnchor:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-600 dark:text-secondary-400",children:o.label})]});return jsxRuntime.jsxs("div",{ref:$,className:rt(Mt(),R),children:[x&&jsxRuntime.jsx("h3",{className:"mb-2 text-sm font-semibold text-primary-700 dark:text-primary-200",children:x}),P&&L==="top"&&jsxRuntime.jsx(jt,{items:nt,position:"top",onToggle:I}),jsxRuntime.jsxs("div",{className:rt("flex items-start",pt&&"gap-0"),children:[P&&L==="left"&&jsxRuntime.jsx(jt,{items:nt,position:"left",onToggle:I}),jsxRuntime.jsx("div",{ref:z,className:"flex-1 min-w-0 overflow-hidden",children:et?dt:jsxRuntime.jsx("div",{className:"flex items-center justify-center text-secondary-400 dark:text-secondary-500",style:{height:C},children:p})}),P&&L==="right"&&jsxRuntime.jsx(jt,{items:nt,position:"right",onToggle:I})]}),P&&L==="bottom"&&jsxRuntime.jsx(jt,{items:nt,position:"bottom",onToggle:I}),K&&jsxRuntime.jsxs("div",{className:Tt(),style:{left:K.x,top:K.y},role:"tooltip",children:[jsxRuntime.jsx("div",{className:"mb-1 font-medium text-primary-200",children:K.category}),K.items.map((n,u)=>jsxRuntime.jsxs("div",{className:"flex items-center gap-1.5",children:[jsxRuntime.jsx("span",{className:"h-2 w-2 rounded-full shrink-0",style:{background:n.color}}),jsxRuntime.jsxs("span",{className:"text-primary-300",children:[n.name,":"]}),jsxRuntime.jsx("span",{className:"font-medium",children:n.value})]},u))]})]})}function Me(t,o,r,e,a,d,s,y,x){let C=t.filter(p=>o.has(p.id)),R=C.reduce((p,$)=>p+$.value,0);if(R===0)return [];let P=new Map(t.map((p,$)=>[p.id,p.color??r[$%r.length]])),L=[],b=y;for(let p of C){let $=p.value/R*360,z=x/2,S=b+z,B=b+$-z,K=(S+B)/2,T;if(Math.abs(B-S)>=359.9){let N=kt(d,s,e,S),w=kt(d,s,e,S+180);T=`M ${N.x.toFixed(3)} ${N.y.toFixed(3)} A ${e} ${e} 0 1 1 ${w.x.toFixed(3)} ${w.y.toFixed(3)} A ${e} ${e} 0 1 1 ${N.x.toFixed(3)} ${N.y.toFixed(3)} Z`;}else if(a>0){let N=kt(d,s,e,S),w=kt(d,s,e,B),I=kt(d,s,a,B),U=kt(d,s,a,S),G=B-S>180?1:0;T=`M ${N.x.toFixed(3)} ${N.y.toFixed(3)} A ${e} ${e} 0 ${G} 1 ${w.x.toFixed(3)} ${w.y.toFixed(3)} L ${I.x.toFixed(3)} ${I.y.toFixed(3)} A ${a} ${a} 0 ${G} 0 ${U.x.toFixed(3)} ${U.y.toFixed(3)} Z`;}else {let N=kt(d,s,e,S),w=kt(d,s,e,B),I=B-S>180?1:0;T=`M ${d.toFixed(3)} ${s.toFixed(3)} L ${N.x.toFixed(3)} ${N.y.toFixed(3)} A ${e} ${e} 0 ${I} 1 ${w.x.toFixed(3)} ${w.y.toFixed(3)} Z`;}L.push({id:p.id,label:p.label,value:p.value,percent:Math.round(p.value/R*1e3)/10,color:P.get(p.id)??"var(--color-chart-1)",startAngle:S,endAngle:B,midAngle:K,path:T,outerR:e,innerR:a,cx:d,cy:s}),b+=$;}return L}function Le(t,o){let r=(t-90)*Math.PI/180;return {dx:Math.cos(r)*o,dy:Math.sin(r)*o}}function Zt({items:t,position:o,onToggle:r}){return jsxRuntime.jsx("div",{className:Lt({position:o}),children:t.map(e=>jsxRuntime.jsxs("button",{onClick:()=>r(e.id),className:rt("flex items-center gap-1.5 cursor-pointer rounded px-1.5 py-1 text-xs text-primary-700 transition-opacity hover:bg-primary-100 dark:text-primary-300 dark:hover:bg-primary-800",!e.visible&&"opacity-40"),"aria-pressed":e.visible,children:[jsxRuntime.jsx("span",{className:"h-2.5 w-2.5 rounded-full shrink-0",style:{background:e.color}}),jsxRuntime.jsx("span",{children:e.label}),jsxRuntime.jsxs("span",{className:"text-secondary-400",children:["(",e.percent,"%)"]})]},e.id))})}function se({data:t,donut:o=false,donutThickness:r=.5,startAngle:e=-90,padAngle:a=0,labelType:d="percent",centerLabel:s,centerSubLabel:y,explodeOnHover:x=true,explodeOffset:C=8,title:R,height:P=300,className:L,legend:b=true,legendPosition:p="bottom",animateOnMount:$=true,emptyText:z="No data to display"}){let S=react.useRef(null),B=react.useRef(null),[K,T]=react.useState(400),[N,w]=react.useState(null),[I,U]=react.useState(null),[G,q]=react.useState({}),D=react.useRef(null);react.useEffect(()=>{let m=B.current;if(!m)return;let M=m.getBoundingClientRect().width;M>0&&T(M);let g=new ResizeObserver(h=>{let _=h[0]?.contentRect.width;_&&_>0&&T(_);});return g.observe(m),()=>g.disconnect()},[]),react.useEffect(()=>{function m(g){let h=D.current;if(!h)return;"touches"in g&&g.cancelable&&g.preventDefault();let _="touches"in g?g.touches[0]?.clientX??h.startX:g.clientX,ht="touches"in g?g.touches[0]?.clientY??h.startY:g.clientY;q(vt=>({...vt,[h.id]:{dx:h.origDx+_-h.startX,dy:h.origDy+ht-h.startY}}));}function M(){D.current=null;}return window.addEventListener("mousemove",m),window.addEventListener("mouseup",M),window.addEventListener("touchmove",m,{passive:false}),window.addEventListener("touchend",M),()=>{window.removeEventListener("mousemove",m),window.removeEventListener("mouseup",M),window.removeEventListener("touchmove",m),window.removeEventListener("touchend",M);}},[]);let gt=react.useMemo(()=>t.map(m=>m.id),[t]),{visible:i,toggle:A,isVisible:c}=$t(gt),F=react.useMemo(()=>Vt(t.length),[t.length]),E=10,ut=6.4,xt=18,mt=14,yt=6,nt=K,et=P,pt=nt/2,dt=et/2,n=d!=="none"?xt+yt+4:yt+4,u=Math.max(Math.min(pt,dt)-n,20),V=o?u*r:0,v=react.useMemo(()=>Me(t,i,F,u,V,pt,dt,e,a),[t,i,F,u,V,pt,dt,e,a]),W=react.useMemo(()=>v.map(m=>m.id).join(","),[v]);react.useEffect(()=>{q({});},[W]);let J=react.useCallback((m,M)=>{if(D.current)return;let g=S.current?.getBoundingClientRect();if(!g)return;w(M);let h=v.find(_=>_.id===M);h&&U({x:m.clientX-g.left+12,y:m.clientY-g.top-10,items:[{label:h.label,value:tt(h.value),percent:`${h.percent}%`,color:h.color}]});},[v]),it=react.useCallback(()=>{w(null),U(null);},[]),l=react.useCallback((m,M,g)=>{let h=G[m]??{dx:0,dy:0};D.current={id:m,startX:M,startY:g,origDx:h.dx,origDy:h.dy};},[G]),k=react.useCallback((m,M)=>{m.preventDefault(),w(M);let g=S.current?.getBoundingClientRect();if(!g)return;let h=m.touches[0];if(!h)return;let _=v.find(ht=>ht.id===M);_&&U({x:h.clientX-g.left+12,y:h.clientY-g.top-10,items:[{label:_.label,value:tt(_.value),percent:`${_.percent}%`,color:_.color}]});},[v]),X=react.useMemo(()=>{let m=t.reduce((M,g)=>M+g.value,0);return t.map((M,g)=>({id:M.id,label:M.label,color:M.color??F[g],visible:c(M.id),percent:m>0?Math.round(M.value/m*1e3)/10:0}))},[t,F,c]),Q=t.length>0&&t.some(m=>m.value>0),j=p==="left"||p==="right",st=react.useMemo(()=>{if(d==="none")return [];let m=E+3,M=yt+E*.5,g=et-yt-E*.5,h=v.filter(f=>f.percent>=3).map(f=>{let at="";switch(d){case "percent":at=`${f.percent}%`;break;case "value":at=tt(f.value);break;case "label":at=f.label;break;case "label+percent":at=`${f.label} ${f.percent}%`;break}let wt=kt(f.cx,f.cy,f.outerR+2,f.midAngle),ct=kt(f.cx,f.cy,f.outerR+xt,f.midAngle),Y=(f.midAngle-90)*Math.PI/180,Wt=Math.cos(Y)>=0,Ht=Math.ceil(at.length*ut);return {id:f.id,color:f.color,text:at,textW:Ht,p1:wt,elbowX:ct.x,y:ct.y,isRight:Wt}}),_=h.filter(f=>f.isRight).sort((f,at)=>f.y-at.y),ht=h.filter(f=>!f.isRight).sort((f,at)=>f.y-at.y);function vt(f){if(f.length!==0)for(let at=0;at<20;at++){let wt=false;for(let Y=1;Y<f.length;Y++){let Wt=f[Y].y-f[Y-1].y;if(Wt<m){let Ht=(m-Wt)/2;f[Y-1].y-=Ht,f[Y].y+=Ht,wt=true;}}f[0].y<M&&(f[0].y=M);for(let Y=1;Y<f.length;Y++)f[Y].y<f[Y-1].y+m&&(f[Y].y=f[Y-1].y+m);let ct=f.length-1;f[ct].y>g&&(f[ct].y=g);for(let Y=ct-1;Y>=0;Y--)f[Y].y>f[Y+1].y-m&&(f[Y].y=f[Y+1].y-m);for(let Y of f)Y.y=Math.max(M,Math.min(g,Y.y));if(!wt)break}}return vt(_),vt(ht),[...ht,..._]},[v,d,et]),bt=jsxRuntime.jsxs("svg",{role:"img","aria-label":R??"Pie chart",width:nt,height:et,viewBox:`0 0 ${nt} ${et}`,shapeRendering:"geometricPrecision",children:[jsxRuntime.jsxs("g",{className:$?"chart-pie-animate":"",children:[v.map((m,M)=>{let g=N===m.id,h=x&&g,_=Le(m.midAngle,h?C:0);return jsxRuntime.jsx("path",{d:m.path,fill:m.color,transform:h?`translate(${_.dx}, ${_.dy})`:void 0,className:rt("chart-slice",$&&`chart-slice-animate-${Math.min(M,7)}`,g&&"chart-slice--exploded"),stroke:m.color,strokeWidth:.6,onMouseMove:ht=>J(ht,m.id),onMouseLeave:it,onTouchStart:ht=>k(ht,m.id),onTouchEnd:it,"aria-label":`${m.label}: ${m.percent}%`},m.id)}),st.map(m=>{let M=G[m.id]??{dx:0,dy:0},g=m.elbowX+M.dx,h=m.y+M.dy,_=g+(m.isRight?mt:-mt),ht=m.isRight?_+3:_-3,vt=mt+3+m.textW+6,f=m.isRight?g:g-vt,at=h-E-2,wt=E*2+4;return jsxRuntime.jsxs("g",{style:{userSelect:"none"},children:[jsxRuntime.jsx("polyline",{points:[`${m.p1.x.toFixed(2)},${m.p1.y.toFixed(2)}`,`${g.toFixed(2)},${h.toFixed(2)}`,`${_.toFixed(2)},${h.toFixed(2)}`].join(" "),fill:"none",stroke:m.color,strokeWidth:1.2,opacity:.85,strokeLinejoin:"round",strokeLinecap:"round",style:{pointerEvents:"none"}}),jsxRuntime.jsx("text",{x:ht.toFixed(2),y:h.toFixed(2),textAnchor:m.isRight?"start":"end",dominantBaseline:"middle",fontSize:E,fill:"currentColor",className:"text-primary-700 dark:text-primary-300",style:{pointerEvents:"none"},children:m.text}),jsxRuntime.jsx("rect",{x:f,y:at,width:vt,height:wt,fill:"transparent",style:{cursor:"grab",touchAction:"none"},onMouseDown:ct=>{ct.stopPropagation(),l(m.id,ct.clientX,ct.clientY);},onTouchStart:ct=>{ct.stopPropagation();let Y=ct.touches[0];Y&&l(m.id,Y.clientX,Y.clientY);}})]},`label-${m.id}`)})]}),o&&jsxRuntime.jsx("g",{style:{pointerEvents:"none"},children:N&&v.find(m=>m.id===N)?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("text",{x:pt,y:dt-8,textAnchor:"middle",dominantBaseline:"middle",fontSize:18,fontWeight:600,fill:"currentColor",className:"text-primary-800 dark:text-primary-100",children:[v.find(m=>m.id===N)?.percent,"%"]}),jsxRuntime.jsx("text",{x:pt,y:dt+12,textAnchor:"middle",dominantBaseline:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:v.find(m=>m.id===N)?.label})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[s&&jsxRuntime.jsx("text",{x:pt,y:dt-(y?8:0),textAnchor:"middle",dominantBaseline:"middle",fontSize:16,fontWeight:600,fill:"currentColor",className:"text-primary-800 dark:text-primary-100",children:s}),y&&jsxRuntime.jsx("text",{x:pt,y:dt+14,textAnchor:"middle",dominantBaseline:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:y})]})})]});return jsxRuntime.jsxs("div",{ref:S,className:rt(Mt(),L),children:[R&&jsxRuntime.jsx("h3",{className:"mb-2 text-sm font-semibold text-primary-700 dark:text-primary-200",children:R}),b&&p==="top"&&jsxRuntime.jsx(Zt,{items:X,position:"top",onToggle:A}),jsxRuntime.jsxs("div",{className:rt("flex items-start justify-center",j&&"gap-0"),children:[b&&p==="left"&&jsxRuntime.jsx(Zt,{items:X,position:"left",onToggle:A}),jsxRuntime.jsx("div",{ref:B,className:"flex-1 min-w-0 overflow-hidden",children:Q?bt:jsxRuntime.jsx("div",{className:"flex items-center justify-center text-secondary-400 dark:text-secondary-500",style:{height:P},children:z})}),b&&p==="right"&&jsxRuntime.jsx(Zt,{items:X,position:"right",onToggle:A})]}),b&&p==="bottom"&&jsxRuntime.jsx(Zt,{items:X,position:"bottom",onToggle:A}),I&&jsxRuntime.jsx("div",{className:Tt(),style:{left:I.x,top:I.y},role:"tooltip",children:I.items.map((m,M)=>jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{className:"h-2.5 w-2.5 rounded-full shrink-0",style:{background:m.color}}),jsxRuntime.jsxs("span",{className:"font-medium",children:[m.label,":"]}),jsxRuntime.jsx("span",{children:m.value}),jsxRuntime.jsxs("span",{className:"text-primary-300",children:["(",m.percent,")"]})]},M))})]})}function Be(t,o,r){let e=1/0,a=-1/0;for(let y of t)if(o.has(y.id))for(let x of y.data){let C=Number(x.x);C<e&&(e=C),C>a&&(a=C);}if(!isFinite(e))return [0,1];let[d,s]=Dt(e,a);return [r?.min??d,r?.max??s]}function Re(t,o,r){let e=1/0,a=-1/0;for(let y of t)if(o.has(y.id))for(let x of y.data)x.y<e&&(e=x.y),x.y>a&&(a=x.y);if(!isFinite(e))return [0,1];let[d,s]=Dt(e,a);return [r?.min??d,r?.max??s]}function ce(t,o){let[r,e]=t,[a,d]=o;return e===r?()=>(a+d)/2:s=>a+(s-r)/(e-r)*(d-a)}function le(t,o=5){return Xt(t[0],t[1],o)}function $e(t,o,r){let e=1.618033988749895,a=t*137+o,d=a*e%1*2-1,s=a*e*e%1*2-1;return [d*r,s*r]}function Ve(t,o,r=12){if(t.length<2)return null;let e=Math.min(...t),a=Math.max(...t),d=Math.min(...o),s=Math.max(...o);return {cx:(e+a)/2,cy:(d+s)/2,rx:(a-e)/2+r,ry:(s-d)/2+r}}function Kt({items:t,position:o,onToggle:r}){return jsxRuntime.jsx("div",{className:Lt({position:o}),children:t.map(e=>jsxRuntime.jsxs("button",{onClick:()=>r(e.id),className:rt("flex items-center gap-1.5 cursor-pointer rounded px-1.5 py-1 text-xs text-primary-700 transition-opacity hover:bg-primary-100 dark:text-primary-300 dark:hover:bg-primary-800",!e.visible&&"opacity-40"),"aria-pressed":e.visible,children:[jsxRuntime.jsx("span",{className:"h-2.5 w-2.5 rounded-full shrink-0",style:{background:e.color}}),e.label]},e.id))})}function me({series:t,xAxis:o,yAxis:r,dotRadius:e=5,dotOpacity:a=.75,clusters:d=false,jitter:s=false,jitterAmount:y=12,linkedLines:x=false,title:C,height:R=300,className:P,legend:L=true,legendPosition:b="bottom",animateOnMount:p=true,emptyText:$="No data to display"}){let z=react.useRef(null),S=react.useRef(null),[B,K]=react.useState(600),[T,N]=react.useState(null);react.useEffect(()=>{let n=S.current;if(!n)return;let u=n.getBoundingClientRect().width;u>0&&K(u);let V=new ResizeObserver(v=>{let W=v[0]?.contentRect.width;W&&W>0&&K(W);});return V.observe(n),()=>V.disconnect()},[]);let w=react.useMemo(()=>t.map(n=>n.id),[t]),{visible:I,toggle:U,isVisible:G}=$t(w),q=react.useMemo(()=>Vt(t.length),[t.length]),D=react.useMemo(()=>new Map(t.map((n,u)=>[n.id,n.color??q[u]])),[t,q]),gt=react.useMemo(()=>Ft(!!o?.label,!!r?.label,false),[o?.label,r?.label]),i=react.useMemo(()=>Et(B,R,gt),[B,R,gt]),A=react.useMemo(()=>Be(t,I,o),[t,I,o]),c=react.useMemo(()=>Re(t,I,r),[t,I,r]),F=react.useMemo(()=>ce(A,[i.plotLeft,i.plotRight]),[A,i]),E=react.useMemo(()=>ce(c,[i.plotBottom,i.plotTop]),[c,i]),ut=react.useMemo(()=>le(A,o?.tickCount??6),[A,o?.tickCount]),xt=react.useMemo(()=>le(c,r?.tickCount??5),[c,r?.tickCount]),mt=react.useCallback((n,u,V,v,W)=>{let J=z.current?.getBoundingClientRect();J&&N({x:n.clientX-J.left+12,y:n.clientY-J.top-10,seriesName:u,xVal:tt(V,o?.format),yVal:tt(v,r?.format),color:W});},[o?.format,r?.format]),yt=react.useCallback((n,u,V,v,W)=>{n.preventDefault();let J=z.current?.getBoundingClientRect();if(!J)return;let it=n.touches[0];it&&N({x:it.clientX-J.left+12,y:it.clientY-J.top-10,seriesName:u,xVal:tt(V,o?.format),yVal:tt(v,r?.format),color:W});},[o?.format,r?.format]),nt=react.useMemo(()=>t.map((n,u)=>({id:n.id,label:n.name,color:n.color??q[u],visible:G(n.id)})),[t,q,G]),et=t.some(n=>n.data.length>0),pt=b==="left"||b==="right",dt=jsxRuntime.jsxs("svg",{role:"img","aria-label":C??"Scatter chart",width:i.width,height:i.height,viewBox:`0 0 ${i.width} ${i.height}`,shapeRendering:"geometricPrecision",children:[xt.map(n=>jsxRuntime.jsx("line",{x1:i.plotLeft,x2:i.plotRight,y1:E(n),y2:E(n),stroke:"currentColor",strokeWidth:.5,strokeDasharray:"4 4",className:"text-secondary-200 dark:text-secondary-700"},n)),d&&t.map((n,u)=>{if(!G(n.id)||n.data.length<2)return null;let V=D.get(n.id)??"var(--color-chart-1)",v=n.data.map(it=>F(Number(it.x))),W=n.data.map(it=>E(it.y)),J=Ve(v,W,16);return J?jsxRuntime.jsx("ellipse",{cx:J.cx,cy:J.cy,rx:J.rx,ry:J.ry,fill:V,fillOpacity:.06,stroke:V,strokeOpacity:.3,strokeWidth:1.5,strokeDasharray:"5 3",className:p?"chart-cluster-ellipse":"",style:{animationDelay:`${u*.1}s`}},`cluster-${n.id}`):null}),x&&t.map(n=>{if(!G(n.id)||n.data.length<2)return null;let u=D.get(n.id)??"var(--color-chart-1)",v=[...n.data].sort((W,J)=>Number(W.x)-Number(J.x)).map(W=>`${F(Number(W.x)).toFixed(2)},${E(W.y).toFixed(2)}`).join(" ");return jsxRuntime.jsx("polyline",{points:v,fill:"none",stroke:u,strokeWidth:1.5,className:"chart-scatter-link"},`link-${n.id}`)}),t.map((n,u)=>{if(!G(n.id))return null;let V=D.get(n.id)??"var(--color-chart-1)";return jsxRuntime.jsx("g",{className:"chart-scatter-group",children:n.data.map((v,W)=>{let[J,it]=s?$e(u,W,y):[0,0],l=F(Number(v.x))+J,k=E(v.y)+it;return jsxRuntime.jsx("circle",{cx:l,cy:k,r:e,fill:V,fillOpacity:a,stroke:V,strokeWidth:1,strokeOpacity:.5,className:rt("chart-scatter-dot",p&&"chart-scatter-dot--animate"),style:{color:V},onMouseMove:X=>mt(X,n.name,v.x,v.y,V),onMouseLeave:()=>N(null),onTouchStart:X=>yt(X,n.name,v.x,v.y,V),onTouchEnd:()=>N(null)},W)})},n.id)}),jsxRuntime.jsx("line",{x1:i.plotLeft,x2:i.plotLeft,y1:i.plotTop,y2:i.plotBottom,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsxRuntime.jsx("line",{x1:i.plotLeft,x2:i.plotRight,y1:i.plotBottom,y2:i.plotBottom,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),xt.map(n=>{let u=E(n);return jsxRuntime.jsxs("g",{children:[jsxRuntime.jsx("line",{x1:i.plotLeft-4,x2:i.plotLeft,y1:u,y2:u,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsxRuntime.jsx("text",{x:i.plotLeft-6,y:u,textAnchor:"end",dominantBaseline:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:tt(n,r?.format)})]},n)}),ut.map(n=>{let u=F(n);return jsxRuntime.jsxs("g",{children:[jsxRuntime.jsx("line",{x1:u,x2:u,y1:i.plotBottom,y2:i.plotBottom+4,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsxRuntime.jsx("text",{x:u,y:i.plotBottom+14,textAnchor:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:tt(n,o?.format)})]},n)}),r?.label&&jsxRuntime.jsx("text",{x:-(i.plotTop+i.plotHeight/2),y:14,textAnchor:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-600 dark:text-secondary-400",transform:"rotate(-90)",children:r.label}),o?.label&&jsxRuntime.jsx("text",{x:i.plotLeft+i.plotWidth/2,y:i.height-4,textAnchor:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-600 dark:text-secondary-400",children:o.label})]});return jsxRuntime.jsxs("div",{ref:z,className:rt(Mt(),P),children:[C&&jsxRuntime.jsx("h3",{className:"mb-2 text-sm font-semibold text-primary-700 dark:text-primary-200",children:C}),L&&b==="top"&&jsxRuntime.jsx(Kt,{items:nt,position:"top",onToggle:U}),jsxRuntime.jsxs("div",{className:rt("flex items-start",pt&&"gap-0"),children:[L&&b==="left"&&jsxRuntime.jsx(Kt,{items:nt,position:"left",onToggle:U}),jsxRuntime.jsx("div",{ref:S,className:"flex-1 min-w-0 overflow-hidden",children:et?dt:jsxRuntime.jsx("div",{className:"flex items-center justify-center text-secondary-400 dark:text-secondary-500",style:{height:R},children:$})}),L&&b==="right"&&jsxRuntime.jsx(Kt,{items:nt,position:"right",onToggle:U})]}),L&&b==="bottom"&&jsxRuntime.jsx(Kt,{items:nt,position:"bottom",onToggle:U}),T&&jsxRuntime.jsxs("div",{className:Tt(),style:{left:T.x,top:T.y},role:"tooltip",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[jsxRuntime.jsx("span",{className:"h-2 w-2 rounded-full",style:{background:T.color}}),jsxRuntime.jsx("span",{className:"font-medium",children:T.seriesName})]}),jsxRuntime.jsxs("div",{className:"text-primary-300",children:["X: ",jsxRuntime.jsx("span",{className:"font-medium text-primary-50",children:T.xVal})," ","Y: ",jsxRuntime.jsx("span",{className:"font-medium text-primary-50",children:T.yVal})]})]})]})}var je={LineChart:oe,BarChart:ne,PieChart:se,ScatterChart:me},lo=je;exports.BarChart=ne;exports.Chart=je;exports.LineChart=oe;exports.PieChart=se;exports.ScatterChart=me;exports.default=lo;
@@ -0,0 +1 @@
1
+ @keyframes chart-line-draw{0%{stroke-dashoffset:3000}to{stroke-dashoffset:0}}@keyframes chart-dot-pop{0%{r:0;opacity:0}to{opacity:1}}@keyframes chart-area-fade{0%{opacity:0}to{opacity:1}}.chart-line-animate{stroke-dasharray:3000;stroke-dashoffset:3000;animation:chart-line-draw 1s ease-out forwards}.chart-line-animate:nth-child(2){animation-delay:.1s}.chart-line-animate:nth-child(3){animation-delay:.2s}.chart-line-animate:nth-child(4){animation-delay:.3s}.chart-line-animate:nth-child(5){animation-delay:.4s}.chart-area-animate{animation:chart-area-fade .8s ease-out forwards;opacity:0}.chart-dot-animate{animation:chart-dot-pop .4s ease-out forwards;animation-delay:.8s;opacity:0}circle.chart-dot{transition:r .15s ease,filter .15s ease;cursor:crosshair}circle.chart-dot:hover,circle.chart-dot.chart-dot--active{filter:drop-shadow(0 0 4px currentColor)}.chart-crosshair{pointer-events:none;transition:opacity .1s ease}@keyframes chart-bar-rise{0%{clip-path:inset(100% 0 0 0);opacity:.5}to{clip-path:inset(0% 0 0 0);opacity:1}}@keyframes chart-bar-extend{0%{clip-path:inset(0 100% 0 0);opacity:.5}to{clip-path:inset(0 0% 0 0);opacity:1}}.chart-bar-v{transition:filter .18s ease}.chart-bar-v.chart-bar-animate{animation:chart-bar-rise .6s cubic-bezier(.22,1,.36,1) both}.chart-bar-h{transition:filter .18s ease}.chart-bar-h.chart-bar-animate{animation:chart-bar-extend .6s cubic-bezier(.22,1,.36,1) both}.chart-bar-v:hover,.chart-bar-h:hover{filter:brightness(1.18);cursor:pointer}.chart-bar-hidden{opacity:0;pointer-events:none}@keyframes chart-pie-scale-in{0%{transform:scale(0);opacity:0}to{transform:scale(1);opacity:1}}@keyframes chart-pie-slice-appear{0%{opacity:0;transform:scale(.7)}to{opacity:1;transform:scale(1)}}.chart-pie-animate{transform-origin:center;animation:chart-pie-scale-in .6s cubic-bezier(.34,1.56,.64,1) forwards}.chart-slice{transform-origin:center;transition:transform .2s ease,filter .15s ease;cursor:pointer}.chart-slice-animate-0{animation:chart-pie-slice-appear .4s ease-out 0s both}.chart-slice-animate-1{animation:chart-pie-slice-appear .4s ease-out .06s both}.chart-slice-animate-2{animation:chart-pie-slice-appear .4s ease-out .12s both}.chart-slice-animate-3{animation:chart-pie-slice-appear .4s ease-out .18s both}.chart-slice-animate-4{animation:chart-pie-slice-appear .4s ease-out .24s both}.chart-slice-animate-5{animation:chart-pie-slice-appear .4s ease-out .3s both}.chart-slice-animate-6{animation:chart-pie-slice-appear .4s ease-out .36s both}.chart-slice-animate-7{animation:chart-pie-slice-appear .4s ease-out .42s both}.chart-slice--exploded{filter:brightness(1.12) drop-shadow(0 4px 8px rgba(0,0,0,.25))}.chart-slice--hidden{opacity:.12;pointer-events:none}@keyframes chart-dot-fade-in{0%{opacity:0;transform:scale(0)}to{opacity:1;transform:scale(1)}}.chart-scatter-dot{transition:r .15s ease,filter .15s ease;cursor:crosshair}.chart-scatter-dot.chart-scatter-dot--animate{animation:chart-dot-fade-in .35s ease-out forwards;opacity:0}.chart-scatter-group:nth-child(1) .chart-scatter-dot{animation-delay:.05s}.chart-scatter-group:nth-child(2) .chart-scatter-dot{animation-delay:.15s}.chart-scatter-group:nth-child(3) .chart-scatter-dot{animation-delay:.25s}.chart-scatter-group:nth-child(4) .chart-scatter-dot{animation-delay:.35s}.chart-scatter-dot:hover{filter:drop-shadow(0 0 5px currentColor)}.chart-cluster-ellipse{pointer-events:none;animation:chart-dot-fade-in .4s ease-out forwards;opacity:0}.chart-scatter-link{pointer-events:none;opacity:.4}
@@ -0,0 +1,12 @@
1
+ export { LineChart_alias_1 as LineChart } from '../_tsup-dts-rollup.cjs';
2
+ export { BarChart_alias_1 as BarChart } from '../_tsup-dts-rollup.cjs';
3
+ export { PieChart_alias_1 as PieChart } from '../_tsup-dts-rollup.cjs';
4
+ export { ScatterChart_alias_1 as ScatterChart } from '../_tsup-dts-rollup.cjs';
5
+ export { Chart_alias_1 as Chart } from '../_tsup-dts-rollup.cjs';
6
+ export { default_alias_1 as default } from '../_tsup-dts-rollup.cjs';
7
+ export { ChartDataPoint_alias_1 as ChartDataPoint } from '../_tsup-dts-rollup.cjs';
8
+ export { ChartSeries_alias_1 as ChartSeries } from '../_tsup-dts-rollup.cjs';
9
+ export { PieSlice_alias_1 as PieSlice } from '../_tsup-dts-rollup.cjs';
10
+ export { AxisConfig_alias_1 as AxisConfig } from '../_tsup-dts-rollup.cjs';
11
+ export { LegendItem_alias_1 as LegendItem } from '../_tsup-dts-rollup.cjs';
12
+ export { BaseChartProps_alias_1 as BaseChartProps } from '../_tsup-dts-rollup.cjs';
@@ -0,0 +1,12 @@
1
+ export { LineChart_alias_1 as LineChart } from '../_tsup-dts-rollup.js';
2
+ export { BarChart_alias_1 as BarChart } from '../_tsup-dts-rollup.js';
3
+ export { PieChart_alias_1 as PieChart } from '../_tsup-dts-rollup.js';
4
+ export { ScatterChart_alias_1 as ScatterChart } from '../_tsup-dts-rollup.js';
5
+ export { Chart_alias_1 as Chart } from '../_tsup-dts-rollup.js';
6
+ export { default_alias_1 as default } from '../_tsup-dts-rollup.js';
7
+ export { ChartDataPoint_alias_1 as ChartDataPoint } from '../_tsup-dts-rollup.js';
8
+ export { ChartSeries_alias_1 as ChartSeries } from '../_tsup-dts-rollup.js';
9
+ export { PieSlice_alias_1 as PieSlice } from '../_tsup-dts-rollup.js';
10
+ export { AxisConfig_alias_1 as AxisConfig } from '../_tsup-dts-rollup.js';
11
+ export { LegendItem_alias_1 as LegendItem } from '../_tsup-dts-rollup.js';
12
+ export { BaseChartProps_alias_1 as BaseChartProps } from '../_tsup-dts-rollup.js';
@@ -0,0 +1 @@
1
+ import {useRef,useState,useEffect,useMemo,useCallback}from'react';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {cva}from'class-variance-authority';import {jsxs,jsx,Fragment}from'react/jsx-runtime';function rt(...t){return twMerge(clsx(t))}var Mt=cva("relative w-full font-sans select-none",{variants:{size:{sm:"text-xs",md:"text-sm",lg:"text-base"}},defaultVariants:{size:"md"}}),Lt=cva("flex flex-wrap gap-3 items-center justify-center",{variants:{position:{top:"mb-3",bottom:"mt-3",left:"flex-col mr-4",right:"flex-col ml-4"}},defaultVariants:{position:"bottom"}}),Tt=cva("absolute z-50 pointer-events-none px-3 py-2 rounded-lg text-xs shadow-lg border transition-opacity duration-150 bg-primary-900 text-primary-50 border-primary-700 dark:bg-primary-950 dark:border-primary-800");function $t(t){let[o,r]=useState(()=>new Set(t)),e=useCallback(s=>{r(y=>{let x=new Set(y);return x.has(s)?x.delete(s):x.add(s),x});},[]),a=useCallback(s=>o.has(s),[o]),d=useCallback(()=>{r(new Set(t));},[t]);return {visible:o,toggle:e,isVisible:a,showAll:d}}function Vt(t){let o=["var(--color-chart-1)","var(--color-chart-2)","var(--color-chart-3)","var(--color-chart-4)","var(--color-chart-5)","var(--color-chart-6)","var(--color-chart-7)","var(--color-chart-8)"];return Array.from({length:t},(r,e)=>o[e%o.length])}function Dt(t,o,r=.1){if(t===o)return [t-1,o+1];let a=(o-t)*r;return [Math.floor(t-a),Math.ceil(o+a)]}function Xt(t,o,r){if(r<=1)return [t];let e=(o-t)/(r-1);return Array.from({length:r},(a,d)=>+(t+d*e).toFixed(10))}function tt(t,o){return o?o(t):typeof t=="number"?Math.abs(t)>=1e6?`${(t/1e6).toFixed(1)}M`:Math.abs(t)>=1e3?`${(t/1e3).toFixed(1)}K`:Number.isInteger(t)?t.toString():t.toFixed(2):String(t)}function kt(t,o,r,e){let a=(e-90)*Math.PI/180;return {x:t+r*Math.cos(a),y:o+r*Math.sin(a)}}function Ft(t,o,r){return {top:20,right:r?65:20,bottom:t?52:36,left:o?65:52}}function Et(t,o,r){let e=Math.max(t,120);return {width:e,height:o,margins:r,plotLeft:r.left,plotTop:r.top,plotRight:e-r.right,plotBottom:o-r.bottom,plotWidth:Math.max(e-r.left-r.right,10),plotHeight:Math.max(o-r.top-r.bottom,10)}}function de(t,o){let r=new Set,e=[];for(let a of t)if(o.has(a.id))for(let d of a.data){let s=String(d.x);r.has(s)||(r.add(s),e.push(s));}return e}function Ut(t,o,r){let e=1/0,a=-1/0;for(let y of t)if(o.has(y.id))for(let x of y.data)x.y<e&&(e=x.y),x.y>a&&(a=x.y);if(!isFinite(e))return [0,1];let[d,s]=Dt(e,a);return [r?.min??d,r?.max??s]}function zt(t,o){let[r,e]=t,[a,d]=o;return e===r?()=>(a+d)/2:s=>a+(s-r)/(e-r)*(d-a)}function It(t,o){let r=t.length;if(r===0)return ()=>(o[0]+o[1])/2;let e=(o[1]-o[0])/r;return a=>{let d=t.indexOf(a);return d<0?(o[0]+o[1])/2:o[0]+d*e+e/2}}function ue(t,o,r){return t.map(e=>`${o(e.x).toFixed(2)},${r(e.y).toFixed(2)}`).join(" ")}function qt(t,o,r){if(t.length===0)return "";let e=t.map(s=>({x:o(s.x),y:r(s.y)}));if(e.length===1)return `M ${e[0].x.toFixed(2)} ${e[0].y.toFixed(2)}`;let a=.5,d=`M ${e[0].x.toFixed(2)} ${e[0].y.toFixed(2)}`;for(let s=0;s<e.length-1;s++){let y=s===0?{x:2*e[0].x-e[1].x,y:2*e[0].y-e[1].y}:e[s-1],x=e[s],C=e[s+1],R=s+2<e.length?e[s+2]:{x:2*e[e.length-1].x-e[e.length-2].x,y:2*e[e.length-1].y-e[e.length-2].y},P=x.x+(C.x-y.x)*a/3,L=x.y+(C.y-y.y)*a/3,b=C.x-(R.x-x.x)*a/3,p=C.y-(R.y-x.y)*a/3;d+=` C ${P.toFixed(2)} ${L.toFixed(2)}, ${b.toFixed(2)} ${p.toFixed(2)}, ${C.x.toFixed(2)} ${C.y.toFixed(2)}`;}return d}function pe(t,o,r,e,a){if(t.length===0)return "";let d=e?qt(t,o,r):`M ${t.map(x=>`${o(x.x).toFixed(2)},${r(x.y).toFixed(2)}`).join(" L ")}`,s=o(t[t.length-1].x).toFixed(2),y=o(t[0].x).toFixed(2);return `${d} L ${s},${a.toFixed(2)} L ${y},${a.toFixed(2)} Z`}function Gt(t,o=5){return Xt(t[0],t[1],o)}function Qt(t,o,r){if(o.length===0)return -1;let e=1/0,a=0;for(let d=0;d<o.length;d++){let s=Math.abs(r(o[d])-t);s<e&&(e=s,a=d);}return a}function te(t,o){return t.data.find(r=>String(r.x)===o)?.y}function he(t){for(let o of t)for(let r of o.data)if(typeof r.x=="string")return true;return false}function Pt({items:t,position:o,onToggle:r}){return jsx("div",{className:Lt({position:o}),children:t.map(e=>jsxs("button",{onClick:()=>r(e.id),className:rt("flex items-center gap-1.5 cursor-pointer rounded px-1.5 py-1 text-xs text-primary-700 transition-opacity hover:bg-primary-100 dark:text-primary-300 dark:hover:bg-primary-800",!e.visible&&"opacity-40"),"aria-pressed":e.visible,children:[jsx("span",{className:"h-2.5 w-5 rounded-sm shrink-0",style:{background:e.color}}),e.label]},e.id))})}function oe({series:t,xAxis:o,yAxis:r,y2Axis:e,y2Series:a=[],smooth:d=false,showDots:s=true,area:y=false,strokeWidth:x=2,title:C,height:R=300,className:P,legend:L=true,legendPosition:b="bottom",animateOnMount:p=true,emptyText:$="No data to display"}){let z=useRef(null),S=useRef(null),[B,K]=useState(600),[T,N]=useState(null),[w,I]=useState(null);useEffect(()=>{let l=S.current;if(!l)return;let k=l.getBoundingClientRect().width;k>0&&K(k);let X=new ResizeObserver(Q=>{let j=Q[0]?.contentRect.width;j&&j>0&&K(j);});return X.observe(l),()=>X.disconnect()},[]);let U=useMemo(()=>t.map(l=>l.id),[t]),{visible:G,toggle:q,isVisible:D}=$t(U),gt=useMemo(()=>Vt(t.length),[t.length]),i=useMemo(()=>new Map(t.map((l,k)=>[l.id,l.color??gt[k]])),[t,gt]),A=useMemo(()=>Ft(!!o?.label,!!r?.label,!!e),[o?.label,r?.label,e]),c=useMemo(()=>Et(B,R,A),[B,R,A]),F=useMemo(()=>he(t),[t]),E=useMemo(()=>F?de(t,G):[],[t,G,F]),ut=useMemo(()=>{if(F){let j=It(E,[c.plotLeft,c.plotRight]);return st=>j(st)}let l=t.flatMap(j=>j.data.map(st=>st.x));if(l.length===0)return ()=>c.plotLeft;let k=Math.min(...l),X=Math.max(...l),Q=zt([k,X],[c.plotLeft,c.plotRight]);return j=>Q(j)},[t,F,E,c]),xt=useMemo(()=>Ut(t,G,r),[t,G,r]),mt=useMemo(()=>zt(xt,[c.plotBottom,c.plotTop]),[xt,c]),yt=useMemo(()=>Gt(xt,r?.tickCount??5),[xt,r?.tickCount]),nt=useMemo(()=>{if(!e)return null;let l=t.filter(k=>a.includes(k.id));return Ut(l,G,e)},[e,t,a,G]),et=useMemo(()=>nt?zt(nt,[c.plotBottom,c.plotTop]):null,[nt,c]),pt=useMemo(()=>nt?Gt(nt,e?.tickCount??5):[],[nt,e?.tickCount]),dt=useMemo(()=>{if(F)return E;let l=t.flatMap(Q=>Q.data.map(j=>Number(j.x)));if(l.length===0)return [];let k=Math.min(...l),X=Math.max(...l);return Gt([k,X],o?.tickCount??6)},[F,E,t,o?.tickCount]),n=useCallback(l=>{let k=l.currentTarget.closest("svg");if(!k)return;let X=k.getBoundingClientRect(),Q=l.clientX-X.left,j=z.current?.getBoundingClientRect();if(!j)return;let st="",bt=Q;if(F&&E.length>0){let h=It(E,[c.plotLeft,c.plotRight]),_=Qt(Q,E,h);st=E[_]??"",bt=h(st);}else if(!F){let h=dt;st=tt((Q-c.plotLeft)/c.plotWidth*(h[h.length-1]-h[0])+h[0],o?.format),bt=Q;}let m=t.filter(h=>D(h.id)).map(h=>{a.includes(h.id)&&et!=null?et:mt;let vt;if(F)vt=te(h,st);else {let f=Q,at=1/0,wt;for(let ct of h.data){let Y=ut(ct.x),Wt=Math.abs(Y-f);Wt<at&&(at=Wt,wt=ct.y);}vt=wt;}return {name:h.name,value:vt!==void 0?tt(vt,r?.format):"\u2014",color:i.get(h.id)??"var(--color-chart-1)"}});bt>=c.plotLeft&&bt<=c.plotRight&&I(bt);let M=l.clientX-j.left+12,g=l.clientY-j.top-10;N({x:M,y:g,label:st,items:m});},[F,E,c,t,D,a,et,mt,ut,dt,o?.format,r?.format,i]),u=useCallback(()=>{N(null),I(null);},[]),V=useCallback(l=>{l.preventDefault();let k=l.touches[0];if(!k)return;let X=l.currentTarget.closest("svg");if(!X)return;let Q=X.getBoundingClientRect(),j=z.current?.getBoundingClientRect();if(!j)return;let st=k.clientX-Q.left,bt=st,m="";if(F&&E.length>0){let g=It(E,[c.plotLeft,c.plotRight]),h=Qt(st,E,g);m=E[h]??"",bt=g(m);}bt>=c.plotLeft&&bt<=c.plotRight&&I(bt);let M=t.filter(g=>D(g.id)).map(g=>({name:g.name,value:F&&m?tt(te(g,m)??0,r?.format):"\u2014",color:i.get(g.id)??"var(--color-chart-1)"}));N({x:k.clientX-j.left+12,y:k.clientY-j.top-10,label:m,items:M});},[F,E,c,t,D,r?.format,i]),v=useMemo(()=>t.map((l,k)=>({id:l.id,label:l.name,color:l.color??gt[k],visible:D(l.id)})),[t,gt,D]),W=t.some(l=>l.data.length>0),J=jsxs("svg",{role:"img","aria-label":C??"Line chart",width:c.width,height:c.height,viewBox:`0 0 ${c.width} ${c.height}`,shapeRendering:"geometricPrecision",children:[r?.gridLines!==false&&yt.map(l=>{let k=mt(l);return jsx("line",{x1:c.plotLeft,x2:c.plotRight,y1:k,y2:k,stroke:"currentColor",strokeWidth:.5,strokeDasharray:"4 4",className:"text-secondary-200 dark:text-secondary-700"},l)}),y&&t.map(l=>{if(!D(l.id)||l.data.length===0)return null;let X=a.includes(l.id)&&et!=null?et:mt,Q=i.get(l.id)??"var(--color-chart-1)",j=pe(l.data,ut,X,d,c.plotBottom);return jsx("path",{d:j,fill:Q,fillOpacity:.15,stroke:"none",className:p?"chart-area-animate":""},`area-${l.id}`)}),t.map(l=>{if(!D(l.id)||l.data.length===0)return null;let X=a.includes(l.id)&&et!=null?et:mt,Q=i.get(l.id)??"var(--color-chart-1)";return d?jsx("path",{d:qt(l.data,ut,X),fill:"none",stroke:Q,strokeWidth:x,strokeLinecap:"round",strokeLinejoin:"round",className:p?"chart-line-animate":""},l.id):jsx("polyline",{points:ue(l.data,ut,X),fill:"none",stroke:Q,strokeWidth:x,strokeLinecap:"round",strokeLinejoin:"round",className:p?"chart-line-animate":""},l.id)}),s&&t.map(l=>{if(!D(l.id))return null;let X=a.includes(l.id)&&et!=null?et:mt,Q=i.get(l.id)??"var(--color-chart-1)";return l.data.map((j,st)=>jsx("circle",{cx:ut(j.x),cy:X(j.y),r:3,fill:Q,stroke:"white",strokeWidth:1.5,className:rt("chart-dot",p?"chart-dot-animate":"")},`${l.id}-${st}`))}),w!=null&&jsx("line",{className:"chart-crosshair",x1:w,x2:w,y1:c.plotTop,y2:c.plotBottom,stroke:"currentColor",strokeWidth:1,strokeDasharray:"4 4",opacity:.5,style:{color:"var(--color-secondary-400)"}}),jsx("line",{x1:c.plotLeft,x2:c.plotLeft,y1:c.plotTop,y2:c.plotBottom,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),yt.map(l=>{let k=mt(l);return jsxs("g",{children:[jsx("line",{x1:c.plotLeft-4,x2:c.plotLeft,y1:k,y2:k,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsx("text",{x:c.plotLeft-6,y:k,textAnchor:"end",dominantBaseline:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:tt(l,r?.format)})]},l)}),r?.label&&jsx("text",{x:-(c.plotTop+c.plotHeight/2),y:14,textAnchor:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-600 dark:text-secondary-400",transform:"rotate(-90)",children:r.label}),e&&et&&jsxs(Fragment,{children:[jsx("line",{x1:c.plotRight,x2:c.plotRight,y1:c.plotTop,y2:c.plotBottom,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),pt.map(l=>{let k=et(l);return jsxs("g",{children:[jsx("line",{x1:c.plotRight,x2:c.plotRight+4,y1:k,y2:k,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsx("text",{x:c.plotRight+6,y:k,textAnchor:"start",dominantBaseline:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:tt(l,e?.format)})]},l)}),e?.label&&jsx("text",{x:c.plotTop+c.plotHeight/2,y:-(c.width-14),textAnchor:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-600 dark:text-secondary-400",transform:"rotate(90)",children:e.label})]}),jsx("line",{x1:c.plotLeft,x2:c.plotRight,y1:c.plotBottom,y2:c.plotBottom,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),(F?E:dt).map((l,k)=>{let X=ut(l);return jsxs("g",{children:[jsx("line",{x1:X,x2:X,y1:c.plotBottom,y2:c.plotBottom+4,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsx("text",{x:X,y:c.plotBottom+14,textAnchor:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:tt(l,o?.format)})]},k)}),o?.label&&jsx("text",{x:c.plotLeft+c.plotWidth/2,y:c.height-4,textAnchor:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-600 dark:text-secondary-400",children:o.label}),jsx("rect",{x:c.plotLeft,y:c.plotTop,width:c.plotWidth,height:c.plotHeight,fill:"transparent",onMouseMove:n,onMouseLeave:u,onTouchStart:V,onTouchMove:V,onTouchEnd:u,style:{cursor:"crosshair"}})]}),it=b==="left"||b==="right";return jsxs("div",{ref:z,className:rt(Mt(),P),children:[C&&jsx("h3",{className:"mb-2 text-sm font-semibold text-primary-700 dark:text-primary-200",children:C}),L&&b==="top"&&jsx(Pt,{items:v,position:"top",onToggle:q}),jsxs("div",{className:rt("flex items-start",it&&"gap-0"),children:[L&&b==="left"&&jsx(Pt,{items:v,position:"left",onToggle:q}),jsx("div",{ref:S,className:"flex-1 min-w-0 overflow-hidden",children:W?J:jsx("div",{className:"flex items-center justify-center text-secondary-400 dark:text-secondary-500",style:{height:R},children:$})}),L&&b==="right"&&jsx(Pt,{items:v,position:"right",onToggle:q})]}),L&&b==="bottom"&&jsx(Pt,{items:v,position:"bottom",onToggle:q}),T&&jsxs("div",{className:Tt(),style:{left:T.x,top:T.y},role:"tooltip",children:[T.label&&jsx("div",{className:"mb-1 font-medium text-primary-200",children:T.label}),T.items.map((l,k)=>jsxs("div",{className:"flex items-center gap-1.5",children:[jsx("span",{className:"h-2 w-2 rounded-full shrink-0",style:{background:l.color}}),jsxs("span",{className:"text-primary-300",children:[l.name,":"]}),jsx("span",{className:"font-medium",children:l.value})]},k))]})]})}function ge(t,o){let r=new Set,e=[];for(let a of t)if(o.has(a.id))for(let d of a.data){let s=String(d.x);r.has(s)||(r.add(s),e.push(s));}return e}function xe(t,o,r,e){if(r){let a=0;for(let s of t)if(o.has(s.id))for(let y of s.data)y.y>a&&(a=y.y);a===0&&(a=1);let[,d]=Dt(0,a,.05);return [e?.min??0,e?.max??d]}else {let a=new Map;for(let y of t)if(o.has(y.id))for(let x of y.data){let C=String(x.x);a.set(C,(a.get(C)??0)+x.y);}let d=Math.max(0,...a.values()),[,s]=Dt(0,d===0?1:d,.05);return [e?.min??0,e?.max??s]}}function ye(t,o){let[r,e]=t,[a,d]=o;return e===r?()=>(a+d)/2:s=>a+(s-r)/(e-r)*(d-a)}function be(t,o=5){return Xt(t[0],t[1],o)}function ve(t,o,r,e,a,d,s,y,x,C,R){let P=t.filter(B=>o.has(B.id)),L=r.length,b=P.length;if(L===0||b===0)return [];let p=d/L,$=p*(1-C),z=b>0?$*(1-R)/b:0,S=[];for(let B=0;B<r.length;B++){let K=r[B],T=a+B*p+(p-$)/2;for(let N=0;N<P.length;N++){let w=P[N],I=w.data.find(q=>String(q.x)===K);if(!I)continue;let U=T+N*(z+$*R/b),G=x(I.y);S.push({seriesId:w.id,category:K,x:U,y:G,width:Math.max(z,1),height:Math.max(s-G,0),stackBase:s,value:I.y,color:e.get(w.id)??"var(--color-chart-1)"});}}return S}function ke(t,o,r,e,a,d,s,y,x,C){let R=t.filter(S=>o.has(S.id)),P=r.length,L=R.length;if(P===0||L===0)return [];let b=s/P,p=b*(1-x),$=L>0?p*(1-C)/L:0,z=[];for(let S=0;S<r.length;S++){let B=r[S],K=d+S*b+(b-p)/2;for(let T=0;T<R.length;T++){let N=R[T],w=N.data.find(G=>String(G.x)===B);if(!w)continue;let I=K+T*($+p*C/Math.max(L,1)),U=y(w.y);z.push({seriesId:N.id,category:B,x:a,y:I,width:Math.max(U-a,0),height:Math.max($,1),stackBase:a,value:w.y,color:e.get(N.id)??"var(--color-chart-1)"});}}return z}function Ce(t,o,r,e,a,d,s,y,x){let C=t.filter(p=>o.has(p.id)),R=r.length;if(R===0)return [];let P=s/R*(1-x),L=[],b=new Map;r.forEach(p=>b.set(p,a));for(let p of C)for(let $ of r){let z=p.data.find(N=>String(N.x)===$);if(!z)continue;let S=b.get($)??a,B=Math.max(y(z.y)-a,0),K=r.indexOf($),T=d+(K+.5)*(s/R);L.push({seriesId:p.id,category:$,x:S,y:T-P/2,width:B,height:Math.max(P,1),stackBase:S,value:z.y,color:e.get(p.id)??"var(--color-chart-1)"}),b.set($,S+B);}return L}function Se(t,o,r,e,a,d,s,y,x){let C=t.filter(p=>o.has(p.id)),R=r.length;if(R===0)return [];let P=d/R*(1-x),L=[],b=new Map;r.forEach(p=>b.set(p,s));for(let p of C)for(let $ of r){let z=p.data.find(w=>String(w.x)===$);if(!z)continue;let S=b.get($)??s,B=Math.max(s-y(z.y),0),K=S-B,T=r.indexOf($),N=a+(T+.5)*(d/R);L.push({seriesId:p.id,category:$,x:N-P/2,y:K,width:Math.max(P,1),height:B,stackBase:S,value:z.y,color:e.get(p.id)??"var(--color-chart-1)"}),b.set($,K);}return L}function jt({items:t,position:o,onToggle:r}){return jsx("div",{className:Lt({position:o}),children:t.map(e=>jsxs("button",{onClick:()=>r(e.id),className:rt("flex items-center gap-1.5 cursor-pointer rounded px-1.5 py-1 text-xs text-primary-700 transition-opacity hover:bg-primary-100 dark:text-primary-300 dark:hover:bg-primary-800",!e.visible&&"opacity-40"),"aria-pressed":e.visible,children:[jsx("span",{className:"h-2.5 w-5 rounded-sm shrink-0",style:{background:e.color}}),e.label]},e.id))})}function ne({series:t,xAxis:o,yAxis:r,orientation:e="vertical",grouped:a=true,barRadius:d=4,barPadding:s=.2,groupPadding:y=.3,title:x,height:C=300,className:R,legend:P=true,legendPosition:L="bottom",animateOnMount:b=true,emptyText:p="No data to display"}){let $=useRef(null),z=useRef(null),[S,B]=useState(600),[K,T]=useState(null);useEffect(()=>{let n=z.current;if(!n)return;let u=n.getBoundingClientRect().width;u>0&&B(u);let V=new ResizeObserver(v=>{let W=v[0]?.contentRect.width;W&&W>0&&B(W);});return V.observe(n),()=>V.disconnect()},[]);let N=useMemo(()=>t.map(n=>n.id),[t]),{visible:w,toggle:I,isVisible:U}=$t(N),G=useMemo(()=>Vt(t.length),[t.length]),q=useMemo(()=>new Map(t.map((n,u)=>[n.id,n.color??G[u]])),[t,G]),D=e==="horizontal",gt=useMemo(()=>Ft(!!o?.label,!!r?.label,false),[o?.label,r?.label]),i=useMemo(()=>Et(S,C,gt),[S,C,gt]),A=useMemo(()=>ge(t,w),[t,w]),c=useMemo(()=>xe(t,w,a,D?o:r),[t,w,a,D,o,r]),F=useMemo(()=>ye(c,D?[i.plotLeft,i.plotRight]:[i.plotBottom,i.plotTop]),[c,i,D]),E=useMemo(()=>be(c,(D?o:r)?.tickCount??5),[c,D,o,r]),ut=useMemo(()=>D?a?ke(t,w,A,q,i.plotLeft,i.plotTop,i.plotHeight,F,y,s):Ce(t,w,A,q,i.plotLeft,i.plotTop,i.plotHeight,F,y):a?ve(t,w,A,q,i.plotLeft,i.plotWidth,i.plotBottom,i.plotTop,F,y,s):Se(t,w,A,q,i.plotLeft,i.plotWidth,i.plotBottom,F,y),[t,w,A,q,i,F,a,D,y,s]),xt=A.length>0?i.plotWidth/A.length:1,mt=A.length>0?i.plotHeight/A.length:1,yt=useCallback((n,u)=>{let V=$.current?.getBoundingClientRect();if(!V)return;let v=t.filter(W=>U(W.id)).map(W=>{let J=W.data.find(it=>String(it.x)===u);return {name:W.name,value:J?tt(J.y,r?.format):"\u2014",color:q.get(W.id)??"var(--color-chart-1)"}});T({x:n.clientX-V.left+12,y:n.clientY-V.top-10,category:u,items:v});},[t,U,q,r?.format]),nt=useMemo(()=>t.map((n,u)=>({id:n.id,label:n.name,color:n.color??G[u],visible:U(n.id)})),[t,G,U]),et=t.some(n=>n.data.length>0),pt=L==="left"||L==="right",dt=jsxs("svg",{role:"img","aria-label":x??"Bar chart",width:i.width,height:i.height,viewBox:`0 0 ${i.width} ${i.height}`,shapeRendering:"geometricPrecision",children:[E.map(n=>{let u=F(n);return D?jsx("line",{x1:u,x2:u,y1:i.plotTop,y2:i.plotBottom,stroke:"currentColor",strokeWidth:.5,strokeDasharray:"4 4",className:"text-secondary-200 dark:text-secondary-700"},n):jsx("line",{x1:i.plotLeft,x2:i.plotRight,y1:u,y2:u,stroke:"currentColor",strokeWidth:.5,strokeDasharray:"4 4",className:"text-secondary-200 dark:text-secondary-700"},n)}),ut.map(n=>{let u=Math.min(d,n.width/2,n.height/2),V=`${n.seriesId}-${n.category}`;return D?jsx("rect",{x:n.x,y:n.y,width:n.width,height:n.height,rx:u,fill:n.color,className:rt("chart-bar-h",b&&"chart-bar-animate"),onMouseMove:v=>yt(v,n.category),onMouseLeave:()=>T(null)},V):jsx("rect",{x:n.x,y:n.y,width:n.width,height:n.height,rx:u,fill:n.color,className:rt("chart-bar-v",b&&"chart-bar-animate"),onMouseMove:v=>yt(v,n.category),onMouseLeave:()=>T(null)},V)}),jsx("line",{x1:i.plotLeft,x2:i.plotLeft,y1:i.plotTop,y2:i.plotBottom,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsx("line",{x1:i.plotLeft,x2:i.plotRight,y1:i.plotBottom,y2:i.plotBottom,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),!D&&E.map(n=>{let u=F(n);return jsxs("g",{children:[jsx("line",{x1:i.plotLeft-4,x2:i.plotLeft,y1:u,y2:u,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsx("text",{x:i.plotLeft-6,y:u,textAnchor:"end",dominantBaseline:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:tt(n,r?.format)})]},n)}),D&&E.map(n=>{let u=F(n);return jsxs("g",{children:[jsx("line",{x1:u,x2:u,y1:i.plotBottom,y2:i.plotBottom+4,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsx("text",{x:u,y:i.plotBottom+14,textAnchor:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:tt(n,o?.format)})]},n)}),A.map((n,u)=>{if(D){let v=i.plotTop+(u+.5)*mt;return jsx("text",{x:i.plotLeft-6,y:v,textAnchor:"end",dominantBaseline:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:n},n)}let V=i.plotLeft+(u+.5)*xt;return jsx("text",{x:V,y:i.plotBottom+14,textAnchor:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:n},n)}),r?.label&&!D&&jsx("text",{x:-(i.plotTop+i.plotHeight/2),y:14,textAnchor:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-600 dark:text-secondary-400",transform:"rotate(-90)",children:r.label}),o?.label&&jsx("text",{x:i.plotLeft+i.plotWidth/2,y:i.height-4,textAnchor:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-600 dark:text-secondary-400",children:o.label})]});return jsxs("div",{ref:$,className:rt(Mt(),R),children:[x&&jsx("h3",{className:"mb-2 text-sm font-semibold text-primary-700 dark:text-primary-200",children:x}),P&&L==="top"&&jsx(jt,{items:nt,position:"top",onToggle:I}),jsxs("div",{className:rt("flex items-start",pt&&"gap-0"),children:[P&&L==="left"&&jsx(jt,{items:nt,position:"left",onToggle:I}),jsx("div",{ref:z,className:"flex-1 min-w-0 overflow-hidden",children:et?dt:jsx("div",{className:"flex items-center justify-center text-secondary-400 dark:text-secondary-500",style:{height:C},children:p})}),P&&L==="right"&&jsx(jt,{items:nt,position:"right",onToggle:I})]}),P&&L==="bottom"&&jsx(jt,{items:nt,position:"bottom",onToggle:I}),K&&jsxs("div",{className:Tt(),style:{left:K.x,top:K.y},role:"tooltip",children:[jsx("div",{className:"mb-1 font-medium text-primary-200",children:K.category}),K.items.map((n,u)=>jsxs("div",{className:"flex items-center gap-1.5",children:[jsx("span",{className:"h-2 w-2 rounded-full shrink-0",style:{background:n.color}}),jsxs("span",{className:"text-primary-300",children:[n.name,":"]}),jsx("span",{className:"font-medium",children:n.value})]},u))]})]})}function Me(t,o,r,e,a,d,s,y,x){let C=t.filter(p=>o.has(p.id)),R=C.reduce((p,$)=>p+$.value,0);if(R===0)return [];let P=new Map(t.map((p,$)=>[p.id,p.color??r[$%r.length]])),L=[],b=y;for(let p of C){let $=p.value/R*360,z=x/2,S=b+z,B=b+$-z,K=(S+B)/2,T;if(Math.abs(B-S)>=359.9){let N=kt(d,s,e,S),w=kt(d,s,e,S+180);T=`M ${N.x.toFixed(3)} ${N.y.toFixed(3)} A ${e} ${e} 0 1 1 ${w.x.toFixed(3)} ${w.y.toFixed(3)} A ${e} ${e} 0 1 1 ${N.x.toFixed(3)} ${N.y.toFixed(3)} Z`;}else if(a>0){let N=kt(d,s,e,S),w=kt(d,s,e,B),I=kt(d,s,a,B),U=kt(d,s,a,S),G=B-S>180?1:0;T=`M ${N.x.toFixed(3)} ${N.y.toFixed(3)} A ${e} ${e} 0 ${G} 1 ${w.x.toFixed(3)} ${w.y.toFixed(3)} L ${I.x.toFixed(3)} ${I.y.toFixed(3)} A ${a} ${a} 0 ${G} 0 ${U.x.toFixed(3)} ${U.y.toFixed(3)} Z`;}else {let N=kt(d,s,e,S),w=kt(d,s,e,B),I=B-S>180?1:0;T=`M ${d.toFixed(3)} ${s.toFixed(3)} L ${N.x.toFixed(3)} ${N.y.toFixed(3)} A ${e} ${e} 0 ${I} 1 ${w.x.toFixed(3)} ${w.y.toFixed(3)} Z`;}L.push({id:p.id,label:p.label,value:p.value,percent:Math.round(p.value/R*1e3)/10,color:P.get(p.id)??"var(--color-chart-1)",startAngle:S,endAngle:B,midAngle:K,path:T,outerR:e,innerR:a,cx:d,cy:s}),b+=$;}return L}function Le(t,o){let r=(t-90)*Math.PI/180;return {dx:Math.cos(r)*o,dy:Math.sin(r)*o}}function Zt({items:t,position:o,onToggle:r}){return jsx("div",{className:Lt({position:o}),children:t.map(e=>jsxs("button",{onClick:()=>r(e.id),className:rt("flex items-center gap-1.5 cursor-pointer rounded px-1.5 py-1 text-xs text-primary-700 transition-opacity hover:bg-primary-100 dark:text-primary-300 dark:hover:bg-primary-800",!e.visible&&"opacity-40"),"aria-pressed":e.visible,children:[jsx("span",{className:"h-2.5 w-2.5 rounded-full shrink-0",style:{background:e.color}}),jsx("span",{children:e.label}),jsxs("span",{className:"text-secondary-400",children:["(",e.percent,"%)"]})]},e.id))})}function se({data:t,donut:o=false,donutThickness:r=.5,startAngle:e=-90,padAngle:a=0,labelType:d="percent",centerLabel:s,centerSubLabel:y,explodeOnHover:x=true,explodeOffset:C=8,title:R,height:P=300,className:L,legend:b=true,legendPosition:p="bottom",animateOnMount:$=true,emptyText:z="No data to display"}){let S=useRef(null),B=useRef(null),[K,T]=useState(400),[N,w]=useState(null),[I,U]=useState(null),[G,q]=useState({}),D=useRef(null);useEffect(()=>{let m=B.current;if(!m)return;let M=m.getBoundingClientRect().width;M>0&&T(M);let g=new ResizeObserver(h=>{let _=h[0]?.contentRect.width;_&&_>0&&T(_);});return g.observe(m),()=>g.disconnect()},[]),useEffect(()=>{function m(g){let h=D.current;if(!h)return;"touches"in g&&g.cancelable&&g.preventDefault();let _="touches"in g?g.touches[0]?.clientX??h.startX:g.clientX,ht="touches"in g?g.touches[0]?.clientY??h.startY:g.clientY;q(vt=>({...vt,[h.id]:{dx:h.origDx+_-h.startX,dy:h.origDy+ht-h.startY}}));}function M(){D.current=null;}return window.addEventListener("mousemove",m),window.addEventListener("mouseup",M),window.addEventListener("touchmove",m,{passive:false}),window.addEventListener("touchend",M),()=>{window.removeEventListener("mousemove",m),window.removeEventListener("mouseup",M),window.removeEventListener("touchmove",m),window.removeEventListener("touchend",M);}},[]);let gt=useMemo(()=>t.map(m=>m.id),[t]),{visible:i,toggle:A,isVisible:c}=$t(gt),F=useMemo(()=>Vt(t.length),[t.length]),E=10,ut=6.4,xt=18,mt=14,yt=6,nt=K,et=P,pt=nt/2,dt=et/2,n=d!=="none"?xt+yt+4:yt+4,u=Math.max(Math.min(pt,dt)-n,20),V=o?u*r:0,v=useMemo(()=>Me(t,i,F,u,V,pt,dt,e,a),[t,i,F,u,V,pt,dt,e,a]),W=useMemo(()=>v.map(m=>m.id).join(","),[v]);useEffect(()=>{q({});},[W]);let J=useCallback((m,M)=>{if(D.current)return;let g=S.current?.getBoundingClientRect();if(!g)return;w(M);let h=v.find(_=>_.id===M);h&&U({x:m.clientX-g.left+12,y:m.clientY-g.top-10,items:[{label:h.label,value:tt(h.value),percent:`${h.percent}%`,color:h.color}]});},[v]),it=useCallback(()=>{w(null),U(null);},[]),l=useCallback((m,M,g)=>{let h=G[m]??{dx:0,dy:0};D.current={id:m,startX:M,startY:g,origDx:h.dx,origDy:h.dy};},[G]),k=useCallback((m,M)=>{m.preventDefault(),w(M);let g=S.current?.getBoundingClientRect();if(!g)return;let h=m.touches[0];if(!h)return;let _=v.find(ht=>ht.id===M);_&&U({x:h.clientX-g.left+12,y:h.clientY-g.top-10,items:[{label:_.label,value:tt(_.value),percent:`${_.percent}%`,color:_.color}]});},[v]),X=useMemo(()=>{let m=t.reduce((M,g)=>M+g.value,0);return t.map((M,g)=>({id:M.id,label:M.label,color:M.color??F[g],visible:c(M.id),percent:m>0?Math.round(M.value/m*1e3)/10:0}))},[t,F,c]),Q=t.length>0&&t.some(m=>m.value>0),j=p==="left"||p==="right",st=useMemo(()=>{if(d==="none")return [];let m=E+3,M=yt+E*.5,g=et-yt-E*.5,h=v.filter(f=>f.percent>=3).map(f=>{let at="";switch(d){case "percent":at=`${f.percent}%`;break;case "value":at=tt(f.value);break;case "label":at=f.label;break;case "label+percent":at=`${f.label} ${f.percent}%`;break}let wt=kt(f.cx,f.cy,f.outerR+2,f.midAngle),ct=kt(f.cx,f.cy,f.outerR+xt,f.midAngle),Y=(f.midAngle-90)*Math.PI/180,Wt=Math.cos(Y)>=0,Ht=Math.ceil(at.length*ut);return {id:f.id,color:f.color,text:at,textW:Ht,p1:wt,elbowX:ct.x,y:ct.y,isRight:Wt}}),_=h.filter(f=>f.isRight).sort((f,at)=>f.y-at.y),ht=h.filter(f=>!f.isRight).sort((f,at)=>f.y-at.y);function vt(f){if(f.length!==0)for(let at=0;at<20;at++){let wt=false;for(let Y=1;Y<f.length;Y++){let Wt=f[Y].y-f[Y-1].y;if(Wt<m){let Ht=(m-Wt)/2;f[Y-1].y-=Ht,f[Y].y+=Ht,wt=true;}}f[0].y<M&&(f[0].y=M);for(let Y=1;Y<f.length;Y++)f[Y].y<f[Y-1].y+m&&(f[Y].y=f[Y-1].y+m);let ct=f.length-1;f[ct].y>g&&(f[ct].y=g);for(let Y=ct-1;Y>=0;Y--)f[Y].y>f[Y+1].y-m&&(f[Y].y=f[Y+1].y-m);for(let Y of f)Y.y=Math.max(M,Math.min(g,Y.y));if(!wt)break}}return vt(_),vt(ht),[...ht,..._]},[v,d,et]),bt=jsxs("svg",{role:"img","aria-label":R??"Pie chart",width:nt,height:et,viewBox:`0 0 ${nt} ${et}`,shapeRendering:"geometricPrecision",children:[jsxs("g",{className:$?"chart-pie-animate":"",children:[v.map((m,M)=>{let g=N===m.id,h=x&&g,_=Le(m.midAngle,h?C:0);return jsx("path",{d:m.path,fill:m.color,transform:h?`translate(${_.dx}, ${_.dy})`:void 0,className:rt("chart-slice",$&&`chart-slice-animate-${Math.min(M,7)}`,g&&"chart-slice--exploded"),stroke:m.color,strokeWidth:.6,onMouseMove:ht=>J(ht,m.id),onMouseLeave:it,onTouchStart:ht=>k(ht,m.id),onTouchEnd:it,"aria-label":`${m.label}: ${m.percent}%`},m.id)}),st.map(m=>{let M=G[m.id]??{dx:0,dy:0},g=m.elbowX+M.dx,h=m.y+M.dy,_=g+(m.isRight?mt:-mt),ht=m.isRight?_+3:_-3,vt=mt+3+m.textW+6,f=m.isRight?g:g-vt,at=h-E-2,wt=E*2+4;return jsxs("g",{style:{userSelect:"none"},children:[jsx("polyline",{points:[`${m.p1.x.toFixed(2)},${m.p1.y.toFixed(2)}`,`${g.toFixed(2)},${h.toFixed(2)}`,`${_.toFixed(2)},${h.toFixed(2)}`].join(" "),fill:"none",stroke:m.color,strokeWidth:1.2,opacity:.85,strokeLinejoin:"round",strokeLinecap:"round",style:{pointerEvents:"none"}}),jsx("text",{x:ht.toFixed(2),y:h.toFixed(2),textAnchor:m.isRight?"start":"end",dominantBaseline:"middle",fontSize:E,fill:"currentColor",className:"text-primary-700 dark:text-primary-300",style:{pointerEvents:"none"},children:m.text}),jsx("rect",{x:f,y:at,width:vt,height:wt,fill:"transparent",style:{cursor:"grab",touchAction:"none"},onMouseDown:ct=>{ct.stopPropagation(),l(m.id,ct.clientX,ct.clientY);},onTouchStart:ct=>{ct.stopPropagation();let Y=ct.touches[0];Y&&l(m.id,Y.clientX,Y.clientY);}})]},`label-${m.id}`)})]}),o&&jsx("g",{style:{pointerEvents:"none"},children:N&&v.find(m=>m.id===N)?jsxs(Fragment,{children:[jsxs("text",{x:pt,y:dt-8,textAnchor:"middle",dominantBaseline:"middle",fontSize:18,fontWeight:600,fill:"currentColor",className:"text-primary-800 dark:text-primary-100",children:[v.find(m=>m.id===N)?.percent,"%"]}),jsx("text",{x:pt,y:dt+12,textAnchor:"middle",dominantBaseline:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:v.find(m=>m.id===N)?.label})]}):jsxs(Fragment,{children:[s&&jsx("text",{x:pt,y:dt-(y?8:0),textAnchor:"middle",dominantBaseline:"middle",fontSize:16,fontWeight:600,fill:"currentColor",className:"text-primary-800 dark:text-primary-100",children:s}),y&&jsx("text",{x:pt,y:dt+14,textAnchor:"middle",dominantBaseline:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:y})]})})]});return jsxs("div",{ref:S,className:rt(Mt(),L),children:[R&&jsx("h3",{className:"mb-2 text-sm font-semibold text-primary-700 dark:text-primary-200",children:R}),b&&p==="top"&&jsx(Zt,{items:X,position:"top",onToggle:A}),jsxs("div",{className:rt("flex items-start justify-center",j&&"gap-0"),children:[b&&p==="left"&&jsx(Zt,{items:X,position:"left",onToggle:A}),jsx("div",{ref:B,className:"flex-1 min-w-0 overflow-hidden",children:Q?bt:jsx("div",{className:"flex items-center justify-center text-secondary-400 dark:text-secondary-500",style:{height:P},children:z})}),b&&p==="right"&&jsx(Zt,{items:X,position:"right",onToggle:A})]}),b&&p==="bottom"&&jsx(Zt,{items:X,position:"bottom",onToggle:A}),I&&jsx("div",{className:Tt(),style:{left:I.x,top:I.y},role:"tooltip",children:I.items.map((m,M)=>jsxs("div",{className:"flex items-center gap-2",children:[jsx("span",{className:"h-2.5 w-2.5 rounded-full shrink-0",style:{background:m.color}}),jsxs("span",{className:"font-medium",children:[m.label,":"]}),jsx("span",{children:m.value}),jsxs("span",{className:"text-primary-300",children:["(",m.percent,")"]})]},M))})]})}function Be(t,o,r){let e=1/0,a=-1/0;for(let y of t)if(o.has(y.id))for(let x of y.data){let C=Number(x.x);C<e&&(e=C),C>a&&(a=C);}if(!isFinite(e))return [0,1];let[d,s]=Dt(e,a);return [r?.min??d,r?.max??s]}function Re(t,o,r){let e=1/0,a=-1/0;for(let y of t)if(o.has(y.id))for(let x of y.data)x.y<e&&(e=x.y),x.y>a&&(a=x.y);if(!isFinite(e))return [0,1];let[d,s]=Dt(e,a);return [r?.min??d,r?.max??s]}function ce(t,o){let[r,e]=t,[a,d]=o;return e===r?()=>(a+d)/2:s=>a+(s-r)/(e-r)*(d-a)}function le(t,o=5){return Xt(t[0],t[1],o)}function $e(t,o,r){let e=1.618033988749895,a=t*137+o,d=a*e%1*2-1,s=a*e*e%1*2-1;return [d*r,s*r]}function Ve(t,o,r=12){if(t.length<2)return null;let e=Math.min(...t),a=Math.max(...t),d=Math.min(...o),s=Math.max(...o);return {cx:(e+a)/2,cy:(d+s)/2,rx:(a-e)/2+r,ry:(s-d)/2+r}}function Kt({items:t,position:o,onToggle:r}){return jsx("div",{className:Lt({position:o}),children:t.map(e=>jsxs("button",{onClick:()=>r(e.id),className:rt("flex items-center gap-1.5 cursor-pointer rounded px-1.5 py-1 text-xs text-primary-700 transition-opacity hover:bg-primary-100 dark:text-primary-300 dark:hover:bg-primary-800",!e.visible&&"opacity-40"),"aria-pressed":e.visible,children:[jsx("span",{className:"h-2.5 w-2.5 rounded-full shrink-0",style:{background:e.color}}),e.label]},e.id))})}function me({series:t,xAxis:o,yAxis:r,dotRadius:e=5,dotOpacity:a=.75,clusters:d=false,jitter:s=false,jitterAmount:y=12,linkedLines:x=false,title:C,height:R=300,className:P,legend:L=true,legendPosition:b="bottom",animateOnMount:p=true,emptyText:$="No data to display"}){let z=useRef(null),S=useRef(null),[B,K]=useState(600),[T,N]=useState(null);useEffect(()=>{let n=S.current;if(!n)return;let u=n.getBoundingClientRect().width;u>0&&K(u);let V=new ResizeObserver(v=>{let W=v[0]?.contentRect.width;W&&W>0&&K(W);});return V.observe(n),()=>V.disconnect()},[]);let w=useMemo(()=>t.map(n=>n.id),[t]),{visible:I,toggle:U,isVisible:G}=$t(w),q=useMemo(()=>Vt(t.length),[t.length]),D=useMemo(()=>new Map(t.map((n,u)=>[n.id,n.color??q[u]])),[t,q]),gt=useMemo(()=>Ft(!!o?.label,!!r?.label,false),[o?.label,r?.label]),i=useMemo(()=>Et(B,R,gt),[B,R,gt]),A=useMemo(()=>Be(t,I,o),[t,I,o]),c=useMemo(()=>Re(t,I,r),[t,I,r]),F=useMemo(()=>ce(A,[i.plotLeft,i.plotRight]),[A,i]),E=useMemo(()=>ce(c,[i.plotBottom,i.plotTop]),[c,i]),ut=useMemo(()=>le(A,o?.tickCount??6),[A,o?.tickCount]),xt=useMemo(()=>le(c,r?.tickCount??5),[c,r?.tickCount]),mt=useCallback((n,u,V,v,W)=>{let J=z.current?.getBoundingClientRect();J&&N({x:n.clientX-J.left+12,y:n.clientY-J.top-10,seriesName:u,xVal:tt(V,o?.format),yVal:tt(v,r?.format),color:W});},[o?.format,r?.format]),yt=useCallback((n,u,V,v,W)=>{n.preventDefault();let J=z.current?.getBoundingClientRect();if(!J)return;let it=n.touches[0];it&&N({x:it.clientX-J.left+12,y:it.clientY-J.top-10,seriesName:u,xVal:tt(V,o?.format),yVal:tt(v,r?.format),color:W});},[o?.format,r?.format]),nt=useMemo(()=>t.map((n,u)=>({id:n.id,label:n.name,color:n.color??q[u],visible:G(n.id)})),[t,q,G]),et=t.some(n=>n.data.length>0),pt=b==="left"||b==="right",dt=jsxs("svg",{role:"img","aria-label":C??"Scatter chart",width:i.width,height:i.height,viewBox:`0 0 ${i.width} ${i.height}`,shapeRendering:"geometricPrecision",children:[xt.map(n=>jsx("line",{x1:i.plotLeft,x2:i.plotRight,y1:E(n),y2:E(n),stroke:"currentColor",strokeWidth:.5,strokeDasharray:"4 4",className:"text-secondary-200 dark:text-secondary-700"},n)),d&&t.map((n,u)=>{if(!G(n.id)||n.data.length<2)return null;let V=D.get(n.id)??"var(--color-chart-1)",v=n.data.map(it=>F(Number(it.x))),W=n.data.map(it=>E(it.y)),J=Ve(v,W,16);return J?jsx("ellipse",{cx:J.cx,cy:J.cy,rx:J.rx,ry:J.ry,fill:V,fillOpacity:.06,stroke:V,strokeOpacity:.3,strokeWidth:1.5,strokeDasharray:"5 3",className:p?"chart-cluster-ellipse":"",style:{animationDelay:`${u*.1}s`}},`cluster-${n.id}`):null}),x&&t.map(n=>{if(!G(n.id)||n.data.length<2)return null;let u=D.get(n.id)??"var(--color-chart-1)",v=[...n.data].sort((W,J)=>Number(W.x)-Number(J.x)).map(W=>`${F(Number(W.x)).toFixed(2)},${E(W.y).toFixed(2)}`).join(" ");return jsx("polyline",{points:v,fill:"none",stroke:u,strokeWidth:1.5,className:"chart-scatter-link"},`link-${n.id}`)}),t.map((n,u)=>{if(!G(n.id))return null;let V=D.get(n.id)??"var(--color-chart-1)";return jsx("g",{className:"chart-scatter-group",children:n.data.map((v,W)=>{let[J,it]=s?$e(u,W,y):[0,0],l=F(Number(v.x))+J,k=E(v.y)+it;return jsx("circle",{cx:l,cy:k,r:e,fill:V,fillOpacity:a,stroke:V,strokeWidth:1,strokeOpacity:.5,className:rt("chart-scatter-dot",p&&"chart-scatter-dot--animate"),style:{color:V},onMouseMove:X=>mt(X,n.name,v.x,v.y,V),onMouseLeave:()=>N(null),onTouchStart:X=>yt(X,n.name,v.x,v.y,V),onTouchEnd:()=>N(null)},W)})},n.id)}),jsx("line",{x1:i.plotLeft,x2:i.plotLeft,y1:i.plotTop,y2:i.plotBottom,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsx("line",{x1:i.plotLeft,x2:i.plotRight,y1:i.plotBottom,y2:i.plotBottom,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),xt.map(n=>{let u=E(n);return jsxs("g",{children:[jsx("line",{x1:i.plotLeft-4,x2:i.plotLeft,y1:u,y2:u,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsx("text",{x:i.plotLeft-6,y:u,textAnchor:"end",dominantBaseline:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:tt(n,r?.format)})]},n)}),ut.map(n=>{let u=F(n);return jsxs("g",{children:[jsx("line",{x1:u,x2:u,y1:i.plotBottom,y2:i.plotBottom+4,stroke:"currentColor",strokeWidth:1,className:"text-secondary-300 dark:text-secondary-600"}),jsx("text",{x:u,y:i.plotBottom+14,textAnchor:"middle",fontSize:10,fill:"currentColor",className:"text-secondary-500 dark:text-secondary-400",children:tt(n,o?.format)})]},n)}),r?.label&&jsx("text",{x:-(i.plotTop+i.plotHeight/2),y:14,textAnchor:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-600 dark:text-secondary-400",transform:"rotate(-90)",children:r.label}),o?.label&&jsx("text",{x:i.plotLeft+i.plotWidth/2,y:i.height-4,textAnchor:"middle",fontSize:11,fill:"currentColor",className:"text-secondary-600 dark:text-secondary-400",children:o.label})]});return jsxs("div",{ref:z,className:rt(Mt(),P),children:[C&&jsx("h3",{className:"mb-2 text-sm font-semibold text-primary-700 dark:text-primary-200",children:C}),L&&b==="top"&&jsx(Kt,{items:nt,position:"top",onToggle:U}),jsxs("div",{className:rt("flex items-start",pt&&"gap-0"),children:[L&&b==="left"&&jsx(Kt,{items:nt,position:"left",onToggle:U}),jsx("div",{ref:S,className:"flex-1 min-w-0 overflow-hidden",children:et?dt:jsx("div",{className:"flex items-center justify-center text-secondary-400 dark:text-secondary-500",style:{height:R},children:$})}),L&&b==="right"&&jsx(Kt,{items:nt,position:"right",onToggle:U})]}),L&&b==="bottom"&&jsx(Kt,{items:nt,position:"bottom",onToggle:U}),T&&jsxs("div",{className:Tt(),style:{left:T.x,top:T.y},role:"tooltip",children:[jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[jsx("span",{className:"h-2 w-2 rounded-full",style:{background:T.color}}),jsx("span",{className:"font-medium",children:T.seriesName})]}),jsxs("div",{className:"text-primary-300",children:["X: ",jsx("span",{className:"font-medium text-primary-50",children:T.xVal})," ","Y: ",jsx("span",{className:"font-medium text-primary-50",children:T.yVal})]})]})]})}var je={LineChart:oe,BarChart:ne,PieChart:se,ScatterChart:me},lo=je;export{ne as BarChart,je as Chart,oe as LineChart,se as PieChart,me as ScatterChart,lo as default};