@synertech/ui 0.47.1 → 0.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/.claude/skills/use-synertech-ui/SKILL.md +33 -1
  2. package/README.md +23 -0
  3. package/dist/components/area-chart/AreaChart.cjs +1 -1
  4. package/dist/components/area-chart/AreaChart.js +1 -1
  5. package/dist/components/bar-chart/BarChart.cjs +1 -1
  6. package/dist/components/bar-chart/BarChart.js +1 -1
  7. package/dist/components/box-plot/BoxPlot.cjs +1 -1
  8. package/dist/components/box-plot/BoxPlot.js +1 -1
  9. package/dist/components/bullet-chart/BulletChart.cjs +1 -1
  10. package/dist/components/bullet-chart/BulletChart.js +1 -1
  11. package/dist/components/calendar/Calendar.cjs +1 -1
  12. package/dist/components/calendar/Calendar.js +1 -1
  13. package/dist/components/candlestick-chart/CandlestickChart.cjs +1 -1
  14. package/dist/components/candlestick-chart/CandlestickChart.js +1 -1
  15. package/dist/components/chart/ChartPeriodPicker.cjs +1 -1
  16. package/dist/components/chart/ChartPeriodPicker.js +1 -1
  17. package/dist/components/datagrid/DataGrid.cjs +1 -1
  18. package/dist/components/datagrid/DataGrid.js +1 -1
  19. package/dist/components/dumbbell-chart/DumbbellChart.cjs +1 -1
  20. package/dist/components/dumbbell-chart/DumbbellChart.js +1 -1
  21. package/dist/components/form/number-input/NumberInput.cjs +1 -1
  22. package/dist/components/form/number-input/NumberInput.js +1 -1
  23. package/dist/components/funnel-chart/FunnelChart.cjs +1 -1
  24. package/dist/components/funnel-chart/FunnelChart.js +1 -1
  25. package/dist/components/gantt-chart/GanttChart.cjs +1 -1
  26. package/dist/components/gantt-chart/GanttChart.js +1 -1
  27. package/dist/components/heat-map/Heatmap.cjs +1 -1
  28. package/dist/components/heat-map/Heatmap.js +1 -1
  29. package/dist/components/line-chart/LineChart.cjs +1 -1
  30. package/dist/components/line-chart/LineChart.js +1 -1
  31. package/dist/components/pie-chart/PieChart.cjs +1 -1
  32. package/dist/components/pie-chart/PieChart.js +1 -1
  33. package/dist/components/scatter-chart/ScatterChart.cjs +1 -1
  34. package/dist/components/scatter-chart/ScatterChart.js +1 -1
  35. package/dist/components/stat-card/StatCard.cjs +1 -1
  36. package/dist/components/stat-card/StatCard.js +1 -1
  37. package/dist/components/waterfall-chart/WaterfallChart.cjs +1 -1
  38. package/dist/components/waterfall-chart/WaterfallChart.js +1 -1
  39. package/dist/index.cjs +1 -1
  40. package/dist/index.d.cts +135 -22
  41. package/dist/index.d.ts +135 -22
  42. package/dist/index.js +1 -1
  43. package/dist/lib/i18n.cjs +1 -1
  44. package/dist/lib/i18n.js +1 -1
  45. package/package.json +1 -1
@@ -1 +1 @@
1
- "use client";import{memo as fe,useCallback as _,useMemo as U,useState as de}from"react";import{ChartAxis as ne}from"../chart/ChartAxis.js";import{ChartContainer as ge}from"../chart/ChartContainer.js";import{ChartGrid as ye}from"../chart/ChartGrid.js";import{ChartLegend as pe}from"../chart/ChartLegend.js";import{ChartTableView as xe}from"../chart/ChartTableView.js";import{ChartTooltip as be,ChartTooltipContent as Ce}from"../chart/ChartTooltip.js";import{CHART_ALL_PAIRS_LIMIT as oe,getSeriesLabel as ae,resolveSeriesColor as ke,toLegendItems as ve}from"../chart/palette.js";import{buildCartesianGeometry as Se,createPlotContext as Pe,splitOverlay as Ve}from"../chart/utils/cartesian.js";import{collectAllValues as ie,readNumber as se}from"../chart/utils/data.js";import{sampleEvenly as Re,warnPointBudget as we}from"../chart/utils/decimate.js";import{formatAuto as le}from"../chart/utils/format.js";import{pressChartMark as Le,stepChartCursor as Q}from"../chart/utils/keyboard.js";import{toNumber as Te}from"../chart/utils/scales.js";import{extent as ce}from"../chart/utils/ticks.js";import{formatTimeValue as Ke}from"../chart/utils/timestamp.js";import{CHART_TOUCH as Ae}from"../chart/utils/touch.js";import{Fragment as De,jsx as d,jsxs as Z}from"react/jsx-runtime";var Ie=4.5,Me=48,ee=!1;function ue(m){return`${m.index}:${m.seriesKey}`}function Ee(m,h){return m.reduce((r,V)=>Math.abs(V.cx-h)<Math.abs(r.cx-h)?V:r)}var $e=fe(function({points:h}){return d("g",{children:h.map(r=>d("circle",{cx:r.cx,cy:r.cy,r:r.r,fill:r.color,fillOpacity:.85,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},`${r.seriesKey}-${r.index}`))})});function We({width:m,height:h,data:r,resolvedSeries:V,x:v,y:I,grid:w,size:X,bubble:x,trendLine:G,quadrants:M,pointRadius:E,overlay:D,maxPoints:L,margin:O,tooltip:T,onPointClick:K,plotLabel:q,formatValue:R,formatX:A}){let[z,$]=de(null),t=U(()=>{let o=V.filter(i=>!i.hidden),c=o.map(i=>i.key),a=Se({width:m,height:h,data:r,x:{...v,scale:v.scale==="time"?"time":"linear"},y:I,bounds:ce(ie(r,c)),margin:O,formatValue:R,formatX:A}),S=x?ie(r,[x.key]):[],P=x?ce(S):null,[s,u]=x?.range??[4,14],l=i=>{if(!x||!P)return E;let f=se(i,x.key);if(f===null)return s;let[n,y]=P,g=y===n?1:(f-n)/(y-n);return Math.sqrt(s*s+g*(u*u-s*s))},k=[],b=[],N=[];o.forEach(i=>{let f=[];r.forEach((y,g)=>{let W=se(y,i.key),p=a.categoryPositions[g];W===null||!Number.isFinite(p)||f.push({seriesKey:i.key,seriesLabel:ae(i),color:i.color,index:g,cx:p,cy:a.valueScale(W),r:l(y),xValue:a.toCategoryNumber(a.xValues[g]),yValue:W})}),L||we("ScatterChart",f.length);let n=L&&L>0?Re(f,L):f;b.push(...f),k.push(...n),n.length>0&&N.push([...n].sort((y,g)=>y.cx-g.cx||y.index-g.index))});let Y=null;if(G&&b.length>1){let i=b.length,f=b.reduce((p,C)=>p+C.xValue,0),n=b.reduce((p,C)=>p+C.yValue,0),y=b.reduce((p,C)=>p+C.xValue*C.yValue,0),g=b.reduce((p,C)=>p+C.xValue*C.xValue,0),W=i*g-f*f;if(W!==0){let p=(i*y-f*n)/W,C=(n-p*f)/i,te=b.map(J=>J.xValue),[me,he]=[Math.min(...te),Math.max(...te)],re=b.map(J=>J.cx);Y={x1:Math.min(...re),y1:a.valueScale(p*me+C),x2:Math.max(...re),y2:a.valueScale(p*he+C)}}}return{visible:o,points:k,tracks:N,marks:new Map(k.map(i=>[ue(i),i])),plot:Pe({geometry:a,width:m,height:h,data:r,series:o,formatValue:R,formatX:A}),trend:Y,xTicks:a.categoryTicks,yTicks:a.valueTicks,valueScale:a.valueScale,positions:a.categoryPositions,innerWidth:a.innerWidth,innerHeight:a.innerHeight,margin:a.margin,xValues:a.xValues}},[r,V,v,I,m,h,O,x,G,E,L,R,A]),e=z===null?null:t.marks.get(ue(z))??null,F=_(o=>{if(T===!1||t.points.length===0)return;let c=o.currentTarget.getBoundingClientRect(),a=o.clientX-c.left-t.margin.left,S=o.clientY-c.top-t.margin.top,P=null,s=Me;for(let u of t.points){let l=Math.hypot(u.cx-a,u.cy-S);l<s&&(s=l,P=u)}$(P)},[T,t.points,t.margin]),H=_(()=>{if(!K||!e)return;let o=r[e.index];o&&K({seriesKey:e.seriesKey,seriesLabel:e.seriesLabel,color:e.color,value:e.yValue,formattedValue:R(e.yValue),datum:o,index:e.index,x:t.xValues[e.index]})},[K,e,R,r,t.xValues]),j=_(o=>{let{tracks:c}=t;if(c.length===0||Le(o,K&&e?H:null))return;let a=e?c.findIndex(k=>k[0].seriesKey===e.seriesKey):-1,S=a<0?null:c[a],P=S&&e?S.indexOf(e):-1,s=S&&P>=0?{track:S,trackIndex:a,markIndex:P}:null,u=s?.track??c[0],l;switch(o.key){case"ArrowRight":l=u[Q(s?.markIndex??null,1,u.length)];break;case"ArrowLeft":l=u[Q(s?.markIndex??null,-1,u.length)];break;case"ArrowDown":case"ArrowUp":{if(!s||!e){l=u[0];break}let k=Q(s.trackIndex,o.key==="ArrowDown"?1:-1,c.length);l=k===s.trackIndex?e:Ee(c[k],e.cx);break}case"Home":l=u[0];break;case"End":l=u[u.length-1];break;case"Escape":l=null;break;default:return}o.preventDefault(),$(l)},[t,e,K,H]),B=Ve(D);return Z(De,{children:[Z("svg",{width:m,height:h,role:"img","aria-label":q??t.visible.map(o=>ae(o)).join(", "),tabIndex:0,className:`${Ae} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500`,onPointerMove:F,onPointerLeave:()=>$(null),onKeyDown:j,onBlur:()=>$(null),onClick:H,children:[Z("g",{transform:`translate(${t.margin.left}, ${t.margin.top})`,children:[d(ye,{width:t.innerWidth,height:t.innerHeight,horizontal:w==="y"||w==="both"?t.yTicks.map(o=>o.offset):void 0,vertical:w==="x"||w==="both"?t.xTicks.map(o=>o.offset):void 0}),M?.y!==void 0?d("line",{x1:0,y1:t.valueScale(M.y),x2:t.innerWidth,y2:t.valueScale(M.y),stroke:"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:"4 4"}):null,B.under?.(t.plot),t.trend?d("line",{x1:t.trend.x1,y1:t.trend.y1,x2:t.trend.x2,y2:t.trend.y2,stroke:"var(--color-chart-muted)",strokeWidth:1.5,strokeDasharray:"4 4"}):null,d($e,{points:t.points}),B.over?.(t.plot),e?d("circle",{cx:e.cx,cy:e.cy,r:e.r+3,fill:"none",stroke:e.color,strokeWidth:2,"aria-hidden":"true"}):null]}),d("g",{transform:`translate(${t.margin.left}, ${t.margin.top+t.innerHeight})`,children:v.hidden?null:d(ne,{orientation:"bottom",ticks:t.xTicks,length:t.innerWidth,label:v.label,size:X})}),d("g",{transform:`translate(${t.margin.left}, ${t.margin.top})`,children:I?.hidden?null:d(ne,{orientation:"left",ticks:t.yTicks,length:t.innerHeight,showLine:!1,label:I?.label,size:X})})]}),e&&r[e.index]&&T!==!1?d(be,{x:t.margin.left+e.cx,y:t.margin.top+e.cy,containerWidth:m,children:typeof T=="function"?T({x:t.xValues[e.index],xLabel:A(t.xValues[e.index],e.index),index:e.index,points:[{seriesKey:e.seriesKey,seriesLabel:e.seriesLabel,color:e.color,value:e.yValue,formattedValue:R(e.yValue),datum:r[e.index]}]}):d(Ce,{title:`${v.label??v.key} ${A(t.xValues[e.index],e.index)}`,points:[{seriesKey:e.seriesKey,seriesLabel:e.seriesLabel,color:e.color,value:e.yValue,formattedValue:R(e.yValue),datum:r[e.index]}]})}):null]})}function tt({data:m,series:h,x:r,y:V,height:v=280,width:I,size:w="md",grid:X="both",legend:x,tooltip:G=!0,tableView:M=!1,emphasis:E,title:D,description:L,loading:O=!1,emptyState:T,error:K=!1,errorState:q,onRetry:R,actions:A,onPointClick:z,bubble:$,trendLine:t=!1,quadrants:e,pointRadius:F=Ie,overlay:H,legendToggle:j=!0,maxPoints:B,margin:o,locale:c,plotLabel:a,className:S,...P}){let[s,u]=de(()=>new Set);h.length>oe&&!ee&&(ee=!0,console.warn(`[@synertech/ui] A ScatterChart was given ${h.length} series. Any two marks can sit side by side here, and only the first ${oe} palette slots stay tellable apart under that test: facet the chart instead.`));let l=U(()=>h.map((n,y)=>({...n,hidden:n.hidden||s.has(n.key),color:ke(n,y,E)})),[h,s,E]),k=U(()=>V?.format??(n=>le(n,c)),[V?.format,c]),b=U(()=>r.format??(n=>r.scale==="time"?Ke(n,c):le(Te(n),c)),[r.format,r.scale,c]),N=_(n=>{u(y=>{let g=new Set(y);return g.has(n)?g.delete(n):g.add(n),g})},[]),Y=x===void 0?h.length>=2:x!==!1,i=typeof x=="string"?x:"bottom",f=l.filter(n=>!n.hidden).length;return d(ge,{title:D,description:L,height:v,width:I,size:w,loading:O,empty:m.length===0||f===0,emptyState:T,error:K,errorState:q,onRetry:R,actions:A,tableView:M,legendPosition:i,legend:Y?d(pe,{items:ve(l,E),position:i,marker:"dot",size:w,onToggle:j?N:void 0}):void 0,table:M?d(xe,{data:m,series:l,xKey:r.key,xLabel:r.label??r.key,formatX:b,formatValue:k,caption:typeof D=="string"?D:void 0}):void 0,className:S,...P,children:({width:n})=>d(We,{width:n,height:v,data:m,resolvedSeries:l,x:r,y:V,grid:X,size:w,bubble:$,trendLine:t,quadrants:e,pointRadius:F,overlay:H,maxPoints:B,margin:o,tooltip:G,onPointClick:z,plotLabel:a,formatValue:k,formatX:b})})}function rt(){ee=!1}export{tt as ScatterChart,rt as resetScatterWarnings};
1
+ "use client";import{memo as fe,useCallback as _,useMemo as U,useState as de}from"react";import{useUILocale as ge}from"../../lib/i18n.js";import{ChartAxis as ne}from"../chart/ChartAxis.js";import{ChartContainer as ye}from"../chart/ChartContainer.js";import{ChartGrid as pe}from"../chart/ChartGrid.js";import{ChartLegend as xe}from"../chart/ChartLegend.js";import{ChartTableView as be}from"../chart/ChartTableView.js";import{ChartTooltip as Ce,ChartTooltipContent as ke}from"../chart/ChartTooltip.js";import{CHART_ALL_PAIRS_LIMIT as oe,getSeriesLabel as ae,resolveSeriesColor as ve,toLegendItems as Se}from"../chart/palette.js";import{buildCartesianGeometry as Pe,createPlotContext as Ve,splitOverlay as Re}from"../chart/utils/cartesian.js";import{collectAllValues as ie,readNumber as se}from"../chart/utils/data.js";import{sampleEvenly as Le,warnPointBudget as we}from"../chart/utils/decimate.js";import{formatAuto as le}from"../chart/utils/format.js";import{pressChartMark as Te,stepChartCursor as Q}from"../chart/utils/keyboard.js";import{toNumber as Ke}from"../chart/utils/scales.js";import{extent as ce}from"../chart/utils/ticks.js";import{formatTimeValue as Ae}from"../chart/utils/timestamp.js";import{CHART_TOUCH as Ie}from"../chart/utils/touch.js";import{Fragment as He,jsx as c,jsxs as Z}from"react/jsx-runtime";var Me=4.5,Ee=48,ee=!1;function ue(d){return`${d.index}:${d.seriesKey}`}function $e(d,m){return d.reduce((r,R)=>Math.abs(R.cx-m)<Math.abs(r.cx-m)?R:r)}var We=fe(function({points:m}){return c("g",{children:m.map(r=>c("circle",{cx:r.cx,cy:r.cy,r:r.r,fill:r.color,fillOpacity:.85,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},`${r.seriesKey}-${r.index}`))})});function De({width:d,height:m,data:r,resolvedSeries:R,x:S,y:M,grid:w,size:G,bubble:x,trendLine:O,quadrants:E,pointRadius:$,overlay:D,maxPoints:T,margin:z,tooltip:K,onPointClick:A,plotLabel:q,formatValue:L,formatX:I}){let[B,W]=de(null),t=U(()=>{let o=R.filter(s=>!s.hidden),y=o.map(s=>s.key),a=Pe({width:d,height:m,data:r,x:{...S,scale:S.scale==="time"?"time":"linear"},y:M,bounds:ce(ie(r,y)),margin:z,formatValue:L,formatX:I}),P=x?ie(r,[x.key]):[],V=x?ce(P):null,[i,l]=x?.range??[4,14],h=s=>{if(!x||!V)return $;let u=se(s,x.key);if(u===null)return i;let[C,n]=V,f=n===C?1:(u-C)/(n-C);return Math.sqrt(i*i+f*(l*l-i*i))},p=[],b=[],X=[];o.forEach(s=>{let u=[];r.forEach((n,f)=>{let v=se(n,s.key),g=a.categoryPositions[f];v===null||!Number.isFinite(g)||u.push({seriesKey:s.key,seriesLabel:ae(s),color:s.color,index:f,cx:g,cy:a.valueScale(v),r:h(n),xValue:a.toCategoryNumber(a.xValues[f]),yValue:v})}),T||we("ScatterChart",u.length);let C=T&&T>0?Le(u,T):u;b.push(...u),p.push(...C),C.length>0&&X.push([...C].sort((n,f)=>n.cx-f.cx||n.index-f.index))});let Y=null;if(O&&b.length>1){let s=b.length,u=b.reduce((g,k)=>g+k.xValue,0),C=b.reduce((g,k)=>g+k.yValue,0),n=b.reduce((g,k)=>g+k.xValue*k.yValue,0),f=b.reduce((g,k)=>g+k.xValue*k.xValue,0),v=s*f-u*u;if(v!==0){let g=(s*n-u*C)/v,k=(C-g*u)/s,te=b.map(J=>J.xValue),[me,he]=[Math.min(...te),Math.max(...te)],re=b.map(J=>J.cx);Y={x1:Math.min(...re),y1:a.valueScale(g*me+k),x2:Math.max(...re),y2:a.valueScale(g*he+k)}}}return{visible:o,points:p,tracks:X,marks:new Map(p.map(s=>[ue(s),s])),plot:Ve({geometry:a,width:d,height:m,data:r,series:o,formatValue:L,formatX:I}),trend:Y,xTicks:a.categoryTicks,yTicks:a.valueTicks,valueScale:a.valueScale,positions:a.categoryPositions,innerWidth:a.innerWidth,innerHeight:a.innerHeight,margin:a.margin,xValues:a.xValues}},[r,R,S,M,d,m,z,x,O,$,T,L,I]),e=B===null?null:t.marks.get(ue(B))??null,F=_(o=>{if(K===!1||t.points.length===0)return;let y=o.currentTarget.getBoundingClientRect(),a=o.clientX-y.left-t.margin.left,P=o.clientY-y.top-t.margin.top,V=null,i=Ee;for(let l of t.points){let h=Math.hypot(l.cx-a,l.cy-P);h<i&&(i=h,V=l)}W(V)},[K,t.points,t.margin]),H=_(()=>{if(!A||!e)return;let o=r[e.index];o&&A({seriesKey:e.seriesKey,seriesLabel:e.seriesLabel,color:e.color,value:e.yValue,formattedValue:L(e.yValue),datum:o,index:e.index,x:t.xValues[e.index]})},[A,e,L,r,t.xValues]),j=_(o=>{let{tracks:y}=t;if(y.length===0||Te(o,A&&e?H:null))return;let a=e?y.findIndex(p=>p[0].seriesKey===e.seriesKey):-1,P=a<0?null:y[a],V=P&&e?P.indexOf(e):-1,i=P&&V>=0?{track:P,trackIndex:a,markIndex:V}:null,l=i?.track??y[0],h;switch(o.key){case"ArrowRight":h=l[Q(i?.markIndex??null,1,l.length)];break;case"ArrowLeft":h=l[Q(i?.markIndex??null,-1,l.length)];break;case"ArrowDown":case"ArrowUp":{if(!i||!e){h=l[0];break}let p=Q(i.trackIndex,o.key==="ArrowDown"?1:-1,y.length);h=p===i.trackIndex?e:$e(y[p],e.cx);break}case"Home":h=l[0];break;case"End":h=l[l.length-1];break;case"Escape":h=null;break;default:return}o.preventDefault(),W(h)},[t,e,A,H]),N=Re(D);return Z(He,{children:[Z("svg",{width:d,height:m,role:"img","aria-label":q??t.visible.map(o=>ae(o)).join(", "),tabIndex:0,className:`${Ie} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500`,onPointerMove:F,onPointerLeave:()=>W(null),onKeyDown:j,onBlur:()=>W(null),onClick:H,children:[Z("g",{transform:`translate(${t.margin.left}, ${t.margin.top})`,children:[c(pe,{width:t.innerWidth,height:t.innerHeight,horizontal:w==="y"||w==="both"?t.yTicks.map(o=>o.offset):void 0,vertical:w==="x"||w==="both"?t.xTicks.map(o=>o.offset):void 0}),E?.y!==void 0?c("line",{x1:0,y1:t.valueScale(E.y),x2:t.innerWidth,y2:t.valueScale(E.y),stroke:"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:"4 4"}):null,N.under?.(t.plot),t.trend?c("line",{x1:t.trend.x1,y1:t.trend.y1,x2:t.trend.x2,y2:t.trend.y2,stroke:"var(--color-chart-muted)",strokeWidth:1.5,strokeDasharray:"4 4"}):null,c(We,{points:t.points}),N.over?.(t.plot),e?c("circle",{cx:e.cx,cy:e.cy,r:e.r+3,fill:"none",stroke:e.color,strokeWidth:2,"aria-hidden":"true"}):null]}),c("g",{transform:`translate(${t.margin.left}, ${t.margin.top+t.innerHeight})`,children:S.hidden?null:c(ne,{orientation:"bottom",ticks:t.xTicks,length:t.innerWidth,label:S.label,size:G})}),c("g",{transform:`translate(${t.margin.left}, ${t.margin.top})`,children:M?.hidden?null:c(ne,{orientation:"left",ticks:t.yTicks,length:t.innerHeight,showLine:!1,label:M?.label,size:G})})]}),e&&r[e.index]&&K!==!1?c(Ce,{x:t.margin.left+e.cx,y:t.margin.top+e.cy,containerWidth:d,children:typeof K=="function"?K({x:t.xValues[e.index],xLabel:I(t.xValues[e.index],e.index),index:e.index,points:[{seriesKey:e.seriesKey,seriesLabel:e.seriesLabel,color:e.color,value:e.yValue,formattedValue:L(e.yValue),datum:r[e.index]}]}):c(ke,{title:`${S.label??S.key} ${I(t.xValues[e.index],e.index)}`,points:[{seriesKey:e.seriesKey,seriesLabel:e.seriesLabel,color:e.color,value:e.yValue,formattedValue:L(e.yValue),datum:r[e.index]}]})}):null]})}function nt({data:d,series:m,x:r,y:R,height:S=280,width:M,size:w="md",grid:G="both",legend:x,tooltip:O=!0,tableView:E=!1,emphasis:$,title:D,description:T,loading:z=!1,emptyState:K,error:A=!1,errorState:q,onRetry:L,actions:I,onPointClick:B,bubble:W,trendLine:t=!1,quadrants:e,pointRadius:F=Me,overlay:H,legendToggle:j=!0,maxPoints:N,margin:o,locale:y,plotLabel:a,className:P,...V}){let i=ge(y),[l,h]=de(()=>new Set);m.length>oe&&!ee&&(ee=!0,console.warn(`[@synertech/ui] A ScatterChart was given ${m.length} series. Any two marks can sit side by side here, and only the first ${oe} palette slots stay tellable apart under that test: facet the chart instead.`));let p=U(()=>m.map((n,f)=>({...n,hidden:n.hidden||l.has(n.key),color:ve(n,f,$)})),[m,l,$]),b=U(()=>R?.format??(n=>le(n,i)),[R?.format,i]),X=U(()=>r.format??(n=>r.scale==="time"?Ae(n,i):le(Ke(n),i)),[r.format,r.scale,i]),Y=_(n=>{h(f=>{let v=new Set(f);return v.has(n)?v.delete(n):v.add(n),v})},[]),s=x===void 0?m.length>=2:x!==!1,u=typeof x=="string"?x:"bottom",C=p.filter(n=>!n.hidden).length;return c(ye,{title:D,description:T,height:S,width:M,size:w,loading:z,empty:d.length===0||C===0,emptyState:K,error:A,errorState:q,onRetry:L,actions:I,tableView:E,legendPosition:u,legend:s?c(xe,{items:Se(p,$),position:u,marker:"dot",size:w,onToggle:j?Y:void 0}):void 0,table:E?c(be,{data:d,series:p,xKey:r.key,xLabel:r.label??r.key,formatX:X,formatValue:b,caption:typeof D=="string"?D:void 0}):void 0,className:P,...V,children:({width:n})=>c(De,{width:n,height:S,data:d,resolvedSeries:p,x:r,y:R,grid:G,size:w,bubble:W,trendLine:t,quadrants:e,pointRadius:F,overlay:H,maxPoints:N,margin:o,tooltip:O,onPointClick:B,plotLabel:a,formatValue:b,formatX:X})})}function ot(){ee=!1}export{nt as ScatterChart,ot as resetScatterWarnings};
@@ -1 +1 @@
1
- "use strict";var m=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var R=(t,r)=>{for(var o in r)m(t,o,{get:r[o],enumerable:!0})},P=(t,r,o,a)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of N(r))!k.call(t,i)&&i!==o&&m(t,i,{get:()=>r[i],enumerable:!(a=D(r,i))||a.enumerable});return t};var L=t=>P(m({},"__esModule",{value:!0}),t);var j={};R(j,{StatCard:()=>Z});module.exports=L(j);var s=require("../../lib/cn.cjs"),d=require("../chart/utils/format.cjs"),h=require("../circular-progress/CircularProgress.cjs"),f=require("../sparkline/Sparkline.cjs"),e=require("react/jsx-runtime"),z={sm:"p-3",md:"p-4",lg:"p-5"},T={sm:"text-[11px]",md:"text-xs",lg:"text-sm"},W={sm:"text-xl",md:"text-2xl",lg:"text-3xl"},p={sm:{width:72,height:22},md:{width:96,height:28},lg:{width:120,height:34}};function A(t){return t.direction?t.direction:t.value>0?"up":t.value<0?"down":"flat"}function B(t,r){return t==="flat"||r==="neutral"?"text-gray-500 dark:text-gray-400":t===r?"text-green-700 dark:text-green-400":"text-red-600 dark:text-red-400"}function M({direction:t}){return t==="flat"?(0,e.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"currentColor","aria-hidden":"true",children:(0,e.jsx)("rect",{x:"1",y:"4.25",width:"8",height:"1.5",rx:"0.75"})}):(0,e.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"currentColor","aria-hidden":"true",children:(0,e.jsx)("path",{d:t==="up"?"M5 1 L9.5 8 L0.5 8 Z":"M5 9 L0.5 2 L9.5 2 Z"})})}function Z({label:t,value:r,format:o,delta:a,trend:i,trendColor:x,icon:c,size:n="md",loading:l=!1,variant:C="card",footer:u,className:v,...y}){let S=typeof r=="number"?(o??d.formatAuto)(r):r,g=a?A(a):"flat",b=a?(a.format??(w=>(0,d.formatPercent)(w,{signed:!0})))(a.value):null;return(0,e.jsxs)("div",{className:(0,s.cn)("flex flex-col gap-2",C==="card"&&(0,s.cn)("rounded-lg border border-gray-200 bg-white dark:border-gray-700 dark:bg-gray-800",z[n]),v),...y,children:[(0,e.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,e.jsx)("span",{className:(0,s.cn)("font-medium text-gray-500 dark:text-gray-400",T[n]),children:t}),c?(0,e.jsx)("span",{className:"shrink-0 text-gray-500 dark:text-gray-400",children:c}):null]}),(0,e.jsxs)("div",{className:"flex items-end justify-between gap-3",children:[(0,e.jsxs)("div",{className:"flex min-w-0 flex-col gap-1",children:[l?(0,e.jsx)("div",{className:"flex items-center",style:{height:n==="lg"?30:24},"aria-busy":"true","aria-live":"polite",children:(0,e.jsx)(h.CircularProgress,{indeterminate:!0,size:n==="lg"?"sm":"xs",thickness:"thin","aria-hidden":"true"})}):(0,e.jsx)("span",{className:(0,s.cn)("leading-none font-semibold text-gray-900 dark:text-gray-100",W[n]),children:S}),a&&!l?(0,e.jsxs)("span",{className:(0,s.cn)("flex items-center gap-1 text-xs font-medium",B(g,a.goodWhen??"up")),children:[(0,e.jsx)(M,{direction:g}),b,a.period?(0,e.jsx)("span",{className:"font-normal text-gray-500 dark:text-gray-400",children:a.period}):null]}):null]}),i&&i.length>0&&!l?(0,e.jsx)(f.Sparkline,{data:i,color:x,emphasizeLast:!0,area:!0,width:p[n].width,height:p[n].height,className:"shrink-0"}):null]}),u?(0,e.jsx)("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:u}):null]})}0&&(module.exports={StatCard});
1
+ "use strict";var g=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var L=(t,r)=>{for(var i in r)g(t,i,{get:r[i],enumerable:!0})},z=(t,r,i,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of R(r))!P.call(t,a)&&a!==i&&g(t,a,{get:()=>r[a],enumerable:!(s=k(r,a))||s.enumerable});return t};var T=t=>z(g({},"__esModule",{value:!0}),t);var V={};L(V,{StatCard:()=>O});module.exports=T(V);var o=require("../../lib/cn.cjs"),l=require("../chart/utils/format.cjs"),v=require("../circular-progress/CircularProgress.cjs"),y=require("../sparkline/Sparkline.cjs"),e=require("react/jsx-runtime"),W={sm:"p-3",md:"p-4",lg:"p-5"},A={sm:"text-[11px]",md:"text-xs",lg:"text-sm"},B={sm:"text-xl",md:"text-2xl",lg:"text-3xl"},C={sm:{width:72,height:22},md:{width:96,height:28},lg:{width:120,height:34}};function M(t,r,i){return t.direction?t.direction:r===i?"flat":t.value>0?"up":t.value<0?"down":"flat"}function Z(t,r){return t==="flat"||r==="neutral"?"text-gray-500 dark:text-gray-400":t===r?"text-green-700 dark:text-green-400":"text-red-600 dark:text-red-400"}function j({direction:t}){return t==="flat"?(0,e.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"currentColor","aria-hidden":"true",children:(0,e.jsx)("rect",{x:"1",y:"4.25",width:"8",height:"1.5",rx:"0.75"})}):(0,e.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"currentColor","aria-hidden":"true",children:(0,e.jsx)("path",{d:t==="up"?"M5 1 L9.5 8 L0.5 8 Z":"M5 9 L0.5 2 L9.5 2 Z"})})}function O({label:t,value:r,format:i,locale:s,delta:a,trend:d,trendColor:S,icon:p,size:n="md",loading:m=!1,variant:b="card",footer:f,className:D,...w}){let N=typeof r=="number"?(i??(u=>(0,l.formatAuto)(u,s)))(r):r,h=a?.format??(u=>(0,l.formatPercent)(u,{locale:s,signed:!0})),c=a?h(a.value):null,x=a&&c!==null?M(a,c,h(0)):"flat";return(0,e.jsxs)("div",{className:(0,o.cn)("flex flex-col gap-2",b==="card"&&(0,o.cn)("rounded-lg border border-gray-200 bg-white dark:border-gray-700 dark:bg-gray-800",W[n]),D),...w,children:[(0,e.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,e.jsx)("span",{className:(0,o.cn)("font-medium text-gray-500 dark:text-gray-400",A[n]),children:t}),p?(0,e.jsx)("span",{className:"shrink-0 text-gray-500 dark:text-gray-400",children:p}):null]}),(0,e.jsxs)("div",{className:"flex items-end justify-between gap-3",children:[(0,e.jsxs)("div",{className:"flex min-w-0 flex-col gap-1",children:[m?(0,e.jsx)("div",{className:"flex items-center",style:{height:n==="lg"?30:24},"aria-busy":"true","aria-live":"polite",children:(0,e.jsx)(v.CircularProgress,{indeterminate:!0,size:n==="lg"?"sm":"xs",thickness:"thin","aria-hidden":"true"})}):(0,e.jsx)("span",{className:(0,o.cn)("leading-none font-semibold text-gray-900 dark:text-gray-100",B[n]),children:N}),a&&!m?(0,e.jsxs)("span",{className:(0,o.cn)("flex items-center gap-1 text-xs font-medium",Z(x,a.goodWhen??"up")),children:[(0,e.jsx)(j,{direction:x}),c,a.period?(0,e.jsx)("span",{className:"font-normal text-gray-500 dark:text-gray-400",children:a.period}):null]}):null]}),d&&d.length>0&&!m?(0,e.jsx)(y.Sparkline,{data:d,color:S,emphasizeLast:!0,area:!0,width:C[n].width,height:C[n].height,className:"shrink-0"}):null]}),f?(0,e.jsx)("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:f}):null]})}0&&(module.exports={StatCard});
@@ -1 +1 @@
1
- import{cn as n}from"../../lib/cn.js";import{formatAuto as S,formatPercent as b}from"../chart/utils/format.js";import{CircularProgress as w}from"../circular-progress/CircularProgress.js";import{Sparkline as D}from"../sparkline/Sparkline.js";import{jsx as t,jsxs as o}from"react/jsx-runtime";var N={sm:"p-3",md:"p-4",lg:"p-5"},k={sm:"text-[11px]",md:"text-xs",lg:"text-sm"},R={sm:"text-xl",md:"text-2xl",lg:"text-3xl"},u={sm:{width:72,height:22},md:{width:96,height:28},lg:{width:120,height:34}};function P(e){return e.direction?e.direction:e.value>0?"up":e.value<0?"down":"flat"}function L(e,i){return e==="flat"||i==="neutral"?"text-gray-500 dark:text-gray-400":e===i?"text-green-700 dark:text-green-400":"text-red-600 dark:text-red-400"}function z({direction:e}){return e==="flat"?t("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"currentColor","aria-hidden":"true",children:t("rect",{x:"1",y:"4.25",width:"8",height:"1.5",rx:"0.75"})}):t("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"currentColor","aria-hidden":"true",children:t("path",{d:e==="up"?"M5 1 L9.5 8 L0.5 8 Z":"M5 9 L0.5 2 L9.5 2 Z"})})}function M({label:e,value:i,format:g,delta:r,trend:s,trendColor:p,icon:l,size:a="md",loading:d=!1,variant:h="card",footer:m,className:f,...x}){let C=typeof i=="number"?(g??S)(i):i,c=r?P(r):"flat",v=r?(r.format??(y=>b(y,{signed:!0})))(r.value):null;return o("div",{className:n("flex flex-col gap-2",h==="card"&&n("rounded-lg border border-gray-200 bg-white dark:border-gray-700 dark:bg-gray-800",N[a]),f),...x,children:[o("div",{className:"flex items-start justify-between gap-2",children:[t("span",{className:n("font-medium text-gray-500 dark:text-gray-400",k[a]),children:e}),l?t("span",{className:"shrink-0 text-gray-500 dark:text-gray-400",children:l}):null]}),o("div",{className:"flex items-end justify-between gap-3",children:[o("div",{className:"flex min-w-0 flex-col gap-1",children:[d?t("div",{className:"flex items-center",style:{height:a==="lg"?30:24},"aria-busy":"true","aria-live":"polite",children:t(w,{indeterminate:!0,size:a==="lg"?"sm":"xs",thickness:"thin","aria-hidden":"true"})}):t("span",{className:n("leading-none font-semibold text-gray-900 dark:text-gray-100",R[a]),children:C}),r&&!d?o("span",{className:n("flex items-center gap-1 text-xs font-medium",L(c,r.goodWhen??"up")),children:[t(z,{direction:c}),v,r.period?t("span",{className:"font-normal text-gray-500 dark:text-gray-400",children:r.period}):null]}):null]}),s&&s.length>0&&!d?t(D,{data:s,color:p,emphasizeLast:!0,area:!0,width:u[a].width,height:u[a].height,className:"shrink-0"}):null]}),m?t("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:m}):null]})}export{M as StatCard};
1
+ import{cn as n}from"../../lib/cn.js";import{formatAuto as D,formatPercent as w}from"../chart/utils/format.js";import{CircularProgress as N}from"../circular-progress/CircularProgress.js";import{Sparkline as k}from"../sparkline/Sparkline.js";import{jsx as t,jsxs as o}from"react/jsx-runtime";var R={sm:"p-3",md:"p-4",lg:"p-5"},P={sm:"text-[11px]",md:"text-xs",lg:"text-sm"},L={sm:"text-xl",md:"text-2xl",lg:"text-3xl"},x={sm:{width:72,height:22},md:{width:96,height:28},lg:{width:120,height:34}};function z(e,a,s){return e.direction?e.direction:a===s?"flat":e.value>0?"up":e.value<0?"down":"flat"}function T(e,a){return e==="flat"||a==="neutral"?"text-gray-500 dark:text-gray-400":e===a?"text-green-700 dark:text-green-400":"text-red-600 dark:text-red-400"}function W({direction:e}){return e==="flat"?t("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"currentColor","aria-hidden":"true",children:t("rect",{x:"1",y:"4.25",width:"8",height:"1.5",rx:"0.75"})}):t("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"currentColor","aria-hidden":"true",children:t("path",{d:e==="up"?"M5 1 L9.5 8 L0.5 8 Z":"M5 9 L0.5 2 L9.5 2 Z"})})}function j({label:e,value:a,format:s,locale:u,delta:r,trend:l,trendColor:C,icon:g,size:i="md",loading:d=!1,variant:v="card",footer:p,className:y,...S}){let b=typeof a=="number"?(s??(c=>D(c,u)))(a):a,f=r?.format??(c=>w(c,{locale:u,signed:!0})),m=r?f(r.value):null,h=r&&m!==null?z(r,m,f(0)):"flat";return o("div",{className:n("flex flex-col gap-2",v==="card"&&n("rounded-lg border border-gray-200 bg-white dark:border-gray-700 dark:bg-gray-800",R[i]),y),...S,children:[o("div",{className:"flex items-start justify-between gap-2",children:[t("span",{className:n("font-medium text-gray-500 dark:text-gray-400",P[i]),children:e}),g?t("span",{className:"shrink-0 text-gray-500 dark:text-gray-400",children:g}):null]}),o("div",{className:"flex items-end justify-between gap-3",children:[o("div",{className:"flex min-w-0 flex-col gap-1",children:[d?t("div",{className:"flex items-center",style:{height:i==="lg"?30:24},"aria-busy":"true","aria-live":"polite",children:t(N,{indeterminate:!0,size:i==="lg"?"sm":"xs",thickness:"thin","aria-hidden":"true"})}):t("span",{className:n("leading-none font-semibold text-gray-900 dark:text-gray-100",L[i]),children:b}),r&&!d?o("span",{className:n("flex items-center gap-1 text-xs font-medium",T(h,r.goodWhen??"up")),children:[t(W,{direction:h}),m,r.period?t("span",{className:"font-normal text-gray-500 dark:text-gray-400",children:r.period}):null]}):null]}),l&&l.length>0&&!d?t(k,{data:l,color:C,emphasizeLast:!0,area:!0,width:x[i].width,height:x[i].height,className:"shrink-0"}):null]}),p?t("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:p}):null]})}export{j as StatCard};
@@ -1 +1 @@
1
- "use strict";"use client";var se=Object.defineProperty;var Re=Object.getOwnPropertyDescriptor;var Se=Object.getOwnPropertyNames;var We=Object.prototype.hasOwnProperty;var Le=(c,a)=>{for(var i in a)se(c,i,{get:a[i],enumerable:!0})},Ee=(c,a,i,r)=>{if(a&&typeof a=="object"||typeof a=="function")for(let d of Se(a))!We.call(c,d)&&d!==i&&se(c,d,{get:()=>a[d],enumerable:!(r=Re(a,d))||r.enumerable});return c};var Pe=c=>Ee(se({},"__esModule",{value:!0}),c);var Be={};Le(Be,{WaterfallChart:()=>Me});module.exports=Pe(Be);var u=require("react"),me=require("../../lib/i18n.cjs"),ce=require("../chart/ChartAxis.cjs"),ue=require("../chart/ChartContainer.cjs"),ge=require("../chart/ChartGrid.cjs"),he=require("../chart/ChartLegend.cjs"),fe=require("../chart/ChartTableView.cjs"),ye=require("../chart/ChartTooltip.cjs"),V=require("../chart/palette.cjs"),be=require("../chart/utils/cartesian.cjs"),re=require("../chart/utils/data.cjs"),ne=require("../chart/utils/format.cjs"),Ce=require("../chart/utils/keyboard.cjs"),pe=require("../chart/utils/path.cjs"),ve=require("../chart/utils/scales.cjs"),ke=require("../chart/utils/text.cjs"),xe=require("../chart/utils/touch.cjs"),t=require("react/jsx-runtime"),Ve=24,Te=4,K=6,Ne=(0,V.rampColor)(V.CHART_DIVERGING_COLORS,1),we=(0,V.rampColor)(V.CHART_DIVERGING_COLORS,0),Ae=(0,u.memo)(function({bars:a,connectors:i}){return(0,t.jsxs)("g",{children:[(0,t.jsx)("g",{className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1,shapeRendering:"crispEdges","aria-hidden":"true",children:i.map(r=>(0,t.jsx)("line",{x1:r.x1,y1:r.y1,x2:r.x2,y2:r.y2},r.key))}),a.map(r=>(0,t.jsxs)("g",{children:[(0,t.jsx)("path",{d:r.d,fill:r.color}),r.label?(0,t.jsx)("text",{x:r.label.x,y:r.label.y,textAnchor:r.label.anchor,dominantBaseline:"middle",className:"fill-gray-600 text-[10px] [font-variant-numeric:tabular-nums] dark:fill-gray-300",children:r.label.text}):null]},r.key))]})});function Ie({width:c,height:a,steps:i,data:r,x:d,y:v,grid:I,size:F,orientation:O,connectors:J,showValues:T,barSize:H,palette:$,margin:M,tooltip:N,plotLabel:B,totalLabel:le,formatValue:G,formatX:_,onStepClick:w}){let[z,D]=(0,u.useState)(null),g=z!==null&&z<i.length?z:null,e=(0,u.useMemo)(()=>{let s=O==="vertical",S=i.flatMap(n=>[n.start,n.end]),C=(0,be.buildCartesianGeometry)({width:c,height:a,data:r,x:d,y:v,bounds:S.length===0?null:[Math.min(...S),Math.max(...S)],margin:M,orientation:O,placement:"band",formatValue:G,formatX:_,defaultIncludeZero:!0}),{valueScale:k,bandwidth:W,categoryPositions:Z,innerWidth:Q,innerHeight:ee}=C,L=k(0),m=Math.min(H??Ve,W),E=[],x=[];return i.forEach((n,b)=>{let P=Z[b]+(W-m)/2,te=k(n.start),ae=k(n.end),j=Math.min(te,ae),l=Math.abs(ae-te),h=n.end>=n.start,A=s?h?"top":"bottom":h?"right":"left",X=s?{x:P,y:j,width:m,height:l}:{x:j,y:P,width:l,height:m},f=null;if(T&&n.value!==null){let p=n.kind==="total"?n.formattedEnd:n.formattedValue,R=(0,ke.estimateTextWidth)(p,10),y=k(h?Math.max(n.start,n.end):Math.min(n.start,n.end));if(s){let q=h?y-K:y+K;R<=W&&q>8&&q<ee-4&&(f={x:P+m/2,y:q,anchor:"middle",text:p})}else{let q=h?Q-y-K:y-K;R<=q&&(f={x:h?y+K:y-K,y:P+m/2,anchor:h?"start":"end",text:p})}}E.push({key:`${b}`,color:$[n.kind],d:(0,pe.buildBarPath)({...X,radius:Te,round:A}),label:f});let de=i[b+1];if(J&&de){let p=k(n.end),R=Z[b+1]+(W-m)/2;x.push(s?{key:`${b}`,x1:P+m,y1:p,x2:R,y2:p}:{key:`${b}`,x1:p,y1:P+m,x2:p,y2:R})}}),{vertical:s,bars:E,rules:x,baseline:L,bandwidth:W,categoryPositions:Z,categoryCenters:C.categoryCenters,categoryTicks:C.categoryTicks,valueTicks:C.valueTicks,valueScale:k,innerWidth:Q,innerHeight:ee,margin:C.margin}},[i,r,d,v,c,a,M,O,J,T,H,$,G,_]),ie=(0,u.useCallback)(s=>{if(N===!1||i.length===0)return;let S=s.currentTarget.getBoundingClientRect(),C=e.vertical?s.clientX-S.left-e.margin.left:s.clientY-S.top-e.margin.top;D((0,ve.nearestIndex)(e.categoryCenters,C))},[N,i.length,e.vertical,e.margin,e.categoryCenters]),U=(0,u.useCallback)(()=>{!w||g===null||w(i[g])},[w,g,i]),oe=(0,u.useCallback)(s=>(0,Ce.handleChartKeyDown)(s,{count:i.length,current:g,axis:e.vertical?"x":"y",onMove:D,pick:w?U:null}),[i.length,g,e.vertical,w,U]),o=g===null?null:i[g],Y=g===null||o===void 0||o===null?null:e.vertical?{x:e.margin.left+e.categoryCenters[g],y:e.margin.top+Math.min(e.valueScale(o.start),e.valueScale(o.end))}:{x:e.margin.left+Math.max(e.valueScale(o.start),e.valueScale(o.end)),y:e.margin.top+e.categoryCenters[g]};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("svg",{width:c,height:a,role:"img","aria-label":B??i.map(s=>s.label).join(", "),tabIndex:0,className:`${xe.CHART_TOUCH} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500`,onPointerMove:ie,onPointerLeave:()=>D(null),onKeyDown:oe,onBlur:()=>D(null),onClick:U,children:[(0,t.jsxs)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[(0,t.jsx)(ge.ChartGrid,{width:e.innerWidth,height:e.innerHeight,horizontal:e.vertical&&(I==="y"||I==="both")?e.valueTicks.map(s=>s.offset):void 0,vertical:!e.vertical&&(I==="y"||I==="both")?e.valueTicks.map(s=>s.offset):void 0}),g!==null?(0,t.jsx)("rect",{x:e.vertical?e.categoryPositions[g]:0,y:e.vertical?0:e.categoryPositions[g],width:e.vertical?e.bandwidth:e.innerWidth,height:e.vertical?e.innerHeight:e.bandwidth,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,(0,t.jsx)(Ae,{bars:e.bars,connectors:e.rules}),(0,t.jsx)("line",{x1:e.vertical?0:e.baseline,y1:e.vertical?e.baseline:0,x2:e.vertical?e.innerWidth:e.baseline,y2:e.vertical?e.baseline:e.innerHeight,className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1,shapeRendering:"crispEdges"})]}),(0,t.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:(e.vertical?d.hidden:v?.hidden)?null:(0,t.jsx)(ce.ChartAxis,{orientation:"bottom",ticks:e.vertical?e.categoryTicks:e.valueTicks,length:e.innerWidth,label:e.vertical?d.label:v?.label,size:F})}),(0,t.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:(e.vertical?v?.hidden:d.hidden)?null:(0,t.jsx)(ce.ChartAxis,{orientation:"left",ticks:e.vertical?e.valueTicks:e.categoryTicks,length:e.innerHeight,showLine:!1,label:e.vertical?v?.label:d.label,size:F})})]}),o&&Y&&N!==!1?(0,t.jsx)(ye.ChartTooltip,{x:Y.x,y:Y.y,containerWidth:c,children:typeof N=="function"?N(o):(0,t.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,t.jsx)("div",{className:"font-medium text-gray-900 dark:text-gray-100",children:o.label}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:"h-2.5 w-2.5 shrink-0 rounded-sm",style:{backgroundColor:$[o.kind]},"aria-hidden":"true"}),(0,t.jsx)("span",{className:"font-semibold text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:o.kind==="total"?o.formattedEnd:o.formattedValue})]}),o.kind==="total"?null:(0,t.jsxs)("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[(0,t.jsx)("span",{children:le}),(0,t.jsx)("span",{className:"[font-variant-numeric:tabular-nums]",children:o.formattedEnd})]})]})}):null]})}function Me({data:c,x:a,y:i,value:r,total:d,start:v=0,orientation:I="vertical",connectors:F=!0,showValues:O=!0,barSize:J,colors:T,height:H=280,width:$,size:M="md",grid:N="y",legend:B,tooltip:le=!0,tableView:G=!1,title:_,description:w,loading:z=!1,emptyState:D,error:g=!1,errorState:e,onRetry:ie,actions:U,margin:oe,locale:o,plotLabel:Y,valueLabel:s,totalLabel:S,increaseLabel:C,decreaseLabel:k,format:W,onStepClick:Z,className:Q,...ee}){let L=(0,me.useUILabels)(),m=(0,u.useMemo)(()=>W??(l=>(0,ne.formatAuto)(l,o)),[W,o]),E=(0,u.useMemo)(()=>a.format??(l=>(0,ne.formatXValue)(l,o)),[a.format,o]),x=(0,u.useMemo)(()=>{let l=v;return c.map((h,A)=>{let X=(0,re.readXValue)(h,a.key,A),f=(0,re.readNumber)(h,r);if(d?!!h[d]:!1){let y=f??l;return l=y,{index:A,x:X,label:E(X,A),value:y,start:0,end:y,kind:"total",formattedValue:m(y),formattedEnd:m(y),datum:h}}let p=l,R=f===null?l:l+f;return l=R,{index:A,x:X,label:E(X,A),value:f,start:p,end:R,kind:f!==null&&f<0?"decrease":"increase",formattedValue:f===null?"\u2014":`${f>0?"+":""}${m(f)}`,formattedEnd:m(R),datum:h}})},[c,a.key,r,d,v,m,E]),n=(0,u.useMemo)(()=>({increase:T?.increase??Ne,decrease:T?.decrease??we,total:T?.total??V.CHART_MUTED_COLOR}),[T]),b=S??L.chartRunningTotal,P=(0,u.useMemo)(()=>{let l=[{key:"increase",label:C??L.chartIncrease,color:n.increase,marker:"rect"},{key:"decrease",label:k??L.chartDecrease,color:n.decrease,marker:"rect"}];return x.some(h=>h.kind==="total")&&l.push({key:"total",label:b,color:n.total,marker:"rect"}),l},[n,x,C,k,b,L.chartIncrease,L.chartDecrease]),te=(0,u.useMemo)(()=>x.map(l=>({[a.key]:l.x,[r]:l.kind==="total"?null:l.value,__running:l.end})),[x,a.key,r]),ae=B===void 0?!0:B!==!1,j=typeof B=="string"?B:"bottom";return(0,t.jsx)(ue.ChartContainer,{title:_,description:w,height:H,width:$,size:M,loading:z,empty:x.length===0,emptyState:D,error:g,errorState:e,onRetry:ie,actions:U,tableView:G,legendPosition:j,legend:ae?(0,t.jsx)(he.ChartLegend,{items:P,position:j,marker:"rect",size:M}):void 0,table:G?(0,t.jsx)(fe.ChartTableView,{data:te,series:[{key:r,label:s??L.chartValue},{key:"__running",label:b}],xKey:a.key,xLabel:a.label??a.key,formatX:E,formatValue:m,caption:typeof _=="string"?_:void 0}):void 0,className:Q,...ee,children:({width:l})=>(0,t.jsx)(Ie,{width:l,height:H,steps:x,data:c,x:a,y:i,grid:N,size:M,orientation:I,connectors:F,showValues:O,barSize:J,palette:n,margin:oe,tooltip:le,plotLabel:Y,totalLabel:b,formatValue:m,formatX:E,onStepClick:Z})})}0&&(module.exports={WaterfallChart});
1
+ "use strict";"use client";var de=Object.defineProperty;var Re=Object.getOwnPropertyDescriptor;var Se=Object.getOwnPropertyNames;var Le=Object.prototype.hasOwnProperty;var We=(s,r)=>{for(var o in r)de(s,o,{get:r[o],enumerable:!0})},Ee=(s,r,o,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let d of Se(r))!Le.call(s,d)&&d!==o&&de(s,d,{get:()=>r[d],enumerable:!(n=Re(r,d))||n.enumerable});return s};var Pe=s=>Ee(de({},"__esModule",{value:!0}),s);var Be={};We(Be,{WaterfallChart:()=>Me});module.exports=Pe(Be);var m=require("react"),ne=require("../../lib/i18n.cjs"),me=require("../chart/ChartAxis.cjs"),ue=require("../chart/ChartContainer.cjs"),ge=require("../chart/ChartGrid.cjs"),he=require("../chart/ChartLegend.cjs"),fe=require("../chart/ChartTableView.cjs"),ye=require("../chart/ChartTooltip.cjs"),V=require("../chart/palette.cjs"),be=require("../chart/utils/cartesian.cjs"),le=require("../chart/utils/data.cjs"),oe=require("../chart/utils/format.cjs"),Ce=require("../chart/utils/keyboard.cjs"),pe=require("../chart/utils/path.cjs"),ve=require("../chart/utils/scales.cjs"),ke=require("../chart/utils/text.cjs"),xe=require("../chart/utils/touch.cjs"),t=require("react/jsx-runtime"),Ve=24,Te=4,O=6,Ne=(0,V.rampColor)(V.CHART_DIVERGING_COLORS,1),we=(0,V.rampColor)(V.CHART_DIVERGING_COLORS,0),Ae=(0,m.memo)(function({bars:r,connectors:o}){return(0,t.jsxs)("g",{children:[(0,t.jsx)("g",{className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1,shapeRendering:"crispEdges","aria-hidden":"true",children:o.map(n=>(0,t.jsx)("line",{x1:n.x1,y1:n.y1,x2:n.x2,y2:n.y2},n.key))}),r.map(n=>(0,t.jsxs)("g",{children:[(0,t.jsx)("path",{d:n.d,fill:n.color}),n.label?(0,t.jsx)("text",{x:n.label.x,y:n.label.y,textAnchor:n.label.anchor,dominantBaseline:"middle",className:"fill-gray-600 text-[10px] [font-variant-numeric:tabular-nums] dark:fill-gray-300",children:n.label.text}):null]},n.key))]})});function Ie({width:s,height:r,steps:o,data:n,x:d,y:k,grid:M,size:F,orientation:H,connectors:J,showValues:T,barSize:$,palette:G,margin:B,tooltip:N,plotLabel:_,totalLabel:ie,formatValue:z,formatX:D,onStepClick:w}){let[U,X]=(0,m.useState)(null),u=U!==null&&U<o.length?U:null,e=(0,m.useMemo)(()=>{let i=H==="vertical",L=o.flatMap(l=>[l.start,l.end]),C=(0,be.buildCartesianGeometry)({width:s,height:r,data:n,x:d,y:k,bounds:L.length===0?null:[Math.min(...L),Math.max(...L)],margin:B,orientation:H,placement:"band",formatValue:z,formatX:D,defaultIncludeZero:!0}),{valueScale:x,bandwidth:W,categoryPositions:j,innerWidth:Q,innerHeight:ee}=C,K=x(0),g=Math.min($??Ve,W),p=[],E=[];return o.forEach((l,h)=>{let f=j[h]+(W-g)/2,te=x(l.start),ae=x(l.end),re=Math.min(te,ae),q=Math.abs(ae-te),a=l.end>=l.start,R=i?a?"top":"bottom":a?"right":"left",A=i?{x:f,y:re,width:g,height:q}:{x:re,y:f,width:q,height:g},P=null;if(T&&l.value!==null){let S=l.kind==="total"?l.formattedEnd:l.formattedValue,I=(0,ke.estimateTextWidth)(S,10),v=x(a?Math.max(l.start,l.end):Math.min(l.start,l.end));if(i){let b=a?v-O:v+O;I<=W&&b>8&&b<ee-4&&(P={x:f+g/2,y:b,anchor:"middle",text:S})}else{let b=a?Q-v-O:v-O;I<=b&&(P={x:a?v+O:v-O,y:f+g/2,anchor:a?"start":"end",text:S})}}p.push({key:`${h}`,color:G[l.kind],d:(0,pe.buildBarPath)({...A,radius:Te,round:R}),label:P});let y=o[h+1];if(J&&y){let S=x(l.end),I=j[h+1]+(W-g)/2;E.push(i?{key:`${h}`,x1:f+g,y1:S,x2:I,y2:S}:{key:`${h}`,x1:S,y1:f+g,x2:S,y2:I})}}),{vertical:i,bars:p,rules:E,baseline:K,bandwidth:W,categoryPositions:j,categoryCenters:C.categoryCenters,categoryTicks:C.categoryTicks,valueTicks:C.valueTicks,valueScale:x,innerWidth:Q,innerHeight:ee,margin:C.margin}},[o,n,d,k,s,r,B,H,J,T,$,G,z,D]),se=(0,m.useCallback)(i=>{if(N===!1||o.length===0)return;let L=i.currentTarget.getBoundingClientRect(),C=e.vertical?i.clientX-L.left-e.margin.left:i.clientY-L.top-e.margin.top;X((0,ve.nearestIndex)(e.categoryCenters,C))},[N,o.length,e.vertical,e.margin,e.categoryCenters]),Y=(0,m.useCallback)(()=>{!w||u===null||w(o[u])},[w,u,o]),ce=(0,m.useCallback)(i=>(0,Ce.handleChartKeyDown)(i,{count:o.length,current:u,axis:e.vertical?"x":"y",onMove:X,pick:w?Y:null}),[o.length,u,e.vertical,w,Y]),c=u===null?null:o[u],Z=u===null||c===void 0||c===null?null:e.vertical?{x:e.margin.left+e.categoryCenters[u],y:e.margin.top+Math.min(e.valueScale(c.start),e.valueScale(c.end))}:{x:e.margin.left+Math.max(e.valueScale(c.start),e.valueScale(c.end)),y:e.margin.top+e.categoryCenters[u]};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("svg",{width:s,height:r,role:"img","aria-label":_??o.map(i=>i.label).join(", "),tabIndex:0,className:`${xe.CHART_TOUCH} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500`,onPointerMove:se,onPointerLeave:()=>X(null),onKeyDown:ce,onBlur:()=>X(null),onClick:Y,children:[(0,t.jsxs)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[(0,t.jsx)(ge.ChartGrid,{width:e.innerWidth,height:e.innerHeight,horizontal:e.vertical&&(M==="y"||M==="both")?e.valueTicks.map(i=>i.offset):void 0,vertical:!e.vertical&&(M==="y"||M==="both")?e.valueTicks.map(i=>i.offset):void 0}),u!==null?(0,t.jsx)("rect",{x:e.vertical?e.categoryPositions[u]:0,y:e.vertical?0:e.categoryPositions[u],width:e.vertical?e.bandwidth:e.innerWidth,height:e.vertical?e.innerHeight:e.bandwidth,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,(0,t.jsx)(Ae,{bars:e.bars,connectors:e.rules}),(0,t.jsx)("line",{x1:e.vertical?0:e.baseline,y1:e.vertical?e.baseline:0,x2:e.vertical?e.innerWidth:e.baseline,y2:e.vertical?e.baseline:e.innerHeight,className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1,shapeRendering:"crispEdges"})]}),(0,t.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:(e.vertical?d.hidden:k?.hidden)?null:(0,t.jsx)(me.ChartAxis,{orientation:"bottom",ticks:e.vertical?e.categoryTicks:e.valueTicks,length:e.innerWidth,label:e.vertical?d.label:k?.label,size:F})}),(0,t.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:(e.vertical?k?.hidden:d.hidden)?null:(0,t.jsx)(me.ChartAxis,{orientation:"left",ticks:e.vertical?e.valueTicks:e.categoryTicks,length:e.innerHeight,showLine:!1,label:e.vertical?k?.label:d.label,size:F})})]}),c&&Z&&N!==!1?(0,t.jsx)(ye.ChartTooltip,{x:Z.x,y:Z.y,containerWidth:s,children:typeof N=="function"?N(c):(0,t.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,t.jsx)("div",{className:"font-medium text-gray-900 dark:text-gray-100",children:c.label}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:"h-2.5 w-2.5 shrink-0 rounded-sm",style:{backgroundColor:G[c.kind]},"aria-hidden":"true"}),(0,t.jsx)("span",{className:"font-semibold text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:c.kind==="total"?c.formattedEnd:c.formattedValue})]}),c.kind==="total"?null:(0,t.jsxs)("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[(0,t.jsx)("span",{children:ie}),(0,t.jsx)("span",{className:"[font-variant-numeric:tabular-nums]",children:c.formattedEnd})]})]})}):null]})}function Me({data:s,x:r,y:o,value:n,total:d,start:k=0,orientation:M="vertical",connectors:F=!0,showValues:H=!0,barSize:J,colors:T,height:$=280,width:G,size:B="md",grid:N="y",legend:_,tooltip:ie=!0,tableView:z=!1,title:D,description:w,loading:U=!1,emptyState:X,error:u=!1,errorState:e,onRetry:se,actions:Y,margin:ce,locale:c,plotLabel:Z,valueLabel:i,totalLabel:L,increaseLabel:C,decreaseLabel:x,format:W,onStepClick:j,className:Q,...ee}){let K=(0,ne.useUILocale)(c),g=(0,ne.useUILabels)(),p=(0,m.useMemo)(()=>W??(a=>(0,oe.formatAuto)(a,K)),[W,K]),E=(0,m.useMemo)(()=>r.format??(a=>(0,oe.formatXValue)(a,K)),[r.format,K]),l=(0,m.useMemo)(()=>{let a=k;return s.map((R,A)=>{let P=(0,le.readXValue)(R,r.key,A),y=(0,le.readNumber)(R,n);if(d?!!R[d]:!1){let b=y??a;return a=b,{index:A,x:P,label:E(P,A),value:b,start:0,end:b,kind:"total",formattedValue:p(b),formattedEnd:p(b),datum:R}}let I=a,v=y===null?a:a+y;return a=v,{index:A,x:P,label:E(P,A),value:y,start:I,end:v,kind:y!==null&&y<0?"decrease":"increase",formattedValue:y===null?"\u2014":`${y>0?"+":""}${p(y)}`,formattedEnd:p(v),datum:R}})},[s,r.key,n,d,k,p,E]),h=(0,m.useMemo)(()=>({increase:T?.increase??Ne,decrease:T?.decrease??we,total:T?.total??V.CHART_MUTED_COLOR}),[T]),f=L??g.chartRunningTotal,te=(0,m.useMemo)(()=>{let a=[{key:"increase",label:C??g.chartIncrease,color:h.increase,marker:"rect"},{key:"decrease",label:x??g.chartDecrease,color:h.decrease,marker:"rect"}];return l.some(R=>R.kind==="total")&&a.push({key:"total",label:f,color:h.total,marker:"rect"}),a},[h,l,C,x,f,g.chartIncrease,g.chartDecrease]),ae=(0,m.useMemo)(()=>l.map(a=>({[r.key]:a.x,[n]:a.kind==="total"?null:a.value,__running:a.end})),[l,r.key,n]),re=_===void 0?!0:_!==!1,q=typeof _=="string"?_:"bottom";return(0,t.jsx)(ue.ChartContainer,{title:D,description:w,height:$,width:G,size:B,loading:U,empty:l.length===0,emptyState:X,error:u,errorState:e,onRetry:se,actions:Y,tableView:z,legendPosition:q,legend:re?(0,t.jsx)(he.ChartLegend,{items:te,position:q,marker:"rect",size:B}):void 0,table:z?(0,t.jsx)(fe.ChartTableView,{data:ae,series:[{key:n,label:i??g.chartValue},{key:"__running",label:f}],xKey:r.key,xLabel:r.label??r.key,formatX:E,formatValue:p,caption:typeof D=="string"?D:void 0}):void 0,className:Q,...ee,children:({width:a})=>(0,t.jsx)(Ie,{width:a,height:$,steps:l,data:s,x:r,y:o,grid:N,size:B,orientation:M,connectors:F,showValues:H,barSize:J,palette:h,margin:ce,tooltip:ie,plotLabel:Z,totalLabel:f,formatValue:p,formatX:E,onStepClick:j})})}0&&(module.exports={WaterfallChart});
@@ -1 +1 @@
1
- "use client";import{memo as me,useCallback as ie,useMemo as A,useState as ue}from"react";import{useUILabels as ge}from"../../lib/i18n.js";import{ChartAxis as se}from"../chart/ChartAxis.js";import{ChartContainer as he}from"../chart/ChartContainer.js";import{ChartGrid as fe}from"../chart/ChartGrid.js";import{ChartLegend as ye}from"../chart/ChartLegend.js";import{ChartTableView as be}from"../chart/ChartTableView.js";import{ChartTooltip as Ce}from"../chart/ChartTooltip.js";import{CHART_DIVERGING_COLORS as ce,CHART_MUTED_COLOR as pe,rampColor as de}from"../chart/palette.js";import{buildCartesianGeometry as ve}from"../chart/utils/cartesian.js";import{readNumber as ke,readXValue as xe}from"../chart/utils/data.js";import{formatAuto as Re,formatXValue as Se}from"../chart/utils/format.js";import{handleChartKeyDown as We}from"../chart/utils/keyboard.js";import{buildBarPath as Le}from"../chart/utils/path.js";import{nearestIndex as Ee}from"../chart/utils/scales.js";import{estimateTextWidth as Pe}from"../chart/utils/text.js";import{CHART_TOUCH as Ve}from"../chart/utils/touch.js";import{Fragment as Be,jsx as n,jsxs as P}from"react/jsx-runtime";var Te=24,Ne=4,K=6,we=de(ce,1),Ae=de(ce,0),Ie=me(function({bars:s,connectors:o}){return P("g",{children:[n("g",{className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1,shapeRendering:"crispEdges","aria-hidden":"true",children:o.map(t=>n("line",{x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2},t.key))}),s.map(t=>P("g",{children:[n("path",{d:t.d,fill:t.color}),t.label?n("text",{x:t.label.x,y:t.label.y,textAnchor:t.label.anchor,dominantBaseline:"middle",className:"fill-gray-600 text-[10px] [font-variant-numeric:tabular-nums] dark:fill-gray-300",children:t.label.text}):null]},t.key))]})});function Me({width:C,height:s,steps:o,data:t,x:f,y:p,grid:I,size:F,orientation:O,connectors:J,showValues:V,barSize:H,palette:$,margin:M,tooltip:T,plotLabel:B,totalLabel:re,formatValue:G,formatX:_,onStepClick:N}){let[z,D]=ue(null),d=z!==null&&z<o.length?z:null,e=A(()=>{let i=O==="vertical",R=o.flatMap(a=>[a.start,a.end]),y=ve({width:C,height:s,data:t,x:f,y:p,bounds:R.length===0?null:[Math.min(...R),Math.max(...R)],margin:M,orientation:O,placement:"band",formatValue:G,formatX:_,defaultIncludeZero:!0}),{valueScale:v,bandwidth:S,categoryPositions:Z,innerWidth:Q,innerHeight:ee}=y,W=v(0),c=Math.min(H??Te,S),L=[],k=[];return o.forEach((a,h)=>{let E=Z[h]+(S-c)/2,te=v(a.start),ae=v(a.end),j=Math.min(te,ae),r=Math.abs(ae-te),m=a.end>=a.start,w=i?m?"top":"bottom":m?"right":"left",X=i?{x:E,y:j,width:c,height:r}:{x:j,y:E,width:r,height:c},u=null;if(V&&a.value!==null){let b=a.kind==="total"?a.formattedEnd:a.formattedValue,x=Pe(b,10),g=v(m?Math.max(a.start,a.end):Math.min(a.start,a.end));if(i){let q=m?g-K:g+K;x<=S&&q>8&&q<ee-4&&(u={x:E+c/2,y:q,anchor:"middle",text:b})}else{let q=m?Q-g-K:g-K;x<=q&&(u={x:m?g+K:g-K,y:E+c/2,anchor:m?"start":"end",text:b})}}L.push({key:`${h}`,color:$[a.kind],d:Le({...X,radius:Ne,round:w}),label:u});let oe=o[h+1];if(J&&oe){let b=v(a.end),x=Z[h+1]+(S-c)/2;k.push(i?{key:`${h}`,x1:E+c,y1:b,x2:x,y2:b}:{key:`${h}`,x1:b,y1:E+c,x2:b,y2:x})}}),{vertical:i,bars:L,rules:k,baseline:W,bandwidth:S,categoryPositions:Z,categoryCenters:y.categoryCenters,categoryTicks:y.categoryTicks,valueTicks:y.valueTicks,valueScale:v,innerWidth:Q,innerHeight:ee,margin:y.margin}},[o,t,f,p,C,s,M,O,J,V,H,$,G,_]),ne=ie(i=>{if(T===!1||o.length===0)return;let R=i.currentTarget.getBoundingClientRect(),y=e.vertical?i.clientX-R.left-e.margin.left:i.clientY-R.top-e.margin.top;D(Ee(e.categoryCenters,y))},[T,o.length,e.vertical,e.margin,e.categoryCenters]),U=ie(()=>{!N||d===null||N(o[d])},[N,d,o]),le=ie(i=>We(i,{count:o.length,current:d,axis:e.vertical?"x":"y",onMove:D,pick:N?U:null}),[o.length,d,e.vertical,N,U]),l=d===null?null:o[d],Y=d===null||l===void 0||l===null?null:e.vertical?{x:e.margin.left+e.categoryCenters[d],y:e.margin.top+Math.min(e.valueScale(l.start),e.valueScale(l.end))}:{x:e.margin.left+Math.max(e.valueScale(l.start),e.valueScale(l.end)),y:e.margin.top+e.categoryCenters[d]};return P(Be,{children:[P("svg",{width:C,height:s,role:"img","aria-label":B??o.map(i=>i.label).join(", "),tabIndex:0,className:`${Ve} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500`,onPointerMove:ne,onPointerLeave:()=>D(null),onKeyDown:le,onBlur:()=>D(null),onClick:U,children:[P("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[n(fe,{width:e.innerWidth,height:e.innerHeight,horizontal:e.vertical&&(I==="y"||I==="both")?e.valueTicks.map(i=>i.offset):void 0,vertical:!e.vertical&&(I==="y"||I==="both")?e.valueTicks.map(i=>i.offset):void 0}),d!==null?n("rect",{x:e.vertical?e.categoryPositions[d]:0,y:e.vertical?0:e.categoryPositions[d],width:e.vertical?e.bandwidth:e.innerWidth,height:e.vertical?e.innerHeight:e.bandwidth,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,n(Ie,{bars:e.bars,connectors:e.rules}),n("line",{x1:e.vertical?0:e.baseline,y1:e.vertical?e.baseline:0,x2:e.vertical?e.innerWidth:e.baseline,y2:e.vertical?e.baseline:e.innerHeight,className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1,shapeRendering:"crispEdges"})]}),n("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:(e.vertical?f.hidden:p?.hidden)?null:n(se,{orientation:"bottom",ticks:e.vertical?e.categoryTicks:e.valueTicks,length:e.innerWidth,label:e.vertical?f.label:p?.label,size:F})}),n("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:(e.vertical?p?.hidden:f.hidden)?null:n(se,{orientation:"left",ticks:e.vertical?e.valueTicks:e.categoryTicks,length:e.innerHeight,showLine:!1,label:e.vertical?p?.label:f.label,size:F})})]}),l&&Y&&T!==!1?n(Ce,{x:Y.x,y:Y.y,containerWidth:C,children:typeof T=="function"?T(l):P("div",{className:"flex flex-col gap-1",children:[n("div",{className:"font-medium text-gray-900 dark:text-gray-100",children:l.label}),P("div",{className:"flex items-center gap-2",children:[n("span",{className:"h-2.5 w-2.5 shrink-0 rounded-sm",style:{backgroundColor:$[l.kind]},"aria-hidden":"true"}),n("span",{className:"font-semibold text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:l.kind==="total"?l.formattedEnd:l.formattedValue})]}),l.kind==="total"?null:P("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[n("span",{children:re}),n("span",{className:"[font-variant-numeric:tabular-nums]",children:l.formattedEnd})]})]})}):null]})}function et({data:C,x:s,y:o,value:t,total:f,start:p=0,orientation:I="vertical",connectors:F=!0,showValues:O=!0,barSize:J,colors:V,height:H=280,width:$,size:M="md",grid:T="y",legend:B,tooltip:re=!0,tableView:G=!1,title:_,description:N,loading:z=!1,emptyState:D,error:d=!1,errorState:e,onRetry:ne,actions:U,margin:le,locale:l,plotLabel:Y,valueLabel:i,totalLabel:R,increaseLabel:y,decreaseLabel:v,format:S,onStepClick:Z,className:Q,...ee}){let W=ge(),c=A(()=>S??(r=>Re(r,l)),[S,l]),L=A(()=>s.format??(r=>Se(r,l)),[s.format,l]),k=A(()=>{let r=p;return C.map((m,w)=>{let X=xe(m,s.key,w),u=ke(m,t);if(f?!!m[f]:!1){let g=u??r;return r=g,{index:w,x:X,label:L(X,w),value:g,start:0,end:g,kind:"total",formattedValue:c(g),formattedEnd:c(g),datum:m}}let b=r,x=u===null?r:r+u;return r=x,{index:w,x:X,label:L(X,w),value:u,start:b,end:x,kind:u!==null&&u<0?"decrease":"increase",formattedValue:u===null?"\u2014":`${u>0?"+":""}${c(u)}`,formattedEnd:c(x),datum:m}})},[C,s.key,t,f,p,c,L]),a=A(()=>({increase:V?.increase??we,decrease:V?.decrease??Ae,total:V?.total??pe}),[V]),h=R??W.chartRunningTotal,E=A(()=>{let r=[{key:"increase",label:y??W.chartIncrease,color:a.increase,marker:"rect"},{key:"decrease",label:v??W.chartDecrease,color:a.decrease,marker:"rect"}];return k.some(m=>m.kind==="total")&&r.push({key:"total",label:h,color:a.total,marker:"rect"}),r},[a,k,y,v,h,W.chartIncrease,W.chartDecrease]),te=A(()=>k.map(r=>({[s.key]:r.x,[t]:r.kind==="total"?null:r.value,__running:r.end})),[k,s.key,t]),ae=B===void 0?!0:B!==!1,j=typeof B=="string"?B:"bottom";return n(he,{title:_,description:N,height:H,width:$,size:M,loading:z,empty:k.length===0,emptyState:D,error:d,errorState:e,onRetry:ne,actions:U,tableView:G,legendPosition:j,legend:ae?n(ye,{items:E,position:j,marker:"rect",size:M}):void 0,table:G?n(be,{data:te,series:[{key:t,label:i??W.chartValue},{key:"__running",label:h}],xKey:s.key,xLabel:s.label??s.key,formatX:L,formatValue:c,caption:typeof _=="string"?_:void 0}):void 0,className:Q,...ee,children:({width:r})=>n(Me,{width:r,height:H,steps:k,data:C,x:s,y:o,grid:T,size:M,orientation:I,connectors:F,showValues:O,barSize:J,palette:a,margin:le,tooltip:re,plotLabel:Y,totalLabel:h,formatValue:c,formatX:L,onStepClick:Z})})}export{et as WaterfallChart};
1
+ "use client";import{memo as me,useCallback as ie,useMemo as I,useState as ue}from"react";import{useUILabels as ge,useUILocale as he}from"../../lib/i18n.js";import{ChartAxis as se}from"../chart/ChartAxis.js";import{ChartContainer as fe}from"../chart/ChartContainer.js";import{ChartGrid as ye}from"../chart/ChartGrid.js";import{ChartLegend as be}from"../chart/ChartLegend.js";import{ChartTableView as Ce}from"../chart/ChartTableView.js";import{ChartTooltip as pe}from"../chart/ChartTooltip.js";import{CHART_DIVERGING_COLORS as ce,CHART_MUTED_COLOR as ve,rampColor as de}from"../chart/palette.js";import{buildCartesianGeometry as ke}from"../chart/utils/cartesian.js";import{readNumber as xe,readXValue as Re}from"../chart/utils/data.js";import{formatAuto as Se,formatXValue as Le}from"../chart/utils/format.js";import{handleChartKeyDown as We}from"../chart/utils/keyboard.js";import{buildBarPath as Ee}from"../chart/utils/path.js";import{nearestIndex as Pe}from"../chart/utils/scales.js";import{estimateTextWidth as Ve}from"../chart/utils/text.js";import{CHART_TOUCH as Te}from"../chart/utils/touch.js";import{Fragment as _e,jsx as n,jsxs as P}from"react/jsx-runtime";var Ne=24,we=4,O=6,Ae=de(ce,1),Ie=de(ce,0),Me=me(function({bars:s,connectors:o}){return P("g",{children:[n("g",{className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1,shapeRendering:"crispEdges","aria-hidden":"true",children:o.map(r=>n("line",{x1:r.x1,y1:r.y1,x2:r.x2,y2:r.y2},r.key))}),s.map(r=>P("g",{children:[n("path",{d:r.d,fill:r.color}),r.label?n("text",{x:r.label.x,y:r.label.y,textAnchor:r.label.anchor,dominantBaseline:"middle",className:"fill-gray-600 text-[10px] [font-variant-numeric:tabular-nums] dark:fill-gray-300",children:r.label.text}):null]},r.key))]})});function Be({width:p,height:s,steps:o,data:r,x:f,y:v,grid:M,size:F,orientation:H,connectors:J,showValues:V,barSize:$,palette:G,margin:B,tooltip:T,plotLabel:_,totalLabel:ne,formatValue:z,formatX:D,onStepClick:N}){let[U,X]=ue(null),c=U!==null&&U<o.length?U:null,e=I(()=>{let l=H==="vertical",S=o.flatMap(a=>[a.start,a.end]),y=ke({width:p,height:s,data:r,x:f,y:v,bounds:S.length===0?null:[Math.min(...S),Math.max(...S)],margin:B,orientation:H,placement:"band",formatValue:z,formatX:D,defaultIncludeZero:!0}),{valueScale:k,bandwidth:L,categoryPositions:j,innerWidth:Q,innerHeight:ee}=y,K=k(0),d=Math.min($??Ne,L),b=[],W=[];return o.forEach((a,m)=>{let u=j[m]+(L-d)/2,te=k(a.start),ae=k(a.end),re=Math.min(te,ae),q=Math.abs(ae-te),t=a.end>=a.start,x=l?t?"top":"bottom":t?"right":"left",w=l?{x:u,y:re,width:d,height:q}:{x:re,y:u,width:q,height:d},E=null;if(V&&a.value!==null){let R=a.kind==="total"?a.formattedEnd:a.formattedValue,A=Ve(R,10),C=k(t?Math.max(a.start,a.end):Math.min(a.start,a.end));if(l){let h=t?C-O:C+O;A<=L&&h>8&&h<ee-4&&(E={x:u+d/2,y:h,anchor:"middle",text:R})}else{let h=t?Q-C-O:C-O;A<=h&&(E={x:t?C+O:C-O,y:u+d/2,anchor:t?"start":"end",text:R})}}b.push({key:`${m}`,color:G[a.kind],d:Ee({...w,radius:we,round:x}),label:E});let g=o[m+1];if(J&&g){let R=k(a.end),A=j[m+1]+(L-d)/2;W.push(l?{key:`${m}`,x1:u+d,y1:R,x2:A,y2:R}:{key:`${m}`,x1:R,y1:u+d,x2:R,y2:A})}}),{vertical:l,bars:b,rules:W,baseline:K,bandwidth:L,categoryPositions:j,categoryCenters:y.categoryCenters,categoryTicks:y.categoryTicks,valueTicks:y.valueTicks,valueScale:k,innerWidth:Q,innerHeight:ee,margin:y.margin}},[o,r,f,v,p,s,B,H,J,V,$,G,z,D]),le=ie(l=>{if(T===!1||o.length===0)return;let S=l.currentTarget.getBoundingClientRect(),y=e.vertical?l.clientX-S.left-e.margin.left:l.clientY-S.top-e.margin.top;X(Pe(e.categoryCenters,y))},[T,o.length,e.vertical,e.margin,e.categoryCenters]),Y=ie(()=>{!N||c===null||N(o[c])},[N,c,o]),oe=ie(l=>We(l,{count:o.length,current:c,axis:e.vertical?"x":"y",onMove:X,pick:N?Y:null}),[o.length,c,e.vertical,N,Y]),i=c===null?null:o[c],Z=c===null||i===void 0||i===null?null:e.vertical?{x:e.margin.left+e.categoryCenters[c],y:e.margin.top+Math.min(e.valueScale(i.start),e.valueScale(i.end))}:{x:e.margin.left+Math.max(e.valueScale(i.start),e.valueScale(i.end)),y:e.margin.top+e.categoryCenters[c]};return P(_e,{children:[P("svg",{width:p,height:s,role:"img","aria-label":_??o.map(l=>l.label).join(", "),tabIndex:0,className:`${Te} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500`,onPointerMove:le,onPointerLeave:()=>X(null),onKeyDown:oe,onBlur:()=>X(null),onClick:Y,children:[P("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[n(ye,{width:e.innerWidth,height:e.innerHeight,horizontal:e.vertical&&(M==="y"||M==="both")?e.valueTicks.map(l=>l.offset):void 0,vertical:!e.vertical&&(M==="y"||M==="both")?e.valueTicks.map(l=>l.offset):void 0}),c!==null?n("rect",{x:e.vertical?e.categoryPositions[c]:0,y:e.vertical?0:e.categoryPositions[c],width:e.vertical?e.bandwidth:e.innerWidth,height:e.vertical?e.innerHeight:e.bandwidth,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,n(Me,{bars:e.bars,connectors:e.rules}),n("line",{x1:e.vertical?0:e.baseline,y1:e.vertical?e.baseline:0,x2:e.vertical?e.innerWidth:e.baseline,y2:e.vertical?e.baseline:e.innerHeight,className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1,shapeRendering:"crispEdges"})]}),n("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:(e.vertical?f.hidden:v?.hidden)?null:n(se,{orientation:"bottom",ticks:e.vertical?e.categoryTicks:e.valueTicks,length:e.innerWidth,label:e.vertical?f.label:v?.label,size:F})}),n("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:(e.vertical?v?.hidden:f.hidden)?null:n(se,{orientation:"left",ticks:e.vertical?e.valueTicks:e.categoryTicks,length:e.innerHeight,showLine:!1,label:e.vertical?v?.label:f.label,size:F})})]}),i&&Z&&T!==!1?n(pe,{x:Z.x,y:Z.y,containerWidth:p,children:typeof T=="function"?T(i):P("div",{className:"flex flex-col gap-1",children:[n("div",{className:"font-medium text-gray-900 dark:text-gray-100",children:i.label}),P("div",{className:"flex items-center gap-2",children:[n("span",{className:"h-2.5 w-2.5 shrink-0 rounded-sm",style:{backgroundColor:G[i.kind]},"aria-hidden":"true"}),n("span",{className:"font-semibold text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:i.kind==="total"?i.formattedEnd:i.formattedValue})]}),i.kind==="total"?null:P("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[n("span",{children:ne}),n("span",{className:"[font-variant-numeric:tabular-nums]",children:i.formattedEnd})]})]})}):null]})}function tt({data:p,x:s,y:o,value:r,total:f,start:v=0,orientation:M="vertical",connectors:F=!0,showValues:H=!0,barSize:J,colors:V,height:$=280,width:G,size:B="md",grid:T="y",legend:_,tooltip:ne=!0,tableView:z=!1,title:D,description:N,loading:U=!1,emptyState:X,error:c=!1,errorState:e,onRetry:le,actions:Y,margin:oe,locale:i,plotLabel:Z,valueLabel:l,totalLabel:S,increaseLabel:y,decreaseLabel:k,format:L,onStepClick:j,className:Q,...ee}){let K=he(i),d=ge(),b=I(()=>L??(t=>Se(t,K)),[L,K]),W=I(()=>s.format??(t=>Le(t,K)),[s.format,K]),a=I(()=>{let t=v;return p.map((x,w)=>{let E=Re(x,s.key,w),g=xe(x,r);if(f?!!x[f]:!1){let h=g??t;return t=h,{index:w,x:E,label:W(E,w),value:h,start:0,end:h,kind:"total",formattedValue:b(h),formattedEnd:b(h),datum:x}}let A=t,C=g===null?t:t+g;return t=C,{index:w,x:E,label:W(E,w),value:g,start:A,end:C,kind:g!==null&&g<0?"decrease":"increase",formattedValue:g===null?"\u2014":`${g>0?"+":""}${b(g)}`,formattedEnd:b(C),datum:x}})},[p,s.key,r,f,v,b,W]),m=I(()=>({increase:V?.increase??Ae,decrease:V?.decrease??Ie,total:V?.total??ve}),[V]),u=S??d.chartRunningTotal,te=I(()=>{let t=[{key:"increase",label:y??d.chartIncrease,color:m.increase,marker:"rect"},{key:"decrease",label:k??d.chartDecrease,color:m.decrease,marker:"rect"}];return a.some(x=>x.kind==="total")&&t.push({key:"total",label:u,color:m.total,marker:"rect"}),t},[m,a,y,k,u,d.chartIncrease,d.chartDecrease]),ae=I(()=>a.map(t=>({[s.key]:t.x,[r]:t.kind==="total"?null:t.value,__running:t.end})),[a,s.key,r]),re=_===void 0?!0:_!==!1,q=typeof _=="string"?_:"bottom";return n(fe,{title:D,description:N,height:$,width:G,size:B,loading:U,empty:a.length===0,emptyState:X,error:c,errorState:e,onRetry:le,actions:Y,tableView:z,legendPosition:q,legend:re?n(be,{items:te,position:q,marker:"rect",size:B}):void 0,table:z?n(Ce,{data:ae,series:[{key:r,label:l??d.chartValue},{key:"__running",label:u}],xKey:s.key,xLabel:s.label??s.key,formatX:W,formatValue:b,caption:typeof D=="string"?D:void 0}):void 0,className:Q,...ee,children:({width:t})=>n(Be,{width:t,height:$,steps:a,data:p,x:s,y:o,grid:T,size:B,orientation:M,connectors:F,showValues:H,barSize:J,palette:m,margin:oe,tooltip:ne,plotLabel:Z,totalLabel:u,formatValue:b,formatX:W,onStepClick:j})})}export{tt as WaterfallChart};
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var p=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var n=Object.prototype.hasOwnProperty;var E=(l,o)=>{for(var a in o)p(l,a,{get:o[a],enumerable:!0})},m=(l,o,a,L)=>{if(o&&typeof o=="object"||typeof o=="function")for(let f of x(o))!n.call(l,f)&&f!==a&&p(l,f,{get:()=>o[f],enumerable:!(L=U(o,f))||L.enumerable});return l},r=(l,o,a)=>(m(l,o,"default"),a&&m(a,o,"default"));var d=l=>m(p({},"__esModule",{value:!0}),l);var e={};E(e,{FOCUSABLE_SELECTOR:()=>t.FOCUSABLE_SELECTOR,INERT_IGNORE_ATTRIBUTE:()=>s.INERT_IGNORE_ATTRIBUTE,UILabelsProvider:()=>i.UILabelsProvider,cn:()=>I.cn,defaultUILabels:()=>b.defaultUILabels,findOwnedLayers:()=>s.findOwnedLayers,formatUILabel:()=>b.formatUILabel,frenchUILabels:()=>b.frenchUILabels,getFocusableElements:()=>t.getFocusableElements,hideOthers:()=>s.hideOthers,isElementVisible:()=>t.isElementVisible,isFocusable:()=>t.isFocusable,registerFloatingLayer:()=>s.registerFloatingLayer,useUILabels:()=>i.useUILabels});module.exports=d(e);r(e,require("./components/index.cjs"),module.exports);r(e,require("./hooks/index.cjs"),module.exports);var I=require("./lib/cn.cjs"),i=require("./lib/i18n.cjs"),b=require("./lib/ui-labels.cjs"),s=require("./lib/aria-hide.cjs"),t=require("./lib/focus.cjs");0&&(module.exports={FOCUSABLE_SELECTOR,INERT_IGNORE_ATTRIBUTE,UILabelsProvider,cn,defaultUILabels,findOwnedLayers,formatUILabel,frenchUILabels,getFocusableElements,hideOthers,isElementVisible,isFocusable,registerFloatingLayer,useUILabels,...require("./components/index.cjs"),...require("./hooks/index.cjs")});
1
+ "use strict";var m=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var n=Object.prototype.hasOwnProperty;var E=(l,o)=>{for(var a in o)m(l,a,{get:o[a],enumerable:!0})},L=(l,o,a,p)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of x(o))!n.call(l,i)&&i!==a&&m(l,i,{get:()=>o[i],enumerable:!(p=U(o,i))||p.enumerable});return l},r=(l,o,a)=>(L(l,o,"default"),a&&L(a,o,"default"));var d=l=>L(m({},"__esModule",{value:!0}),l);var e={};E(e,{FOCUSABLE_SELECTOR:()=>t.FOCUSABLE_SELECTOR,INERT_IGNORE_ATTRIBUTE:()=>s.INERT_IGNORE_ATTRIBUTE,UILabelsProvider:()=>b.UILabelsProvider,cn:()=>I.cn,defaultUILabels:()=>f.defaultUILabels,findOwnedLayers:()=>s.findOwnedLayers,formatUILabel:()=>f.formatUILabel,frenchUILabels:()=>f.frenchUILabels,getFocusableElements:()=>t.getFocusableElements,hideOthers:()=>s.hideOthers,isElementVisible:()=>t.isElementVisible,isFocusable:()=>t.isFocusable,registerFloatingLayer:()=>s.registerFloatingLayer,useUILabels:()=>b.useUILabels,useUILocale:()=>b.useUILocale});module.exports=d(e);r(e,require("./components/index.cjs"),module.exports);r(e,require("./hooks/index.cjs"),module.exports);var I=require("./lib/cn.cjs"),b=require("./lib/i18n.cjs"),f=require("./lib/ui-labels.cjs"),s=require("./lib/aria-hide.cjs"),t=require("./lib/focus.cjs");0&&(module.exports={FOCUSABLE_SELECTOR,INERT_IGNORE_ATTRIBUTE,UILabelsProvider,cn,defaultUILabels,findOwnedLayers,formatUILabel,frenchUILabels,getFocusableElements,hideOthers,isElementVisible,isFocusable,registerFloatingLayer,useUILabels,useUILocale,...require("./components/index.cjs"),...require("./hooks/index.cjs")});