@nice2dev/ui-forms 1.0.15 → 1.0.17
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.
- package/dist/NicePinCodeInput-CPQhsGVC-DPpoMLTg.js +10669 -0
- package/dist/NicePinCodeInput-CPQhsGVC-PkFBRDst.cjs +419 -0
- package/dist/NicePinCodeInput-Co42gC9R-BvP5ALYI.cjs +419 -0
- package/dist/NicePinCodeInput-Co42gC9R-b_glabhE.js +10669 -0
- package/dist/NiceSavedQueryPanel-D9Z3gF87-D5O7LI49.js +6607 -0
- package/dist/NiceSavedQueryPanel-D9Z3gF87-D_thxcah.cjs +596 -0
- package/dist/NiceSavedQueryPanel-DR-j6eA5-D-3A9RSO.cjs +596 -0
- package/dist/NiceSavedQueryPanel-DR-j6eA5-DezHfV1O.js +6607 -0
- package/dist/charts-D5Qd_0sO-BdCkzpv5.cjs +546 -0
- package/dist/charts-D5Qd_0sO-DQbp9tKf.js +3868 -0
- package/dist/charts-SHnY1_oD-BS4fRzWz.cjs +546 -0
- package/dist/charts-SHnY1_oD-nVQzwfV9.js +3868 -0
- package/dist/index-BOp82nlQ.js +21651 -0
- package/dist/index-C23e16Aj.js +21651 -0
- package/dist/index-DEIGcdCr.cjs +404 -0
- package/dist/index-DqpmYrH_-DFudsaZb.js +39406 -0
- package/dist/index-DqpmYrH_-EvphvDuo.cjs +4504 -0
- package/dist/index-GIkNMdRp-Dnu5p9Wz.js +39413 -0
- package/dist/index-GIkNMdRp-GCY_2fCs.cjs +4504 -0
- package/dist/index-JytTbH4x.cjs +404 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,546 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),x=require("react"),we=require("./index-JytTbH4x.cjs"),ve=["var(--color-primary, #3b82f6)","var(--color-error, #ef4444)","var(--color-success, #22c55e)","var(--color-warning, #f59e0b)","var(--color-accent, #8b5cf6)","var(--color-accent-pink, #ec4899)","var(--color-info, #06b6d4)","var(--nice-success, #84cc16)"],Se=({series:t,categories:u,width:c=600,height:m=400,title:n,showLegend:g=!0,showGrid:j=!0,axisLabels:M=!0,yAxisLabel:z,xAxisLabel:l,stacked:p,animated:b,zoomable:f,crosshair:$,annotations:k,legendInteractive:s,onDataPointClick:d,exportable:o,className:w,style:_})=>{var be,ke,je;const S=x.useRef(null),[y,v]=x.useState(new Set),[i,D]=x.useState(null),[r,W]=x.useState(null),[T,X]=x.useState(!1),q=x.useRef(null),Z=x.useMemo(()=>t.filter(N=>!y.has(N.name)),[t,y]),ee=x.useCallback(N=>{s&&v(re=>{const te=new Set(re);return te.has(N)?te.delete(N):te.add(N),te})},[s]),J={top:n?40:20,right:20,bottom:l?60:40,left:z?60:50},ae=c-J.left-J.right,Y=m-J.top-J.bottom,U=((be=Z[0])==null?void 0:be.data.length)??((ke=t[0])==null?void 0:ke.data.length)??0,ce=(r==null?void 0:r.start)??0,oe=(r==null?void 0:r.end)??U,C=oe-ce,A=x.useMemo(()=>Z.map(N=>({...N,data:N.data.slice(ce,oe)})),[Z,ce,oe]),F=x.useMemo(()=>u==null?void 0:u.slice(ce,oe),[u,ce,oe]),{minY:G,maxY:K,yTicks:V}=x.useMemo(()=>{let N;if(p){N=[];for(let H=0;H<C;H++)N.push(A.reduce((ne,le)=>ne+(le.data[H]||0),0))}else N=A.flatMap(H=>H.data);N.length===0&&(N=[0]);const re=Math.min(0,...N),te=Math.max(0,...N),a=te-re||1,I=Math.pow(10,Math.floor(Math.log10(a)))||1,R=Math.floor(re/I)*I,h=Math.ceil(te/I)*I,P=[];for(let H=R;H<=h;H+=I)P.push(Math.round(H*1e6)/1e6);return P.length<2&&P.push(h),{minY:R,maxY:h,yTicks:P}},[A,C,p]),O=N=>Y-(N-G)/(K-G||1)*Y,B=N=>(N+.5)/C*ae,Q=C>0?ae/C/(p?1.5:Math.max(Z.length,1)*1.5):20,L=x.useCallback(N=>{if(!f)return;N.preventDefault();const re=r??{start:0,end:U},te=re.end-re.start,a=(re.start+re.end)/2,I=N.deltaY>0?1.2:.8,R=Math.max(2,Math.min(U,Math.round(te*I))),h=Math.max(0,Math.round(a-R/2)),P=Math.min(U,h+R);W({start:h,end:P})},[f,r,U]),E=x.useCallback(N=>{f&&(X(!0),q.current={x:N.clientX,range:r??{start:0,end:U}})},[f,r,U]),ie=x.useCallback(N=>{var te;const re=(te=S.current)==null?void 0:te.getBoundingClientRect();if(re&&D({x:N.clientX-re.left-J.left,y:N.clientY-re.top-J.top}),T&&q.current&&f){const a=N.clientX-q.current.x,I=ae/C,R=-Math.round(a/I),h=q.current.range,P=h.end-h.start;let H=h.start+R;H<0&&(H=0),H+P>U&&(H=U-P),W({start:H,end:H+P})}},[T,f,ae,C,U,J.left,J.top]),he=x.useCallback(()=>{X(!1),q.current=null},[]),me=x.useCallback(()=>{D(null),X(!1),q.current=null},[]),fe=x.useCallback(()=>{const N=S.current;if(!N)return;const re=new XMLSerializer().serializeToString(N),te=document.createElement("canvas");te.width=c,te.height=m+(g?30:0);const a=te.getContext("2d");if(!a)return;const I=new Image;I.onload=()=>{a.fillStyle="var(--bg-primary, #fff)",a.fillRect(0,0,te.width,te.height),a.drawImage(I,0,0);const R=document.createElement("a");R.download="chart.png",R.href=te.toDataURL("image/png"),R.click()},I.src="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(re)},[c,m,g]),pe=m+(g?30:0),_e=A.length>0&&A.every(N=>N.type==="radar"),ye=x.useMemo(()=>{if(!_e)return 1;const N=A.flatMap(re=>re.data);return Math.max(1,...N)},[_e,A]);if(_e){const N=c/2,re=(m-J.top-J.bottom)/2+J.top,te=Math.min(ae,m-J.top-J.bottom)/2-10,a=(F==null?void 0:F.length)??((je=A[0])==null?void 0:je.data.length)??0,I=P=>P/a*Math.PI*2-Math.PI/2,R=(P,H)=>{const ne=H/ye*te;return[N+Math.cos(I(P))*ne,re+Math.sin(I(P))*ne]},h=4;return e.jsx("div",{className:`nice-chart nice-chart--radar ${w||""}`,style:_,children:e.jsxs("svg",{ref:S,viewBox:`0 0 ${c} ${pe}`,preserveAspectRatio:"xMidYMid meet",width:"100%",height:"100%",className:"nice-chart__svg",style:{display:"block",maxWidth:"100%",maxHeight:"100%"},children:[n&&e.jsx("text",{x:c/2,y:20,textAnchor:"middle",className:"nice-chart__title",children:n}),j&&Array.from({length:h},(P,H)=>{const ne=(H+1)/h*te,le=[];for(let se=0;se<a;se++)le.push(`${N+Math.cos(I(se))*ne},${re+Math.sin(I(se))*ne}`);return e.jsx("polygon",{points:le.join(" "),fill:"none",className:"nice-chart__grid-line"},H)}),Array.from({length:a},(P,H)=>{const[ne,le]=R(H,ye);return e.jsx("line",{x1:N,y1:re,x2:ne,y2:le,className:"nice-chart__grid-line"},H)}),M&&(F==null?void 0:F.map((P,H)=>{const[ne,le]=R(H,ye*1.12);return e.jsx("text",{x:ne,y:le,textAnchor:"middle",dominantBaseline:"middle",className:"nice-chart__axis-label",children:P},H)})),A.map((P,H)=>{const ne=P.color||ve[H%ve.length],le=P.data.map((se,ge)=>R(ge,se).join(",")).join(" ");return e.jsxs("g",{className:b?"nice-chart__series nice-chart__series--radar nice-chart__series--anim":"nice-chart__series nice-chart__series--radar",children:[e.jsx("polygon",{points:le,fill:ne,fillOpacity:.2,stroke:ne,strokeWidth:2}),P.data.map((se,ge)=>{const[$e,Ne]=R(ge,se);return e.jsx("circle",{cx:$e,cy:Ne,r:3,fill:ne,children:e.jsx("title",{children:`${P.name}: ${se}`})},ge)})]},P.name)}),g&&e.jsx("g",{transform:`translate(${J.left}, ${m})`,children:t.map((P,H)=>{const ne=H*120,le=y.has(P.name);return e.jsxs("g",{transform:`translate(${ne}, 10)`,style:s?{cursor:"pointer"}:void 0,onClick:()=>ee(P.name),opacity:le?.35:1,children:[e.jsx("rect",{width:12,height:12,rx:2,fill:P.color||ve[H%ve.length]}),e.jsx("text",{x:16,y:10,className:"nice-chart__legend-text",children:P.name})]},P.name)})})]})})}return e.jsxs("div",{className:`nice-chart ${w||""}`,style:_,children:[o&&e.jsx("button",{type:"button",className:"nice-chart__export-btn",onClick:fe,title:"Export PNG",children:"📷"}),e.jsxs("svg",{ref:S,viewBox:`0 0 ${c} ${pe}`,preserveAspectRatio:"xMidYMid meet",width:"100%",height:"100%",style:{display:"block",maxWidth:"100%",maxHeight:"100%"},className:"nice-chart__svg",onWheel:L,onMouseDown:E,onMouseMove:ie,onMouseUp:he,onMouseLeave:me,children:[e.jsxs("g",{transform:`translate(${J.left},${J.top})`,children:[n&&e.jsx("text",{x:ae/2,y:-10,textAnchor:"middle",className:"nice-chart__title",children:n}),j&&V.map(N=>e.jsx("line",{x1:0,y1:O(N),x2:ae,y2:O(N),className:"nice-chart__grid-line"},`grid-${N}`)),M&&V.map(N=>e.jsx("text",{x:-8,y:O(N)+4,textAnchor:"end",className:"nice-chart__axis-label",children:N},`ylabel-${N}`)),M&&F&&F.map((N,re)=>e.jsx("text",{x:B(re),y:Y+20,textAnchor:"middle",className:"nice-chart__axis-label",children:N},re)),z&&e.jsx("text",{x:-J.left+14,y:Y/2,textAnchor:"middle",transform:`rotate(-90, -${J.left-14}, ${Y/2})`,className:"nice-chart__axis-title",children:z}),l&&e.jsx("text",{x:ae/2,y:Y+45,textAnchor:"middle",className:"nice-chart__axis-title",children:l}),e.jsx("line",{x1:0,y1:0,x2:0,y2:Y,className:"nice-chart__axis"}),e.jsx("line",{x1:0,y1:Y,x2:ae,y2:Y,className:"nice-chart__axis"}),k==null?void 0:k.map((N,re)=>{if(N.type==="line"){const te=O(N.value);return e.jsxs("g",{children:[e.jsx("line",{x1:0,y1:te,x2:ae,y2:te,stroke:N.color||"var(--color-error, #ef4444)",strokeWidth:1.5,strokeDasharray:N.dash||"6,3"}),N.label&&e.jsx("text",{x:ae+4,y:te+4,className:"nice-chart__annotation-label",fill:N.color||"var(--color-error, #ef4444)",children:N.label})]},re)}return e.jsx("text",{x:B(N.value),y:-4,textAnchor:"middle",className:"nice-chart__annotation-label",fill:N.color||"var(--text-muted, #6b7280)",children:N.label},re)}),$&&i&&i.x>=0&&i.x<=ae&&i.y>=0&&i.y<=Y&&e.jsxs(e.Fragment,{children:[e.jsx("line",{x1:i.x,y1:0,x2:i.x,y2:Y,stroke:"var(--nice-text-muted, #9ca3af)",strokeWidth:1,strokeDasharray:"4,2"}),e.jsx("line",{x1:0,y1:i.y,x2:ae,y2:i.y,stroke:"var(--nice-text-muted, #9ca3af)",strokeWidth:1,strokeDasharray:"4,2"})]}),A.map((N,re)=>{const te=N.color||ve[re%ve.length],a=N.type||"bar";if(a==="bar")return e.jsx("g",{className:b?"nice-chart__series nice-chart__series--bar nice-chart__series--anim":"nice-chart__series nice-chart__series--bar",children:N.data.map((R,h)=>{let P,H;if(p){const le=A.slice(0,re).reduce((se,ge)=>se+(ge.data[h]||0),0);P=O(le+R),H=O(le)-P}else P=O(Math.max(0,R)),H=Math.abs(O(R)-O(0));const ne=p?B(h)-Q/2:B(h)-A.length*Q/2+re*Q;return e.jsx("rect",{x:ne,y:P,width:Q*.9,height:Math.max(0,H),fill:te,rx:2,style:{transformOrigin:`${ne+Q*.9/2}px ${O(0)}px`,...d?{cursor:"pointer"}:{}},onClick:d?()=>d(N.name,ce+h,R):void 0,children:e.jsx("title",{children:`${N.name}: ${R}`})},h)})},N.name);if(a==="scatter")return e.jsx("g",{className:b?"nice-chart__series nice-chart__series--scatter nice-chart__series--anim":"nice-chart__series nice-chart__series--scatter",children:N.data.map((R,h)=>e.jsx("circle",{cx:B(h),cy:O(R),r:5,fill:te,fillOpacity:.7,stroke:te,strokeWidth:1.5,style:d?{cursor:"pointer"}:void 0,onClick:d?()=>d(N.name,ce+h,R):void 0,children:e.jsx("title",{children:`${N.name}: ${R}`})},h))},N.name);const I=N.data.map((R,h)=>`${B(h)},${O(R)}`);return e.jsxs("g",{className:b?`nice-chart__series nice-chart__series--${a} nice-chart__series--anim`:`nice-chart__series nice-chart__series--${a}`,children:[a==="area"&&e.jsx("polygon",{points:`${B(0)},${O(0)} ${I.join(" ")} ${B(C-1)},${O(0)}`,fill:te,opacity:.15}),e.jsx("polyline",{points:I.join(" "),fill:"none",stroke:te,strokeWidth:2,className:b?"nice-chart__line":void 0}),N.data.map((R,h)=>e.jsx("circle",{cx:B(h),cy:O(R),r:3,fill:te,style:d?{cursor:"pointer"}:void 0,onClick:d?()=>d(N.name,ce+h,R):void 0,children:e.jsx("title",{children:`${N.name}: ${R}`})},h))]},N.name)})]}),g&&e.jsx("g",{transform:`translate(${J.left}, ${m})`,children:t.map((N,re)=>{const te=re*120,a=y.has(N.name);return e.jsxs("g",{transform:`translate(${te}, 10)`,style:s?{cursor:"pointer"}:void 0,onClick:()=>ee(N.name),opacity:a?.35:1,children:[e.jsx("rect",{width:12,height:12,rx:2,fill:N.color||ve[re%ve.length]}),e.jsx("text",{x:16,y:10,className:"nice-chart__legend-text",style:a?{textDecoration:"line-through"}:void 0,children:N.name})]},N.name)})})]})]})},Ee=Object.freeze(Object.defineProperty({__proto__:null,NiceChart:Se},Symbol.toStringTag,{value:"Module"}));function Xe(t){if(!t.length)return{categories:[],numericFields:[],sampleValues:{}};const u=t[0],c=[],m={};let n=null;for(const[g,j]of Object.entries(u))typeof j=="number"?(c.push(g),m[g]=t.map(M=>Number(M[g])||0)):!n&&(typeof j=="string"||j instanceof Date)&&(n=g);return{categories:n?t.map(g=>String(g[n]||"")):t.map((g,j)=>`Item ${j+1}`),numericFields:c,sampleValues:m}}function Be(t,u){const{categories:c,numericFields:m,sampleValues:n}=Xe(t);return{series:m.map((g,j)=>({name:g.replace(/([A-Z])/g," $1").replace(/^./,M=>M.toUpperCase()).trim(),data:n[g],type:u==="area"?"area":u==="line"?"line":"bar"})),categories:c}}x.forwardRef(function(t,u){const{rawData:c,enableAI:m=!0,aiModel:n,enableAutoType:g=!0,enableInsights:j=!0,dataDescription:M,onChartSuggestion:z,onInsights:l,showAIToolbar:p=!0,showInsightsOnLoad:b=!1,series:f,categories:$,...k}=t,[s,d]=x.useState("bar"),[o,w]=x.useState(null),[_,S]=x.useState([]),[y,v]=x.useState(b),[i,D]=x.useState(null),{t:r}=we.ue(),W=we.me(),{suggestChartType:T,generateInsights:X,isLoading:q}=we.Nd(),Z=m&&W.isConfigured,{series:ee,categories:J}=c?Be(c,i||s):{series:f||[],categories:$},ae=x.useCallback(async()=>{if(!Z||!g)return{type:"bar",reason:"Default",config:{}};const C=c||(f!=null&&f.length?f.flatMap(A=>A.data.map((F,G)=>({[A.name]:F,index:G}))):[]);try{const A=await T(C,M),F={type:A.type,reason:A.reason,config:A.config};return w(F),d(F.type),z==null||z(F),F}catch{return{type:"bar",reason:"Default fallback",config:{}}}},[Z,g,c,f,M,T,z]),Y=x.useCallback(async()=>{if(!Z||!j)return[];const C=c||(f!=null&&f.length?f.flatMap(A=>A.data.map((F,G)=>({[A.name]:F,category:($==null?void 0:$[G])||G}))):[]);try{const A=await X(C,i||s);return S(A),l==null||l(A),A}catch{return[]}},[Z,j,c,f,$,s,i,X,l]),U=x.useCallback(()=>i||s,[i,s]);x.useEffect(()=>{Z&&g&&(c!=null&&c.length||f!=null&&f.length)&&ae()},[Z,g,c,f]),x.useImperativeHandle(u,()=>({getSuggestion:ae,generateInsights:Y,getCurrentType:U}));const ce=[{type:"bar",icon:"📊",label:"Bar"},{type:"line",icon:"📈",label:"Line"},{type:"area",icon:"🏔️",label:"Area"},{type:"pie",icon:"🥧",label:"Pie"},{type:"donut",icon:"🍩",label:"Donut"},{type:"scatter",icon:"⭐",label:"Scatter"}],oe=i||s;return e.jsxs("div",{className:"nice-chart-ai","data-testid":t["data-testid"],children:[p&&Z&&e.jsxs("div",{className:"nice-chart-ai__toolbar",children:[e.jsxs("div",{className:"nice-chart-ai__toolbar-left",children:[e.jsx("span",{className:"nice-chart-ai__badge",children:"AI"}),o&&e.jsxs("div",{className:"nice-chart-ai__suggestion",children:[e.jsx("span",{className:"nice-chart-ai__suggestion-icon",children:"💡"}),e.jsxs("span",{className:"nice-chart-ai__suggestion-text",children:[r("chartAI.suggestedType","Suggested:")," ",o.type]}),e.jsxs("span",{className:"nice-chart-ai__suggestion-reason",title:o.reason,children:["(",o.reason,")"]})]}),q&&e.jsx("span",{className:"nice-chart-ai__loading",children:r("chartAI.analyzing","Analyzing...")})]}),e.jsx("div",{className:"nice-chart-ai__toolbar-center",children:e.jsx("div",{className:"nice-chart-ai__type-selector",children:ce.filter(C=>["bar","line","area"].includes(C.type)).map(({type:C,icon:A,label:F})=>e.jsx("button",{type:"button",className:`nice-chart-ai__type-btn ${oe===C?"nice-chart-ai__type-btn--active":""}`,onClick:()=>D(C),title:F,children:A},C))})}),e.jsxs("div",{className:"nice-chart-ai__toolbar-right",children:[e.jsxs("button",{type:"button",className:"nice-chart-ai__auto-btn",onClick:()=>ae(),disabled:q,title:r("chartAI.autoDetect","Auto-detect best chart type"),children:["🔮 ",r("chartAI.auto","Auto")]}),j&&e.jsxs("button",{type:"button",className:"nice-chart-ai__insights-btn",onClick:()=>{_.length||Y(),v(!y)},disabled:q,title:r("chartAI.showInsights","Show data insights"),children:["💡 ",r("chartAI.insights","Insights")]})]})]}),e.jsx("div",{className:"nice-chart-ai__chart-wrapper",children:e.jsx(Se,{series:ee,categories:J,...k})}),y&&_.length>0&&e.jsxs("div",{className:"nice-chart-ai__insights",children:[e.jsxs("div",{className:"nice-chart-ai__insights-header",children:[e.jsxs("h4",{children:["💡 ",r("chartAI.dataInsights","Data Insights")]}),e.jsx("button",{type:"button",className:"nice-chart-ai__insights-close",onClick:()=>v(!1),children:"✕"})]}),e.jsx("ul",{className:"nice-chart-ai__insights-list",children:_.map((C,A)=>e.jsxs("li",{className:"nice-chart-ai__insight",children:[e.jsx("span",{className:"nice-chart-ai__insight-icon",children:"•"}),C]},A))}),e.jsx("div",{className:"nice-chart-ai__insights-footer",children:e.jsxs("button",{type:"button",className:"nice-chart-ai__refresh",onClick:()=>Y(),disabled:q,children:["🔄 ",r("chartAI.refresh","Refresh")]})})]}),y&&q&&e.jsx("div",{className:"nice-chart-ai__insights nice-chart-ai__insights--loading",children:e.jsxs("div",{className:"nice-chart-ai__loading-content",children:[e.jsx("span",{className:"nice-chart-ai__spinner"}),r("chartAI.generatingInsights","Generating insights...")]})})]})});function Ze(t,u){const c=t?typeof t=="number"?new Date(t):new Date(t):new Date,m=z=>z.toString().padStart(2,"0"),n=m(c.getHours()),g=m(c.getMinutes()),j=m(c.getSeconds()),M=c.getMilliseconds().toString().padStart(3,"0");switch(u){case"HH:mm:ss":return`${n}:${g}:${j}`;case"HH:mm":return`${n}:${g}`;case"mm:ss":return`${g}:${j}`;case"ss.SSS":return`${j}.${M}`;case"ISO":return c.toISOString();default:return`${n}:${g}:${j}`}}function De(t){if(t.length===0)return null;const u=Math.min(...t),c=Math.max(...t),m=t.reduce((g,j)=>g+j,0)/t.length,n=t[t.length-1];return{min:u,max:c,avg:m,current:n,count:t.length}}const Le=x.forwardRef(({series:t,maxPoints:u=100,slidingWindow:c=!0,refreshRate:m=16,dataSource:n,width:g=600,height:j=400,title:M,showLegend:z=!0,showGrid:l=!0,yAxisLabel:p,xAxisLabel:b,stacked:f,zoomable:$,crosshair:k,annotations:s=[],legendInteractive:d,onDataPointClick:o,exportable:w,showControls:_=!0,showStatus:S=!0,initialPaused:y=!1,onDataReceived:v,onDataDropped:i,timeFormat:D="HH:mm:ss",showStats:r,thresholds:W=[],className:T,style:X},q)=>{const[Z,ee]=x.useState(()=>{var E;const L=new Map;for(const ie of t)L.set(ie.name,((E=ie.initialData)==null?void 0:E.slice())??[]);return L}),[J,ae]=x.useState([]),[Y,U]=x.useState(y),[ce,oe]=x.useState(!1),C=x.useRef([]),A=x.useRef(Date.now()),F=x.useRef(null),G=x.useCallback(()=>{const L=C.current;L.length!==0&&(C.current=[],ee(E=>{const ie=new Map(E);for(const he of L){const me=ie.get(he.series);if(!me)continue;const fe=[...me,he.value];if(c&&fe.length>u){const pe=fe.length-u;i==null||i(pe,he.series),fe.splice(0,pe)}ie.set(he.series,fe)}return ie}),L.length>0&&ae(E=>{const ie=[...E];for(const he of L){const me=he.category??Ze(he.timestamp,D);ie.push(me)}return c&&ie.length>u&&ie.splice(0,ie.length-u),ie}))},[c,u,D,i]),K=x.useCallback(()=>{const L=Date.now();L-A.current>=m&&(G(),A.current=L),F.current=requestAnimationFrame(K)},[m,G]);x.useEffect(()=>(Y||(F.current=requestAnimationFrame(K)),()=>{F.current!==null&&(cancelAnimationFrame(F.current),F.current=null)}),[Y,K]);const V=x.useCallback(L=>{if(Y)return;const E="points"in L?L.points:[L];for(const ie of E)Z.has(ie.series)&&(C.current.push(ie),v==null||v(ie))},[Y,Z,v]);x.useEffect(()=>{if(!n)return;const L=n.subscribe(V);let E;return n.onStatusChange?E=n.onStatusChange(oe):oe(!0),n.fetchHistory&&n.fetchHistory(u).then(ie=>{for(const he of ie)C.current.push(he);G()}),()=>{L(),E==null||E()}},[n,V,u,G]);const O=x.useMemo(()=>t.map(L=>({name:L.name,color:L.color,type:L.type,data:Z.get(L.name)??[]})),[t,Z]),B=x.useMemo(()=>{const L=[...s];for(const E of W)L.push({type:"line",value:E.value,color:E.color,label:E.label,dash:E.style==="dashed"?"5,5":E.style==="dotted"?"2,2":void 0});return L},[s,W]);x.useImperativeHandle(q,()=>({pause(){U(!0)},resume(){U(!1)},isPaused(){return Y},clear(){ee(L=>{const E=new Map(L);for(const ie of E.keys())E.set(ie,[]);return E}),ae([]),C.current=[]},addPoint(L){V(L)},addPoints(L){V({points:L})},getData(L){return Z.get(L)??[]},getCategories(){return J},exportData(){return{series:O,categories:J}},getStats(L){const E=Z.get(L);return E?De(E):null}}),[Y,Z,J,O,V]);const Q=x.useMemo(()=>{if(!r)return null;const L={};for(const[E,ie]of Z)L[E]=De(ie);return L},[r,Z]);return e.jsxs("div",{className:T,style:{position:"relative",...X},children:[S&&e.jsxs("div",{style:{position:"absolute",top:8,right:8,display:"flex",alignItems:"center",gap:4,fontSize:12,color:ce?"var(--color-success, #22c55e)":"var(--color-error, #ef4444)",zIndex:10},children:[e.jsx("span",{style:{width:8,height:8,borderRadius:"50%",backgroundColor:ce?"var(--color-success, #22c55e)":"var(--color-error, #ef4444)"}}),ce?"Live":"Disconnected"]}),_&&e.jsx("div",{style:{position:"absolute",top:8,left:8,display:"flex",gap:4,zIndex:10},children:e.jsx("button",{onClick:()=>U(L=>!L),style:{padding:"4px 8px",fontSize:12,border:"1px solid var(--border-color, #ddd)",borderRadius:4,background:Y?"var(--warning-bg, #fef3c7)":"var(--bg-primary, #fff)",cursor:"pointer"},title:Y?"Resume":"Pause",children:Y?"▶":"⏸"})}),r&&Q&&e.jsx("div",{style:{position:"absolute",bottom:50,right:8,background:"var(--nice-overlay-light-90, rgba(255, 255, 255, 0.9))",border:"1px solid var(--border-color, #ddd)",borderRadius:4,padding:8,fontSize:11,zIndex:10},children:Object.entries(Q).map(([L,E])=>E?e.jsxs("div",{style:{marginBottom:4},children:[e.jsx("strong",{children:L}),e.jsxs("div",{children:["Min: ",E.min.toFixed(2)," | Max: ",E.max.toFixed(2)]}),e.jsxs("div",{children:["Avg: ",E.avg.toFixed(2)," | Now: ",E.current.toFixed(2)]})]},L):null)}),e.jsx(Se,{series:O,categories:J,width:g,height:j,title:M,showLegend:z,showGrid:l,yAxisLabel:p,xAxisLabel:b,stacked:f,zoomable:$,crosshair:k,annotations:B,legendInteractive:d,onDataPointClick:o,exportable:w})]})});Le.displayName="NiceLiveChart";const ue=["#3b82f6","#ef4444","#22c55e","#f59e0b","#8b5cf6","#ec4899","#06b6d4","#84cc16"],Ge=({data:t,width:u=400,height:c=400,innerRadius:m=0,title:n,showLegend:g=!0,showLabels:j=!0,className:M,style:z})=>{const l=u/2,p=(c-(g?30:0))/2+(n?10:0),b=Math.min(l,p)-40,f=t.reduce((s,d)=>s+d.value,0);let $=-Math.PI/2;const k=t.map((s,d)=>{const o=s.value/(f||1)*Math.PI*2,w=$;$+=o;const _=$,S=(w+_)/2,y=l+b*Math.cos(w),v=p+b*Math.sin(w),i=l+b*Math.cos(_),D=p+b*Math.sin(_),r=o>Math.PI?1:0,W=s.color||ue[d%ue.length];let T;if(m>0){const ee=l+m*Math.cos(w),J=p+m*Math.sin(w),ae=l+m*Math.cos(_),Y=p+m*Math.sin(_);T=`M${y},${v} A${b},${b} 0 ${r},1 ${i},${D} L${ae},${Y} A${m},${m} 0 ${r},0 ${ee},${J} Z`}else T=`M${l},${p} L${y},${v} A${b},${b} 0 ${r},1 ${i},${D} Z`;const X=l+b*.7*Math.cos(S),q=p+b*.7*Math.sin(S),Z=f>0?Math.round(s.value/f*100):0;return{...s,path:T,labelX:X,labelY:q,pct:Z,color:W}});return e.jsx("div",{className:`nice-piechart ${M||""}`,style:z,children:e.jsxs("svg",{viewBox:`0 0 ${u} ${c}`,preserveAspectRatio:"xMidYMid meet",width:"100%",height:"100%",style:{display:"block",maxWidth:"100%",maxHeight:"100%"},className:"nice-piechart__svg",children:[n&&e.jsx("text",{x:l,y:20,textAnchor:"middle",className:"nice-chart__title",children:n}),k.map((s,d)=>e.jsxs("g",{children:[e.jsx("path",{d:s.path,fill:s.color,stroke:"var(--bg-primary, #fff)",strokeWidth:2,children:e.jsx("title",{children:`${s.label}: ${s.value} (${s.pct}%)`})}),j&&s.pct>=5&&e.jsxs("text",{x:s.labelX,y:s.labelY,textAnchor:"middle",dominantBaseline:"middle",className:"nice-piechart__label",children:[s.pct,"%"]})]},d)),g&&e.jsx("g",{transform:`translate(10, ${c-25})`,children:t.map((s,d)=>e.jsxs("g",{transform:`translate(${d*100}, 0)`,children:[e.jsx("rect",{width:10,height:10,rx:2,fill:s.color||ue[d%ue.length]}),e.jsx("text",{x:14,y:9,className:"nice-chart__legend-text",children:s.label})]},d))})]})})},Ue=({series:t,categories:u,width:c=400,height:m=400,maxValue:n,title:g,showLegend:j=!0,className:M,style:z})=>{const l=c/2,p=(m-(j?30:0))/2+(g?10:0),b=Math.min(l,p)-60,f=u.length,$=n??Math.max(...t.flatMap(o=>o.data),1),k=Math.PI*2/f,s=5,d=(o,w)=>{const _=o*k-Math.PI/2,S=w/$*b;return{x:l+S*Math.cos(_),y:p+S*Math.sin(_)}};return e.jsx("div",{className:`nice-polarchart ${M||""}`,style:z,children:e.jsxs("svg",{width:c,height:m,className:"nice-polarchart__svg",children:[g&&e.jsx("text",{x:l,y:20,textAnchor:"middle",className:"nice-chart__title",children:g}),Array.from({length:s},(o,w)=>{const _=b*((w+1)/s);return e.jsx("circle",{cx:l,cy:p,r:_,fill:"none",stroke:"var(--border-color, #ddd)",strokeWidth:.5},w)}),u.map((o,w)=>{const _=d(w,$),S=d(w,$*1.22),y=w*k-Math.PI/2,v=Math.cos(y),i=Math.sin(y),D=v>.2?"start":v<-.2?"end":"middle",r=i>.2?"hanging":i<-.2?"auto":"middle";return e.jsxs("g",{children:[e.jsx("line",{x1:l,y1:p,x2:_.x,y2:_.y,stroke:"var(--border-color, #ddd)",strokeWidth:.5}),e.jsx("text",{x:S.x,y:S.y,textAnchor:D,dominantBaseline:r,className:"nice-chart__axis-label nice-chart__axis-label--polar",children:o})]},w)}),t.map((o,w)=>{const _=o.color||ue[w%ue.length],S=o.data.map((y,v)=>{const i=d(v,y);return`${i.x},${i.y}`}).join(" ");return e.jsxs("g",{children:[e.jsx("polygon",{points:S,fill:o.fill!==!1?_:"none",fillOpacity:.15,stroke:_,strokeWidth:2}),o.data.map((y,v)=>{const i=d(v,y);return e.jsx("circle",{cx:i.x,cy:i.y,r:3,fill:_,children:e.jsx("title",{children:`${o.name} - ${u[v]}: ${y}`})},v)})]},o.name)}),j&&e.jsx("g",{transform:`translate(10, ${m-25})`,children:t.map((o,w)=>e.jsxs("g",{transform:`translate(${w*100}, 0)`,children:[e.jsx("rect",{width:10,height:10,rx:2,fill:o.color||ue[w%ue.length]}),e.jsx("text",{x:14,y:9,className:"nice-chart__legend-text",children:o.name})]},w))})]})})},qe=({value:t,min:u=0,max:c=100,width:m=200,height:n=200,startAngle:g=225,endAngle:j=-45,color:M="var(--color-primary, #3b82f6)",trackColor:z,label:l,formatValue:p,ranges:b,className:f,style:$})=>{const k=m/2,s=n/2,d=Math.min(k,s)-20,o=Math.max(0,Math.min(1,(t-u)/(c-u||1))),w=r=>r*Math.PI/180,_=(g-j+360)%360||360,S=r=>({x:k+d*Math.cos(w(r)),y:s-d*Math.sin(w(r))}),y=(r,W)=>{const T=S(r),X=S(W),q=(r-W+360)%360>180?1:0;return`M${T.x},${T.y} A${d},${d} 0 ${q},1 ${X.x},${X.y}`},v=g-o*_,i=S(v);let D=M;if(b){for(const r of b)if(t>=r.start&&t<=r.end){D=r.color;break}}return e.jsx("div",{className:`nice-gauge nice-gauge--circular ${f||""}`,style:$,children:e.jsxs("svg",{width:m,height:n,children:[e.jsx("path",{d:y(g,j),fill:"none",stroke:z||"var(--border-color, #e2e8f0)",strokeWidth:12,strokeLinecap:"round"}),o>0&&e.jsx("path",{d:y(g,v),fill:"none",stroke:D,strokeWidth:12,strokeLinecap:"round"}),e.jsx("line",{x1:k,y1:s,x2:i.x,y2:i.y,stroke:"var(--text-primary, #333)",strokeWidth:2,strokeLinecap:"round"}),e.jsx("circle",{cx:k,cy:s,r:4,fill:"var(--text-primary, #333)"}),e.jsx("text",{x:k,y:s+d*.6,textAnchor:"middle",className:"nice-gauge__value",children:p?p(t):t}),l&&e.jsx("text",{x:k,y:s+d*.95,textAnchor:"middle",className:"nice-gauge__label",children:l})]})})},Ye=({value:t,min:u=0,max:c=100,width:m=300,height:n=60,orientation:g="horizontal",color:j="var(--color-primary, #3b82f6)",label:M,formatValue:z,ranges:l,showTicks:p=!0,tickCount:b=5,className:f,style:$})=>{const k=g==="horizontal",s=k?m-40:n-40,d=Math.max(0,Math.min(1,(t-u)/(c-u||1))),o=10;let w=j;if(l){for(const S of l)if(t>=S.start&&t<=S.end){w=S.color;break}}const _=Array.from({length:b},(S,y)=>u+(c-u)*(y/(b-1)));return k?e.jsx("div",{className:`nice-gauge nice-gauge--linear ${f||""}`,style:$,children:e.jsxs("svg",{width:m,height:n,children:[e.jsx("text",{x:20+s*d,y:14,textAnchor:"middle",className:"nice-gauge__value",style:{fontSize:12},children:z?z(t):t}),e.jsx("rect",{x:20,y:n/2-o/2,width:s,height:o,rx:5,fill:"var(--border-color, #e2e8f0)"}),e.jsx("rect",{x:20,y:n/2-o/2,width:s*d,height:o,rx:5,fill:w}),e.jsx("polygon",{points:`${20+s*d},${n/2-o/2-2} ${20+s*d-5},${n/2-o/2-8} ${20+s*d+5},${n/2-o/2-8}`,fill:"var(--text-primary, #333)"}),p&&_.map((S,y)=>{const v=20+(S-u)/(c-u)*s;return e.jsx("text",{x:v,y:n/2+o/2+12,textAnchor:"middle",className:"nice-gauge__tick",children:S},y)}),M&&e.jsx("text",{x:m/2,y:n-2,textAnchor:"middle",className:"nice-gauge__label",children:M})]})}):e.jsx("div",{className:`nice-gauge nice-gauge--linear nice-gauge--vertical ${f||""}`,style:$,children:e.jsxs("svg",{width:m,height:n,children:[e.jsx("rect",{x:m/2-o/2,y:20,width:o,height:s,rx:5,fill:"var(--border-color, #e2e8f0)"}),e.jsx("rect",{x:m/2-o/2,y:20+s*(1-d),width:o,height:s*d,rx:5,fill:w}),e.jsx("text",{x:m/2,y:14,textAnchor:"middle",className:"nice-gauge__value",children:z?z(t):t}),M&&e.jsx("text",{x:m/2,y:n-4,textAnchor:"middle",className:"nice-gauge__label",children:M})]})})},Qe=({items:t,min:u=0,max:c=100,width:m=300,height:n=300,startAngle:g=225,endAngle:j=-45,formatValue:M,title:z,className:l,style:p})=>{const b=m/2,f=n/2,$=Math.min(b,f)-30,k=Math.min(20,$/(t.length+1)),s=4,d=_=>_*Math.PI/180,o=(g-j+360)%360||360,w=(_,S,y)=>{const v=b+_*Math.cos(d(S)),i=f-_*Math.sin(d(S)),D=b+_*Math.cos(d(y)),r=f-_*Math.sin(d(y)),W=(S-y+360)%360;return`M${v},${i} A${_},${_} 0 ${W>180?1:0},1 ${D},${r}`};return e.jsx("div",{className:`nice-bargauge ${l||""}`,style:p,children:e.jsxs("svg",{width:m,height:n,children:[z&&e.jsx("text",{x:b,y:20,textAnchor:"middle",className:"nice-chart__title",children:z}),t.map((_,S)=>{const y=$-S*(k+s),v=Math.max(0,Math.min(1,(_.value-u)/(c-u||1))),i=g-v*o,D=_.color||ue[S%ue.length];return e.jsxs("g",{children:[e.jsx("path",{d:w(y,g,j),fill:"none",stroke:"var(--border-color, #e2e8f0)",strokeWidth:k,strokeLinecap:"round"}),v>0&&e.jsx("path",{d:w(y,g,i),fill:"none",stroke:D,strokeWidth:k,strokeLinecap:"round"})]},S)}),e.jsx("g",{children:t.map((_,S)=>e.jsxs("text",{x:b,y:f-((t.length-1)/2-S)*16,textAnchor:"middle",dominantBaseline:"middle",className:"nice-gauge__value",style:{fontSize:12},children:[_.label?`${_.label}: `:"",M?M(_.value):_.value]},S))})]})})},Je=({data:t,width:u=120,height:c=30,type:m="line",color:n="var(--color-primary, #3b82f6)",showMinMax:g,showLastPoint:j=!0,className:M,style:z})=>{if(t.length===0)return null;const l=2,p=Math.min(...t),b=Math.max(...t),f=b-p||1,$=u-l*2,k=c-l*2,s=y=>l+y/(t.length-1||1)*$,d=y=>l+k-(y-p)/f*k;if(m==="bar"){const y=Math.max(1,$/t.length-1);return e.jsx("svg",{width:u,height:c,className:`nice-sparkline ${M||""}`,style:z,children:t.map((v,i)=>e.jsx("rect",{x:l+i/t.length*$,y:d(v),width:y,height:k-(d(v)-l),fill:n,rx:1},i))})}const o=t.map((y,v)=>`${s(v)},${d(y)}`).join(" "),w=t.indexOf(p),_=t.indexOf(b),S=t.length-1;return e.jsxs("svg",{width:u,height:c,className:`nice-sparkline ${M||""}`,style:z,children:[m==="area"&&e.jsx("polygon",{points:`${s(0)},${l+k} ${o} ${s(S)},${l+k}`,fill:n,opacity:.15}),e.jsx("polyline",{points:o,fill:"none",stroke:n,strokeWidth:1.5}),g&&e.jsx("circle",{cx:s(w),cy:d(p),r:2,fill:"var(--nice-danger, #ef4444)"}),g&&e.jsx("circle",{cx:s(_),cy:d(b),r:2,fill:"var(--nice-success, #22c55e)"}),j&&e.jsx("circle",{cx:s(S),cy:d(t[S]),r:2,fill:n})]})},Ke={sm:{width:160,height:22,fontSize:11},md:{width:220,height:32,fontSize:12},lg:{width:320,height:44,fontSize:14}},et=({value:t,target:u,min:c=0,max:m=100,width:n,height:g,color:j="var(--color-primary, #3b82f6)",targetColor:M="var(--color-error, #ef4444)",size:z="md",label:l,labelPlacement:p="top",showValue:b=!1,showTarget:f=!1,formatValue:$=w=>String(w),state:k="normal",errorMessage:s,className:d,style:o})=>{const w=Ke[z],_=n??w.width,S=g??w.height,y=w.fontSize,v=4,i=_-v*2,D=f&&u!=null?y+4:v,r=f&&u!=null?S+(D-v):S,W=r-D-v,T=Math.max(0,Math.min(1,(t-c)/(m-c||1))),X=u!=null?Math.max(0,Math.min(1,(u-c)/(m-c||1))):null,q=()=>k==="error"?e.jsx("div",{role:"alert",style:{width:_,height:r,display:"flex",alignItems:"center",justifyContent:"center",border:"1px dashed var(--color-error, #ef4444)",borderRadius:4,color:"var(--color-error, #ef4444)",fontSize:y,padding:"0 8px",boxSizing:"border-box"},children:s??"Error"}):k==="loading"?e.jsx("div",{role:"status","aria-label":"Loading",className:"nice-bullet__skeleton",style:{width:_,height:r,borderRadius:4,background:"linear-gradient(90deg, var(--bg-tertiary, #e5e7eb) 25%, var(--bg-secondary, #f3f4f6) 50%, var(--bg-tertiary, #e5e7eb) 75%)",backgroundSize:"200% 100%",animation:"nice-bullet-shimmer 1.4s linear infinite"}}):e.jsxs("svg",{width:_,height:r,role:"img","aria-label":typeof l=="string"?l:void 0,children:[e.jsx("rect",{x:v,y:D,width:i,height:W,rx:3,fill:"var(--border-color, #e2e8f0)"}),e.jsx("rect",{x:v,y:D+W*.2,width:i*T,height:W*.6,rx:2,fill:j}),X!=null&&e.jsx("line",{x1:v+i*X,y1:D+2,x2:v+i*X,y2:D+W-2,stroke:M,strokeWidth:2}),b&&e.jsx("text",{x:v+Math.max(i*T,4),y:D+W/2,dx:i*T>24?-4:4,textAnchor:i*T>24?"end":"start",dominantBaseline:"middle",fontSize:y,fill:i*T>24?"var(--text-on-primary, #ffffff)":"var(--text-primary)",fontWeight:600,children:$(t)}),f&&X!=null&&e.jsxs("text",{x:v+i*X,y:D-2,textAnchor:"middle",fontSize:y-1,fill:M,fontWeight:600,children:["▼",$(u)]})]});if(p==="none"||!l)return e.jsxs("div",{className:`nice-bullet ${d||""}`,style:o,children:[q(),e.jsx("style",{children:Ie})]});const Z=p==="top"||p==="bottom",ee=e.jsx("span",{className:"nice-bullet__label",style:{fontSize:y,fontWeight:600,color:"var(--text-primary)",...Z?{marginBottom:p==="top"?4:0,marginTop:p==="bottom"?4:0}:{},...p==="left"?{marginRight:8}:{},...p==="right"?{marginLeft:8}:{}},children:l});return e.jsxs("div",{className:`nice-bullet nice-bullet--${p} ${d||""}`,style:{display:"inline-flex",flexDirection:Z?"column":"row",alignItems:Z?"flex-start":"center",...o},children:[(p==="top"||p==="left")&&ee,q(),(p==="bottom"||p==="right")&&ee,e.jsx("style",{children:Ie})]})},Ie=`
|
|
2
|
+
@keyframes nice-bullet-shimmer {
|
|
3
|
+
0% { background-position: 200% 0; }
|
|
4
|
+
100% { background-position: -200% 0; }
|
|
5
|
+
}
|
|
6
|
+
`,tt=({data:t,width:u=400,height:c=300,inverted:m,showLabels:n=!0,showValues:g=!0,title:j,className:M,style:z})=>{const l={top:j?30:10,bottom:10,x:40},p=u-l.x*2,b=c-l.top-l.bottom,f=m?[...t].reverse():t,$=Math.max(...f.map(s=>s.value),1),k=b/f.length;return e.jsx("div",{className:`nice-funnel ${M||""}`,style:z,children:e.jsxs("svg",{width:u,height:c,children:[j&&e.jsx("text",{x:u/2,y:20,textAnchor:"middle",className:"nice-chart__title",children:j}),f.map((s,d)=>{const o=s.value/$*p,w=d<f.length-1?f[d+1].value/$*p:o*.3,_=l.top+d*k,S=_+k,y=u/2,v=`${y-o/2},${_} ${y+o/2},${_} ${y+w/2},${S} ${y-w/2},${S}`,i=s.color||ue[d%ue.length];return e.jsxs("g",{children:[e.jsx("polygon",{points:v,fill:i,stroke:"var(--bg-primary, #fff)",strokeWidth:1,children:e.jsx("title",{children:`${s.label}: ${s.value}`})}),n&&e.jsx("text",{x:y,y:_+k/2-(g?4:0),textAnchor:"middle",dominantBaseline:"middle",className:"nice-funnel__label",children:s.label}),g&&e.jsx("text",{x:y,y:_+k/2+10,textAnchor:"middle",dominantBaseline:"middle",className:"nice-funnel__value",children:s.value})]},d)})]})})},Re=({nodes:t,links:u,width:c=600,height:m=400,nodeWidth:n=20,nodePadding:g=10,title:j,className:M,style:z})=>{const l={top:j?40:20,bottom:20,left:20,right:20},p=c-l.left-l.right,b=m-l.top-l.bottom,f=new Set(u.map(r=>r.source)),$=new Set(u.map(r=>r.target)),k=t.filter(r=>f.has(r.id)&&!$.has(r.id)),s=t.filter(r=>$.has(r.id)),d=t.filter(r=>f.has(r.id)&&$.has(r.id)),o=[k,...d.length?[d]:[],s].filter(r=>r.length>0),w=o.length,_=new Map;t.forEach(r=>{const W=u.filter(X=>X.source===r.id).reduce((X,q)=>X+q.value,0),T=u.filter(X=>X.target===r.id).reduce((X,q)=>X+q.value,0);_.set(r.id,Math.max(W,T))});const S=o.map(r=>r.reduce((W,T)=>W+(_.get(T.id)||0),0)+(r.length-1)*g),y=Math.max(...S,1),v=new Map;o.forEach((r,W)=>{const T=l.left+W/(w-1||1)*(p-n);let X=0;r.forEach(q=>{const Z=(_.get(q.id)||0)/y*b;v.set(q.id,{x:T,y:l.top+X,h:Z}),X+=Z+g})});const i=new Map,D=new Map;return t.forEach(r=>{i.set(r.id,0),D.set(r.id,0)}),e.jsx("div",{className:`nice-sankey ${M||""}`,style:z,children:e.jsxs("svg",{width:c,height:m,children:[j&&e.jsx("text",{x:c/2,y:20,textAnchor:"middle",className:"nice-chart__title",children:j}),u.map((r,W)=>{var C;const T=v.get(r.source),X=v.get(r.target);if(!T||!X)return null;const q=i.get(r.source)||0,Z=D.get(r.target)||0,ee=r.value/y*b;i.set(r.source,q+ee),D.set(r.target,Z+ee);const J=T.x+n,ae=T.y+q,Y=X.x,U=X.y+Z,ce=(J+Y)/2,oe=((C=t.find(A=>A.id===r.source))==null?void 0:C.color)||ue[W%ue.length];return e.jsx("path",{d:`M${J},${ae} C${ce},${ae} ${ce},${U} ${Y},${U} L${Y},${U+ee} C${ce},${U+ee} ${ce},${ae+ee} ${J},${ae+ee} Z`,fill:oe,fillOpacity:.3,stroke:oe,strokeOpacity:.5,strokeWidth:.5,children:e.jsx("title",{children:`${r.source} → ${r.target}: ${r.value}`})},W)}),t.map((r,W)=>{const T=v.get(r.id);if(!T)return null;const X=r.color||ue[W%ue.length];return e.jsxs("g",{children:[e.jsx("rect",{x:T.x,y:T.y,width:n,height:Math.max(T.h,2),fill:X,rx:2}),e.jsx("text",{x:T.x<p/2?T.x+n+4:T.x-4,y:T.y+T.h/2,textAnchor:T.x<p/2?"start":"end",dominantBaseline:"middle",className:"nice-chart__legend-text",children:r.label})]},r.id)})]})})},at=Object.freeze(Object.defineProperty({__proto__:null,NiceSankey:Re},Symbol.toStringTag,{value:"Module"})),rt=({data:t,min:u,max:c,start:m,end:n,onChange:g,width:j=500,height:M=100,step:z=1,formatValue:l,chartColor:p="var(--color-primary, #3b82f6)",className:b,style:f})=>{const $={top:10,bottom:30,left:10,right:10},k=j-$.left-$.right,s=M-$.top-$.bottom,d=y=>$.left+(y-u)/(c-u||1)*k,o=y=>{const v=Math.max(0,Math.min(1,(y-$.left)/k)),i=u+v*(c-u);return Math.round(i/z)*z},w=(y,v)=>{v.preventDefault();const i=v.target.closest("svg");if(!i)return;const D=W=>{const T=i.getBoundingClientRect(),X=o(W.clientX-T.left);y==="start"?g(Math.min(X,n),n):g(m,Math.max(X,m))},r=()=>{document.removeEventListener("pointermove",D),document.removeEventListener("pointerup",r)};document.addEventListener("pointermove",D),document.addEventListener("pointerup",r)},_=t?Math.min(...t):0,S=(t?Math.max(...t):1)-_||1;return e.jsx("div",{className:`nice-rangeselector ${b||""}`,style:f,children:e.jsxs("svg",{width:j,height:M,children:[t&&t.length>1&&e.jsx("polygon",{points:`${$.left},${$.top+s} ${t.map((y,v)=>`${$.left+v/(t.length-1)*k},${$.top+s-(y-_)/S*s}`).join(" ")} ${$.left+k},${$.top+s}`,fill:p,opacity:.15}),e.jsx("rect",{x:d(m),y:$.top,width:d(n)-d(m),height:s,fill:p,opacity:.1}),e.jsx("rect",{x:$.left,y:$.top,width:d(m)-$.left,height:s,fill:"var(--bg-secondary, #f5f5f5)",opacity:.6}),e.jsx("rect",{x:d(n),y:$.top,width:$.left+k-d(n),height:s,fill:"var(--bg-secondary, #f5f5f5)",opacity:.6}),e.jsx("rect",{x:d(m)-4,y:$.top,width:8,height:s,fill:p,rx:2,cursor:"ew-resize",onPointerDown:y=>w("start",y)}),e.jsx("rect",{x:d(n)-4,y:$.top,width:8,height:s,fill:p,rx:2,cursor:"ew-resize",onPointerDown:y=>w("end",y)}),e.jsx("text",{x:d(m),y:$.top+s+18,textAnchor:"middle",className:"nice-chart__axis-label",children:l?l(m):m}),e.jsx("text",{x:d(n),y:$.top+s+18,textAnchor:"middle",className:"nice-chart__axis-label",children:l?l(n):n})]})})},Pe=({regions:t,width:u=600,height:c=400,viewBox:m="0 0 1000 600",colorRange:n=["var(--info-bg, #dbeafe)","var(--color-primary-active, #1d4ed8)"],maxValue:g,onRegionClick:j,selectedRegionId:M,title:z,showTooltip:l=!0,className:p,style:b})=>{const f=g??Math.max(...t.map(k=>k.value??0),1),$=k=>{const s=r=>[parseInt(r.slice(1,3),16),parseInt(r.slice(3,5),16),parseInt(r.slice(5,7),16)],[d,o,w]=s(n[0]),[_,S,y]=s(n[1]),v=Math.round(d+(_-d)*k),i=Math.round(o+(S-o)*k),D=Math.round(w+(y-w)*k);return`rgb(${v},${i},${D})`};return e.jsxs("div",{className:`nice-vectormap ${p||""}`,style:b,children:[z&&e.jsx("div",{className:"nice-vectormap__title",children:z}),e.jsx("svg",{width:u,height:c,viewBox:m,children:t.map(k=>{const s=k.value!=null?Math.max(0,Math.min(1,k.value/f)):0,d=k.value!=null?$(s):"var(--bg-tertiary, #e5e7eb)",o=k.id===M;return e.jsx("path",{d:k.path,fill:d,stroke:o?"var(--color-primary, #3b82f6)":"var(--border-color, #d1d5db)",strokeWidth:o?2:.5,cursor:j?"pointer":void 0,onClick:()=>j==null?void 0:j(k),children:l&&e.jsx("title",{children:`${k.name}${k.value!=null?`: ${k.value}`:""}`})},k.id)})})]})},nt=Object.freeze(Object.defineProperty({__proto__:null,NiceVectorMap:Pe},Symbol.toStringTag,{value:"Module"})),it=`
|
|
7
|
+
.nice-forecast-chart {
|
|
8
|
+
display: flex;
|
|
9
|
+
flex-direction: column;
|
|
10
|
+
background: var(--nice-bg-primary, #ffffff);
|
|
11
|
+
border: 1px solid var(--nice-border-color, #e5e7eb);
|
|
12
|
+
border-radius: var(--nice-radius-lg, 0.5rem);
|
|
13
|
+
overflow: hidden;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.nice-forecast-chart__header {
|
|
17
|
+
display: flex;
|
|
18
|
+
align-items: center;
|
|
19
|
+
justify-content: space-between;
|
|
20
|
+
padding: 0.75rem 1rem;
|
|
21
|
+
border-bottom: 1px solid var(--nice-border-color, #e5e7eb);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.nice-forecast-chart__title {
|
|
25
|
+
font-size: 1rem;
|
|
26
|
+
font-weight: 600;
|
|
27
|
+
color: var(--nice-text-primary);
|
|
28
|
+
margin: 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.nice-forecast-chart__actions {
|
|
32
|
+
display: flex;
|
|
33
|
+
gap: 0.5rem;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.nice-forecast-chart__btn {
|
|
37
|
+
display: inline-flex;
|
|
38
|
+
align-items: center;
|
|
39
|
+
justify-content: center;
|
|
40
|
+
width: 2rem;
|
|
41
|
+
height: 2rem;
|
|
42
|
+
font-size: 1rem;
|
|
43
|
+
border-radius: var(--nice-radius-md, 0.375rem);
|
|
44
|
+
cursor: pointer;
|
|
45
|
+
transition: all 0.15s ease;
|
|
46
|
+
border: 1px solid var(--nice-border-color, #d1d5db);
|
|
47
|
+
background: var(--nice-bg-primary, #ffffff);
|
|
48
|
+
color: var(--nice-text-secondary);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.nice-forecast-chart__btn:hover {
|
|
52
|
+
background: var(--nice-bg-hover, #f3f4f6);
|
|
53
|
+
color: var(--nice-text-primary);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.nice-forecast-chart__btn:disabled {
|
|
57
|
+
opacity: 0.5;
|
|
58
|
+
cursor: not-allowed;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.nice-forecast-chart__container {
|
|
62
|
+
position: relative;
|
|
63
|
+
width: 100%;
|
|
64
|
+
padding: 1rem;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.nice-forecast-chart__svg {
|
|
68
|
+
width: 100%;
|
|
69
|
+
overflow: visible;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.nice-forecast-chart__grid-line {
|
|
73
|
+
stroke: var(--nice-border-divider, #f3f4f6);
|
|
74
|
+
stroke-width: 1;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.nice-forecast-chart__axis-line {
|
|
78
|
+
stroke: var(--nice-border-color, #e5e7eb);
|
|
79
|
+
stroke-width: 1;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.nice-forecast-chart__axis-label {
|
|
83
|
+
font-size: 0.6875rem;
|
|
84
|
+
fill: var(--nice-text-secondary);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.nice-forecast-chart__axis-title {
|
|
88
|
+
font-size: 0.75rem;
|
|
89
|
+
font-weight: 500;
|
|
90
|
+
fill: var(--nice-text-primary);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.nice-forecast-chart__historical-line {
|
|
94
|
+
fill: none;
|
|
95
|
+
stroke-width: 2;
|
|
96
|
+
stroke-linecap: round;
|
|
97
|
+
stroke-linejoin: round;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.nice-forecast-chart__forecast-line {
|
|
101
|
+
fill: none;
|
|
102
|
+
stroke-width: 2;
|
|
103
|
+
stroke-linecap: round;
|
|
104
|
+
stroke-linejoin: round;
|
|
105
|
+
stroke-dasharray: 6, 4;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.nice-forecast-chart__confidence-band {
|
|
109
|
+
opacity: 0.2;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.nice-forecast-chart__forecast-region {
|
|
113
|
+
fill: var(--nice-bg-secondary, #f9fafb);
|
|
114
|
+
opacity: 0.5;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.nice-forecast-chart__point {
|
|
118
|
+
cursor: pointer;
|
|
119
|
+
transition: r 0.15s ease;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.nice-forecast-chart__point:hover {
|
|
123
|
+
r: 6;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.nice-forecast-chart__annotation-line {
|
|
127
|
+
stroke-dasharray: 4, 2;
|
|
128
|
+
stroke-width: 1;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.nice-forecast-chart__annotation-marker {
|
|
132
|
+
cursor: pointer;
|
|
133
|
+
transition: transform 0.15s ease;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.nice-forecast-chart__annotation-marker:hover {
|
|
137
|
+
transform: scale(1.2);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.nice-forecast-chart__reference-line {
|
|
141
|
+
stroke-width: 1;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.nice-forecast-chart__reference-label {
|
|
145
|
+
font-size: 0.625rem;
|
|
146
|
+
fill: var(--nice-text-secondary);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.nice-forecast-chart__cash-runway {
|
|
150
|
+
pointer-events: none;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.nice-forecast-chart__cash-runway-line {
|
|
154
|
+
stroke: var(--nice-danger, #ef4444);
|
|
155
|
+
stroke-width: 2;
|
|
156
|
+
stroke-dasharray: 8, 4;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
.nice-forecast-chart__cash-runway-label-bg {
|
|
160
|
+
fill: var(--nice-danger, #ef4444);
|
|
161
|
+
rx: 4;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.nice-forecast-chart__cash-runway-label {
|
|
165
|
+
font-size: 0.6875rem;
|
|
166
|
+
font-weight: 600;
|
|
167
|
+
fill: var(--nice-bg, #FFFFFF);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.nice-forecast-chart__cash-runway-date {
|
|
171
|
+
font-size: 0.625rem;
|
|
172
|
+
fill: var(--nice-danger, #ef4444);
|
|
173
|
+
font-weight: 500;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.nice-forecast-chart__tooltip {
|
|
177
|
+
position: absolute;
|
|
178
|
+
pointer-events: none;
|
|
179
|
+
z-index: 100;
|
|
180
|
+
padding: 0.75rem;
|
|
181
|
+
background: var(--nice-bg-primary, #ffffff);
|
|
182
|
+
border: 1px solid var(--nice-border-color, #e5e7eb);
|
|
183
|
+
border-radius: var(--nice-radius-lg, 0.5rem);
|
|
184
|
+
box-shadow: 0 4px 12px var(--nice-overlay-10, rgba(0, 0, 0, 0.1));
|
|
185
|
+
font-size: 0.8125rem;
|
|
186
|
+
max-width: 250px;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
.nice-forecast-chart__tooltip-date {
|
|
190
|
+
font-weight: 600;
|
|
191
|
+
color: var(--nice-text-primary);
|
|
192
|
+
margin-bottom: 0.5rem;
|
|
193
|
+
padding-bottom: 0.5rem;
|
|
194
|
+
border-bottom: 1px solid var(--nice-border-divider, #f3f4f6);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.nice-forecast-chart__tooltip-item {
|
|
198
|
+
display: flex;
|
|
199
|
+
align-items: center;
|
|
200
|
+
gap: 0.5rem;
|
|
201
|
+
margin-bottom: 0.25rem;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.nice-forecast-chart__tooltip-color {
|
|
205
|
+
width: 10px;
|
|
206
|
+
height: 10px;
|
|
207
|
+
border-radius: var(--nice-radius-sm, 2px);
|
|
208
|
+
flex-shrink: 0;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.nice-forecast-chart__tooltip-label {
|
|
212
|
+
color: var(--nice-text-secondary);
|
|
213
|
+
flex: 1;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
.nice-forecast-chart__tooltip-value {
|
|
217
|
+
font-weight: 600;
|
|
218
|
+
color: var(--nice-text-primary);
|
|
219
|
+
font-variant-numeric: tabular-nums;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
.nice-forecast-chart__tooltip-confidence {
|
|
223
|
+
font-size: 0.75rem;
|
|
224
|
+
color: var(--nice-text-tertiary);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
.nice-forecast-chart__legend {
|
|
228
|
+
display: flex;
|
|
229
|
+
flex-wrap: wrap;
|
|
230
|
+
gap: 1rem;
|
|
231
|
+
padding: 0.75rem 1rem;
|
|
232
|
+
border-top: 1px solid var(--nice-border-color, #e5e7eb);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
.nice-forecast-chart__legend-item {
|
|
236
|
+
display: flex;
|
|
237
|
+
align-items: center;
|
|
238
|
+
gap: 0.375rem;
|
|
239
|
+
font-size: 0.8125rem;
|
|
240
|
+
color: var(--nice-text-secondary);
|
|
241
|
+
cursor: pointer;
|
|
242
|
+
user-select: none;
|
|
243
|
+
transition: opacity 0.15s ease;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
.nice-forecast-chart__legend-item:hover {
|
|
247
|
+
color: var(--nice-text-primary);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
.nice-forecast-chart__legend-item--hidden {
|
|
251
|
+
opacity: 0.4;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
.nice-forecast-chart__legend-color {
|
|
255
|
+
width: 16px;
|
|
256
|
+
height: 3px;
|
|
257
|
+
border-radius: var(--nice-radius-xs, 1px);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
.nice-forecast-chart__legend-color--dashed {
|
|
261
|
+
background: repeating-linear-gradient(
|
|
262
|
+
90deg,
|
|
263
|
+
currentColor,
|
|
264
|
+
currentColor 4px,
|
|
265
|
+
transparent 4px,
|
|
266
|
+
transparent 6px
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
.nice-forecast-chart__empty {
|
|
271
|
+
display: flex;
|
|
272
|
+
align-items: center;
|
|
273
|
+
justify-content: center;
|
|
274
|
+
height: 300px;
|
|
275
|
+
color: var(--nice-text-secondary);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/* Dark mode */
|
|
279
|
+
.dark .nice-forecast-chart {
|
|
280
|
+
background: var(--nice-bg-primary-dark, #111827);
|
|
281
|
+
border-color: var(--nice-border-color-dark, #374151);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
.dark .nice-forecast-chart__tooltip {
|
|
285
|
+
background: var(--nice-bg-secondary-dark, #1f2937);
|
|
286
|
+
border-color: var(--nice-border-color-dark, #374151);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
.dark .nice-forecast-chart__forecast-region {
|
|
290
|
+
fill: var(--nice-bg-secondary-dark, #1f2937);
|
|
291
|
+
}
|
|
292
|
+
`,ze=["var(--color-primary, #3b82f6)","var(--color-success, #10b981)","var(--color-warning, #f59e0b)","var(--color-error, #ef4444)","var(--color-accent, #8b5cf6)","var(--color-accent-pink, #ec4899)","var(--color-info, #06b6d4)","var(--nice-warning, #f97316)"];function xe(t){return t instanceof Date?t:new Date(t)}function Ae(t,u="pl-PL"){return t.toLocaleDateString(u,{year:"numeric",month:"short",day:"numeric"})}function Me(t,u="pl-PL"){return new Intl.NumberFormat(u,{minimumFractionDigits:0,maximumFractionDigits:2}).format(t)}x.forwardRef(function(t,u){var re,te;const{scenarios:c,data:m,annotations:n=[],referenceLines:g=[],forecastStartDate:j,cashRunway:M,xAxis:z,yAxis:l,confidenceBands:p=[{level:95,color:"var(--color-primary, #3b82f6)",opacity:.15}],tooltip:b,legend:f={enabled:!0,position:"bottom",interactive:!0},height:$=350,showForecastRegion:k=!0,lineWidth:s=2,showPoints:d=!1,pointRadius:o=4,enableZoom:w=!1,zoomEnabled:_,animationDuration:S=300,showLegend:y,responsive:v=!0,onPointClick:i,onAnnotationClick:D,onScenarioToggle:r,onViewportChange:W,size:T="medium",disabled:X=!1,labels:q={},locale:Z="pl-PL",className:ee,style:J}=t,ae=c&&c.length>0?c:m?[{id:"default",name:"Series",data:m}]:[],Y={...f,enabled:y??f.enabled},[U,ce]=x.useState(()=>ae.map((a,I)=>({...a,color:a.color??ze[I%ze.length],visible:a.visible!==!1}))),[oe,C]=x.useState(null),[A,F]=x.useState({x:0,y:0}),G=x.useRef(null),K=x.useRef(null),V={top:20,right:30,bottom:40,left:60},[O,B]=x.useState({width:600,height:typeof $=="number"?$:350});x.useEffect(()=>{if(!v||!G.current)return;const a=new ResizeObserver(I=>{for(const R of I)B(h=>({width:R.contentRect.width,height:h.height}))});return a.observe(G.current),()=>a.disconnect()},[v]),x.useEffect(()=>{const a="nice-forecast-chart-styles";if(!document.getElementById(a)){const I=document.createElement("style");I.id=a,I.textContent=it,document.head.appendChild(I)}},[]);const{xScale:Q,yScale:L,allDates:E,minY:ie,maxY:he}=x.useMemo(()=>{const a=U.filter(de=>de.visible!==!1).flatMap(de=>de.data);if(a.length===0)return{xScale:()=>0,yScale:()=>0,allDates:[],minY:0,maxY:100};const I=a.map(de=>xe(de.date).getTime()),R=Math.min(...I),h=Math.max(...I),P=a.flatMap(de=>[de.value,de.forecast,de.lowerBound,de.upperBound]).filter(de=>de!=null),H=(l==null?void 0:l.min)??Math.min(...P)*.95,ne=(l==null?void 0:l.max)??Math.max(...P)*1.05,le=O.width-V.left-V.right,se=O.height-V.top-V.bottom,ge=de=>{const Ce=typeof de=="number"?de:de.getTime();return V.left+(Ce-R)/(h-R)*le},$e=de=>V.top+se-(de-H)/(ne-H)*se,Ne=[...new Set(I)].sort((de,Ce)=>de-Ce).map(de=>new Date(de));return{xScale:ge,yScale:$e,allDates:Ne,minY:H,maxY:ne}},[U,O,V,l]),me=j?xe(j):null,fe=x.useMemo(()=>{if(!(M!=null&&M.enabled))return null;const a=M.threshold??0,I=M.scenarioId?U.find(h=>h.id===M.scenarioId&&h.visible!==!1):U.find(h=>h.visible!==!1);if(!I)return null;const R=I.data.sort((h,P)=>xe(h.date).getTime()-xe(P.date).getTime());for(let h=1;h<R.length;h++){const P=R[h-1],H=R[h],ne=P.forecast??P.value,le=H.forecast??H.value;if(ne!=null&&le!=null&&ne>a&&le<=a){const se=(ne-a)/(ne-le),ge=xe(P.date).getTime(),$e=xe(H.date).getTime(),Ne=ge+se*($e-ge);return new Date(Ne)}}return null},[M,U]),pe=x.useCallback((a,I)=>{const R=a.filter(h=>h[I]!=null).map(h=>({x:Q(xe(h.date)),y:L(h[I])}));return R.length===0?"":`M ${R.map(h=>`${h.x},${h.y}`).join(" L ")}`},[Q,L]),_e=x.useCallback(a=>{const I=a.filter(P=>P.lowerBound!=null&&P.upperBound!=null);if(I.length===0)return"";const R=I.map(P=>({x:Q(xe(P.date)),y:L(P.upperBound)})),h=I.map(P=>({x:Q(xe(P.date)),y:L(P.lowerBound)})).reverse();return`M ${R.map(P=>`${P.x},${P.y}`).join(" L ")} L ${h.map(P=>`${P.x},${P.y}`).join(" L ")} Z`},[Q,L]),ye=x.useCallback(a=>{if(!K.current||(b==null?void 0:b.enabled)===!1)return;const I=K.current.getBoundingClientRect(),R=a.clientX-I.left;a.clientY-I.top;let h=null,P=1/0;for(const H of E){const ne=Q(H),le=Math.abs(ne-R);le<P&&(P=le,h=H)}if(h&&P<50){const H=U.filter(le=>le.visible!==!1).map(le=>{const se=le.data.find(ge=>xe(ge.date).getTime()===h.getTime());return{scenario:le,value:se==null?void 0:se.value,forecast:se==null?void 0:se.forecast,lowerBound:se==null?void 0:se.lowerBound,upperBound:se==null?void 0:se.upperBound}}),ne=n.filter(le=>Math.abs(xe(le.date).getTime()-h.getTime())<864e5);C({date:h,values:H,annotations:ne}),F({x:a.clientX-I.left+10,y:a.clientY-I.top-10})}else C(null)},[Q,E,U,n,b]),be=x.useCallback(a=>{if(!Y.interactive)return;ce(R=>R.map(h=>h.id===a?{...h,visible:!h.visible}:h));const I=U.find(R=>R.id===a);I&&(r==null||r(a,!I.visible))},[Y.interactive,U,r]);x.useImperativeHandle(u,()=>({getScenarios:()=>U,updateScenario:(a,I)=>{ce(R=>R.map(h=>h.id===a?{...h,data:I}:h))},toggleScenario:be,setZoomRange:()=>{},resetZoom:()=>{},exportImage:a=>{if(!K.current)return null;const I=K.current,R=new XMLSerializer().serializeToString(I);return`data:image/svg+xml;base64,${btoa(R)}`},getDataAtDate:a=>{const I=U.filter(R=>R.visible!==!1).map(R=>{const h=R.data.find(P=>xe(P.date).getTime()===a.getTime());return{scenario:R,value:h==null?void 0:h.value,forecast:h==null?void 0:h.forecast,lowerBound:h==null?void 0:h.lowerBound,upperBound:h==null?void 0:h.upperBound}});return{date:a,values:I,annotations:n.filter(R=>xe(R.date).getTime()===a.getTime())}}}),[U,n,be]),O.width-V.left-V.right;const ke=O.height-V.top-V.bottom,je=x.useMemo(()=>{const a=(l==null?void 0:l.tickCount)??5,I=[],R=(he-ie)/(a-1);for(let h=0;h<a;h++)I.push(ie+R*h);return I},[ie,he,l==null?void 0:l.tickCount]),N=x.useMemo(()=>{const a=(z==null?void 0:z.tickCount)??6;if(E.length===0)return[];const I=Math.max(1,Math.floor(E.length/(a-1)));return E.filter((R,h)=>h%I===0||h===E.length-1)},[E,z==null?void 0:z.tickCount]);return U.length===0||U.every(a=>a.data.length===0)?e.jsx("div",{className:`nice-forecast-chart ${ee??""}`,style:J,children:e.jsx("div",{className:"nice-forecast-chart__empty",children:q.noData??"No data available"})}):e.jsxs("div",{className:`nice-forecast-chart ${ee??""}`,style:{...J,height:$},children:[e.jsxs("div",{ref:G,className:"nice-forecast-chart__container",children:[e.jsxs("svg",{ref:K,className:"nice-forecast-chart__svg",width:O.width,height:O.height,onMouseMove:ye,onMouseLeave:()=>C(null),children:[(l==null?void 0:l.showGrid)!==!1&&je.map(a=>e.jsx("line",{className:"nice-forecast-chart__grid-line",x1:V.left,x2:O.width-V.right,y1:L(a),y2:L(a)},a)),k&&me&&e.jsx("rect",{className:"nice-forecast-chart__forecast-region",x:Q(me),y:V.top,width:O.width-V.right-Q(me),height:ke}),g.map(a=>e.jsxs("g",{children:[e.jsx("line",{className:"nice-forecast-chart__reference-line",x1:V.left,x2:O.width-V.right,y1:L(a.value),y2:L(a.value),stroke:a.color??"var(--text-muted, #9ca3af)",strokeDasharray:a.dashArray??"4,2"}),a.label&&e.jsx("text",{className:"nice-forecast-chart__reference-label",x:O.width-V.right-4,y:L(a.value)-4,textAnchor:"end",children:a.label})]},a.id)),fe&&(M==null?void 0:M.enabled)&&e.jsxs("g",{className:"nice-forecast-chart__cash-runway",children:[e.jsx("line",{className:"nice-forecast-chart__cash-runway-line",x1:Q(fe),x2:Q(fe),y1:V.top,y2:O.height-V.bottom,stroke:M.color??"var(--color-error, #ef4444)"}),M.showLabel!==!1&&e.jsxs(e.Fragment,{children:[e.jsx("rect",{className:"nice-forecast-chart__cash-runway-label-bg",x:Q(fe)-60,y:V.top-2,width:120,height:M.showDate!==!1?32:20,fill:M.color??"var(--color-error, #ef4444)",rx:4}),e.jsx("text",{className:"nice-forecast-chart__cash-runway-label",x:Q(fe),y:V.top+12,textAnchor:"middle",fill:"var(--nice-bg, #fff)",children:M.label??q.cashRunsOut??"💰 Cash runs out"}),M.showDate!==!1&&e.jsx("text",{className:"nice-forecast-chart__cash-runway-label",x:Q(fe),y:V.top+26,textAnchor:"middle",fill:"var(--nice-bg, #fff)",style:{fontSize:"0.625rem",opacity:.9},children:Ae(fe,Z)})]})]}),U.filter(a=>a.visible!==!1&&a.showConfidenceBand).map(a=>e.jsx("path",{className:"nice-forecast-chart__confidence-band",d:_e(a.data),fill:a.color},`band-${a.id}`)),U.filter(a=>a.visible!==!1).map(a=>{const I=me?a.data.filter(h=>xe(h.date)<me):a.data.filter(h=>h.value!=null),R=me?a.data.filter(h=>xe(h.date)>=me):a.data.filter(h=>h.forecast!=null);return e.jsxs("g",{children:[e.jsx("path",{className:"nice-forecast-chart__historical-line",d:pe(I,"value"),stroke:a.color,strokeWidth:s}),e.jsx("path",{className:"nice-forecast-chart__forecast-line",d:pe(R,me?"value":"forecast"),stroke:a.color,strokeWidth:s}),R.length>0&&a.data.some(h=>h.forecast!=null)&&e.jsx("path",{className:"nice-forecast-chart__forecast-line",d:pe(a.data,"forecast"),stroke:a.color,strokeWidth:s}),d&&a.data.map((h,P)=>{const H=h.value??h.forecast;return H==null?null:e.jsx("circle",{className:"nice-forecast-chart__point",cx:Q(xe(h.date)),cy:L(H),r:o,fill:a.color,onClick:()=>i==null?void 0:i(h,a)},P)})]},a.id)}),n.map(a=>{const I=Q(xe(a.date));return e.jsxs("g",{className:"nice-forecast-chart__annotation-marker",onClick:()=>D==null?void 0:D(a),children:[a.showLine!==!1&&e.jsx("line",{className:"nice-forecast-chart__annotation-line",x1:I,x2:I,y1:V.top,y2:O.height-V.bottom,stroke:a.color??"var(--text-muted, #9ca3af)"}),e.jsx("circle",{cx:I,cy:V.top+10,r:8,fill:a.color??"var(--text-muted, #9ca3af)"}),e.jsx("text",{x:I,y:V.top+14,textAnchor:"middle",fill:"white",fontSize:"10",children:a.icon??"!"})]},a.id)}),e.jsx("line",{className:"nice-forecast-chart__axis-line",x1:V.left,x2:V.left,y1:V.top,y2:O.height-V.bottom}),e.jsx("line",{className:"nice-forecast-chart__axis-line",x1:V.left,x2:O.width-V.right,y1:O.height-V.bottom,y2:O.height-V.bottom}),je.map(a=>e.jsx("text",{className:"nice-forecast-chart__axis-label",x:V.left-8,y:L(a)+4,textAnchor:"end",children:l!=null&&l.format?l.format(a):Me(a,Z)},a)),N.map(a=>e.jsx("text",{className:"nice-forecast-chart__axis-label",x:Q(a),y:O.height-V.bottom+16,textAnchor:"middle",children:z!=null&&z.format?z.format(a):Ae(a,Z)},a.getTime())),(l==null?void 0:l.title)&&e.jsx("text",{className:"nice-forecast-chart__axis-title",x:15,y:O.height/2,textAnchor:"middle",transform:`rotate(-90, 15, ${O.height/2})`,children:l.title})]}),oe&&e.jsxs("div",{className:"nice-forecast-chart__tooltip",style:{left:A.x,top:A.y},children:[e.jsx("div",{className:"nice-forecast-chart__tooltip-date",children:Ae(oe.date,Z)}),oe.values.map(a=>{const I=a.value??a.forecast;return I==null?null:e.jsxs("div",{className:"nice-forecast-chart__tooltip-item",children:[e.jsx("span",{className:"nice-forecast-chart__tooltip-color",style:{background:a.scenario.color}}),e.jsx("span",{className:"nice-forecast-chart__tooltip-label",children:a.scenario.name}),e.jsx("span",{className:"nice-forecast-chart__tooltip-value",children:Me(I,Z)})]},a.scenario.id)}),oe.values.some(a=>a.lowerBound!=null)&&e.jsxs("div",{className:"nice-forecast-chart__tooltip-confidence",children:[q.confidence??"CI",":"," ",Me(((re=oe.values[0])==null?void 0:re.lowerBound)??0,Z)," –"," ",Me(((te=oe.values[0])==null?void 0:te.upperBound)??0,Z)]})]})]}),Y.enabled&&e.jsx("div",{className:"nice-forecast-chart__legend",children:U.map(a=>e.jsxs("div",{className:`nice-forecast-chart__legend-item ${a.visible===!1?"nice-forecast-chart__legend-item--hidden":""}`,onClick:()=>be(a.id),children:[e.jsx("span",{className:`nice-forecast-chart__legend-color ${a.isBase?"":"nice-forecast-chart__legend-color--dashed"}`,style:{background:a.color}}),a.name]},a.id))})]})});const lt=["var(--color-primary, #3b82f6)","var(--color-error, #ef4444)","var(--color-success, #22c55e)","var(--color-warning, #f59e0b)","var(--color-accent, #8b5cf6)","var(--color-accent-pink, #ec4899)","var(--color-info, #06b6d4)","var(--nice-success, #84cc16)","var(--nice-warning, #f97316)","var(--color-accent, #6366f1)"],We=x.forwardRef((t,u)=>{var ce,oe;const{levels:c,initialLevelId:m,chartType:n="bar",width:g=600,height:j=400,showBreadcrumbs:M=!0,showBackButton:z=!0,animationDuration:l=300,onLevelChange:p,onItemClick:b,colors:f=lt,showValues:$=!0,showLegend:k=!0,className:s,style:d,...o}=t,[w,_]=x.useState(m||((ce=c[0])==null?void 0:ce.id)),[S,y]=x.useState([m||((oe=c[0])==null?void 0:oe.id)]),[v,i]=x.useState(!1),[D,r]=x.useState("in"),W=x.useMemo(()=>c.find(C=>C.id===w),[c,w]),T=x.useCallback(C=>{c.find(A=>A.id===C)&&(r("in"),i(!0),setTimeout(()=>{_(C),y(A=>[...A,C]),p==null||p(C,[...S,C]),i(!1)},l/2))},[c,S,l,p]),X=x.useCallback(()=>{if(S.length<=1)return;r("out"),i(!0);const C=S.slice(0,-1),A=C[C.length-1];setTimeout(()=>{_(A),y(C),p==null||p(A,C),i(!1)},l/2)},[S,l,p]),q=x.useCallback(()=>{var A;const C=(A=c[0])==null?void 0:A.id;C&&(r("out"),i(!0),setTimeout(()=>{_(C),y([C]),p==null||p(C,[C]),i(!1)},l/2))},[c,l,p]);x.useImperativeHandle(u,()=>({drillDown:T,drillUp:X,resetToRoot:q,getCurrentLevel:()=>w,getPath:()=>S}),[T,X,q,w,S]);const Z=x.useCallback((C,A)=>{b==null||b(C,w);const F=c.find(G=>{var K;return G.parentId===w&&G.id===((K=C.metadata)==null?void 0:K.childLevelId)});F&&T(F.id)},[w,c,T,b]),ee=x.useMemo(()=>(W==null?void 0:W.data.reduce((C,A)=>C+A.value,0))||0,[W]),J=x.useMemo(()=>S.map(C=>{var A;return((A=c.find(F=>F.id===C))==null?void 0:A.label)||C}),[S,c]),ae=()=>{if(!W)return null;const C=W.data,A=Math.max(...C.map(G=>G.value)),F=Math.min(40,(j-100)/C.length-8);return e.jsx("div",{className:"nice-drilldown-bars",children:C.map((G,K)=>{const V=G.value/A*100;return e.jsxs("div",{className:"nice-drilldown-bar-row",onClick:()=>Z(G,K),children:[e.jsx("span",{className:"nice-drilldown-bar-label",children:G.label||`Item ${K+1}`}),e.jsx("div",{className:"nice-drilldown-bar-track",children:e.jsx("div",{className:"nice-drilldown-bar-fill",style:{width:`${V}%`,backgroundColor:G.color||f[K%f.length],height:F}})}),$&&e.jsx("span",{className:"nice-drilldown-bar-value",children:G.value.toLocaleString()})]},K)})})},Y=()=>{if(!W)return null;const C=W.data,A=g/2,F=(j-60)/2+30,G=Math.min(A,F)-40;let K=-90;const V=C.map((O,B)=>{const Q=O.value/ee*360,L=K+Q,E=Q>180?1:0,ie=K*Math.PI/180,he=L*Math.PI/180,me=A+G*Math.cos(ie),fe=F+G*Math.sin(ie),pe=A+G*Math.cos(he),_e=F+G*Math.sin(he),ye=(K+Q/2)*Math.PI/180,be=A+G*.7*Math.cos(ye),ke=F+G*.7*Math.sin(ye),je=`M ${A} ${F} L ${me} ${fe} A ${G} ${G} 0 ${E} 1 ${pe} ${_e} Z`;return K=L,{path:je,color:O.color||f[B%f.length],label:O.label||`Item ${B+1}`,value:O.value,percentage:(O.value/ee*100).toFixed(1),labelX:be,labelY:ke,item:O,index:B}});return e.jsx("svg",{width:g,height:j-40,className:"nice-drilldown-pie",children:e.jsx("g",{children:V.map((O,B)=>e.jsxs("g",{onClick:()=>Z(O.item,O.index),children:[e.jsx("path",{d:O.path,fill:O.color,stroke:"white",strokeWidth:2,className:"nice-drilldown-pie-slice"}),$&&parseFloat(O.percentage)>5&&e.jsxs("text",{x:O.labelX,y:O.labelY,textAnchor:"middle",dominantBaseline:"middle",fill:"white",fontSize:"12",fontWeight:"600",children:[O.percentage,"%"]})]},B))})})},U=()=>{if(!W)return null;const C=W.data,A=Math.max(...C.map(K=>K.value)),F=Math.min(60,(g-100)/C.length-8),G=j-100;return e.jsx("svg",{width:g,height:j-40,className:"nice-drilldown-columns",children:e.jsxs("g",{transform:"translate(50, 20)",children:[[0,.25,.5,.75,1].map((K,V)=>e.jsxs("g",{children:[e.jsx("line",{x1:0,y1:G*(1-K),x2:g-80,y2:G*(1-K),stroke:"var(--border-color, #e5e7eb)",strokeDasharray:K===0?void 0:"4"}),e.jsx("text",{x:-8,y:G*(1-K),textAnchor:"end",dominantBaseline:"middle",fontSize:"11",fill:"var(--text-secondary, #6b7280)",children:Math.round(A*K).toLocaleString()})]},V)),C.map((K,V)=>{const O=K.value/A*G,B=V*((g-100)/C.length)+((g-100)/C.length-F)/2;return e.jsxs("g",{onClick:()=>Z(K,V),children:[e.jsx("rect",{x:B,y:G-O,width:F,height:O,fill:K.color||f[V%f.length],rx:4,className:"nice-drilldown-column-bar"}),e.jsx("text",{x:B+F/2,y:G+16,textAnchor:"middle",fontSize:"11",fill:"var(--text-primary, #374151)",children:(K.label||`${V+1}`).slice(0,10)}),$&&e.jsx("text",{x:B+F/2,y:G-O-8,textAnchor:"middle",fontSize:"11",fill:"var(--text-primary, #374151)",fontWeight:"500",children:K.value.toLocaleString()})]},V)})]})})};return e.jsxs("div",{className:`nice-drilldown-chart ${v?`animating ${D}`:""} ${s||""}`,style:{width:g,...d},...o,children:[e.jsxs("div",{className:"nice-drilldown-header",children:[z&&S.length>1&&e.jsx("button",{className:"nice-drilldown-back",onClick:X,children:"← Wstecz"}),M&&e.jsx("div",{className:"nice-drilldown-breadcrumbs",children:J.map((C,A)=>e.jsxs(x.Fragment,{children:[A>0&&e.jsx("span",{className:"nice-drilldown-separator",children:"/"}),e.jsx("span",{className:`nice-drilldown-crumb ${A===J.length-1?"active":""}`,onClick:()=>{if(A<J.length-1){const F=S.slice(0,A+1);y(F),_(F[F.length-1])}},children:C})]},A))})]}),e.jsxs("div",{className:"nice-drilldown-content",style:{height:j-40},children:[n==="bar"&&ae(),n==="pie"&&Y(),n==="column"&&U()]}),k&&W&&e.jsx("div",{className:"nice-drilldown-legend",children:W.data.map((C,A)=>e.jsxs("div",{className:"nice-drilldown-legend-item",children:[e.jsx("span",{className:"nice-drilldown-legend-color",style:{backgroundColor:C.color||f[A%f.length]}}),e.jsx("span",{className:"nice-drilldown-legend-label",children:C.label||`Item ${A+1}`})]},A))}),e.jsx("style",{children:`
|
|
293
|
+
.nice-drilldown-chart {
|
|
294
|
+
font-family: inherit;
|
|
295
|
+
color: var(--text-primary, #111827);
|
|
296
|
+
background: var(--bg-elevated, #ffffff);
|
|
297
|
+
border-radius: 8px;
|
|
298
|
+
overflow: hidden;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
.nice-drilldown-header {
|
|
302
|
+
display: flex;
|
|
303
|
+
align-items: center;
|
|
304
|
+
gap: 12px;
|
|
305
|
+
padding: 12px 16px;
|
|
306
|
+
border-bottom: 1px solid var(--border-color, #e5e7eb);
|
|
307
|
+
min-height: 40px;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
.nice-drilldown-back {
|
|
311
|
+
background: var(--bg-secondary, #f3f4f6);
|
|
312
|
+
border: none;
|
|
313
|
+
padding: 6px 12px;
|
|
314
|
+
border-radius: 6px;
|
|
315
|
+
cursor: pointer;
|
|
316
|
+
font-size: 13px;
|
|
317
|
+
font-family: inherit;
|
|
318
|
+
color: var(--text-primary, #374151);
|
|
319
|
+
transition: background 0.2s;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
.nice-drilldown-back:hover {
|
|
323
|
+
background: var(--hover-bg, #e5e7eb);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
.nice-drilldown-breadcrumbs {
|
|
327
|
+
display: flex;
|
|
328
|
+
align-items: center;
|
|
329
|
+
gap: 4px;
|
|
330
|
+
font-size: 13px;
|
|
331
|
+
font-family: inherit;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
.nice-drilldown-separator {
|
|
335
|
+
color: var(--text-muted, #9ca3af);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
.nice-drilldown-crumb {
|
|
339
|
+
color: var(--text-secondary, #6b7280);
|
|
340
|
+
cursor: pointer;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
.nice-drilldown-crumb:hover:not(.active) {
|
|
344
|
+
color: var(--color-primary, #3b82f6);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
.nice-drilldown-crumb.active {
|
|
348
|
+
color: var(--text-primary, #111827);
|
|
349
|
+
font-weight: 500;
|
|
350
|
+
cursor: default;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
.nice-drilldown-content {
|
|
354
|
+
padding: 16px;
|
|
355
|
+
transition: opacity 0.15s, transform 0.15s;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
.nice-drilldown-chart.animating .nice-drilldown-content {
|
|
359
|
+
opacity: 0;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
.nice-drilldown-chart.animating.in .nice-drilldown-content {
|
|
363
|
+
transform: translateX(20px);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
.nice-drilldown-chart.animating.out .nice-drilldown-content {
|
|
367
|
+
transform: translateX(-20px);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
.nice-drilldown-bars {
|
|
371
|
+
display: flex;
|
|
372
|
+
flex-direction: column;
|
|
373
|
+
gap: 8px;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
.nice-drilldown-bar-row {
|
|
377
|
+
display: flex;
|
|
378
|
+
align-items: center;
|
|
379
|
+
gap: 12px;
|
|
380
|
+
cursor: pointer;
|
|
381
|
+
padding: 4px 8px;
|
|
382
|
+
margin: -4px -8px;
|
|
383
|
+
border-radius: 6px;
|
|
384
|
+
transition: background 0.2s;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
.nice-drilldown-bar-row:hover {
|
|
388
|
+
background: var(--hover-bg, #f9fafb);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
.nice-drilldown-bar-label {
|
|
392
|
+
width: 120px;
|
|
393
|
+
font-size: 13px;
|
|
394
|
+
font-family: inherit;
|
|
395
|
+
color: var(--text-primary, #374151);
|
|
396
|
+
overflow: hidden;
|
|
397
|
+
text-overflow: ellipsis;
|
|
398
|
+
white-space: nowrap;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
.nice-drilldown-bar-track {
|
|
402
|
+
flex: 1;
|
|
403
|
+
background: var(--bg-tertiary, #f3f4f6);
|
|
404
|
+
border-radius: 6px;
|
|
405
|
+
overflow: hidden;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
.nice-drilldown-bar-fill {
|
|
409
|
+
transition: width 0.3s ease;
|
|
410
|
+
border-radius: 6px;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
.nice-drilldown-bar-value {
|
|
414
|
+
width: 80px;
|
|
415
|
+
text-align: right;
|
|
416
|
+
font-size: 13px;
|
|
417
|
+
font-family: inherit;
|
|
418
|
+
font-weight: 500;
|
|
419
|
+
color: var(--text-primary, #111827);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
.nice-drilldown-pie-slice {
|
|
423
|
+
cursor: pointer;
|
|
424
|
+
transition: transform 0.2s, opacity 0.2s;
|
|
425
|
+
transform-origin: center;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
.nice-drilldown-pie-slice:hover {
|
|
429
|
+
opacity: 0.85;
|
|
430
|
+
transform: scale(1.02);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
.nice-drilldown-column-bar {
|
|
434
|
+
cursor: pointer;
|
|
435
|
+
transition: opacity 0.2s;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
.nice-drilldown-column-bar:hover {
|
|
439
|
+
opacity: 0.8;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
.nice-drilldown-legend {
|
|
443
|
+
display: flex;
|
|
444
|
+
flex-wrap: wrap;
|
|
445
|
+
gap: 16px;
|
|
446
|
+
padding: 12px 16px;
|
|
447
|
+
border-top: 1px solid var(--border-color, #e5e7eb);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
.nice-drilldown-legend-item {
|
|
451
|
+
display: flex;
|
|
452
|
+
align-items: center;
|
|
453
|
+
gap: 6px;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
.nice-drilldown-legend-color {
|
|
457
|
+
width: 12px;
|
|
458
|
+
height: 12px;
|
|
459
|
+
border-radius: 3px;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
.nice-drilldown-legend-label {
|
|
463
|
+
font-size: 12px;
|
|
464
|
+
font-family: inherit;
|
|
465
|
+
color: var(--text-secondary, #6b7280);
|
|
466
|
+
}
|
|
467
|
+
`})]})});We.displayName="NiceDrillDownChart";const Oe=x.forwardRef((t,u)=>{const{initialData:c,data:m,maxPoints:n=60,updateInterval:g=1e3,fetchData:j,width:M=600,height:z=200,chartType:l="line",color:p="var(--color-primary, #3b82f6)",showGrid:b=!0,showTimeAxis:f=!0,showCurrentValue:$=!0,title:k,valueFormatter:s=B=>B.toFixed(2),timeFormatter:d=B=>new Date(B).toLocaleTimeString(),onDataUpdate:o,paused:w,className:_,style:S,...y}=t,[v,i]=x.useState(c??m??[]),[D,r]=x.useState(w||!1),W=x.useRef();x.useEffect(()=>{w!==void 0&&r(w)},[w]),x.useEffect(()=>{if(D||!j)return;const B=async()=>{try{const Q=await j();i(L=>{const E=[...L,Q].slice(-n);return o==null||o(E),E})}catch(Q){console.error("Failed to fetch realtime data:",Q)}};return W.current=setInterval(B,g),()=>{W.current&&clearInterval(W.current)}},[D,j,g,n,o]);const T=x.useCallback(B=>{i(Q=>{const L=[...Q,B].slice(-n);return o==null||o(L),L})},[n,o]),X=x.useCallback(()=>{i([]),o==null||o([])},[o]),q=x.useCallback(()=>r(!0),[]),Z=x.useCallback(()=>r(!1),[]);x.useImperativeHandle(u,()=>({addDataPoint:T,clearData:X,pause:q,resume:Z,getData:()=>v}),[T,X,v]);const ee={top:20,right:60,bottom:f?40:20,left:50},J=M-ee.left-ee.right,ae=z-ee.top-ee.bottom,Y=v.map(B=>B.value),U=Y.length?Math.min(...Y):0,ce=Y.length?Math.max(...Y):100,oe=(ce-U||1)*.1,C=U-oe,A=ce+oe-C,F=B=>{const Q=j?n-1:Math.max(1,v.length-1);return ee.left+B/Q*J},G=B=>ee.top+ae-(B-C)/A*ae,K=v.map((B,Q)=>`${F(Q)},${G(B.value)}`).join(" "),V=v.length>0?`M ${F(0)},${ee.top+ae} L ${K} L ${F(v.length-1)},${ee.top+ae} Z`:"",O=v.length>0?v[v.length-1].value:null;return e.jsxs("div",{className:`nice-realtime-chart ${_||""}`,style:{width:M,...S},...y,children:[e.jsxs("div",{className:"nice-realtime-header",children:[e.jsx("span",{className:"nice-realtime-title",children:k}),e.jsxs("div",{className:"nice-realtime-controls",children:[e.jsxs("span",{className:`nice-realtime-status ${D?"paused":"live"}`,children:[e.jsx("span",{className:"nice-realtime-status-dot"}),e.jsx("span",{children:D?"Wstrzymano":"Na żywo"})]}),e.jsx("button",{className:`nice-realtime-btn ${D?"paused":""}`,onClick:()=>r(!D),children:D?"▶️":"⏸️"}),$&&O!==null&&e.jsx("span",{className:"nice-realtime-value",children:s(O)})]})]}),e.jsxs("svg",{width:M,height:z,className:"nice-realtime-svg",children:[b&&e.jsx("g",{className:"nice-realtime-grid",children:[0,.25,.5,.75,1].map((B,Q)=>{const L=ee.top+ae*(1-B),E=C+A*B;return e.jsxs("g",{children:[e.jsx("line",{x1:ee.left,y1:L,x2:M-ee.right,y2:L,stroke:"var(--border-color, #e5e7eb)",strokeDasharray:B===0?void 0:"3"}),e.jsx("text",{x:ee.left-8,y:L,textAnchor:"end",dominantBaseline:"middle",fontSize:"10",fill:"var(--text-secondary, #6b7280)",children:Math.round(E).toLocaleString()})]},Q)})}),l==="area"&&v.length>0&&e.jsx("path",{d:V,fill:p,fillOpacity:.2}),v.length>1&&e.jsx("polyline",{points:K,fill:"none",stroke:p,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}),v.length>0&&e.jsx("circle",{cx:F(v.length-1),cy:G(v[v.length-1].value),r:3,fill:p,className:"nice-realtime-point"}),f&&v.length>0&&e.jsx("g",{className:"nice-realtime-time-axis",children:Array.from(new Set([0,Math.floor(v.length/2),v.length-1].filter(B=>v[B]))).map(B=>e.jsx("text",{x:F(B),y:z-8,textAnchor:"middle",fontSize:"10",fill:"var(--text-secondary, #6b7280)",children:d(v[B].timestamp)},`tx-${B}`))})]}),e.jsx("style",{children:`
|
|
468
|
+
.nice-realtime-chart {
|
|
469
|
+
font-family: inherit;
|
|
470
|
+
color: var(--text-primary, #111827);
|
|
471
|
+
background: var(--bg-elevated, #ffffff);
|
|
472
|
+
border-radius: 8px;
|
|
473
|
+
position: relative;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
.nice-realtime-header {
|
|
477
|
+
display: flex;
|
|
478
|
+
justify-content: space-between;
|
|
479
|
+
align-items: center;
|
|
480
|
+
padding: 12px 16px;
|
|
481
|
+
border-bottom: 1px solid var(--border-color, #e5e7eb);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
.nice-realtime-title {
|
|
485
|
+
font-size: 14px;
|
|
486
|
+
font-weight: 600;
|
|
487
|
+
color: var(--text-primary, #111827);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
.nice-realtime-controls {
|
|
491
|
+
display: flex;
|
|
492
|
+
align-items: center;
|
|
493
|
+
gap: 12px;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
.nice-realtime-btn {
|
|
497
|
+
background: none;
|
|
498
|
+
border: none;
|
|
499
|
+
cursor: pointer;
|
|
500
|
+
font-size: 16px;
|
|
501
|
+
padding: 4px;
|
|
502
|
+
font-family: inherit;
|
|
503
|
+
color: inherit;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
.nice-realtime-value {
|
|
507
|
+
font-size: 18px;
|
|
508
|
+
font-weight: 600;
|
|
509
|
+
color: ${p};
|
|
510
|
+
font-variant-numeric: tabular-nums;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/* Static current-value dot — no pulsing animation (was distracting) */
|
|
514
|
+
|
|
515
|
+
.nice-realtime-status {
|
|
516
|
+
display: inline-flex;
|
|
517
|
+
align-items: center;
|
|
518
|
+
gap: 6px;
|
|
519
|
+
font-size: 11px;
|
|
520
|
+
font-family: inherit;
|
|
521
|
+
color: var(--text-secondary, #6b7280);
|
|
522
|
+
background: var(--bg-secondary, #f3f4f6);
|
|
523
|
+
padding: 2px 10px;
|
|
524
|
+
border-radius: 999px;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
.nice-realtime-status-dot {
|
|
528
|
+
width: 8px;
|
|
529
|
+
height: 8px;
|
|
530
|
+
border-radius: 50%;
|
|
531
|
+
background: var(--color-success, #22c55e);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
.nice-realtime-status.paused .nice-realtime-status-dot {
|
|
535
|
+
background: var(--color-warning, #f59e0b);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
.nice-realtime-status.live .nice-realtime-status-dot {
|
|
539
|
+
animation: live-pulse 2s ease-in-out infinite;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
@keyframes live-pulse {
|
|
543
|
+
0%, 100% { opacity: 1; }
|
|
544
|
+
50% { opacity: 0.4; }
|
|
545
|
+
}
|
|
546
|
+
`})]})});Oe.displayName="NiceRealtimeChart";const Te=x.forwardRef(({data:t,renderNode:u,selectable:c,selectedKey:m,onSelect:n,direction:g="top-down",collapsible:j=!0,className:M,style:z,id:l},p)=>{const b=we.Xs(l),[f,$]=x.useState(new Set),k=x.useCallback(o=>{$(w=>{const _=new Set(w);return _.has(o)?_.delete(o):_.add(o),_})},[]),s=x.useCallback(o=>{c&&(n==null||n(o))},[c,n]),d=x.useCallback(o=>{const w=f.has(o.key),_=o.children&&o.children.length>0;return e.jsxs("li",{className:"nice-org-chart__item",children:[e.jsxs("div",{className:`nice-org-chart__node${m===o.key?" nice-org-chart__node--selected":""}`,onClick:()=>s(o.key),role:c?"button":void 0,children:[u?u(o):e.jsx("span",{children:o.label}),j&&_&&e.jsx("button",{type:"button",className:"nice-org-chart__toggle",onClick:S=>{S.stopPropagation(),k(o.key)},"aria-label":w?"Expand":"Collapse",children:w?"+":"−"})]}),_&&!w&&e.jsx("ul",{className:"nice-org-chart__children",children:o.children.map(S=>d(S))})]},o.key)},[f,m,u,c,j,s,k]);return e.jsx("div",{ref:p,id:b,className:`nice-org-chart nice-org-chart--${g} ${M||""}`,style:z,children:e.jsx("ul",{className:"nice-org-chart__root",children:d(t)})})});Te.displayName="NiceOrganizationChart";function st(t,u,c){const m=$=>{const k=$.replace("#","");return[parseInt(k.slice(0,2),16),parseInt(k.slice(2,4),16),parseInt(k.slice(4,6),16)]},[n,g,j]=m(t),[M,z,l]=m(u),p=Math.round(n+(M-n)*c),b=Math.round(g+(z-g)*c),f=Math.round(j+(l-j)*c);return`rgb(${p},${b},${f})`}const Ve=x.forwardRef(({data:t,xLabels:u,yLabels:c,colors:m=["var(--nice-primary-bg, #e0f2fe)","var(--color-primary-active, #1d4ed8)"],onCellClick:n,cellSize:g=40,showValues:j=!0,className:M,style:z,id:l},p)=>{const b=we.Xs(l),{minVal:f,maxVal:$}=x.useMemo(()=>{let s=1/0,d=-1/0;for(const o of t)for(const w of o)w<s&&(s=w),w>d&&(d=w);return{minVal:s,maxVal:d}},[t]),k=x.useCallback(s=>$===f?.5:(s-f)/($-f),[f,$]);return e.jsx("div",{ref:p,id:b,className:`nice-heatmap ${M||""}`,style:z,children:e.jsxs("table",{className:"nice-heatmap__table",children:[u&&e.jsx("thead",{children:e.jsxs("tr",{children:[c&&e.jsx("th",{}),u.map((s,d)=>e.jsx("th",{className:"nice-heatmap__header",children:s},d))]})}),e.jsx("tbody",{children:t.map((s,d)=>e.jsxs("tr",{children:[c&&e.jsx("th",{className:"nice-heatmap__row-label",children:c[d]}),s.map((o,w)=>e.jsx("td",{className:"nice-heatmap__cell",style:{background:st(m[0],m[1],k(o)),width:g,height:g,textAlign:"center",color:k(o)>.6?"var(--bg-primary, #fff)":"var(--bg-tertiary, #333)",cursor:n?"pointer":void 0},onClick:()=>n==null?void 0:n(d,w,o),title:String(o),children:j?o:""},w))]},d))})]})})});Ve.displayName="NiceHeatMap";function ct(t,u){const c=t.reduce((l,p)=>l+p.value,0);if(c===0||t.length===0)return[];const m=[];let{x:n,y:g,w:j,h:M}=u;const z=[...t].sort((l,p)=>p.value-l.value);for(const l of z){const p=l.value/c;if(j>=M){const b=j*p;m.push({x:n,y:g,w:b,h:M,node:l}),n+=b,j-=b}else{const b=M*p;m.push({x:n,y:g,w:j,h:b,node:l}),g+=b,M-=b}}return m}const ot=["var(--color-primary, #3b82f6)","var(--color-success, #10b981)","var(--color-warning, #f59e0b)","var(--color-error, #ef4444)","var(--color-accent, #8b5cf6)","var(--color-info, #06b6d4)","var(--color-accent-pink, #ec4899)","var(--nice-success, #84cc16)"],Fe=x.forwardRef(({data:t,width:u=600,height:c=400,onNodeClick:m,colors:n=ot,className:g,style:j,id:M},z)=>{const l=we.Xs(M),p=x.useMemo(()=>{const b=t.children??[t];return ct(b,{x:0,y:0,w:u,h:c})},[t,u,c]);return e.jsx("div",{ref:z,id:l,className:`nice-treemap ${g||""}`,style:j,children:e.jsx("svg",{width:u,height:c,className:"nice-treemap__svg",children:p.map((b,f)=>e.jsxs("g",{onClick:()=>m==null?void 0:m(b.node),style:{cursor:m?"pointer":void 0},children:[e.jsx("rect",{x:b.x,y:b.y,width:Math.max(b.w-1,0),height:Math.max(b.h-1,0),fill:b.node.color??n[f%n.length],rx:2}),b.w>40&&b.h>20&&e.jsx("text",{x:b.x+b.w/2,y:b.y+b.h/2,textAnchor:"middle",dominantBaseline:"central",fill:"var(--nice-bg, #fff)",fontSize:Math.min(12,b.w/6),className:"nice-treemap__label",children:b.node.label})]},b.node.key))})})});Fe.displayName="NiceTreeMap";const He=x.forwardRef(({data:t,type:u="candlestick",showVolume:c=!0,width:m=800,height:n=400,bullColor:g="var(--color-success, #22c55e)",bearColor:j="var(--color-error, #ef4444)",className:M,style:z,id:l},p)=>{const b=we.Xs(l),f={top:20,right:20,bottom:c?80:30,left:60},$=m-f.left-f.right,k=c?50:0,s=n-f.top-f.bottom-k,{minP:d,maxP:o,maxVol:w}=x.useMemo(()=>{let i=1/0,D=-1/0,r=0;for(const W of t)W.low<i&&(i=W.low),W.high>D&&(D=W.high),W.volume&&W.volume>r&&(r=W.volume);return{minP:i,maxP:D,maxVol:r}},[t]),_=Math.max(1,$/t.length*.7),S=i=>f.left+(i+.5)*($/t.length),y=i=>f.top+s-(i-d)/(o-d||1)*s,v=i=>n-f.bottom-k+k*(1-i/(w||1));return e.jsx("div",{ref:p,id:b,className:`nice-stock-chart ${M||""}`,style:z,children:e.jsxs("svg",{width:m,height:n,className:"nice-stock-chart__svg",children:[[0,.25,.5,.75,1].map(i=>{const D=d+i*(o-d);return e.jsxs("g",{children:[e.jsx("line",{x1:f.left,x2:m-f.right,y1:y(D),y2:y(D),stroke:"var(--nice-border, #e5e7eb)",strokeDasharray:"2,2"}),e.jsx("text",{x:f.left-4,y:y(D)+4,textAnchor:"end",fontSize:10,fill:"var(--nice-text-secondary, #888)",children:D.toFixed(2)})]},i)}),u==="line"?e.jsx("polyline",{points:t.map((i,D)=>`${S(D)},${y(i.close)}`).join(" "),fill:"none",stroke:g,strokeWidth:1.5}):t.map((i,D)=>{const r=i.close>=i.open,W=r?g:j,T=S(D);if(u==="ohlc")return e.jsxs("g",{children:[e.jsx("line",{x1:T,x2:T,y1:y(i.high),y2:y(i.low),stroke:W,strokeWidth:1}),e.jsx("line",{x1:T-_/2,x2:T,y1:y(i.open),y2:y(i.open),stroke:W,strokeWidth:1.5}),e.jsx("line",{x1:T,x2:T+_/2,y1:y(i.close),y2:y(i.close),stroke:W,strokeWidth:1.5})]},D);const X=y(Math.max(i.open,i.close)),q=y(Math.min(i.open,i.close));return e.jsxs("g",{children:[e.jsx("line",{x1:T,x2:T,y1:y(i.high),y2:y(i.low),stroke:W,strokeWidth:1}),e.jsx("rect",{x:T-_/2,y:X,width:_,height:Math.max(q-X,1),fill:r?"transparent":W,stroke:W,strokeWidth:1})]},D)}),c&&t.map((i,D)=>{if(!i.volume)return null;const r=i.close>=i.open;return e.jsx("rect",{x:S(D)-_/2,y:v(i.volume),width:_,height:n-f.bottom-v(i.volume),fill:r?g:j,opacity:.3},`v${D}`)}),t.map((i,D)=>D%Math.max(1,Math.floor(t.length/8))!==0?null:e.jsx("text",{x:S(D),y:n-f.bottom+k+14,textAnchor:"middle",fontSize:9,fill:"var(--nice-text-secondary, #888)",children:i.date},`l${D}`))]})})});He.displayName="NiceStockChart";exports.A=Ee;exports.B=at;exports.C=ue;exports.D=nt;exports.N=Pe;exports.a=rt;exports.b=Te;exports.c=He;exports.d=Fe;exports.e=Ve;exports.f=Re;exports.g=tt;exports.h=et;exports.i=Je;exports.j=Qe;exports.k=Ye;exports.l=qe;exports.m=Ue;exports.n=Ge;exports.o=Se;exports.q=We;exports.s=Le;exports.u=Oe;
|