@nice2dev/ui-forms 1.0.10 → 1.0.12
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-BmRO9HSQ-7FC0AexB.cjs +419 -0
- package/dist/NicePinCodeInput-BmRO9HSQ-CmusgJGw.js +10624 -0
- package/dist/NicePinCodeInput-jMNfPqOx-B06fDseE.cjs +419 -0
- package/dist/NicePinCodeInput-jMNfPqOx-DNGx8-XN.js +10660 -0
- package/dist/NiceSavedQueryPanel-BSGzs7Oc-Bo9UxBec.cjs +596 -0
- package/dist/NiceSavedQueryPanel-BSGzs7Oc-CjNobdAO.js +6610 -0
- package/dist/NiceSavedQueryPanel-BkYRk5cX-BuLBRLRh.js +6602 -0
- package/dist/NiceSavedQueryPanel-BkYRk5cX-DS9qBIkd.cjs +596 -0
- package/dist/charts-DZvmvfhM-DN5tnI16.cjs +544 -0
- package/dist/charts-DZvmvfhM-E0Huk8_7.js +3844 -0
- package/dist/charts-F_b5-OR8-COpLbKJt.js +3844 -0
- package/dist/charts-F_b5-OR8-CcZRSqKt.cjs +544 -0
- package/dist/index-BU6KCDpP-BlC8u6S9.cjs +4504 -0
- package/dist/index-BU6KCDpP-DGwh6tPZ.js +35436 -0
- package/dist/index-CYrOf5uD.js +21039 -0
- package/dist/index-DlHlXz8e-B_hFrHO1.cjs +4504 -0
- package/dist/index-DlHlXz8e-DEMTlEW8.js +35492 -0
- package/dist/index-P3TTpN4Q.cjs +404 -0
- package/dist/index-SnTWfHQ_.js +21479 -0
- package/dist/index-tVSzr4V7.cjs +404 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +26 -0
- package/dist/index.mjs +7 -6
- package/dist/style.css +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),x=require("react"),we=require("./index-P3TTpN4Q.cjs"),ye=["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:f=!0,showGrid:j=!0,axisLabels:S=!0,yAxisLabel:z,xAxisLabel:l,stacked:g,animated:b,zoomable:p,crosshair:$,annotations:w,legendInteractive:i,onDataPointClick:d,exportable:o,className:k,style:_})=>{var ve,ke,je;const N=x.useRef(null),[v,y]=x.useState(new Set),[s,L]=x.useState(null),[r,B]=x.useState(null),[V,X]=x.useState(!1),Y=x.useRef(null),G=x.useMemo(()=>t.filter(M=>!v.has(M.name)),[t,v]),re=x.useCallback(M=>{i&&y(ae=>{const ee=new Set(ae);return ee.has(M)?ee.delete(M):ee.add(M),ee})},[i]),J={top:n?40:20,right:20,bottom:l?60:40,left:z?60:50},te=c-J.left-J.right,T=m-J.top-J.bottom,q=((ve=G[0])==null?void 0:ve.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)??q,C=oe-ce,A=x.useMemo(()=>G.map(M=>({...M,data:M.data.slice(ce,oe)})),[G,ce,oe]),O=x.useMemo(()=>u==null?void 0:u.slice(ce,oe),[u,ce,oe]),{minY:Z,maxY:K,yTicks:F}=x.useMemo(()=>{let M;if(g){M=[];for(let E=0;E<C;E++)M.push(A.reduce((ne,se)=>ne+(se.data[E]||0),0))}else M=A.flatMap(E=>E.data);M.length===0&&(M=[0]);const ae=Math.min(0,...M),ee=Math.max(0,...M),a=ee-ae||1,I=Math.pow(10,Math.floor(Math.log10(a)))||1,P=Math.floor(ae/I)*I,h=Math.ceil(ee/I)*I,R=[];for(let E=P;E<=h;E+=I)R.push(Math.round(E*1e6)/1e6);return R.length<2&&R.push(h),{minY:P,maxY:h,yTicks:R}},[A,C,g]),W=M=>T-(M-Z)/(K-Z||1)*T,U=M=>(M+.5)/C*te,Q=C>0?te/C/(g?1.5:Math.max(G.length,1)*1.5):20,D=x.useCallback(M=>{if(!p)return;M.preventDefault();const ae=r??{start:0,end:q},ee=ae.end-ae.start,a=(ae.start+ae.end)/2,I=M.deltaY>0?1.2:.8,P=Math.max(2,Math.min(q,Math.round(ee*I))),h=Math.max(0,Math.round(a-P/2)),R=Math.min(q,h+P);B({start:h,end:R})},[p,r,q]),H=x.useCallback(M=>{p&&(X(!0),Y.current={x:M.clientX,range:r??{start:0,end:q}})},[p,r,q]),ie=x.useCallback(M=>{var ee;const ae=(ee=N.current)==null?void 0:ee.getBoundingClientRect();if(ae&&L({x:M.clientX-ae.left-J.left,y:M.clientY-ae.top-J.top}),V&&Y.current&&p){const a=M.clientX-Y.current.x,I=te/C,P=-Math.round(a/I),h=Y.current.range,R=h.end-h.start;let E=h.start+P;E<0&&(E=0),E+R>q&&(E=q-R),B({start:E,end:E+R})}},[V,p,te,C,q,J.left,J.top]),he=x.useCallback(()=>{X(!1),Y.current=null},[]),me=x.useCallback(()=>{L(null),X(!1),Y.current=null},[]),fe=x.useCallback(()=>{const M=N.current;if(!M)return;const ae=new XMLSerializer().serializeToString(M),ee=document.createElement("canvas");ee.width=c,ee.height=m+(f?30:0);const a=ee.getContext("2d");if(!a)return;const I=new Image;I.onload=()=>{a.fillStyle="var(--bg-primary, #fff)",a.fillRect(0,0,ee.width,ee.height),a.drawImage(I,0,0);const P=document.createElement("a");P.download="chart.png",P.href=ee.toDataURL("image/png"),P.click()},I.src="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(ae)},[c,m,f]),pe=m+(f?30:0),_e=A.length>0&&A.every(M=>M.type==="radar"),be=x.useMemo(()=>{if(!_e)return 1;const M=A.flatMap(ae=>ae.data);return Math.max(1,...M)},[_e,A]);if(_e){const M=c/2,ae=(m-J.top-J.bottom)/2+J.top,ee=Math.min(te,m-J.top-J.bottom)/2-10,a=(O==null?void 0:O.length)??((je=A[0])==null?void 0:je.data.length)??0,I=R=>R/a*Math.PI*2-Math.PI/2,P=(R,E)=>{const ne=E/be*ee;return[M+Math.cos(I(R))*ne,ae+Math.sin(I(R))*ne]},h=4;return e.jsx("div",{className:`nice-chart nice-chart--radar ${k||""}`,style:_,children:e.jsxs("svg",{ref:N,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},(R,E)=>{const ne=(E+1)/h*ee,se=[];for(let le=0;le<a;le++)se.push(`${M+Math.cos(I(le))*ne},${ae+Math.sin(I(le))*ne}`);return e.jsx("polygon",{points:se.join(" "),fill:"none",className:"nice-chart__grid-line"},E)}),Array.from({length:a},(R,E)=>{const[ne,se]=P(E,be);return e.jsx("line",{x1:M,y1:ae,x2:ne,y2:se,className:"nice-chart__grid-line"},E)}),S&&(O==null?void 0:O.map((R,E)=>{const[ne,se]=P(E,be*1.12);return e.jsx("text",{x:ne,y:se,textAnchor:"middle",dominantBaseline:"middle",className:"nice-chart__axis-label",children:R},E)})),A.map((R,E)=>{const ne=R.color||ye[E%ye.length],se=R.data.map((le,ge)=>P(ge,le).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:se,fill:ne,fillOpacity:.2,stroke:ne,strokeWidth:2}),R.data.map((le,ge)=>{const[$e,Ne]=P(ge,le);return e.jsx("circle",{cx:$e,cy:Ne,r:3,fill:ne,children:e.jsx("title",{children:`${R.name}: ${le}`})},ge)})]},R.name)}),f&&e.jsx("g",{transform:`translate(${J.left}, ${m})`,children:t.map((R,E)=>{const ne=E*120,se=v.has(R.name);return e.jsxs("g",{transform:`translate(${ne}, 10)`,style:i?{cursor:"pointer"}:void 0,onClick:()=>re(R.name),opacity:se?.35:1,children:[e.jsx("rect",{width:12,height:12,rx:2,fill:R.color||ye[E%ye.length]}),e.jsx("text",{x:16,y:10,className:"nice-chart__legend-text",children:R.name})]},R.name)})})]})})}return e.jsxs("div",{className:`nice-chart ${k||""}`,style:_,children:[o&&e.jsx("button",{type:"button",className:"nice-chart__export-btn",onClick:fe,title:"Export PNG",children:"📷"}),e.jsxs("svg",{ref:N,viewBox:`0 0 ${c} ${pe}`,preserveAspectRatio:"xMidYMid meet",width:"100%",height:"100%",style:{display:"block",maxWidth:"100%",maxHeight:"100%"},className:"nice-chart__svg",onWheel:D,onMouseDown:H,onMouseMove:ie,onMouseUp:he,onMouseLeave:me,children:[e.jsxs("g",{transform:`translate(${J.left},${J.top})`,children:[n&&e.jsx("text",{x:te/2,y:-10,textAnchor:"middle",className:"nice-chart__title",children:n}),j&&F.map(M=>e.jsx("line",{x1:0,y1:W(M),x2:te,y2:W(M),className:"nice-chart__grid-line"},`grid-${M}`)),S&&F.map(M=>e.jsx("text",{x:-8,y:W(M)+4,textAnchor:"end",className:"nice-chart__axis-label",children:M},`ylabel-${M}`)),S&&O&&O.map((M,ae)=>e.jsx("text",{x:U(ae),y:T+20,textAnchor:"middle",className:"nice-chart__axis-label",children:M},ae)),z&&e.jsx("text",{x:-J.left+14,y:T/2,textAnchor:"middle",transform:`rotate(-90, -${J.left-14}, ${T/2})`,className:"nice-chart__axis-title",children:z}),l&&e.jsx("text",{x:te/2,y:T+45,textAnchor:"middle",className:"nice-chart__axis-title",children:l}),e.jsx("line",{x1:0,y1:0,x2:0,y2:T,className:"nice-chart__axis"}),e.jsx("line",{x1:0,y1:T,x2:te,y2:T,className:"nice-chart__axis"}),w==null?void 0:w.map((M,ae)=>{if(M.type==="line"){const ee=W(M.value);return e.jsxs("g",{children:[e.jsx("line",{x1:0,y1:ee,x2:te,y2:ee,stroke:M.color||"var(--color-error, #ef4444)",strokeWidth:1.5,strokeDasharray:M.dash||"6,3"}),M.label&&e.jsx("text",{x:te+4,y:ee+4,className:"nice-chart__annotation-label",fill:M.color||"var(--color-error, #ef4444)",children:M.label})]},ae)}return e.jsx("text",{x:U(M.value),y:-4,textAnchor:"middle",className:"nice-chart__annotation-label",fill:M.color||"var(--text-muted, #6b7280)",children:M.label},ae)}),$&&s&&s.x>=0&&s.x<=te&&s.y>=0&&s.y<=T&&e.jsxs(e.Fragment,{children:[e.jsx("line",{x1:s.x,y1:0,x2:s.x,y2:T,stroke:"var(--nice-text-muted, #9ca3af)",strokeWidth:1,strokeDasharray:"4,2"}),e.jsx("line",{x1:0,y1:s.y,x2:te,y2:s.y,stroke:"var(--nice-text-muted, #9ca3af)",strokeWidth:1,strokeDasharray:"4,2"})]}),A.map((M,ae)=>{const ee=M.color||ye[ae%ye.length],a=M.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:M.data.map((P,h)=>{let R,E;if(g){const se=A.slice(0,ae).reduce((le,ge)=>le+(ge.data[h]||0),0);R=W(se+P),E=W(se)-R}else R=W(Math.max(0,P)),E=Math.abs(W(P)-W(0));const ne=g?U(h)-Q/2:U(h)-A.length*Q/2+ae*Q;return e.jsx("rect",{x:ne,y:R,width:Q*.9,height:Math.max(0,E),fill:ee,rx:2,style:{transformOrigin:`${ne+Q*.9/2}px ${W(0)}px`,...d?{cursor:"pointer"}:{}},onClick:d?()=>d(M.name,ce+h,P):void 0,children:e.jsx("title",{children:`${M.name}: ${P}`})},h)})},M.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:M.data.map((P,h)=>e.jsx("circle",{cx:U(h),cy:W(P),r:5,fill:ee,fillOpacity:.7,stroke:ee,strokeWidth:1.5,style:d?{cursor:"pointer"}:void 0,onClick:d?()=>d(M.name,ce+h,P):void 0,children:e.jsx("title",{children:`${M.name}: ${P}`})},h))},M.name);const I=M.data.map((P,h)=>`${U(h)},${W(P)}`);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:`${U(0)},${W(0)} ${I.join(" ")} ${U(C-1)},${W(0)}`,fill:ee,opacity:.15}),e.jsx("polyline",{points:I.join(" "),fill:"none",stroke:ee,strokeWidth:2,className:b?"nice-chart__line":void 0}),M.data.map((P,h)=>e.jsx("circle",{cx:U(h),cy:W(P),r:3,fill:ee,style:d?{cursor:"pointer"}:void 0,onClick:d?()=>d(M.name,ce+h,P):void 0,children:e.jsx("title",{children:`${M.name}: ${P}`})},h))]},M.name)})]}),f&&e.jsx("g",{transform:`translate(${J.left}, ${m})`,children:t.map((M,ae)=>{const ee=ae*120,a=v.has(M.name);return e.jsxs("g",{transform:`translate(${ee}, 10)`,style:i?{cursor:"pointer"}:void 0,onClick:()=>re(M.name),opacity:a?.35:1,children:[e.jsx("rect",{width:12,height:12,rx:2,fill:M.color||ye[ae%ye.length]}),e.jsx("text",{x:16,y:10,className:"nice-chart__legend-text",style:a?{textDecoration:"line-through"}:void 0,children:M.name})]},M.name)})})]})]})},He=Object.freeze(Object.defineProperty({__proto__:null,NiceChart:Se},Symbol.toStringTag,{value:"Module"}));function Ue(t){if(!t.length)return{categories:[],numericFields:[],sampleValues:{}};const u=t[0],c=[],m={};let n=null;for(const[f,j]of Object.entries(u))typeof j=="number"?(c.push(f),m[f]=t.map(S=>Number(S[f])||0)):!n&&(typeof j=="string"||j instanceof Date)&&(n=f);return{categories:n?t.map(f=>String(f[n]||"")):t.map((f,j)=>`Item ${j+1}`),numericFields:c,sampleValues:m}}function Xe(t,u){const{categories:c,numericFields:m,sampleValues:n}=Ue(t);return{series:m.map((f,j)=>({name:f.replace(/([A-Z])/g," $1").replace(/^./,S=>S.toUpperCase()).trim(),data:n[f],type:u==="area"?"area":u==="line"?"line":"bar"})),categories:c}}x.forwardRef(function(t,u){const{rawData:c,enableAI:m=!0,aiModel:n,enableAutoType:f=!0,enableInsights:j=!0,dataDescription:S,onChartSuggestion:z,onInsights:l,showAIToolbar:g=!0,showInsightsOnLoad:b=!1,series:p,categories:$,...w}=t,[i,d]=x.useState("bar"),[o,k]=x.useState(null),[_,N]=x.useState([]),[v,y]=x.useState(b),[s,L]=x.useState(null),{t:r}=we.ue(),B=we.me(),{suggestChartType:V,generateInsights:X,isLoading:Y}=we.Ad(),G=m&&B.isConfigured,{series:re,categories:J}=c?Xe(c,s||i):{series:p||[],categories:$},te=x.useCallback(async()=>{if(!G||!f)return{type:"bar",reason:"Default",config:{}};const C=c||(p!=null&&p.length?p.flatMap(A=>A.data.map((O,Z)=>({[A.name]:O,index:Z}))):[]);try{const A=await V(C,S),O={type:A.type,reason:A.reason,config:A.config};return k(O),d(O.type),z==null||z(O),O}catch{return{type:"bar",reason:"Default fallback",config:{}}}},[G,f,c,p,S,V,z]),T=x.useCallback(async()=>{if(!G||!j)return[];const C=c||(p!=null&&p.length?p.flatMap(A=>A.data.map((O,Z)=>({[A.name]:O,category:($==null?void 0:$[Z])||Z}))):[]);try{const A=await X(C,s||i);return N(A),l==null||l(A),A}catch{return[]}},[G,j,c,p,$,i,s,X,l]),q=x.useCallback(()=>s||i,[s,i]);x.useEffect(()=>{G&&f&&(c!=null&&c.length||p!=null&&p.length)&&te()},[G,f,c,p]),x.useImperativeHandle(u,()=>({getSuggestion:te,generateInsights:T,getCurrentType:q}));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=s||i;return e.jsxs("div",{className:"nice-chart-ai","data-testid":t["data-testid"],children:[g&&G&&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,")"]})]}),Y&&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:O})=>e.jsx("button",{type:"button",className:`nice-chart-ai__type-btn ${oe===C?"nice-chart-ai__type-btn--active":""}`,onClick:()=>L(C),title:O,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:()=>te(),disabled:Y,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||T(),y(!v)},disabled:Y,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:re,categories:J,...w})}),v&&_.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:()=>y(!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:()=>T(),disabled:Y,children:["🔄 ",r("chartAI.refresh","Refresh")]})})]}),v&&Y&&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()),f=m(c.getMinutes()),j=m(c.getSeconds()),S=c.getMilliseconds().toString().padStart(3,"0");switch(u){case"HH:mm:ss":return`${n}:${f}:${j}`;case"HH:mm":return`${n}:${f}`;case"mm:ss":return`${f}:${j}`;case"ss.SSS":return`${j}.${S}`;case"ISO":return c.toISOString();default:return`${n}:${f}:${j}`}}function Ie(t){if(t.length===0)return null;const u=Math.min(...t),c=Math.max(...t),m=t.reduce((f,j)=>f+j,0)/t.length,n=t[t.length-1];return{min:u,max:c,avg:m,current:n,count:t.length}}const De=x.forwardRef(({series:t,maxPoints:u=100,slidingWindow:c=!0,refreshRate:m=16,dataSource:n,width:f=600,height:j=400,title:S,showLegend:z=!0,showGrid:l=!0,yAxisLabel:g,xAxisLabel:b,stacked:p,zoomable:$,crosshair:w,annotations:i=[],legendInteractive:d,onDataPointClick:o,exportable:k,showControls:_=!0,showStatus:N=!0,initialPaused:v=!1,onDataReceived:y,onDataDropped:s,timeFormat:L="HH:mm:ss",showStats:r,thresholds:B=[],className:V,style:X},Y)=>{const[G,re]=x.useState(()=>{var H;const D=new Map;for(const ie of t)D.set(ie.name,((H=ie.initialData)==null?void 0:H.slice())??[]);return D}),[J,te]=x.useState([]),[T,q]=x.useState(v),[ce,oe]=x.useState(!1),C=x.useRef([]),A=x.useRef(Date.now()),O=x.useRef(null),Z=x.useCallback(()=>{const D=C.current;D.length!==0&&(C.current=[],re(H=>{const ie=new Map(H);for(const he of D){const me=ie.get(he.series);if(!me)continue;const fe=[...me,he.value];if(c&&fe.length>u){const pe=fe.length-u;s==null||s(pe,he.series),fe.splice(0,pe)}ie.set(he.series,fe)}return ie}),D.length>0&&te(H=>{const ie=[...H];for(const he of D){const me=he.category??Ze(he.timestamp,L);ie.push(me)}return c&&ie.length>u&&ie.splice(0,ie.length-u),ie}))},[c,u,L,s]),K=x.useCallback(()=>{const D=Date.now();D-A.current>=m&&(Z(),A.current=D),O.current=requestAnimationFrame(K)},[m,Z]);x.useEffect(()=>(T||(O.current=requestAnimationFrame(K)),()=>{O.current!==null&&(cancelAnimationFrame(O.current),O.current=null)}),[T,K]);const F=x.useCallback(D=>{if(T)return;const H="points"in D?D.points:[D];for(const ie of H)G.has(ie.series)&&(C.current.push(ie),y==null||y(ie))},[T,G,y]);x.useEffect(()=>{if(!n)return;const D=n.subscribe(F);let H;return n.onStatusChange?H=n.onStatusChange(oe):oe(!0),n.fetchHistory&&n.fetchHistory(u).then(ie=>{for(const he of ie)C.current.push(he);Z()}),()=>{D(),H==null||H()}},[n,F,u,Z]);const W=x.useMemo(()=>t.map(D=>({name:D.name,color:D.color,type:D.type,data:G.get(D.name)??[]})),[t,G]),U=x.useMemo(()=>{const D=[...i];for(const H of B)D.push({type:"line",value:H.value,color:H.color,label:H.label,dash:H.style==="dashed"?"5,5":H.style==="dotted"?"2,2":void 0});return D},[i,B]);x.useImperativeHandle(Y,()=>({pause(){q(!0)},resume(){q(!1)},isPaused(){return T},clear(){re(D=>{const H=new Map(D);for(const ie of H.keys())H.set(ie,[]);return H}),te([]),C.current=[]},addPoint(D){F(D)},addPoints(D){F({points:D})},getData(D){return G.get(D)??[]},getCategories(){return J},exportData(){return{series:W,categories:J}},getStats(D){const H=G.get(D);return H?Ie(H):null}}),[T,G,J,W,F]);const Q=x.useMemo(()=>{if(!r)return null;const D={};for(const[H,ie]of G)D[H]=Ie(ie);return D},[r,G]);return e.jsxs("div",{className:V,style:{position:"relative",...X},children:[N&&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:()=>q(D=>!D),style:{padding:"4px 8px",fontSize:12,border:"1px solid var(--border-color, #ddd)",borderRadius:4,background:T?"var(--warning-bg, #fef3c7)":"var(--bg-primary, #fff)",cursor:"pointer"},title:T?"Resume":"Pause",children:T?"▶":"⏸"})}),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(([D,H])=>H?e.jsxs("div",{style:{marginBottom:4},children:[e.jsx("strong",{children:D}),e.jsxs("div",{children:["Min: ",H.min.toFixed(2)," | Max: ",H.max.toFixed(2)]}),e.jsxs("div",{children:["Avg: ",H.avg.toFixed(2)," | Now: ",H.current.toFixed(2)]})]},D):null)}),e.jsx(Se,{series:W,categories:J,width:f,height:j,title:S,showLegend:z,showGrid:l,yAxisLabel:g,xAxisLabel:b,stacked:p,zoomable:$,crosshair:w,annotations:U,legendInteractive:d,onDataPointClick:o,exportable:k})]})});De.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:f=!0,showLabels:j=!0,className:S,style:z})=>{const l=u/2,g=(c-(f?30:0))/2+(n?10:0),b=Math.min(l,g)-40,p=t.reduce((i,d)=>i+d.value,0);let $=-Math.PI/2;const w=t.map((i,d)=>{const o=i.value/(p||1)*Math.PI*2,k=$;$+=o;const _=$,N=(k+_)/2,v=l+b*Math.cos(k),y=g+b*Math.sin(k),s=l+b*Math.cos(_),L=g+b*Math.sin(_),r=o>Math.PI?1:0,B=i.color||ue[d%ue.length];let V;if(m>0){const re=l+m*Math.cos(k),J=g+m*Math.sin(k),te=l+m*Math.cos(_),T=g+m*Math.sin(_);V=`M${v},${y} A${b},${b} 0 ${r},1 ${s},${L} L${te},${T} A${m},${m} 0 ${r},0 ${re},${J} Z`}else V=`M${l},${g} L${v},${y} A${b},${b} 0 ${r},1 ${s},${L} Z`;const X=l+b*.7*Math.cos(N),Y=g+b*.7*Math.sin(N),G=p>0?Math.round(i.value/p*100):0;return{...i,path:V,labelX:X,labelY:Y,pct:G,color:B}});return e.jsx("div",{className:`nice-piechart ${S||""}`,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}),w.map((i,d)=>e.jsxs("g",{children:[e.jsx("path",{d:i.path,fill:i.color,stroke:"var(--bg-primary, #fff)",strokeWidth:2,children:e.jsx("title",{children:`${i.label}: ${i.value} (${i.pct}%)`})}),j&&i.pct>=5&&e.jsxs("text",{x:i.labelX,y:i.labelY,textAnchor:"middle",dominantBaseline:"middle",className:"nice-piechart__label",children:[i.pct,"%"]})]},d)),f&&e.jsx("g",{transform:`translate(10, ${c-25})`,children:t.map((i,d)=>e.jsxs("g",{transform:`translate(${d*100}, 0)`,children:[e.jsx("rect",{width:10,height:10,rx:2,fill:i.color||ue[d%ue.length]}),e.jsx("text",{x:14,y:9,className:"nice-chart__legend-text",children:i.label})]},d))})]})})},qe=({series:t,categories:u,width:c=400,height:m=400,maxValue:n,title:f,showLegend:j=!0,className:S,style:z})=>{const l=c/2,g=(m-(j?30:0))/2+(f?10:0),b=Math.min(l,g)-60,p=u.length,$=n??Math.max(...t.flatMap(o=>o.data),1),w=Math.PI*2/p,i=5,d=(o,k)=>{const _=o*w-Math.PI/2,N=k/$*b;return{x:l+N*Math.cos(_),y:g+N*Math.sin(_)}};return e.jsx("div",{className:`nice-polarchart ${S||""}`,style:z,children:e.jsxs("svg",{width:c,height:m,className:"nice-polarchart__svg",children:[f&&e.jsx("text",{x:l,y:20,textAnchor:"middle",className:"nice-chart__title",children:f}),Array.from({length:i},(o,k)=>{const _=b*((k+1)/i);return e.jsx("circle",{cx:l,cy:g,r:_,fill:"none",stroke:"var(--border-color, #ddd)",strokeWidth:.5},k)}),u.map((o,k)=>{const _=d(k,$),N=d(k,$*1.22),v=k*w-Math.PI/2,y=Math.cos(v),s=Math.sin(v),L=y>.2?"start":y<-.2?"end":"middle",r=s>.2?"hanging":s<-.2?"auto":"middle";return e.jsxs("g",{children:[e.jsx("line",{x1:l,y1:g,x2:_.x,y2:_.y,stroke:"var(--border-color, #ddd)",strokeWidth:.5}),e.jsx("text",{x:N.x,y:N.y,textAnchor:L,dominantBaseline:r,className:"nice-chart__axis-label nice-chart__axis-label--polar",children:o})]},k)}),t.map((o,k)=>{const _=o.color||ue[k%ue.length],N=o.data.map((v,y)=>{const s=d(y,v);return`${s.x},${s.y}`}).join(" ");return e.jsxs("g",{children:[e.jsx("polygon",{points:N,fill:o.fill!==!1?_:"none",fillOpacity:.15,stroke:_,strokeWidth:2}),o.data.map((v,y)=>{const s=d(y,v);return e.jsx("circle",{cx:s.x,cy:s.y,r:3,fill:_,children:e.jsx("title",{children:`${o.name} - ${u[y]}: ${v}`})},y)})]},o.name)}),j&&e.jsx("g",{transform:`translate(10, ${m-25})`,children:t.map((o,k)=>e.jsxs("g",{transform:`translate(${k*100}, 0)`,children:[e.jsx("rect",{width:10,height:10,rx:2,fill:o.color||ue[k%ue.length]}),e.jsx("text",{x:14,y:9,className:"nice-chart__legend-text",children:o.name})]},k))})]})})},Ye=({value:t,min:u=0,max:c=100,width:m=200,height:n=200,startAngle:f=225,endAngle:j=-45,color:S="var(--color-primary, #3b82f6)",trackColor:z,label:l,formatValue:g,ranges:b,className:p,style:$})=>{const w=m/2,i=n/2,d=Math.min(w,i)-20,o=Math.max(0,Math.min(1,(t-u)/(c-u||1))),k=r=>r*Math.PI/180,_=(f-j+360)%360||360,N=r=>({x:w+d*Math.cos(k(r)),y:i-d*Math.sin(k(r))}),v=(r,B)=>{const V=N(r),X=N(B),Y=(r-B+360)%360>180?1:0;return`M${V.x},${V.y} A${d},${d} 0 ${Y},1 ${X.x},${X.y}`},y=f-o*_,s=N(y);let L=S;if(b){for(const r of b)if(t>=r.start&&t<=r.end){L=r.color;break}}return e.jsx("div",{className:`nice-gauge nice-gauge--circular ${p||""}`,style:$,children:e.jsxs("svg",{width:m,height:n,children:[e.jsx("path",{d:v(f,j),fill:"none",stroke:z||"var(--border-color, #e2e8f0)",strokeWidth:12,strokeLinecap:"round"}),o>0&&e.jsx("path",{d:v(f,y),fill:"none",stroke:L,strokeWidth:12,strokeLinecap:"round"}),e.jsx("line",{x1:w,y1:i,x2:s.x,y2:s.y,stroke:"var(--text-primary, #333)",strokeWidth:2,strokeLinecap:"round"}),e.jsx("circle",{cx:w,cy:i,r:4,fill:"var(--text-primary, #333)"}),e.jsx("text",{x:w,y:i+d*.6,textAnchor:"middle",className:"nice-gauge__value",children:g?g(t):t}),l&&e.jsx("text",{x:w,y:i+d*.95,textAnchor:"middle",className:"nice-gauge__label",children:l})]})})},Te=({value:t,min:u=0,max:c=100,width:m=300,height:n=60,orientation:f="horizontal",color:j="var(--color-primary, #3b82f6)",label:S,formatValue:z,ranges:l,showTicks:g=!0,tickCount:b=5,className:p,style:$})=>{const w=f==="horizontal",i=w?m-40:n-40,d=Math.max(0,Math.min(1,(t-u)/(c-u||1))),o=10;let k=j;if(l){for(const N of l)if(t>=N.start&&t<=N.end){k=N.color;break}}const _=Array.from({length:b},(N,v)=>u+(c-u)*(v/(b-1)));return w?e.jsx("div",{className:`nice-gauge nice-gauge--linear ${p||""}`,style:$,children:e.jsxs("svg",{width:m,height:n,children:[e.jsx("text",{x:20+i*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:i,height:o,rx:5,fill:"var(--border-color, #e2e8f0)"}),e.jsx("rect",{x:20,y:n/2-o/2,width:i*d,height:o,rx:5,fill:k}),e.jsx("polygon",{points:`${20+i*d},${n/2-o/2-2} ${20+i*d-5},${n/2-o/2-8} ${20+i*d+5},${n/2-o/2-8}`,fill:"var(--text-primary, #333)"}),g&&_.map((N,v)=>{const y=20+(N-u)/(c-u)*i;return e.jsx("text",{x:y,y:n/2+o/2+12,textAnchor:"middle",className:"nice-gauge__tick",children:N},v)}),S&&e.jsx("text",{x:m/2,y:n-2,textAnchor:"middle",className:"nice-gauge__label",children:S})]})}):e.jsx("div",{className:`nice-gauge nice-gauge--linear nice-gauge--vertical ${p||""}`,style:$,children:e.jsxs("svg",{width:m,height:n,children:[e.jsx("rect",{x:m/2-o/2,y:20,width:o,height:i,rx:5,fill:"var(--border-color, #e2e8f0)"}),e.jsx("rect",{x:m/2-o/2,y:20+i*(1-d),width:o,height:i*d,rx:5,fill:k}),e.jsx("text",{x:m/2,y:14,textAnchor:"middle",className:"nice-gauge__value",children:z?z(t):t}),S&&e.jsx("text",{x:m/2,y:n-4,textAnchor:"middle",className:"nice-gauge__label",children:S})]})})},Qe=({items:t,min:u=0,max:c=100,width:m=300,height:n=300,startAngle:f=225,endAngle:j=-45,formatValue:S,title:z,className:l,style:g})=>{const b=m/2,p=n/2,$=Math.min(b,p)-30,w=Math.min(20,$/(t.length+1)),i=4,d=_=>_*Math.PI/180,o=(f-j+360)%360||360,k=(_,N,v)=>{const y=b+_*Math.cos(d(N)),s=p-_*Math.sin(d(N)),L=b+_*Math.cos(d(v)),r=p-_*Math.sin(d(v)),B=(N-v+360)%360;return`M${y},${s} A${_},${_} 0 ${B>180?1:0},1 ${L},${r}`};return e.jsx("div",{className:`nice-bargauge ${l||""}`,style:g,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((_,N)=>{const v=$-N*(w+i),y=Math.max(0,Math.min(1,(_.value-u)/(c-u||1))),s=f-y*o,L=_.color||ue[N%ue.length];return e.jsxs("g",{children:[e.jsx("path",{d:k(v,f,j),fill:"none",stroke:"var(--border-color, #e2e8f0)",strokeWidth:w,strokeLinecap:"round"}),y>0&&e.jsx("path",{d:k(v,f,s),fill:"none",stroke:L,strokeWidth:w,strokeLinecap:"round"})]},N)}),e.jsx("g",{children:t.map((_,N)=>e.jsxs("text",{x:b,y:p-((t.length-1)/2-N)*16,textAnchor:"middle",dominantBaseline:"middle",className:"nice-gauge__value",style:{fontSize:12},children:[_.label?`${_.label}: `:"",S?S(_.value):_.value]},N))})]})})},Je=({data:t,width:u=120,height:c=30,type:m="line",color:n="var(--color-primary, #3b82f6)",showMinMax:f,showLastPoint:j=!0,className:S,style:z})=>{if(t.length===0)return null;const l=2,g=Math.min(...t),b=Math.max(...t),p=b-g||1,$=u-l*2,w=c-l*2,i=v=>l+v/(t.length-1||1)*$,d=v=>l+w-(v-g)/p*w;if(m==="bar"){const v=Math.max(1,$/t.length-1);return e.jsx("svg",{width:u,height:c,className:`nice-sparkline ${S||""}`,style:z,children:t.map((y,s)=>e.jsx("rect",{x:l+s/t.length*$,y:d(y),width:v,height:w-(d(y)-l),fill:n,rx:1},s))})}const o=t.map((v,y)=>`${i(y)},${d(v)}`).join(" "),k=t.indexOf(g),_=t.indexOf(b),N=t.length-1;return e.jsxs("svg",{width:u,height:c,className:`nice-sparkline ${S||""}`,style:z,children:[m==="area"&&e.jsx("polygon",{points:`${i(0)},${l+w} ${o} ${i(N)},${l+w}`,fill:n,opacity:.15}),e.jsx("polyline",{points:o,fill:"none",stroke:n,strokeWidth:1.5}),f&&e.jsx("circle",{cx:i(k),cy:d(g),r:2,fill:"var(--nice-danger, #ef4444)"}),f&&e.jsx("circle",{cx:i(_),cy:d(b),r:2,fill:"var(--nice-success, #22c55e)"}),j&&e.jsx("circle",{cx:i(N),cy:d(t[N]),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:f,color:j="var(--color-primary, #3b82f6)",targetColor:S="var(--color-error, #ef4444)",size:z="md",label:l,labelPlacement:g="top",showValue:b=!1,showTarget:p=!1,formatValue:$=k=>String(k),state:w="normal",errorMessage:i,className:d,style:o})=>{const k=Ke[z],_=n??k.width,N=f??k.height,v=k.fontSize,y=4,s=_-y*2,L=N-y*2,r=Math.max(0,Math.min(1,(t-c)/(m-c||1))),B=u!=null?Math.max(0,Math.min(1,(u-c)/(m-c||1))):null,V=()=>w==="error"?e.jsx("div",{role:"alert",style:{width:_,height:N,display:"flex",alignItems:"center",justifyContent:"center",border:"1px dashed var(--color-error, #ef4444)",borderRadius:4,color:"var(--color-error, #ef4444)",fontSize:v,padding:"0 8px",boxSizing:"border-box"},children:i??"Error"}):w==="loading"?e.jsx("div",{role:"status","aria-label":"Loading",className:"nice-bullet__skeleton",style:{width:_,height:N,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:N,role:"img","aria-label":typeof l=="string"?l:void 0,children:[e.jsx("rect",{x:y,y,width:s,height:L,rx:3,fill:"var(--border-color, #e2e8f0)"}),e.jsx("rect",{x:y,y:y+L*.2,width:s*r,height:L*.6,rx:2,fill:j}),B!=null&&e.jsx("line",{x1:y+s*B,y1:y+2,x2:y+s*B,y2:y+L-2,stroke:S,strokeWidth:2}),b&&e.jsx("text",{x:y+Math.max(s*r,4),y:N/2,dx:s*r>24?-4:4,textAnchor:s*r>24?"end":"start",dominantBaseline:"middle",fontSize:v,fill:s*r>24?"var(--nice-bg, #fff)":"var(--text-primary)",fontWeight:600,children:$(t)}),p&&B!=null&&e.jsxs("text",{x:y+s*B,y:y-1,textAnchor:"middle",fontSize:v-1,fill:S,fontWeight:600,children:["▼",$(u)]})]});if(g==="none"||!l)return e.jsxs("div",{className:`nice-bullet ${d||""}`,style:o,children:[V(),e.jsx("style",{children:ze})]});const X=g==="top"||g==="bottom",Y=e.jsx("span",{className:"nice-bullet__label",style:{fontSize:v,fontWeight:600,color:"var(--text-primary)",...X?{marginBottom:g==="top"?4:0,marginTop:g==="bottom"?4:0}:{},...g==="left"?{marginRight:8}:{},...g==="right"?{marginLeft:8}:{}},children:l});return e.jsxs("div",{className:`nice-bullet nice-bullet--${g} ${d||""}`,style:{display:"inline-flex",flexDirection:X?"column":"row",alignItems:X?"flex-start":"center",...o},children:[(g==="top"||g==="left")&&Y,V(),(g==="bottom"||g==="right")&&Y,e.jsx("style",{children:ze})]})},ze=`
|
|
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:f=!0,title:j,className:S,style:z})=>{const l={top:j?30:10,bottom:10,x:40},g=u-l.x*2,b=c-l.top-l.bottom,p=m?[...t].reverse():t,$=Math.max(...p.map(i=>i.value),1),w=b/p.length;return e.jsx("div",{className:`nice-funnel ${S||""}`,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}),p.map((i,d)=>{const o=i.value/$*g,k=d<p.length-1?p[d+1].value/$*g:o*.3,_=l.top+d*w,N=_+w,v=u/2,y=`${v-o/2},${_} ${v+o/2},${_} ${v+k/2},${N} ${v-k/2},${N}`,s=i.color||ue[d%ue.length];return e.jsxs("g",{children:[e.jsx("polygon",{points:y,fill:s,stroke:"var(--bg-primary, #fff)",strokeWidth:1,children:e.jsx("title",{children:`${i.label}: ${i.value}`})}),n&&e.jsx("text",{x:v,y:_+w/2-(f?4:0),textAnchor:"middle",dominantBaseline:"middle",className:"nice-funnel__label",children:i.label}),f&&e.jsx("text",{x:v,y:_+w/2+10,textAnchor:"middle",dominantBaseline:"middle",className:"nice-funnel__value",children:i.value})]},d)})]})})},Pe=({nodes:t,links:u,width:c=600,height:m=400,nodeWidth:n=20,nodePadding:f=10,title:j,className:S,style:z})=>{const l={top:j?40:20,bottom:20,left:20,right:20},g=c-l.left-l.right,b=m-l.top-l.bottom,p=new Set(u.map(r=>r.source)),$=new Set(u.map(r=>r.target)),w=t.filter(r=>p.has(r.id)&&!$.has(r.id)),i=t.filter(r=>$.has(r.id)),d=t.filter(r=>p.has(r.id)&&$.has(r.id)),o=[w,...d.length?[d]:[],i].filter(r=>r.length>0),k=o.length,_=new Map;t.forEach(r=>{const B=u.filter(X=>X.source===r.id).reduce((X,Y)=>X+Y.value,0),V=u.filter(X=>X.target===r.id).reduce((X,Y)=>X+Y.value,0);_.set(r.id,Math.max(B,V))});const N=o.map(r=>r.reduce((B,V)=>B+(_.get(V.id)||0),0)+(r.length-1)*f),v=Math.max(...N,1),y=new Map;o.forEach((r,B)=>{const V=l.left+B/(k-1||1)*(g-n);let X=0;r.forEach(Y=>{const G=(_.get(Y.id)||0)/v*b;y.set(Y.id,{x:V,y:l.top+X,h:G}),X+=G+f})});const s=new Map,L=new Map;return t.forEach(r=>{s.set(r.id,0),L.set(r.id,0)}),e.jsx("div",{className:`nice-sankey ${S||""}`,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,B)=>{var C;const V=y.get(r.source),X=y.get(r.target);if(!V||!X)return null;const Y=s.get(r.source)||0,G=L.get(r.target)||0,re=r.value/v*b;s.set(r.source,Y+re),L.set(r.target,G+re);const J=V.x+n,te=V.y+Y,T=X.x,q=X.y+G,ce=(J+T)/2,oe=((C=t.find(A=>A.id===r.source))==null?void 0:C.color)||ue[B%ue.length];return e.jsx("path",{d:`M${J},${te} C${ce},${te} ${ce},${q} ${T},${q} L${T},${q+re} C${ce},${q+re} ${ce},${te+re} ${J},${te+re} Z`,fill:oe,fillOpacity:.3,stroke:oe,strokeOpacity:.5,strokeWidth:.5,children:e.jsx("title",{children:`${r.source} → ${r.target}: ${r.value}`})},B)}),t.map((r,B)=>{const V=y.get(r.id);if(!V)return null;const X=r.color||ue[B%ue.length];return e.jsxs("g",{children:[e.jsx("rect",{x:V.x,y:V.y,width:n,height:Math.max(V.h,2),fill:X,rx:2}),e.jsx("text",{x:V.x<g/2?V.x+n+4:V.x-4,y:V.y+V.h/2,textAnchor:V.x<g/2?"start":"end",dominantBaseline:"middle",className:"nice-chart__legend-text",children:r.label})]},r.id)})]})})},at=Object.freeze(Object.defineProperty({__proto__:null,NiceSankey:Pe},Symbol.toStringTag,{value:"Module"})),rt=({data:t,min:u,max:c,start:m,end:n,onChange:f,width:j=500,height:S=100,step:z=1,formatValue:l,chartColor:g="var(--color-primary, #3b82f6)",className:b,style:p})=>{const $={top:10,bottom:30,left:10,right:10},w=j-$.left-$.right,i=S-$.top-$.bottom,d=v=>$.left+(v-u)/(c-u||1)*w,o=v=>{const y=Math.max(0,Math.min(1,(v-$.left)/w)),s=u+y*(c-u);return Math.round(s/z)*z},k=(v,y)=>{y.preventDefault();const s=y.target.closest("svg");if(!s)return;const L=B=>{const V=s.getBoundingClientRect(),X=o(B.clientX-V.left);v==="start"?f(Math.min(X,n),n):f(m,Math.max(X,m))},r=()=>{document.removeEventListener("pointermove",L),document.removeEventListener("pointerup",r)};document.addEventListener("pointermove",L),document.addEventListener("pointerup",r)},_=t?Math.min(...t):0,N=(t?Math.max(...t):1)-_||1;return e.jsx("div",{className:`nice-rangeselector ${b||""}`,style:p,children:e.jsxs("svg",{width:j,height:S,children:[t&&t.length>1&&e.jsx("polygon",{points:`${$.left},${$.top+i} ${t.map((v,y)=>`${$.left+y/(t.length-1)*w},${$.top+i-(v-_)/N*i}`).join(" ")} ${$.left+w},${$.top+i}`,fill:g,opacity:.15}),e.jsx("rect",{x:d(m),y:$.top,width:d(n)-d(m),height:i,fill:g,opacity:.1}),e.jsx("rect",{x:$.left,y:$.top,width:d(m)-$.left,height:i,fill:"var(--bg-secondary, #f5f5f5)",opacity:.6}),e.jsx("rect",{x:d(n),y:$.top,width:$.left+w-d(n),height:i,fill:"var(--bg-secondary, #f5f5f5)",opacity:.6}),e.jsx("rect",{x:d(m)-4,y:$.top,width:8,height:i,fill:g,rx:2,cursor:"ew-resize",onPointerDown:v=>k("start",v)}),e.jsx("rect",{x:d(n)-4,y:$.top,width:8,height:i,fill:g,rx:2,cursor:"ew-resize",onPointerDown:v=>k("end",v)}),e.jsx("text",{x:d(m),y:$.top+i+18,textAnchor:"middle",className:"nice-chart__axis-label",children:l?l(m):m}),e.jsx("text",{x:d(n),y:$.top+i+18,textAnchor:"middle",className:"nice-chart__axis-label",children:l?l(n):n})]})})},Re=({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:f,onRegionClick:j,selectedRegionId:S,title:z,showTooltip:l=!0,className:g,style:b})=>{const p=f??Math.max(...t.map(w=>w.value??0),1),$=w=>{const i=r=>[parseInt(r.slice(1,3),16),parseInt(r.slice(3,5),16),parseInt(r.slice(5,7),16)],[d,o,k]=i(n[0]),[_,N,v]=i(n[1]),y=Math.round(d+(_-d)*w),s=Math.round(o+(N-o)*w),L=Math.round(k+(v-k)*w);return`rgb(${y},${s},${L})`};return e.jsxs("div",{className:`nice-vectormap ${g||""}`,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(w=>{const i=w.value!=null?Math.max(0,Math.min(1,w.value/p)):0,d=w.value!=null?$(i):"var(--bg-tertiary, #e5e7eb)",o=w.id===S;return e.jsx("path",{d:w.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(w),children:l&&e.jsx("title",{children:`${w.name}${w.value!=null?`: ${w.value}`:""}`})},w.id)})})]})},nt=Object.freeze(Object.defineProperty({__proto__:null,NiceVectorMap:Re},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
|
+
`,Le=["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 ae,ee;const{scenarios:c,data:m,annotations:n=[],referenceLines:f=[],forecastStartDate:j,cashRunway:S,xAxis:z,yAxis:l,confidenceBands:g=[{level:95,color:"var(--color-primary, #3b82f6)",opacity:.15}],tooltip:b,legend:p={enabled:!0,position:"bottom",interactive:!0},height:$=350,showForecastRegion:w=!0,lineWidth:i=2,showPoints:d=!1,pointRadius:o=4,enableZoom:k=!1,zoomEnabled:_,animationDuration:N=300,showLegend:v,responsive:y=!0,onPointClick:s,onAnnotationClick:L,onScenarioToggle:r,onViewportChange:B,size:V="medium",disabled:X=!1,labels:Y={},locale:G="pl-PL",className:re,style:J}=t,te=c&&c.length>0?c:m?[{id:"default",name:"Series",data:m}]:[],T={...p,enabled:v??p.enabled},[q,ce]=x.useState(()=>te.map((a,I)=>({...a,color:a.color??Le[I%Le.length],visible:a.visible!==!1}))),[oe,C]=x.useState(null),[A,O]=x.useState({x:0,y:0}),Z=x.useRef(null),K=x.useRef(null),F={top:20,right:30,bottom:40,left:60},[W,U]=x.useState({width:600,height:typeof $=="number"?$:350});x.useEffect(()=>{if(!y||!Z.current)return;const a=new ResizeObserver(I=>{for(const P of I)U(h=>({width:P.contentRect.width,height:h.height}))});return a.observe(Z.current),()=>a.disconnect()},[y]),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:D,allDates:H,minY:ie,maxY:he}=x.useMemo(()=>{const a=q.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()),P=Math.min(...I),h=Math.max(...I),R=a.flatMap(de=>[de.value,de.forecast,de.lowerBound,de.upperBound]).filter(de=>de!=null),E=(l==null?void 0:l.min)??Math.min(...R)*.95,ne=(l==null?void 0:l.max)??Math.max(...R)*1.05,se=W.width-F.left-F.right,le=W.height-F.top-F.bottom,ge=de=>{const Ce=typeof de=="number"?de:de.getTime();return F.left+(Ce-P)/(h-P)*se},$e=de=>F.top+le-(de-E)/(ne-E)*le,Ne=[...new Set(I)].sort((de,Ce)=>de-Ce).map(de=>new Date(de));return{xScale:ge,yScale:$e,allDates:Ne,minY:E,maxY:ne}},[q,W,F,l]),me=j?xe(j):null,fe=x.useMemo(()=>{if(!(S!=null&&S.enabled))return null;const a=S.threshold??0,I=S.scenarioId?q.find(h=>h.id===S.scenarioId&&h.visible!==!1):q.find(h=>h.visible!==!1);if(!I)return null;const P=I.data.sort((h,R)=>xe(h.date).getTime()-xe(R.date).getTime());for(let h=1;h<P.length;h++){const R=P[h-1],E=P[h],ne=R.forecast??R.value,se=E.forecast??E.value;if(ne!=null&&se!=null&&ne>a&&se<=a){const le=(ne-a)/(ne-se),ge=xe(R.date).getTime(),$e=xe(E.date).getTime(),Ne=ge+le*($e-ge);return new Date(Ne)}}return null},[S,q]),pe=x.useCallback((a,I)=>{const P=a.filter(h=>h[I]!=null).map(h=>({x:Q(xe(h.date)),y:D(h[I])}));return P.length===0?"":`M ${P.map(h=>`${h.x},${h.y}`).join(" L ")}`},[Q,D]),_e=x.useCallback(a=>{const I=a.filter(R=>R.lowerBound!=null&&R.upperBound!=null);if(I.length===0)return"";const P=I.map(R=>({x:Q(xe(R.date)),y:D(R.upperBound)})),h=I.map(R=>({x:Q(xe(R.date)),y:D(R.lowerBound)})).reverse();return`M ${P.map(R=>`${R.x},${R.y}`).join(" L ")} L ${h.map(R=>`${R.x},${R.y}`).join(" L ")} Z`},[Q,D]),be=x.useCallback(a=>{if(!K.current||(b==null?void 0:b.enabled)===!1)return;const I=K.current.getBoundingClientRect(),P=a.clientX-I.left;a.clientY-I.top;let h=null,R=1/0;for(const E of H){const ne=Q(E),se=Math.abs(ne-P);se<R&&(R=se,h=E)}if(h&&R<50){const E=q.filter(se=>se.visible!==!1).map(se=>{const le=se.data.find(ge=>xe(ge.date).getTime()===h.getTime());return{scenario:se,value:le==null?void 0:le.value,forecast:le==null?void 0:le.forecast,lowerBound:le==null?void 0:le.lowerBound,upperBound:le==null?void 0:le.upperBound}}),ne=n.filter(se=>Math.abs(xe(se.date).getTime()-h.getTime())<864e5);C({date:h,values:E,annotations:ne}),O({x:a.clientX-I.left+10,y:a.clientY-I.top-10})}else C(null)},[Q,H,q,n,b]),ve=x.useCallback(a=>{if(!T.interactive)return;ce(P=>P.map(h=>h.id===a?{...h,visible:!h.visible}:h));const I=q.find(P=>P.id===a);I&&(r==null||r(a,!I.visible))},[T.interactive,q,r]);x.useImperativeHandle(u,()=>({getScenarios:()=>q,updateScenario:(a,I)=>{ce(P=>P.map(h=>h.id===a?{...h,data:I}:h))},toggleScenario:ve,setZoomRange:()=>{},resetZoom:()=>{},exportImage:a=>{if(!K.current)return null;const I=K.current,P=new XMLSerializer().serializeToString(I);return`data:image/svg+xml;base64,${btoa(P)}`},getDataAtDate:a=>{const I=q.filter(P=>P.visible!==!1).map(P=>{const h=P.data.find(R=>xe(R.date).getTime()===a.getTime());return{scenario:P,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(P=>xe(P.date).getTime()===a.getTime())}}}),[q,n,ve]),W.width-F.left-F.right;const ke=W.height-F.top-F.bottom,je=x.useMemo(()=>{const a=(l==null?void 0:l.tickCount)??5,I=[],P=(he-ie)/(a-1);for(let h=0;h<a;h++)I.push(ie+P*h);return I},[ie,he,l==null?void 0:l.tickCount]),M=x.useMemo(()=>{const a=(z==null?void 0:z.tickCount)??6;if(H.length===0)return[];const I=Math.max(1,Math.floor(H.length/(a-1)));return H.filter((P,h)=>h%I===0||h===H.length-1)},[H,z==null?void 0:z.tickCount]);return q.length===0||q.every(a=>a.data.length===0)?e.jsx("div",{className:`nice-forecast-chart ${re??""}`,style:J,children:e.jsx("div",{className:"nice-forecast-chart__empty",children:Y.noData??"No data available"})}):e.jsxs("div",{className:`nice-forecast-chart ${re??""}`,style:{...J,height:$},children:[e.jsxs("div",{ref:Z,className:"nice-forecast-chart__container",children:[e.jsxs("svg",{ref:K,className:"nice-forecast-chart__svg",width:W.width,height:W.height,onMouseMove:be,onMouseLeave:()=>C(null),children:[(l==null?void 0:l.showGrid)!==!1&&je.map(a=>e.jsx("line",{className:"nice-forecast-chart__grid-line",x1:F.left,x2:W.width-F.right,y1:D(a),y2:D(a)},a)),w&&me&&e.jsx("rect",{className:"nice-forecast-chart__forecast-region",x:Q(me),y:F.top,width:W.width-F.right-Q(me),height:ke}),f.map(a=>e.jsxs("g",{children:[e.jsx("line",{className:"nice-forecast-chart__reference-line",x1:F.left,x2:W.width-F.right,y1:D(a.value),y2:D(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:W.width-F.right-4,y:D(a.value)-4,textAnchor:"end",children:a.label})]},a.id)),fe&&(S==null?void 0:S.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:F.top,y2:W.height-F.bottom,stroke:S.color??"var(--color-error, #ef4444)"}),S.showLabel!==!1&&e.jsxs(e.Fragment,{children:[e.jsx("rect",{className:"nice-forecast-chart__cash-runway-label-bg",x:Q(fe)-60,y:F.top-2,width:120,height:S.showDate!==!1?32:20,fill:S.color??"var(--color-error, #ef4444)",rx:4}),e.jsx("text",{className:"nice-forecast-chart__cash-runway-label",x:Q(fe),y:F.top+12,textAnchor:"middle",fill:"var(--nice-bg, #fff)",children:S.label??Y.cashRunsOut??"💰 Cash runs out"}),S.showDate!==!1&&e.jsx("text",{className:"nice-forecast-chart__cash-runway-label",x:Q(fe),y:F.top+26,textAnchor:"middle",fill:"var(--nice-bg, #fff)",style:{fontSize:"0.625rem",opacity:.9},children:Ae(fe,G)})]})]}),q.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}`)),q.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),P=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:i}),e.jsx("path",{className:"nice-forecast-chart__forecast-line",d:pe(P,me?"value":"forecast"),stroke:a.color,strokeWidth:i}),P.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:i}),d&&a.data.map((h,R)=>{const E=h.value??h.forecast;return E==null?null:e.jsx("circle",{className:"nice-forecast-chart__point",cx:Q(xe(h.date)),cy:D(E),r:o,fill:a.color,onClick:()=>s==null?void 0:s(h,a)},R)})]},a.id)}),n.map(a=>{const I=Q(xe(a.date));return e.jsxs("g",{className:"nice-forecast-chart__annotation-marker",onClick:()=>L==null?void 0:L(a),children:[a.showLine!==!1&&e.jsx("line",{className:"nice-forecast-chart__annotation-line",x1:I,x2:I,y1:F.top,y2:W.height-F.bottom,stroke:a.color??"var(--text-muted, #9ca3af)"}),e.jsx("circle",{cx:I,cy:F.top+10,r:8,fill:a.color??"var(--text-muted, #9ca3af)"}),e.jsx("text",{x:I,y:F.top+14,textAnchor:"middle",fill:"white",fontSize:"10",children:a.icon??"!"})]},a.id)}),e.jsx("line",{className:"nice-forecast-chart__axis-line",x1:F.left,x2:F.left,y1:F.top,y2:W.height-F.bottom}),e.jsx("line",{className:"nice-forecast-chart__axis-line",x1:F.left,x2:W.width-F.right,y1:W.height-F.bottom,y2:W.height-F.bottom}),je.map(a=>e.jsx("text",{className:"nice-forecast-chart__axis-label",x:F.left-8,y:D(a)+4,textAnchor:"end",children:l!=null&&l.format?l.format(a):Me(a,G)},a)),M.map(a=>e.jsx("text",{className:"nice-forecast-chart__axis-label",x:Q(a),y:W.height-F.bottom+16,textAnchor:"middle",children:z!=null&&z.format?z.format(a):Ae(a,G)},a.getTime())),(l==null?void 0:l.title)&&e.jsx("text",{className:"nice-forecast-chart__axis-title",x:15,y:W.height/2,textAnchor:"middle",transform:`rotate(-90, 15, ${W.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,G)}),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,G)})]},a.scenario.id)}),oe.values.some(a=>a.lowerBound!=null)&&e.jsxs("div",{className:"nice-forecast-chart__tooltip-confidence",children:[Y.confidence??"CI",":"," ",Me(((ae=oe.values[0])==null?void 0:ae.lowerBound)??0,G)," –"," ",Me(((ee=oe.values[0])==null?void 0:ee.upperBound)??0,G)]})]})]}),T.enabled&&e.jsx("div",{className:"nice-forecast-chart__legend",children:q.map(a=>e.jsxs("div",{className:`nice-forecast-chart__legend-item ${a.visible===!1?"nice-forecast-chart__legend-item--hidden":""}`,onClick:()=>ve(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 st=["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)"],Be=x.forwardRef((t,u)=>{var ce,oe;const{levels:c,initialLevelId:m,chartType:n="bar",width:f=600,height:j=400,showBreadcrumbs:S=!0,showBackButton:z=!0,animationDuration:l=300,onLevelChange:g,onItemClick:b,colors:p=st,showValues:$=!0,showLegend:w=!0,className:i,style:d,...o}=t,[k,_]=x.useState(m||((ce=c[0])==null?void 0:ce.id)),[N,v]=x.useState([m||((oe=c[0])==null?void 0:oe.id)]),[y,s]=x.useState(!1),[L,r]=x.useState("in"),B=x.useMemo(()=>c.find(C=>C.id===k),[c,k]),V=x.useCallback(C=>{c.find(A=>A.id===C)&&(r("in"),s(!0),setTimeout(()=>{_(C),v(A=>[...A,C]),g==null||g(C,[...N,C]),s(!1)},l/2))},[c,N,l,g]),X=x.useCallback(()=>{if(N.length<=1)return;r("out"),s(!0);const C=N.slice(0,-1),A=C[C.length-1];setTimeout(()=>{_(A),v(C),g==null||g(A,C),s(!1)},l/2)},[N,l,g]),Y=x.useCallback(()=>{var A;const C=(A=c[0])==null?void 0:A.id;C&&(r("out"),s(!0),setTimeout(()=>{_(C),v([C]),g==null||g(C,[C]),s(!1)},l/2))},[c,l,g]);x.useImperativeHandle(u,()=>({drillDown:V,drillUp:X,resetToRoot:Y,getCurrentLevel:()=>k,getPath:()=>N}),[V,X,Y,k,N]);const G=x.useCallback((C,A)=>{b==null||b(C,k);const O=c.find(Z=>{var K;return Z.parentId===k&&Z.id===((K=C.metadata)==null?void 0:K.childLevelId)});O&&V(O.id)},[k,c,V,b]),re=x.useMemo(()=>(B==null?void 0:B.data.reduce((C,A)=>C+A.value,0))||0,[B]),J=x.useMemo(()=>N.map(C=>{var A;return((A=c.find(O=>O.id===C))==null?void 0:A.label)||C}),[N,c]),te=()=>{if(!B)return null;const C=B.data,A=Math.max(...C.map(Z=>Z.value)),O=Math.min(40,(j-100)/C.length-8);return e.jsx("div",{className:"nice-drilldown-bars",children:C.map((Z,K)=>{const F=Z.value/A*100;return e.jsxs("div",{className:"nice-drilldown-bar-row",onClick:()=>G(Z,K),children:[e.jsx("span",{className:"nice-drilldown-bar-label",children:Z.label||`Item ${K+1}`}),e.jsx("div",{className:"nice-drilldown-bar-track",children:e.jsx("div",{className:"nice-drilldown-bar-fill",style:{width:`${F}%`,backgroundColor:Z.color||p[K%p.length],height:O}})}),$&&e.jsx("span",{className:"nice-drilldown-bar-value",children:Z.value.toLocaleString()})]},K)})})},T=()=>{if(!B)return null;const C=B.data,A=f/2,O=(j-60)/2+30,Z=Math.min(A,O)-40;let K=-90;const F=C.map((W,U)=>{const Q=W.value/re*360,D=K+Q,H=Q>180?1:0,ie=K*Math.PI/180,he=D*Math.PI/180,me=A+Z*Math.cos(ie),fe=O+Z*Math.sin(ie),pe=A+Z*Math.cos(he),_e=O+Z*Math.sin(he),be=(K+Q/2)*Math.PI/180,ve=A+Z*.7*Math.cos(be),ke=O+Z*.7*Math.sin(be),je=`M ${A} ${O} L ${me} ${fe} A ${Z} ${Z} 0 ${H} 1 ${pe} ${_e} Z`;return K=D,{path:je,color:W.color||p[U%p.length],label:W.label||`Item ${U+1}`,value:W.value,percentage:(W.value/re*100).toFixed(1),labelX:ve,labelY:ke,item:W,index:U}});return e.jsx("svg",{width:f,height:j-40,className:"nice-drilldown-pie",children:e.jsx("g",{children:F.map((W,U)=>e.jsxs("g",{onClick:()=>G(W.item,W.index),children:[e.jsx("path",{d:W.path,fill:W.color,stroke:"white",strokeWidth:2,className:"nice-drilldown-pie-slice"}),$&&parseFloat(W.percentage)>5&&e.jsxs("text",{x:W.labelX,y:W.labelY,textAnchor:"middle",dominantBaseline:"middle",fill:"white",fontSize:"12",fontWeight:"600",children:[W.percentage,"%"]})]},U))})})},q=()=>{if(!B)return null;const C=B.data,A=Math.max(...C.map(K=>K.value)),O=Math.min(60,(f-100)/C.length-8),Z=j-100;return e.jsx("svg",{width:f,height:j-40,className:"nice-drilldown-columns",children:e.jsxs("g",{transform:"translate(50, 20)",children:[[0,.25,.5,.75,1].map((K,F)=>e.jsxs("g",{children:[e.jsx("line",{x1:0,y1:Z*(1-K),x2:f-80,y2:Z*(1-K),stroke:"var(--nice-border, #e5e7eb)",strokeDasharray:K===0?void 0:"4"}),e.jsx("text",{x:-8,y:Z*(1-K),textAnchor:"end",dominantBaseline:"middle",fontSize:"11",fill:"var(--nice-text-secondary, #6b7280)",children:Math.round(A*K).toLocaleString()})]},F)),C.map((K,F)=>{const W=K.value/A*Z,U=F*((f-100)/C.length)+((f-100)/C.length-O)/2;return e.jsxs("g",{onClick:()=>G(K,F),children:[e.jsx("rect",{x:U,y:Z-W,width:O,height:W,fill:K.color||p[F%p.length],rx:4,className:"nice-drilldown-column-bar"}),e.jsx("text",{x:U+O/2,y:Z+16,textAnchor:"middle",fontSize:"11",fill:"var(--nice-text, #374151)",children:(K.label||`${F+1}`).slice(0,10)}),$&&e.jsx("text",{x:U+O/2,y:Z-W-8,textAnchor:"middle",fontSize:"11",fill:"var(--nice-text, #374151)",fontWeight:"500",children:K.value.toLocaleString()})]},F)})]})})};return e.jsxs("div",{className:`nice-drilldown-chart ${y?`animating ${L}`:""} ${i||""}`,style:{width:f,...d},...o,children:[e.jsxs("div",{className:"nice-drilldown-header",children:[z&&N.length>1&&e.jsx("button",{className:"nice-drilldown-back",onClick:X,children:"← Wstecz"}),S&&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 O=N.slice(0,A+1);v(O),_(O[O.length-1])}},children:C})]},A))})]}),e.jsxs("div",{className:"nice-drilldown-content",style:{height:j-40},children:[n==="bar"&&te(),n==="pie"&&T(),n==="column"&&q()]}),w&&B&&e.jsx("div",{className:"nice-drilldown-legend",children:B.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||p[A%p.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: system-ui, -apple-system, sans-serif;
|
|
295
|
+
background: white;
|
|
296
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
297
|
+
overflow: hidden;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
.nice-drilldown-header {
|
|
301
|
+
display: flex;
|
|
302
|
+
align-items: center;
|
|
303
|
+
gap: var(--nice-space-3, 12px);
|
|
304
|
+
padding: var(--nice-space-3, 12px) var(--nice-space-4, 16px);
|
|
305
|
+
border-bottom: 1px solid var(--border-color, #e5e7eb);
|
|
306
|
+
min-height: 40px;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
.nice-drilldown-back {
|
|
310
|
+
background: var(--nice-bg-secondary, #f3f4f6);
|
|
311
|
+
border: none;
|
|
312
|
+
padding: var(--nice-space-1-5, 6px) var(--nice-space-3, 12px);
|
|
313
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
314
|
+
cursor: pointer;
|
|
315
|
+
font-size: 13px;
|
|
316
|
+
color: var(--nice-text, #374151);
|
|
317
|
+
transition: background 0.2s;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
.nice-drilldown-back:hover {
|
|
321
|
+
background: var(--nice-border, #e5e7eb);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
.nice-drilldown-breadcrumbs {
|
|
325
|
+
display: flex;
|
|
326
|
+
align-items: center;
|
|
327
|
+
gap: var(--nice-space-1, 4px);
|
|
328
|
+
font-size: 13px;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
.nice-drilldown-separator {
|
|
332
|
+
color: var(--nice-text-muted, #9ca3af);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
.nice-drilldown-crumb {
|
|
336
|
+
color: var(--nice-text-secondary, #6b7280);
|
|
337
|
+
cursor: pointer;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
.nice-drilldown-crumb:hover:not(.active) {
|
|
341
|
+
color: var(--nice-primary, #3b82f6);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
.nice-drilldown-crumb.active {
|
|
345
|
+
color: var(--nice-text, #111827);
|
|
346
|
+
font-weight: 500;
|
|
347
|
+
cursor: default;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
.nice-drilldown-content {
|
|
351
|
+
padding: var(--nice-space-4, 16px);
|
|
352
|
+
transition: opacity 0.15s, transform 0.15s;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
.nice-drilldown-chart.animating .nice-drilldown-content {
|
|
356
|
+
opacity: 0;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
.nice-drilldown-chart.animating.in .nice-drilldown-content {
|
|
360
|
+
transform: translateX(20px);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
.nice-drilldown-chart.animating.out .nice-drilldown-content {
|
|
364
|
+
transform: translateX(-20px);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
.nice-drilldown-bars {
|
|
368
|
+
display: flex;
|
|
369
|
+
flex-direction: column;
|
|
370
|
+
gap: var(--nice-space-2, 8px);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
.nice-drilldown-bar-row {
|
|
374
|
+
display: flex;
|
|
375
|
+
align-items: center;
|
|
376
|
+
gap: var(--nice-space-3, 12px);
|
|
377
|
+
cursor: pointer;
|
|
378
|
+
padding: var(--nice-space-1, 4px) var(--nice-space-2, 8px);
|
|
379
|
+
margin: -4px -8px;
|
|
380
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
381
|
+
transition: background 0.2s;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
.nice-drilldown-bar-row:hover {
|
|
385
|
+
background: var(--nice-bg-secondary, #f9fafb);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
.nice-drilldown-bar-label {
|
|
389
|
+
width: 120px;
|
|
390
|
+
font-size: 13px;
|
|
391
|
+
color: var(--nice-text, #374151);
|
|
392
|
+
overflow: hidden;
|
|
393
|
+
text-overflow: ellipsis;
|
|
394
|
+
white-space: nowrap;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
.nice-drilldown-bar-track {
|
|
398
|
+
flex: 1;
|
|
399
|
+
background: var(--nice-bg-secondary, #f3f4f6);
|
|
400
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
401
|
+
overflow: hidden;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
.nice-drilldown-bar-fill {
|
|
405
|
+
transition: width 0.3s ease;
|
|
406
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
.nice-drilldown-bar-value {
|
|
410
|
+
width: 80px;
|
|
411
|
+
text-align: right;
|
|
412
|
+
font-size: 13px;
|
|
413
|
+
font-weight: 500;
|
|
414
|
+
color: var(--nice-text, #111827);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
.nice-drilldown-pie-slice {
|
|
418
|
+
cursor: pointer;
|
|
419
|
+
transition: transform 0.2s, opacity 0.2s;
|
|
420
|
+
transform-origin: center;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
.nice-drilldown-pie-slice:hover {
|
|
424
|
+
opacity: 0.85;
|
|
425
|
+
transform: scale(1.02);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
.nice-drilldown-column-bar {
|
|
429
|
+
cursor: pointer;
|
|
430
|
+
transition: opacity 0.2s;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
.nice-drilldown-column-bar:hover {
|
|
434
|
+
opacity: 0.8;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
.nice-drilldown-legend {
|
|
438
|
+
display: flex;
|
|
439
|
+
flex-wrap: wrap;
|
|
440
|
+
gap: var(--nice-space-4, 16px);
|
|
441
|
+
padding: var(--nice-space-3, 12px) var(--nice-space-4, 16px);
|
|
442
|
+
border-top: 1px solid var(--border-color, #e5e7eb);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
.nice-drilldown-legend-item {
|
|
446
|
+
display: flex;
|
|
447
|
+
align-items: center;
|
|
448
|
+
gap: var(--nice-space-1-5, 6px);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
.nice-drilldown-legend-color {
|
|
452
|
+
width: 12px;
|
|
453
|
+
height: 12px;
|
|
454
|
+
border-radius: var(--nice-radius-sm, 3px);
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
.nice-drilldown-legend-label {
|
|
458
|
+
font-size: 12px;
|
|
459
|
+
color: var(--nice-text-secondary, #6b7280);
|
|
460
|
+
}
|
|
461
|
+
`})]})});Be.displayName="NiceDrillDownChart";const We=x.forwardRef((t,u)=>{const{initialData:c,data:m,maxPoints:n=60,updateInterval:f=1e3,fetchData:j,width:S=600,height:z=200,chartType:l="line",color:g="var(--color-primary, #3b82f6)",showGrid:b=!0,showTimeAxis:p=!0,showCurrentValue:$=!0,title:w,valueFormatter:i=U=>U.toFixed(2),timeFormatter:d=U=>new Date(U).toLocaleTimeString(),onDataUpdate:o,paused:k,className:_,style:N,...v}=t,[y,s]=x.useState(c??m??[]),[L,r]=x.useState(k||!1),B=x.useRef();x.useEffect(()=>{k!==void 0&&r(k)},[k]),x.useEffect(()=>{if(L||!j)return;const U=async()=>{try{const Q=await j();s(D=>{const H=[...D,Q].slice(-n);return o==null||o(H),H})}catch(Q){console.error("Failed to fetch realtime data:",Q)}};return B.current=setInterval(U,f),()=>{B.current&&clearInterval(B.current)}},[L,j,f,n,o]);const V=x.useCallback(U=>{s(Q=>{const D=[...Q,U].slice(-n);return o==null||o(D),D})},[n,o]),X=x.useCallback(()=>{s([]),o==null||o([])},[o]),Y=x.useCallback(()=>r(!0),[]),G=x.useCallback(()=>r(!1),[]);x.useImperativeHandle(u,()=>({addDataPoint:V,clearData:X,pause:Y,resume:G,getData:()=>y}),[V,X,y]);const re={top:20,right:60,bottom:p?40:20,left:50},J=S-re.left-re.right,te=z-re.top-re.bottom,T=y.map(U=>U.value),q=T.length?Math.min(...T):0,ce=T.length?Math.max(...T):100,oe=(ce-q||1)*.1,C=q-oe,A=ce+oe-C,O=U=>{const Q=j?n-1:Math.max(1,y.length-1);return re.left+U/Q*J},Z=U=>re.top+te-(U-C)/A*te,K=y.map((U,Q)=>`${O(Q)},${Z(U.value)}`).join(" "),F=y.length>0?`M ${O(0)},${re.top+te} L ${K} L ${O(y.length-1)},${re.top+te} Z`:"",W=y.length>0?y[y.length-1].value:null;return e.jsxs("div",{className:`nice-realtime-chart ${_||""}`,style:{width:S,...N},...v,children:[w&&e.jsxs("div",{className:"nice-realtime-header",children:[e.jsx("span",{className:"nice-realtime-title",children:w}),e.jsxs("div",{className:"nice-realtime-controls",children:[e.jsx("button",{className:`nice-realtime-btn ${L?"paused":""}`,onClick:()=>r(!L),children:L?"▶️":"⏸️"}),$&&W!==null&&e.jsx("span",{className:"nice-realtime-value",children:i(W)})]})]}),e.jsxs("svg",{width:S,height:z,className:"nice-realtime-svg",children:[b&&e.jsx("g",{className:"nice-realtime-grid",children:[0,.25,.5,.75,1].map((U,Q)=>{const D=re.top+te*(1-U),H=C+A*U;return e.jsxs("g",{children:[e.jsx("line",{x1:re.left,y1:D,x2:S-re.right,y2:D,stroke:"var(--nice-border, #e5e7eb)",strokeDasharray:U===0?void 0:"3"}),e.jsx("text",{x:re.left-8,y:D,textAnchor:"end",dominantBaseline:"middle",fontSize:"10",fill:"var(--nice-text-secondary, #6b7280)",children:i(H)})]},Q)})}),l==="area"&&y.length>0&&e.jsx("path",{d:F,fill:g,fillOpacity:.2}),y.length>1&&e.jsx("polyline",{points:K,fill:"none",stroke:g,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}),y.length>0&&e.jsx("circle",{cx:O(y.length-1),cy:Z(y[y.length-1].value),r:4,fill:g,className:"nice-realtime-point"}),p&&y.length>0&&e.jsx("g",{className:"nice-realtime-time-axis",children:[0,Math.floor(y.length/2),y.length-1].filter(U=>y[U]).map(U=>e.jsx("text",{x:O(U),y:z-8,textAnchor:"middle",fontSize:"10",fill:"var(--nice-text-secondary, #6b7280)",children:d(y[U].timestamp)},U))})]}),e.jsxs("div",{className:`nice-realtime-status ${L?"paused":"live"}`,children:[e.jsx("span",{className:"nice-realtime-status-dot"}),e.jsx("span",{children:L?"Wstrzymano":"Na żywo"})]}),e.jsx("style",{children:`
|
|
462
|
+
.nice-realtime-chart {
|
|
463
|
+
font-family: system-ui, -apple-system, sans-serif;
|
|
464
|
+
background: white;
|
|
465
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
466
|
+
position: relative;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
.nice-realtime-header {
|
|
470
|
+
display: flex;
|
|
471
|
+
justify-content: space-between;
|
|
472
|
+
align-items: center;
|
|
473
|
+
padding: var(--nice-space-3, 12px) var(--nice-space-4, 16px);
|
|
474
|
+
border-bottom: 1px solid var(--border-color, #e5e7eb);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
.nice-realtime-title {
|
|
478
|
+
font-size: 14px;
|
|
479
|
+
font-weight: 600;
|
|
480
|
+
color: var(--nice-text, #111827);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
.nice-realtime-controls {
|
|
484
|
+
display: flex;
|
|
485
|
+
align-items: center;
|
|
486
|
+
gap: var(--nice-space-3, 12px);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
.nice-realtime-btn {
|
|
490
|
+
background: none;
|
|
491
|
+
border: none;
|
|
492
|
+
cursor: pointer;
|
|
493
|
+
font-size: 16px;
|
|
494
|
+
padding: var(--nice-space-1, 4px);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
.nice-realtime-value {
|
|
498
|
+
font-size: 18px;
|
|
499
|
+
font-weight: 600;
|
|
500
|
+
color: ${g};
|
|
501
|
+
font-variant-numeric: tabular-nums;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
.nice-realtime-point {
|
|
505
|
+
animation: realtime-pulse 1s ease-out infinite;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
@keyframes realtime-pulse {
|
|
509
|
+
0% { opacity: 1; transform: scale(1); }
|
|
510
|
+
50% { opacity: 0.5; transform: scale(1.5); }
|
|
511
|
+
100% { opacity: 1; transform: scale(1); }
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
.nice-realtime-status {
|
|
515
|
+
position: absolute;
|
|
516
|
+
bottom: 8px;
|
|
517
|
+
right: 8px;
|
|
518
|
+
display: flex;
|
|
519
|
+
align-items: center;
|
|
520
|
+
gap: var(--nice-space-1-5, 6px);
|
|
521
|
+
font-size: 11px;
|
|
522
|
+
color: var(--nice-text-secondary, #6b7280);
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
.nice-realtime-status-dot {
|
|
526
|
+
width: 8px;
|
|
527
|
+
height: 8px;
|
|
528
|
+
border-radius: var(--nice-radius-full, 50%);
|
|
529
|
+
background: var(--nice-success, #22c55e);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
.nice-realtime-status.paused .nice-realtime-status-dot {
|
|
533
|
+
background: var(--nice-warning, #f59e0b);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
.nice-realtime-status.live .nice-realtime-status-dot {
|
|
537
|
+
animation: live-pulse 2s ease-in-out infinite;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
@keyframes live-pulse {
|
|
541
|
+
0%, 100% { opacity: 1; }
|
|
542
|
+
50% { opacity: 0.4; }
|
|
543
|
+
}
|
|
544
|
+
`})]})});We.displayName="NiceRealtimeChart";const Fe=x.forwardRef(({data:t,renderNode:u,selectable:c,selectedKey:m,onSelect:n,direction:f="top-down",collapsible:j=!0,className:S,style:z,id:l},g)=>{const b=we.Us(l),[p,$]=x.useState(new Set),w=x.useCallback(o=>{$(k=>{const _=new Set(k);return _.has(o)?_.delete(o):_.add(o),_})},[]),i=x.useCallback(o=>{c&&(n==null||n(o))},[c,n]),d=x.useCallback(o=>{const k=p.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:()=>i(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:N=>{N.stopPropagation(),w(o.key)},"aria-label":k?"Expand":"Collapse",children:k?"+":"−"})]}),_&&!k&&e.jsx("ul",{className:"nice-org-chart__children",children:o.children.map(N=>d(N))})]},o.key)},[p,m,u,c,j,i,w]);return e.jsx("div",{ref:g,id:b,className:`nice-org-chart nice-org-chart--${f} ${S||""}`,style:z,children:e.jsx("ul",{className:"nice-org-chart__root",children:d(t)})})});Fe.displayName="NiceOrganizationChart";function lt(t,u,c){const m=$=>{const w=$.replace("#","");return[parseInt(w.slice(0,2),16),parseInt(w.slice(2,4),16),parseInt(w.slice(4,6),16)]},[n,f,j]=m(t),[S,z,l]=m(u),g=Math.round(n+(S-n)*c),b=Math.round(f+(z-f)*c),p=Math.round(j+(l-j)*c);return`rgb(${g},${b},${p})`}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:f=40,showValues:j=!0,className:S,style:z,id:l},g)=>{const b=we.Us(l),{minVal:p,maxVal:$}=x.useMemo(()=>{let i=1/0,d=-1/0;for(const o of t)for(const k of o)k<i&&(i=k),k>d&&(d=k);return{minVal:i,maxVal:d}},[t]),w=x.useCallback(i=>$===p?.5:(i-p)/($-p),[p,$]);return e.jsx("div",{ref:g,id:b,className:`nice-heatmap ${S||""}`,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((i,d)=>e.jsx("th",{className:"nice-heatmap__header",children:i},d))]})}),e.jsx("tbody",{children:t.map((i,d)=>e.jsxs("tr",{children:[c&&e.jsx("th",{className:"nice-heatmap__row-label",children:c[d]}),i.map((o,k)=>e.jsx("td",{className:"nice-heatmap__cell",style:{background:lt(m[0],m[1],w(o)),width:f,height:f,textAlign:"center",color:w(o)>.6?"var(--bg-primary, #fff)":"var(--bg-tertiary, #333)",cursor:n?"pointer":void 0},onClick:()=>n==null?void 0:n(d,k,o),title:String(o),children:j?o:""},k))]},d))})]})})});Ve.displayName="NiceHeatMap";function ct(t,u){const c=t.reduce((l,g)=>l+g.value,0);if(c===0||t.length===0)return[];const m=[];let{x:n,y:f,w:j,h:S}=u;const z=[...t].sort((l,g)=>g.value-l.value);for(const l of z){const g=l.value/c;if(j>=S){const b=j*g;m.push({x:n,y:f,w:b,h:S,node:l}),n+=b,j-=b}else{const b=S*g;m.push({x:n,y:f,w:j,h:b,node:l}),f+=b,S-=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)"],Oe=x.forwardRef(({data:t,width:u=600,height:c=400,onNodeClick:m,colors:n=ot,className:f,style:j,id:S},z)=>{const l=we.Us(S),g=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 ${f||""}`,style:j,children:e.jsx("svg",{width:u,height:c,className:"nice-treemap__svg",children:g.map((b,p)=>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[p%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))})})});Oe.displayName="NiceTreeMap";const Ee=x.forwardRef(({data:t,type:u="candlestick",showVolume:c=!0,width:m=800,height:n=400,bullColor:f="var(--color-success, #22c55e)",bearColor:j="var(--color-error, #ef4444)",className:S,style:z,id:l},g)=>{const b=we.Us(l),p={top:20,right:20,bottom:c?80:30,left:60},$=m-p.left-p.right,w=c?50:0,i=n-p.top-p.bottom-w,{minP:d,maxP:o,maxVol:k}=x.useMemo(()=>{let s=1/0,L=-1/0,r=0;for(const B of t)B.low<s&&(s=B.low),B.high>L&&(L=B.high),B.volume&&B.volume>r&&(r=B.volume);return{minP:s,maxP:L,maxVol:r}},[t]),_=Math.max(1,$/t.length*.7),N=s=>p.left+(s+.5)*($/t.length),v=s=>p.top+i-(s-d)/(o-d||1)*i,y=s=>n-p.bottom-w+w*(1-s/(k||1));return e.jsx("div",{ref:g,id:b,className:`nice-stock-chart ${S||""}`,style:z,children:e.jsxs("svg",{width:m,height:n,className:"nice-stock-chart__svg",children:[[0,.25,.5,.75,1].map(s=>{const L=d+s*(o-d);return e.jsxs("g",{children:[e.jsx("line",{x1:p.left,x2:m-p.right,y1:v(L),y2:v(L),stroke:"var(--nice-border, #e5e7eb)",strokeDasharray:"2,2"}),e.jsx("text",{x:p.left-4,y:v(L)+4,textAnchor:"end",fontSize:10,fill:"var(--nice-text-secondary, #888)",children:L.toFixed(2)})]},s)}),u==="line"?e.jsx("polyline",{points:t.map((s,L)=>`${N(L)},${v(s.close)}`).join(" "),fill:"none",stroke:f,strokeWidth:1.5}):t.map((s,L)=>{const r=s.close>=s.open,B=r?f:j,V=N(L);if(u==="ohlc")return e.jsxs("g",{children:[e.jsx("line",{x1:V,x2:V,y1:v(s.high),y2:v(s.low),stroke:B,strokeWidth:1}),e.jsx("line",{x1:V-_/2,x2:V,y1:v(s.open),y2:v(s.open),stroke:B,strokeWidth:1.5}),e.jsx("line",{x1:V,x2:V+_/2,y1:v(s.close),y2:v(s.close),stroke:B,strokeWidth:1.5})]},L);const X=v(Math.max(s.open,s.close)),Y=v(Math.min(s.open,s.close));return e.jsxs("g",{children:[e.jsx("line",{x1:V,x2:V,y1:v(s.high),y2:v(s.low),stroke:B,strokeWidth:1}),e.jsx("rect",{x:V-_/2,y:X,width:_,height:Math.max(Y-X,1),fill:r?"transparent":B,stroke:B,strokeWidth:1})]},L)}),c&&t.map((s,L)=>{if(!s.volume)return null;const r=s.close>=s.open;return e.jsx("rect",{x:N(L)-_/2,y:y(s.volume),width:_,height:n-p.bottom-y(s.volume),fill:r?f:j,opacity:.3},`v${L}`)}),t.map((s,L)=>L%Math.max(1,Math.floor(t.length/8))!==0?null:e.jsx("text",{x:N(L),y:n-p.bottom+w+14,textAnchor:"middle",fontSize:9,fill:"var(--nice-text-secondary, #888)",children:s.date},`l${L}`))]})})});Ee.displayName="NiceStockChart";exports.A=He;exports.B=at;exports.C=ue;exports.D=nt;exports.N=Re;exports.a=rt;exports.b=Fe;exports.c=Ee;exports.d=Oe;exports.e=Ve;exports.f=Pe;exports.g=tt;exports.h=et;exports.i=Je;exports.j=Qe;exports.k=Te;exports.l=Ye;exports.m=qe;exports.n=Ge;exports.o=Se;exports.q=Be;exports.s=De;exports.u=We;
|