@synertech/ui 0.45.0 → 0.45.1

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 (43) hide show
  1. package/.claude/skills/use-synertech-ui/SKILL.md +1 -1
  2. package/dist/components/area-chart/AreaChart.cjs +1 -1
  3. package/dist/components/area-chart/AreaChart.js +1 -1
  4. package/dist/components/bar-chart/BarChart.cjs +1 -1
  5. package/dist/components/bar-chart/BarChart.js +1 -1
  6. package/dist/components/box-plot/BoxPlot.cjs +1 -1
  7. package/dist/components/box-plot/BoxPlot.js +1 -1
  8. package/dist/components/bullet-chart/BulletChart.cjs +1 -1
  9. package/dist/components/bullet-chart/BulletChart.js +1 -1
  10. package/dist/components/candlestick-chart/CandlestickChart.cjs +1 -1
  11. package/dist/components/candlestick-chart/CandlestickChart.js +1 -1
  12. package/dist/components/chart/ChartSync.cjs +1 -1
  13. package/dist/components/chart/ChartSync.js +1 -1
  14. package/dist/components/chart/utils/cartesian.cjs +1 -1
  15. package/dist/components/chart/utils/cartesian.js +1 -1
  16. package/dist/components/chart/utils/path.cjs +1 -1
  17. package/dist/components/chart/utils/path.js +1 -1
  18. package/dist/components/chart/utils/time.cjs +1 -1
  19. package/dist/components/chart/utils/time.js +1 -1
  20. package/dist/components/chart/utils/timestamp.cjs +1 -0
  21. package/dist/components/chart/utils/timestamp.js +1 -0
  22. package/dist/components/chart/utils/touch.cjs +1 -0
  23. package/dist/components/chart/utils/touch.js +1 -0
  24. package/dist/components/dumbbell-chart/DumbbellChart.cjs +1 -1
  25. package/dist/components/dumbbell-chart/DumbbellChart.js +1 -1
  26. package/dist/components/funnel-chart/FunnelChart.cjs +1 -1
  27. package/dist/components/funnel-chart/FunnelChart.js +1 -1
  28. package/dist/components/gantt-chart/GanttChart.cjs +1 -1
  29. package/dist/components/gantt-chart/GanttChart.js +1 -1
  30. package/dist/components/heat-map/Heatmap.cjs +1 -1
  31. package/dist/components/heat-map/Heatmap.js +1 -1
  32. package/dist/components/line-chart/LineChart.cjs +1 -1
  33. package/dist/components/line-chart/LineChart.js +1 -1
  34. package/dist/components/pie-chart/PieChart.cjs +1 -1
  35. package/dist/components/pie-chart/PieChart.js +1 -1
  36. package/dist/components/scatter-chart/ScatterChart.cjs +1 -1
  37. package/dist/components/scatter-chart/ScatterChart.js +1 -1
  38. package/dist/components/waterfall-chart/WaterfallChart.cjs +1 -1
  39. package/dist/components/waterfall-chart/WaterfallChart.js +1 -1
  40. package/dist/index.d.cts +16 -3
  41. package/dist/index.d.ts +16 -3
  42. package/dist/styles.css +27 -0
  43. package/package.json +13 -13
@@ -1 +1 @@
1
- "use client";import{memo as Q,useCallback as q,useMemo as E,useState as Z}from"react";import{useUILabels as J}from"../../lib/i18n.js";import{ChartAxis as ee}from"../chart/ChartAxis.js";import{ChartContainer as te}from"../chart/ChartContainer.js";import{ChartTooltip as ne}from"../chart/ChartTooltip.js";import{CHART_ORDINAL_COLORS as re,CHART_ORDINAL_DARK_STOPS as ae,createSequentialScale as le}from"../chart/palette.js";import{readNumber as Y,readXValue as oe}from"../chart/utils/data.js";import{formatAuto as ie,formatPercent as B,formatXValue as se}from"../chart/utils/format.js";import{buildBarPath as ue}from"../chart/utils/path.js";import{createBandScale as me,createLinearScale as ce,nearestIndex as de}from"../chart/utils/scales.js";import{estimateTextWidth as fe,widestLabel as he}from"../chart/utils/text.js";import{Table as pe}from"../table/Table.js";import{TableBody as be}from"../table/TableBody.js";import{TableCell as _}from"../table/TableCell.js";import{TableHeader as ge}from"../table/TableHeader.js";import{TableHeaderCell as z}from"../table/TableHeaderCell.js";import{TableRow as ve}from"../table/TableRow.js";import{Fragment as Te,jsx as t,jsxs as h}from"react/jsx-runtime";var ye=8,xe=12,Ce=44,j="text-right [font-variant-numeric:tabular-nums]",ke=Q(function({stages:u}){return t("g",{children:u.map(e=>h("g",{children:[t("path",{d:e.d,fill:e.color}),e.value?t("text",{x:e.value.x,y:e.value.y,textAnchor:e.value.anchor,dominantBaseline:"middle",className:e.value.inside?e.value.onDark?"fill-gray-50 text-[11px] font-semibold [font-variant-numeric:tabular-nums] dark:fill-gray-900":"fill-gray-900 text-[11px] font-semibold [font-variant-numeric:tabular-nums] dark:fill-gray-50":"fill-gray-700 text-[11px] font-semibold [font-variant-numeric:tabular-nums] dark:fill-gray-200",children:e.value.text}):null,e.conversion?t("text",{x:e.conversion.x,y:e.conversion.y,textAnchor:"middle",dominantBaseline:"middle",className:"fill-gray-500 text-[10px] [font-variant-numeric:tabular-nums] dark:fill-gray-400",children:e.conversion.text}):null]},e.key))})});function Se({width:p,height:u,stages:e,x:y,size:H,align:V,showConversion:D,showValues:N,stageSize:M,ramp:F,tooltip:v,plotLabel:I,locale:x,onStageClick:C}){let[o,R]=Z(null),X=J(),n=E(()=>{let s=e.map(l=>l.label),m={top:6,right:12,bottom:6,left:y.hidden?8:y.height??he(s)+xe},d=Math.max(0,p-m.left-m.right),k=Math.max(0,u-m.top-m.bottom),c=me(e.map((l,a)=>a),[0,k],{paddingInner:D?.45:.28}),S=Math.min(M??Ce,c.bandwidth),U=Math.max(0,...e.map(l=>l.value??0)),$=ce([0,U],[0,d]),P=e.map((l,a)=>{let T=l.value===null?0:Math.max(0,$(l.value)),w=V==="center"?(d-T)/2:0,r=c(a)+(c.bandwidth-S)/2,L=r+S/2,b=null;if(N&&l.value!==null){let g=l.formattedValue;b=fe(g,11)+16<=T?{x:w+T/2,y:L,anchor:"middle",text:g,inside:!0,onDark:F.onDark(a)}:{x:w+T+ye,y:L,anchor:"start",text:g,inside:!1,onDark:!1}}let O=c(a-1)+(c.bandwidth-S)/2+S,f=D&&l.conversion!==null&&a>0?{x:d/2,y:(O+r)/2,text:B(l.conversion,{locale:x,maximumFractionDigits:0})}:null;return{key:`${a}`,d:ue({x:w,y:r,width:T,height:S,radius:4,round:V==="center"?"none":"right"}),color:F(a),value:b,conversion:f,top:c(a),height:c.bandwidth}}),A=y.hidden?[]:e.map((l,a)=>({value:l.x,offset:c.center(a),label:l.label}));return{margin:m,innerWidth:d,innerHeight:k,rendered:P,stageTicks:A,centers:e.map((l,a)=>c.center(a))}},[e,y,p,u,V,D,N,M,F,x]),W=q(s=>{if(v===!1||e.length===0)return;let m=s.currentTarget.getBoundingClientRect(),d=s.clientY-m.top-n.margin.top;R(de(n.centers,d))},[v,e.length,n.margin.top,n.centers]),G=q(s=>{if(e.length===0)return;let m=e.length-1,d=o??0,k=s.key==="ArrowDown"?Math.min(m,d+1):s.key==="ArrowUp"?Math.max(0,d-1):s.key==="Home"?0:s.key==="End"?m:s.key==="Escape"?null:void 0;k!==void 0&&(s.preventDefault(),R(k))},[e.length,o]),K=q(()=>{!C||o===null||C(e[o])},[C,o,e]),i=o===null?null:e[o];return h(Te,{children:[h("svg",{width:p,height:u,role:"img","aria-label":I??e.map(s=>s.label).join(", "),tabIndex:0,className:"touch-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500",onPointerMove:W,onPointerLeave:()=>R(null),onKeyDown:G,onBlur:()=>R(null),onClick:K,children:[h("g",{transform:`translate(${n.margin.left}, ${n.margin.top})`,children:[o!==null&&n.rendered[o]?t("rect",{x:-4,y:n.rendered[o].top,width:n.innerWidth+8,height:n.rendered[o].height,rx:4,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,t(ke,{stages:n.rendered})]}),t("g",{transform:`translate(${n.margin.left}, ${n.margin.top})`,children:y.hidden?null:t(ee,{orientation:"left",ticks:n.stageTicks,length:n.innerHeight,showLine:!1,tickSize:0,size:H})})]}),i&&o!==null&&v!==!1?t(ne,{x:n.margin.left+n.innerWidth/2,y:n.margin.top+n.centers[o],containerWidth:p,children:typeof v=="function"?v(i):h("div",{className:"flex flex-col gap-1",children:[t("div",{className:"font-medium text-gray-900 dark:text-gray-100",children:i.label}),h("div",{className:"flex items-center gap-2",children:[t("span",{className:"h-2.5 w-2.5 shrink-0 rounded-sm",style:{backgroundColor:n.rendered[o]?.color},"aria-hidden":"true"}),t("span",{className:"font-semibold text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:i.formattedValue})]}),i.conversion!==null?h("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[t("span",{children:X.chartConversion}),t("span",{className:"[font-variant-numeric:tabular-nums]",children:B(i.conversion,{locale:x,maximumFractionDigits:1})})]}):null,i.overall!==null?h("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[t("span",{children:e[0]?.label}),t("span",{className:"[font-variant-numeric:tabular-nums]",children:B(i.overall,{locale:x,maximumFractionDigits:1})})]}):null]})}):null]})}function Ge({data:p,x:u,value:e,align:y="center",showConversion:H=!0,showValues:V=!0,stageSize:D,colors:N,height:M,width:F,size:v="md",tooltip:I=!0,tableView:x=!1,title:C,description:o,loading:R=!1,emptyState:X,error:n=!1,errorState:W,onRetry:G,actions:K,locale:i,plotLabel:s,valueLabel:m,conversionLabel:d,dropOffLabel:k,format:c,onStageClick:S,className:U,...$}){let P=J(),A=E(()=>c??(r=>ie(r,i)),[c,i]),l=E(()=>u.format??(r=>se(r,i)),[u.format,i]),a=E(()=>{let r=Y(p[0]??{},e);return p.map((L,b)=>{let O=oe(L,u.key,b),f=Y(L,e),g=b===0?null:Y(p[b-1],e);return{index:b,x:O,label:l(O,b),value:f,overall:b===0||r===null||r===0||f===null?null:f/r,conversion:g===null||g===0||f===null?null:f/g,dropOff:g===null||f===null?null:g-f,formattedValue:f===null?"\u2014":A(f),datum:L}})},[p,u.key,e,A,l]),T=E(()=>le([0,Math.max(1,a.length-1)],{colors:N??re,...N?{}:{darkStops:ae}}),[a.length,N]),w=M??Math.max(96,a.length*(H?56:44)+12);return t(te,{title:C,description:o,height:w,width:F,size:v,loading:R,empty:a.length===0,emptyState:X,error:n,errorState:W,onRetry:G,actions:K,tableView:x,table:x?t("div",{className:"w-full overflow-x-auto",children:h(pe,{children:[typeof C=="string"?t("caption",{className:"sr-only",children:C}):null,h(ge,{children:[t(z,{children:u.label??u.key}),t(z,{className:"text-right",children:m??P.chartValue}),t(z,{className:"text-right",children:d??P.chartConversion}),t(z,{className:"text-right",children:k??P.chartDropOff})]}),t(be,{children:a.map(r=>h(ve,{clickable:!1,children:[t(_,{className:"font-medium text-gray-900 dark:text-gray-100",children:r.label}),t(_,{className:j,children:r.formattedValue}),t(_,{className:j,children:r.conversion===null?"\u2014":B(r.conversion,{locale:i,maximumFractionDigits:1})}),t(_,{className:j,children:r.dropOff===null?"\u2014":A(r.dropOff)})]},r.index))})]})}):void 0,className:U,...$,children:({width:r})=>t(Se,{width:r,height:w,stages:a,x:u,size:v,align:y,showConversion:H,showValues:V,stageSize:D,ramp:T,tooltip:I,plotLabel:s,locale:i,onStageClick:S})})}export{Ge as FunnelChart};
1
+ "use client";import{memo as Z,useCallback as Y,useMemo as M,useState as ee}from"react";import{useUILabels as Q}from"../../lib/i18n.js";import{ChartAxis as te}from"../chart/ChartAxis.js";import{ChartContainer as ne}from"../chart/ChartContainer.js";import{ChartTooltip as re}from"../chart/ChartTooltip.js";import{CHART_ORDINAL_COLORS as ae,CHART_ORDINAL_DARK_STOPS as le,createSequentialScale as oe}from"../chart/palette.js";import{readNumber as j,readXValue as ie}from"../chart/utils/data.js";import{formatAuto as se,formatPercent as X,formatXValue as ue}from"../chart/utils/format.js";import{buildBarPath as me}from"../chart/utils/path.js";import{createBandScale as ce,createLinearScale as de,nearestIndex as fe}from"../chart/utils/scales.js";import{estimateTextWidth as he,widestLabel as pe}from"../chart/utils/text.js";import{CHART_TOUCH as be}from"../chart/utils/touch.js";import{Table as ge}from"../table/Table.js";import{TableBody as ve}from"../table/TableBody.js";import{TableCell as z}from"../table/TableCell.js";import{TableHeader as ye}from"../table/TableHeader.js";import{TableHeaderCell as B}from"../table/TableHeaderCell.js";import{TableRow as xe}from"../table/TableRow.js";import{Fragment as Re,jsx as t,jsxs as f}from"react/jsx-runtime";var Ce=8,ke=12,Se=44,J="text-right [font-variant-numeric:tabular-nums]",Te=Z(function({stages:s}){return t("g",{children:s.map(e=>f("g",{children:[t("path",{d:e.d,fill:e.color}),e.value?t("text",{x:e.value.x,y:e.value.y,textAnchor:e.value.anchor,dominantBaseline:"middle",className:e.value.inside?e.value.onDark?"fill-gray-50 text-[11px] font-semibold [font-variant-numeric:tabular-nums] dark:fill-gray-900":"fill-gray-900 text-[11px] font-semibold [font-variant-numeric:tabular-nums] dark:fill-gray-50":"fill-gray-700 text-[11px] font-semibold [font-variant-numeric:tabular-nums] dark:fill-gray-200",children:e.value.text}):null,e.conversion?t("text",{x:e.conversion.x,y:e.conversion.y,textAnchor:"middle",dominantBaseline:"middle",className:"fill-gray-500 text-[10px] [font-variant-numeric:tabular-nums] dark:fill-gray-400",children:e.conversion.text}):null]},e.key))})});function Ne({width:h,height:s,stages:e,x:C,size:O,align:V,showConversion:D,showValues:w,stageSize:_,ramp:P,tooltip:g,plotLabel:W,locale:k,onStageClick:S}){let[A,L]=ee(null),l=A!==null&&A<e.length?A:null,G=Q(),n=M(()=>{let o=e.map(r=>r.label),u={top:6,right:12,bottom:6,left:C.hidden?8:C.height??pe(o)+ke},m=Math.max(0,h-u.left-u.right),y=Math.max(0,s-u.top-u.bottom),c=ce(e.map((r,i)=>i),[0,y],{paddingInner:D?.45:.28}),T=Math.min(_??Se,c.bandwidth),$=Math.max(0,...e.map(r=>r.value??0)),F=de([0,$],[0,m]),E=e.map((r,i)=>{let x=r.value===null?0:Math.max(0,F(r.value)),a=V==="center"?(m-x)/2:0,N=c(i)+(c.bandwidth-T)/2,b=N+T/2,H=null;if(w&&r.value!==null){let q=r.formattedValue;H=he(q,11)+16<=x?{x:a+x/2,y:b,anchor:"middle",text:q,inside:!0,onDark:P.onDark(i)}:{x:a+x+Ce,y:b,anchor:"start",text:q,inside:!1,onDark:!1}}let d=c(i-1)+(c.bandwidth-T)/2+T,R=D&&r.conversion!==null&&i>0?{x:m/2,y:(d+N)/2,text:X(r.conversion,{locale:k,maximumFractionDigits:0})}:null;return{key:`${i}`,d:me({x:a,y:N,width:x,height:T,radius:4,round:V==="center"?"none":"right"}),color:P(i),value:H,conversion:R,top:c(i),height:c.bandwidth}}),I=C.hidden?[]:e.map((r,i)=>({value:r.x,offset:c.center(i),label:r.label}));return{margin:u,innerWidth:m,innerHeight:y,rendered:E,stageTicks:I,centers:e.map((r,i)=>c.center(i))}},[e,C,h,s,V,D,w,_,P,k]),K=Y(o=>{if(g===!1||e.length===0)return;let u=o.currentTarget.getBoundingClientRect(),m=o.clientY-u.top-n.margin.top;L(fe(n.centers,m))},[g,e.length,n.margin.top,n.centers]),U=Y(o=>{if(e.length===0)return;let u=e.length-1,m=l??0,y=o.key==="ArrowDown"?Math.min(u,m+1):o.key==="ArrowUp"?Math.max(0,m-1):o.key==="Home"?0:o.key==="End"?u:o.key==="Escape"?null:void 0;y!==void 0&&(o.preventDefault(),L(y))},[e.length,l]),v=Y(()=>{!S||l===null||S(e[l])},[S,l,e]),p=l===null?null:e[l];return f(Re,{children:[f("svg",{width:h,height:s,role:"img","aria-label":W??e.map(o=>o.label).join(", "),tabIndex:0,className:`${be} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500`,onPointerMove:K,onPointerLeave:()=>L(null),onKeyDown:U,onBlur:()=>L(null),onClick:v,children:[f("g",{transform:`translate(${n.margin.left}, ${n.margin.top})`,children:[l!==null&&n.rendered[l]?t("rect",{x:-4,y:n.rendered[l].top,width:n.innerWidth+8,height:n.rendered[l].height,rx:4,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,t(Te,{stages:n.rendered})]}),t("g",{transform:`translate(${n.margin.left}, ${n.margin.top})`,children:C.hidden?null:t(te,{orientation:"left",ticks:n.stageTicks,length:n.innerHeight,showLine:!1,tickSize:0,size:O})})]}),p&&l!==null&&g!==!1?t(re,{x:n.margin.left+n.innerWidth/2,y:n.margin.top+n.centers[l],containerWidth:h,children:typeof g=="function"?g(p):f("div",{className:"flex flex-col gap-1",children:[t("div",{className:"font-medium text-gray-900 dark:text-gray-100",children:p.label}),f("div",{className:"flex items-center gap-2",children:[t("span",{className:"h-2.5 w-2.5 shrink-0 rounded-sm",style:{backgroundColor:n.rendered[l]?.color},"aria-hidden":"true"}),t("span",{className:"font-semibold text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:p.formattedValue})]}),p.conversion!==null?f("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[t("span",{children:G.chartConversion}),t("span",{className:"[font-variant-numeric:tabular-nums]",children:X(p.conversion,{locale:k,maximumFractionDigits:1})})]}):null,p.overall!==null?f("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[t("span",{children:e[0]?.label}),t("span",{className:"[font-variant-numeric:tabular-nums]",children:X(p.overall,{locale:k,maximumFractionDigits:1})})]}):null]})}):null]})}function $e({data:h,x:s,value:e,align:C="center",showConversion:O=!0,showValues:V=!0,stageSize:D,colors:w,height:_,width:P,size:g="md",tooltip:W=!0,tableView:k=!1,title:S,description:A,loading:L=!1,emptyState:l,error:G=!1,errorState:n,onRetry:K,actions:U,locale:v,plotLabel:p,valueLabel:o,conversionLabel:u,dropOffLabel:m,format:y,onStageClick:c,className:T,...$}){let F=Q(),E=M(()=>y??(a=>se(a,v)),[y,v]),I=M(()=>s.format??(a=>ue(a,v)),[s.format,v]),r=M(()=>{let a=j(h[0]??{},e);return h.map((N,b)=>{let H=ie(N,s.key,b),d=j(N,e),R=b===0?null:j(h[b-1],e);return{index:b,x:H,label:I(H,b),value:d,overall:b===0||a===null||a===0||d===null?null:d/a,conversion:R===null||R===0||d===null?null:d/R,dropOff:R===null||d===null?null:R-d,formattedValue:d===null?"\u2014":E(d),datum:N}})},[h,s.key,e,E,I]),i=M(()=>oe([0,Math.max(1,r.length-1)],{colors:w??ae,...w?{}:{darkStops:le}}),[r.length,w]),x=_??Math.max(96,r.length*(O?56:44)+12);return t(ne,{title:S,description:A,height:x,width:P,size:g,loading:L,empty:r.length===0,emptyState:l,error:G,errorState:n,onRetry:K,actions:U,tableView:k,table:k?t("div",{className:"w-full overflow-x-auto",children:f(ge,{children:[typeof S=="string"?t("caption",{className:"sr-only",children:S}):null,f(ye,{children:[t(B,{children:s.label??s.key}),t(B,{className:"text-right",children:o??F.chartValue}),t(B,{className:"text-right",children:u??F.chartConversion}),t(B,{className:"text-right",children:m??F.chartDropOff})]}),t(ve,{children:r.map(a=>f(xe,{clickable:!1,children:[t(z,{className:"font-medium text-gray-900 dark:text-gray-100",children:a.label}),t(z,{className:J,children:a.formattedValue}),t(z,{className:J,children:a.conversion===null?"\u2014":X(a.conversion,{locale:v,maximumFractionDigits:1})}),t(z,{className:J,children:a.dropOff===null?"\u2014":E(a.dropOff)})]},a.index))})]})}):void 0,className:T,...$,children:({width:a})=>t(Ne,{width:a,height:x,stages:r,x:s,size:g,align:C,showConversion:O,showValues:V,stageSize:D,ramp:i,tooltip:W,plotLabel:p,locale:v,onStageClick:c})})}export{$e as FunnelChart};
@@ -1 +1 @@
1
- "use strict";"use client";var ut=Object.defineProperty;var Et=Object.getOwnPropertyDescriptor;var Ot=Object.getOwnPropertyNames;var It=Object.prototype.hasOwnProperty;var Ht=(m,o)=>{for(var y in o)ut(m,y,{get:o[y],enumerable:!0})},Wt=(m,o,y,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let g of Ot(o))!It.call(m,g)&&g!==y&&ut(m,g,{get:()=>o[g],enumerable:!(r=Et(o,g))||r.enumerable});return m};var Xt=m=>Wt(ut({},"__esModule",{value:!0}),m);var Ut={};Ht(Ut,{GanttChart:()=>Kt});module.exports=Xt(Ut);var c=require("react"),pt=require("../../lib/i18n.cjs"),dt=require("../chart/ChartAxis.cjs"),vt=require("../chart/ChartContainer.cjs"),wt=require("../chart/ChartGrid.cjs"),Nt=require("../chart/ChartLegend.cjs"),St=require("../chart/ChartTooltip.cjs"),tt=require("../chart/palette.cjs"),$t=require("../chart/utils/cartesian.cjs"),et=require("../chart/utils/data.cjs"),U=require("../chart/utils/format.cjs"),ht=require("../chart/utils/path.cjs"),Lt=require("../chart/utils/scales.cjs"),x=require("../chart/utils/time.cjs"),Pt=require("../table/Table.cjs"),Rt=require("../table/TableBody.cjs"),B=require("../table/TableCell.cjs"),Mt=require("../table/TableHeader.cjs"),K=require("../table/TableHeaderCell.cjs"),Gt=require("../table/TableRow.cjs"),t=require("react/jsx-runtime"),Vt=18,kt=.5,zt=.3,Q=7,Tt=10,xt=.02,gt="text-right [font-variant-numeric:tabular-nums]",_t=(0,c.memo)(function({tasks:o,arrows:y}){return(0,t.jsxs)("g",{children:[(0,t.jsx)("g",{className:"fill-gray-400 stroke-gray-400 dark:fill-gray-500 dark:stroke-gray-500",children:y.map(r=>(0,t.jsxs)("g",{children:[(0,t.jsx)("path",{d:r.d,fill:"none",strokeWidth:1}),(0,t.jsx)("path",{d:r.head,strokeWidth:0})]},r.key))}),o.map(r=>(0,t.jsxs)("g",{children:[r.track?(0,t.jsx)("path",{d:r.track,fill:r.color,fillOpacity:r.trackOpacity}):null,r.progress?(0,t.jsx)("path",{d:r.progress,fill:r.color}):null,r.milestone?(0,t.jsx)("path",{d:r.milestone,fill:r.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"}):null]},r.key))]})});function Bt({width:m,height:o,data:y,tasks:r,x:g,domain:w,unit:G,timeTicks:E,today:L,grid:O,size:I,barSize:W,colorOf:Y,margin:F,tooltip:P,plotLabel:rt,todayLabel:nt,locale:R,formatDate:Z,formatX:D,onTaskClick:X}){let[d,M]=(0,c.useState)(null),V=(0,pt.useUILabels)(),n=(0,c.useMemo)(()=>{let l=(0,$t.buildCartesianGeometry)({width:m,height:o,data:y,x:g,y:{domain:w},bounds:w,margin:F,orientation:"horizontal",placement:"band",formatValue:a=>(0,x.formatTimeTick)(a,G,R),formatX:D}),{valueScale:f,bandwidth:i,categoryPositions:C,innerWidth:it,innerHeight:st}=l,A=Math.min(W??Vt,i),ct=new Map(r.map((a,u)=>[a.id,u])),j=r.map((a,u)=>{let N=C[u]+(i-A)/2,s=N+A/2,b=Y(a);if(a.start===null)return{key:`${u}`,color:b,track:null,trackOpacity:1,progress:null,milestone:null,top:C[u],height:i};let k=f(a.start);if(a.milestone)return{key:`${u}`,color:b,track:null,trackOpacity:1,progress:null,milestone:`M${k},${s-Q} L${k+Q},${s} L${k},${s+Q} L${k-Q},${s} Z`,top:C[u],height:i};let S=f(a.end??a.start),T=Math.max(2,S-k);return{key:`${u}`,color:b,track:(0,ht.buildBarPath)({x:k,y:N,width:T,height:A,radius:3}),trackOpacity:a.progress===null?1:zt,progress:a.progress===null?null:(0,ht.buildBarPath)({x:k,y:s-A*kt/2,width:Math.max(0,T*Math.min(1,Math.max(0,a.progress))),height:A*kt,radius:2,round:"right"}),milestone:null,top:C[u],height:i}}),q=[];r.forEach((a,u)=>{if(a.start!==null)for(let N of a.dependsOn){let s=ct.get(N);if(s===void 0||s===u)continue;let b=r[s];if(b.start===null)continue;let k=f(b.end??b.start),S=C[s]+i/2,T=f(a.start),$=C[u]+i/2,J=Math.max(k+Tt,T-Tt);q.push({key:`${N}-${a.id}`,d:`M${k},${S} L${J},${S} L${J},${$} L${T-5},${$}`,head:`M${T},${$} L${T-5},${$-3.5} L${T-5},${$+3.5} Z`})}});let mt=E.map(a=>({value:a,offset:f(a),label:(0,x.formatTimeTick)(a,G,R)}));return{rendered:j,arrows:q,categoryPositions:C,categoryCenters:l.categoryCenters,bandwidth:i,categoryTicks:l.categoryTicks,valueTicks:mt,valueScale:f,innerWidth:it,innerHeight:st,margin:l.margin}},[r,y,g,w,G,E,m,o,F,W,Y,R,D]),at=(0,c.useCallback)(l=>{if(P===!1||r.length===0)return;let f=l.currentTarget.getBoundingClientRect(),i=l.clientY-f.top-n.margin.top;M((0,Lt.nearestIndex)(n.categoryCenters,i))},[P,r.length,n.margin.top,n.categoryCenters]),ot=(0,c.useCallback)(l=>{if(r.length===0)return;let f=r.length-1,i=d??0,C=l.key==="ArrowDown"?Math.min(f,i+1):l.key==="ArrowUp"?Math.max(0,i-1):l.key==="Home"?0:l.key==="End"?f:l.key==="Escape"?null:void 0;C!==void 0&&(l.preventDefault(),M(C))},[r.length,d]),lt=(0,c.useCallback)(()=>{!X||d===null||X(r[d])},[X,d,r]),h=d===null?null:r[d];return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("svg",{width:m,height:o,role:"img","aria-label":rt??r.map(l=>l.label).join(", "),tabIndex:0,className:"touch-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500",onPointerMove:at,onPointerLeave:()=>M(null),onKeyDown:ot,onBlur:()=>M(null),onClick:lt,children:[(0,t.jsxs)("g",{transform:`translate(${n.margin.left}, ${n.margin.top})`,children:[(0,t.jsx)(wt.ChartGrid,{width:n.innerWidth,height:n.innerHeight,vertical:O?n.valueTicks.map(l=>l.offset):void 0}),d!==null?(0,t.jsx)("rect",{x:0,y:n.categoryPositions[d],width:n.innerWidth,height:n.bandwidth,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,(0,t.jsx)(_t,{tasks:n.rendered,arrows:n.arrows}),L!==null?(0,t.jsxs)("g",{children:[(0,t.jsx)("line",{x1:n.valueScale(L),y1:0,x2:n.valueScale(L),y2:n.innerHeight,className:"stroke-gray-900 dark:stroke-white",strokeWidth:1,strokeDasharray:"4 4"}),(0,t.jsx)("text",{x:n.valueScale(L)+4,y:8,className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:nt})]}):null]}),(0,t.jsx)("g",{transform:`translate(${n.margin.left}, ${n.margin.top+n.innerHeight})`,children:(0,t.jsx)(dt.ChartAxis,{orientation:"bottom",ticks:n.valueTicks,length:n.innerWidth,size:I})}),(0,t.jsx)("g",{transform:`translate(${n.margin.left}, ${n.margin.top})`,children:g.hidden?null:(0,t.jsx)(dt.ChartAxis,{orientation:"left",ticks:n.categoryTicks,length:n.innerHeight,showLine:!1,tickSize:0,label:g.label,size:I})})]}),h&&d!==null&&P!==!1?(0,t.jsx)(St.ChartTooltip,{x:n.margin.left+(h.start===null?n.innerWidth/2:n.valueScale(h.start)),y:n.margin.top+n.categoryCenters[d],containerWidth:m,children:typeof P=="function"?P(h):(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:h.label}),(0,t.jsxs)("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[(0,t.jsx)("span",{children:V.chartStart}),(0,t.jsx)("span",{className:"[font-variant-numeric:tabular-nums] text-gray-900 dark:text-gray-100",children:h.start===null?"\u2014":Z(h.start)})]}),h.milestone?null:(0,t.jsxs)("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[(0,t.jsx)("span",{children:V.chartEnd}),(0,t.jsx)("span",{className:"[font-variant-numeric:tabular-nums] text-gray-900 dark:text-gray-100",children:h.end===null?"\u2014":Z(h.end)})]}),h.progress===null?null:(0,t.jsxs)("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[(0,t.jsx)("span",{children:V.chartProgress}),(0,t.jsx)("span",{className:"[font-variant-numeric:tabular-nums] text-gray-900 dark:text-gray-100",children:(0,U.formatPercent)(h.progress,{locale:R,maximumFractionDigits:0})})]})]})}):null]})}function Kt({data:m,x:o,start:y,end:r,id:g,progress:w,milestone:G,dependencies:E,group:L,domain:O,today:I,ticks:W=6,barSize:Y,rowSize:F=30,color:P,height:rt,width:nt,size:R="md",grid:Z=!0,legend:D,tooltip:X=!0,tableView:d=!1,title:M,description:V,loading:n=!1,emptyState:at,error:ot=!1,errorState:lt,onRetry:h,actions:l,margin:f,locale:i,plotLabel:C,startLabel:it,endLabel:st,progressLabel:A,todayLabel:ct,formatDate:j,onTaskClick:q,className:mt,...a}){let u=(0,pt.useUILabels)(),N=(0,c.useMemo)(()=>o.format??(e=>(0,U.formatXValue)(e,i)),[o.format,i]),s=(0,c.useMemo)(()=>m.map((e,p)=>{let z=(0,et.readXValue)(e,o.key,p),H=(0,x.toTimestamp)(e[y]),v=r?(0,x.toTimestamp)(e[r]):null,_=G?!!e[G]:v===null,Ct=E?e[E]:void 0;return{index:p,id:String(g?e[g]??p:p),x:z,label:N(z,p),start:H,end:_?H:v??H,progress:w?(0,et.readNumber)(e,w):null,milestone:_,dependsOn:Array.isArray(Ct)?Ct.map(At=>String(At)):[],group:L?e[L]??null:null,datum:e}}),[m,o.key,y,r,g,w,G,E,L,N]),b=(0,c.useMemo)(()=>{let e=[];for(let p of s)p.group!==null&&!e.includes(p.group)&&e.push(p.group);return e},[s]),k=(0,c.useCallback)(e=>e.group===null?P??(0,tt.getSeriesColor)(0):(0,tt.getSeriesColor)(b.indexOf(e.group)),[b,P]),S=(0,c.useMemo)(()=>{if(O){let v=(0,x.toTimestamp)(O[0]),_=(0,x.toTimestamp)(O[1]);if(v!==null&&_!==null)return[v,_]}let e=s.flatMap(v=>v.start===null?[]:[v.start,v.end??v.start]);if(e.length===0)return[0,1];let p=Math.min(...e),z=Math.max(...e),H=z-p||864e5;return[p-H*xt,z+H*xt]},[O,s]),T=(0,c.useMemo)(()=>(0,x.niceTimeTicks)(S[0],S[1],W),[S,W]),$=(0,c.useMemo)(()=>j??(e=>new Intl.DateTimeFormat(i,{day:"numeric",month:"short",year:"numeric"}).format(new Date(e))),[j,i]),J=(0,c.useMemo)(()=>I===!1?null:(0,x.toTimestamp)(I??Date.now()),[I]),ft=(0,c.useMemo)(()=>b.map((e,p)=>({key:e,label:e,color:(0,tt.getSeriesColor)(p),marker:"rect"})),[b]),bt=rt??Math.max(120,s.length*F+48),Dt=D===void 0?b.length>=2:D!==!1,yt=typeof D=="string"?D:"bottom";return(0,t.jsx)(vt.ChartContainer,{title:M,description:V,height:bt,width:nt,size:R,loading:n,empty:s.length===0,emptyState:at,error:ot,errorState:lt,onRetry:h,actions:l,tableView:d,legendPosition:yt,legend:Dt&&ft.length>0?(0,t.jsx)(Nt.ChartLegend,{items:ft,position:yt,marker:"rect",size:R}):void 0,table:d?(0,t.jsx)("div",{className:"w-full overflow-x-auto",children:(0,t.jsxs)(Pt.Table,{children:[typeof M=="string"?(0,t.jsx)("caption",{className:"sr-only",children:M}):null,(0,t.jsxs)(Mt.TableHeader,{children:[(0,t.jsx)(K.TableHeaderCell,{children:o.label??o.key}),(0,t.jsx)(K.TableHeaderCell,{className:"text-right",children:it??u.chartStart}),(0,t.jsx)(K.TableHeaderCell,{className:"text-right",children:st??u.chartEnd}),w?(0,t.jsx)(K.TableHeaderCell,{className:"text-right",children:A??u.chartProgress}):null]}),(0,t.jsx)(Rt.TableBody,{children:s.map(e=>(0,t.jsxs)(Gt.TableRow,{clickable:!1,children:[(0,t.jsx)(B.TableCell,{className:"font-medium text-gray-900 dark:text-gray-100",children:e.label}),(0,t.jsx)(B.TableCell,{className:gt,children:e.start===null?"\u2014":$(e.start)}),(0,t.jsx)(B.TableCell,{className:gt,children:e.milestone||e.end===null?"\u2014":$(e.end)}),w?(0,t.jsx)(B.TableCell,{className:gt,children:e.progress===null?"\u2014":(0,U.formatPercent)(e.progress,{locale:i,maximumFractionDigits:0})}):null]},e.index))})]})}):void 0,className:mt,...a,children:({width:e})=>(0,t.jsx)(Bt,{width:e,height:bt,data:m,tasks:s,x:o,domain:S,unit:T.unit,timeTicks:T.values,today:J,grid:Z,size:R,barSize:Y,colorOf:k,margin:f,tooltip:X,plotLabel:C,todayLabel:ct??u.chartToday,locale:i,formatDate:$,formatX:N,onTaskClick:q})})}0&&(module.exports={GanttChart});
1
+ "use strict";"use client";var gt=Object.defineProperty;var Et=Object.getOwnPropertyDescriptor;var It=Object.getOwnPropertyNames;var Ht=Object.prototype.hasOwnProperty;var Wt=(c,o)=>{for(var C in o)gt(c,C,{get:o[C],enumerable:!0})},Xt=(c,o,C,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let h of It(o))!Ht.call(c,h)&&h!==C&&gt(c,h,{get:()=>o[h],enumerable:!(r=Et(o,h))||r.enumerable});return c};var Vt=c=>Xt(gt({},"__esModule",{value:!0}),c);var Yt={};Wt(Yt,{GanttChart:()=>Ut});module.exports=Vt(Yt);var i=require("react"),ft=require("../../lib/i18n.cjs"),ht=require("../chart/ChartAxis.cjs"),vt=require("../chart/ChartContainer.cjs"),wt=require("../chart/ChartGrid.cjs"),Nt=require("../chart/ChartLegend.cjs"),St=require("../chart/ChartTooltip.cjs"),et=require("../chart/palette.cjs"),$t=require("../chart/utils/cartesian.cjs"),rt=require("../chart/utils/data.cjs"),F=require("../chart/utils/format.cjs"),pt=require("../chart/utils/path.cjs"),Lt=require("../chart/utils/scales.cjs"),x=require("../chart/utils/time.cjs"),Pt=require("../chart/utils/touch.cjs"),Rt=require("../table/Table.cjs"),Mt=require("../table/TableBody.cjs"),U=require("../table/TableCell.cjs"),Gt=require("../table/TableHeader.cjs"),Y=require("../table/TableHeaderCell.cjs"),Dt=require("../table/TableRow.cjs"),t=require("react/jsx-runtime"),zt=18,Tt=.5,_t=.3,tt=7,kt=10,xt=.02,dt="text-right [font-variant-numeric:tabular-nums]",Bt=(0,i.memo)(function({tasks:o,arrows:C}){return(0,t.jsxs)("g",{children:[(0,t.jsx)("g",{className:"fill-gray-400 stroke-gray-400 dark:fill-gray-500 dark:stroke-gray-500",children:C.map(r=>(0,t.jsxs)("g",{children:[(0,t.jsx)("path",{d:r.d,fill:"none",strokeWidth:1}),(0,t.jsx)("path",{d:r.head,strokeWidth:0})]},r.key))}),o.map(r=>(0,t.jsxs)("g",{children:[r.track?(0,t.jsx)("path",{d:r.track,fill:r.color,fillOpacity:r.trackOpacity}):null,r.progress?(0,t.jsx)("path",{d:r.progress,fill:r.color}):null,r.milestone?(0,t.jsx)("path",{d:r.milestone,fill:r.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"}):null]},r.key))]})});function Kt({width:c,height:o,data:C,tasks:r,x:h,domain:w,unit:R,timeTicks:O,today:S,grid:E,size:I,barSize:X,colorOf:Z,margin:j,tooltip:$,plotLabel:nt,todayLabel:at,locale:L,formatDate:q,formatX:M,onTaskClick:V}){let[H,P]=(0,i.useState)(null),y=H!==null&&H<r.length?H:null,z=(0,ft.useUILabels)(),n=(0,i.useMemo)(()=>{let l=(0,$t.buildCartesianGeometry)({width:c,height:o,data:C,x:h,y:{domain:w},bounds:w,margin:j,orientation:"horizontal",placement:"band",formatValue:a=>(0,x.formatTimeTick)(a,R,L),formatX:M}),{valueScale:s,bandwidth:g,categoryPositions:T,innerWidth:st,innerHeight:ct}=l,G=Math.min(X??zt,g),J=new Map(r.map((a,m)=>[a.id,m])),mt=r.map((a,m)=>{let f=T[m]+(g-G)/2,u=f+G/2,N=Z(a);if(a.start===null)return{key:`${m}`,color:N,track:null,trackOpacity:1,progress:null,milestone:null,top:T[m],height:g};let d=s(a.start);if(a.milestone)return{key:`${m}`,color:N,track:null,trackOpacity:1,progress:null,milestone:`M${d},${u-tt} L${d+tt},${u} L${d},${u+tt} L${d-tt},${u} Z`,top:T[m],height:g};let D=s(a.end??a.start),k=Math.max(2,D-d);return{key:`${m}`,color:N,track:(0,pt.buildBarPath)({x:d,y:f,width:k,height:G,radius:3}),trackOpacity:a.progress===null?1:_t,progress:a.progress===null?null:(0,pt.buildBarPath)({x:d,y:u-G*Tt/2,width:Math.max(0,k*Math.min(1,Math.max(0,a.progress))),height:G*Tt,radius:2,round:"right"}),milestone:null,top:T[m],height:g}}),Q=[];r.forEach((a,m)=>{if(a.start!==null)for(let f of a.dependsOn){let u=J.get(f);if(u===void 0||u===m)continue;let N=r[u];if(N.start===null)continue;let d=s(N.end??N.start),D=T[u]+g/2,k=s(a.start),A=T[m]+g/2,_=Math.max(d+kt,k-kt);Q.push({key:`${f}-${a.id}`,d:`M${d},${D} L${_},${D} L${_},${A} L${k-5},${A}`,head:`M${k},${A} L${k-5},${A-3.5} L${k-5},${A+3.5} Z`})}});let ut=O.map(a=>({value:a,offset:s(a),label:(0,x.formatTimeTick)(a,R,L)}));return{rendered:mt,arrows:Q,categoryPositions:T,categoryCenters:l.categoryCenters,bandwidth:g,categoryTicks:l.categoryTicks,valueTicks:ut,valueScale:s,innerWidth:st,innerHeight:ct,margin:l.margin}},[r,C,h,w,R,O,c,o,j,X,Z,L,M]),ot=(0,i.useCallback)(l=>{if($===!1||r.length===0)return;let s=l.currentTarget.getBoundingClientRect(),g=l.clientY-s.top-n.margin.top;P((0,Lt.nearestIndex)(n.categoryCenters,g))},[$,r.length,n.margin.top,n.categoryCenters]),lt=(0,i.useCallback)(l=>{if(r.length===0)return;let s=r.length-1,g=y??0,T=l.key==="ArrowDown"?Math.min(s,g+1):l.key==="ArrowUp"?Math.max(0,g-1):l.key==="Home"?0:l.key==="End"?s:l.key==="Escape"?null:void 0;T!==void 0&&(l.preventDefault(),P(T))},[r.length,y]),it=(0,i.useCallback)(()=>{!V||y===null||V(r[y])},[V,y,r]),p=y===null?null:r[y];return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("svg",{width:c,height:o,role:"img","aria-label":nt??r.map(l=>l.label).join(", "),tabIndex:0,className:`${Pt.CHART_TOUCH} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500`,onPointerMove:ot,onPointerLeave:()=>P(null),onKeyDown:lt,onBlur:()=>P(null),onClick:it,children:[(0,t.jsxs)("g",{transform:`translate(${n.margin.left}, ${n.margin.top})`,children:[(0,t.jsx)(wt.ChartGrid,{width:n.innerWidth,height:n.innerHeight,vertical:E?n.valueTicks.map(l=>l.offset):void 0}),y!==null?(0,t.jsx)("rect",{x:0,y:n.categoryPositions[y],width:n.innerWidth,height:n.bandwidth,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,(0,t.jsx)(Bt,{tasks:n.rendered,arrows:n.arrows}),S!==null?(0,t.jsxs)("g",{children:[(0,t.jsx)("line",{x1:n.valueScale(S),y1:0,x2:n.valueScale(S),y2:n.innerHeight,className:"stroke-gray-900 dark:stroke-white",strokeWidth:1,strokeDasharray:"4 4"}),(0,t.jsx)("text",{x:n.valueScale(S)+4,y:8,className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:at})]}):null]}),(0,t.jsx)("g",{transform:`translate(${n.margin.left}, ${n.margin.top+n.innerHeight})`,children:(0,t.jsx)(ht.ChartAxis,{orientation:"bottom",ticks:n.valueTicks,length:n.innerWidth,size:I})}),(0,t.jsx)("g",{transform:`translate(${n.margin.left}, ${n.margin.top})`,children:h.hidden?null:(0,t.jsx)(ht.ChartAxis,{orientation:"left",ticks:n.categoryTicks,length:n.innerHeight,showLine:!1,tickSize:0,label:h.label,size:I})})]}),p&&y!==null&&$!==!1?(0,t.jsx)(St.ChartTooltip,{x:n.margin.left+(p.start===null?n.innerWidth/2:n.valueScale(p.start)),y:n.margin.top+n.categoryCenters[y],containerWidth:c,children:typeof $=="function"?$(p):(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:p.label}),(0,t.jsxs)("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[(0,t.jsx)("span",{children:z.chartStart}),(0,t.jsx)("span",{className:"[font-variant-numeric:tabular-nums] text-gray-900 dark:text-gray-100",children:p.start===null?"\u2014":q(p.start)})]}),p.milestone?null:(0,t.jsxs)("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[(0,t.jsx)("span",{children:z.chartEnd}),(0,t.jsx)("span",{className:"[font-variant-numeric:tabular-nums] text-gray-900 dark:text-gray-100",children:p.end===null?"\u2014":q(p.end)})]}),p.progress===null?null:(0,t.jsxs)("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[(0,t.jsx)("span",{children:z.chartProgress}),(0,t.jsx)("span",{className:"[font-variant-numeric:tabular-nums] text-gray-900 dark:text-gray-100",children:(0,F.formatPercent)(p.progress,{locale:L,maximumFractionDigits:0})})]})]})}):null]})}function Ut({data:c,x:o,start:C,end:r,id:h,progress:w,milestone:R,dependencies:O,group:S,domain:E,today:I,ticks:X=6,barSize:Z,rowSize:j=30,color:$,height:nt,width:at,size:L="md",grid:q=!0,legend:M,tooltip:V=!0,tableView:H=!1,title:P,description:y,loading:z=!1,emptyState:n,error:ot=!1,errorState:lt,onRetry:it,actions:p,margin:l,locale:s,plotLabel:g,startLabel:T,endLabel:st,progressLabel:ct,todayLabel:G,formatDate:J,onTaskClick:mt,className:Q,...ut}){let a=(0,ft.useUILabels)(),m=(0,i.useMemo)(()=>o.format??(e=>(0,F.formatXValue)(e,s)),[o.format,s]),f=(0,i.useMemo)(()=>c.map((e,b)=>{let B=(0,rt.readXValue)(e,o.key,b),W=(0,x.toTimestamp)(e[C]),v=r?(0,x.toTimestamp)(e[r]):null,K=R?!!e[R]:v===null,Ct=O?e[O]:void 0;return{index:b,id:String(h?e[h]??b:b),x:B,label:m(B,b),start:W,end:K?W:v??W,progress:w?(0,rt.readNumber)(e,w):null,milestone:K,dependsOn:Array.isArray(Ct)?Ct.map(Ot=>String(Ot)):[],group:S?e[S]??null:null,datum:e}}),[c,o.key,C,r,h,w,R,O,S,m]),u=(0,i.useMemo)(()=>{let e=[];for(let b of f)b.group!==null&&!e.includes(b.group)&&e.push(b.group);return e},[f]),N=(0,i.useCallback)(e=>e.group===null?$??(0,et.getSeriesColor)(0):(0,et.getSeriesColor)(u.indexOf(e.group)),[u,$]),d=(0,i.useMemo)(()=>{if(E){let v=(0,x.toTimestamp)(E[0]),K=(0,x.toTimestamp)(E[1]);if(v!==null&&K!==null)return[v,K]}let e=f.flatMap(v=>v.start===null?[]:[v.start,v.end??v.start]);if(e.length===0)return[0,1];let b=Math.min(...e),B=Math.max(...e),W=B-b||864e5;return[b-W*xt,B+W*xt]},[E,f]),D=(0,i.useMemo)(()=>(0,x.niceTimeTicks)(d[0],d[1],X),[d,X]),k=(0,i.useMemo)(()=>J??(e=>new Intl.DateTimeFormat(s,{day:"numeric",month:"short",year:"numeric"}).format(new Date(e))),[J,s]),A=(0,i.useMemo)(()=>I===!1?null:(0,x.toTimestamp)(I??Date.now()),[I]),_=(0,i.useMemo)(()=>u.map((e,b)=>({key:e,label:e,color:(0,et.getSeriesColor)(b),marker:"rect"})),[u]),bt=nt??Math.max(120,f.length*j+48),At=M===void 0?u.length>=2:M!==!1,yt=typeof M=="string"?M:"bottom";return(0,t.jsx)(vt.ChartContainer,{title:P,description:y,height:bt,width:at,size:L,loading:z,empty:f.length===0,emptyState:n,error:ot,errorState:lt,onRetry:it,actions:p,tableView:H,legendPosition:yt,legend:At&&_.length>0?(0,t.jsx)(Nt.ChartLegend,{items:_,position:yt,marker:"rect",size:L}):void 0,table:H?(0,t.jsx)("div",{className:"w-full overflow-x-auto",children:(0,t.jsxs)(Rt.Table,{children:[typeof P=="string"?(0,t.jsx)("caption",{className:"sr-only",children:P}):null,(0,t.jsxs)(Gt.TableHeader,{children:[(0,t.jsx)(Y.TableHeaderCell,{children:o.label??o.key}),(0,t.jsx)(Y.TableHeaderCell,{className:"text-right",children:T??a.chartStart}),(0,t.jsx)(Y.TableHeaderCell,{className:"text-right",children:st??a.chartEnd}),w?(0,t.jsx)(Y.TableHeaderCell,{className:"text-right",children:ct??a.chartProgress}):null]}),(0,t.jsx)(Mt.TableBody,{children:f.map(e=>(0,t.jsxs)(Dt.TableRow,{clickable:!1,children:[(0,t.jsx)(U.TableCell,{className:"font-medium text-gray-900 dark:text-gray-100",children:e.label}),(0,t.jsx)(U.TableCell,{className:dt,children:e.start===null?"\u2014":k(e.start)}),(0,t.jsx)(U.TableCell,{className:dt,children:e.milestone||e.end===null?"\u2014":k(e.end)}),w?(0,t.jsx)(U.TableCell,{className:dt,children:e.progress===null?"\u2014":(0,F.formatPercent)(e.progress,{locale:s,maximumFractionDigits:0})}):null]},e.index))})]})}):void 0,className:Q,...ut,children:({width:e})=>(0,t.jsx)(Kt,{width:e,height:bt,data:c,tasks:f,x:o,domain:d,unit:D.unit,timeTicks:D.values,today:A,grid:q,size:L,barSize:Z,colorOf:N,margin:l,tooltip:V,plotLabel:g,todayLabel:G??a.chartToday,locale:s,formatDate:k,formatX:m,onTaskClick:mt})})}0&&(module.exports={GanttChart});
@@ -1 +1 @@
1
- "use client";import{memo as St,useCallback as tt,useMemo as N,useState as $t}from"react";import{useUILabels as xt}from"../../lib/i18n.js";import{ChartAxis as ft}from"../chart/ChartAxis.js";import{ChartContainer as Lt}from"../chart/ChartContainer.js";import{ChartGrid as Pt}from"../chart/ChartGrid.js";import{ChartLegend as Rt}from"../chart/ChartLegend.js";import{ChartTooltip as Mt}from"../chart/ChartTooltip.js";import{getSeriesColor as mt}from"../chart/palette.js";import{buildCartesianGeometry as Gt}from"../chart/utils/cartesian.js";import{readNumber as Dt,readXValue as At}from"../chart/utils/data.js";import{formatPercent as vt,formatXValue as Et}from"../chart/utils/format.js";import{buildBarPath as bt}from"../chart/utils/path.js";import{nearestIndex as Ot}from"../chart/utils/scales.js";import{formatTimeTick as yt,niceTimeTicks as It,toTimestamp as B}from"../chart/utils/time.js";import{Table as Ht}from"../table/Table.js";import{TableBody as Wt}from"../table/TableBody.js";import{TableCell as q}from"../table/TableCell.js";import{TableHeader as Xt}from"../table/TableHeader.js";import{TableHeaderCell as J}from"../table/TableHeaderCell.js";import{TableRow as Vt}from"../table/TableRow.js";import{Fragment as Ut,jsx as e,jsxs as g}from"react/jsx-runtime";var zt=18,Ct=.5,_t=.3,Q=7,kt=10,Tt=.02,ut="text-right [font-variant-numeric:tabular-nums]",Bt=St(function({tasks:d,arrows:M}){return g("g",{children:[e("g",{className:"fill-gray-400 stroke-gray-400 dark:fill-gray-500 dark:stroke-gray-500",children:M.map(r=>g("g",{children:[e("path",{d:r.d,fill:"none",strokeWidth:1}),e("path",{d:r.head,strokeWidth:0})]},r.key))}),d.map(r=>g("g",{children:[r.track?e("path",{d:r.track,fill:r.color,fillOpacity:r.trackOpacity}):null,r.progress?e("path",{d:r.progress,fill:r.color}):null,r.milestone?e("path",{d:r.milestone,fill:r.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"}):null]},r.key))]})});function Kt({width:k,height:d,data:M,tasks:r,x:S,domain:T,unit:G,timeTicks:E,today:$,grid:O,size:I,barSize:W,colorOf:K,margin:U,tooltip:L,plotLabel:et,todayLabel:rt,locale:P,formatDate:Y,formatX:D,onTaskClick:X}){let[c,R]=$t(null),V=xt(),n=N(()=>{let o=Gt({width:k,height:d,data:M,x:S,y:{domain:T},bounds:T,margin:U,orientation:"horizontal",placement:"band",formatValue:a=>yt(a,G,P),formatX:D}),{valueScale:h,bandwidth:l,categoryPositions:f,innerWidth:lt,innerHeight:it}=o,A=Math.min(W??zt,l),st=new Map(r.map((a,s)=>[a.id,s])),F=r.map((a,s)=>{let x=f[s]+(l-A)/2,i=x+A/2,p=K(a);if(a.start===null)return{key:`${s}`,color:p,track:null,trackOpacity:1,progress:null,milestone:null,top:f[s],height:l};let b=h(a.start);if(a.milestone)return{key:`${s}`,color:p,track:null,trackOpacity:1,progress:null,milestone:`M${b},${i-Q} L${b+Q},${i} L${b},${i+Q} L${b-Q},${i} Z`,top:f[s],height:l};let v=h(a.end??a.start),y=Math.max(2,v-b);return{key:`${s}`,color:p,track:bt({x:b,y:x,width:y,height:A,radius:3}),trackOpacity:a.progress===null?1:_t,progress:a.progress===null?null:bt({x:b,y:i-A*Ct/2,width:Math.max(0,y*Math.min(1,Math.max(0,a.progress))),height:A*Ct,radius:2,round:"right"}),milestone:null,top:f[s],height:l}}),Z=[];r.forEach((a,s)=>{if(a.start!==null)for(let x of a.dependsOn){let i=st.get(x);if(i===void 0||i===s)continue;let p=r[i];if(p.start===null)continue;let b=h(p.end??p.start),v=f[i]+l/2,y=h(a.start),w=f[s]+l/2,j=Math.max(b+kt,y-kt);Z.push({key:`${x}-${a.id}`,d:`M${b},${v} L${j},${v} L${j},${w} L${y-5},${w}`,head:`M${y},${w} L${y-5},${w-3.5} L${y-5},${w+3.5} Z`})}});let ct=E.map(a=>({value:a,offset:h(a),label:yt(a,G,P)}));return{rendered:F,arrows:Z,categoryPositions:f,categoryCenters:o.categoryCenters,bandwidth:l,categoryTicks:o.categoryTicks,valueTicks:ct,valueScale:h,innerWidth:lt,innerHeight:it,margin:o.margin}},[r,M,S,T,G,E,k,d,U,W,K,P,D]),nt=tt(o=>{if(L===!1||r.length===0)return;let h=o.currentTarget.getBoundingClientRect(),l=o.clientY-h.top-n.margin.top;R(Ot(n.categoryCenters,l))},[L,r.length,n.margin.top,n.categoryCenters]),at=tt(o=>{if(r.length===0)return;let h=r.length-1,l=c??0,f=o.key==="ArrowDown"?Math.min(h,l+1):o.key==="ArrowUp"?Math.max(0,l-1):o.key==="Home"?0:o.key==="End"?h:o.key==="Escape"?null:void 0;f!==void 0&&(o.preventDefault(),R(f))},[r.length,c]),ot=tt(()=>{!X||c===null||X(r[c])},[X,c,r]),m=c===null?null:r[c];return g(Ut,{children:[g("svg",{width:k,height:d,role:"img","aria-label":et??r.map(o=>o.label).join(", "),tabIndex:0,className:"touch-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500",onPointerMove:nt,onPointerLeave:()=>R(null),onKeyDown:at,onBlur:()=>R(null),onClick:ot,children:[g("g",{transform:`translate(${n.margin.left}, ${n.margin.top})`,children:[e(Pt,{width:n.innerWidth,height:n.innerHeight,vertical:O?n.valueTicks.map(o=>o.offset):void 0}),c!==null?e("rect",{x:0,y:n.categoryPositions[c],width:n.innerWidth,height:n.bandwidth,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,e(Bt,{tasks:n.rendered,arrows:n.arrows}),$!==null?g("g",{children:[e("line",{x1:n.valueScale($),y1:0,x2:n.valueScale($),y2:n.innerHeight,className:"stroke-gray-900 dark:stroke-white",strokeWidth:1,strokeDasharray:"4 4"}),e("text",{x:n.valueScale($)+4,y:8,className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:rt})]}):null]}),e("g",{transform:`translate(${n.margin.left}, ${n.margin.top+n.innerHeight})`,children:e(ft,{orientation:"bottom",ticks:n.valueTicks,length:n.innerWidth,size:I})}),e("g",{transform:`translate(${n.margin.left}, ${n.margin.top})`,children:S.hidden?null:e(ft,{orientation:"left",ticks:n.categoryTicks,length:n.innerHeight,showLine:!1,tickSize:0,label:S.label,size:I})})]}),m&&c!==null&&L!==!1?e(Mt,{x:n.margin.left+(m.start===null?n.innerWidth/2:n.valueScale(m.start)),y:n.margin.top+n.categoryCenters[c],containerWidth:k,children:typeof L=="function"?L(m):g("div",{className:"flex flex-col gap-1",children:[e("div",{className:"font-medium text-gray-900 dark:text-gray-100",children:m.label}),g("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[e("span",{children:V.chartStart}),e("span",{className:"[font-variant-numeric:tabular-nums] text-gray-900 dark:text-gray-100",children:m.start===null?"\u2014":Y(m.start)})]}),m.milestone?null:g("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[e("span",{children:V.chartEnd}),e("span",{className:"[font-variant-numeric:tabular-nums] text-gray-900 dark:text-gray-100",children:m.end===null?"\u2014":Y(m.end)})]}),m.progress===null?null:g("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[e("span",{children:V.chartProgress}),e("span",{className:"[font-variant-numeric:tabular-nums] text-gray-900 dark:text-gray-100",children:vt(m.progress,{locale:P,maximumFractionDigits:0})})]})]})}):null]})}function de({data:k,x:d,start:M,end:r,id:S,progress:T,milestone:G,dependencies:E,group:$,domain:O,today:I,ticks:W=6,barSize:K,rowSize:U=30,color:L,height:et,width:rt,size:P="md",grid:Y=!0,legend:D,tooltip:X=!0,tableView:c=!1,title:R,description:V,loading:n=!1,emptyState:nt,error:at=!1,errorState:ot,onRetry:m,actions:o,margin:h,locale:l,plotLabel:f,startLabel:lt,endLabel:it,progressLabel:A,todayLabel:st,formatDate:F,onTaskClick:Z,className:ct,...a}){let s=xt(),x=N(()=>d.format??(t=>Et(t,l)),[d.format,l]),i=N(()=>k.map((t,u)=>{let z=At(t,d.key,u),H=B(t[M]),C=r?B(t[r]):null,_=G?!!t[G]:C===null,pt=E?t[E]:void 0;return{index:u,id:String(S?t[S]??u:u),x:z,label:x(z,u),start:H,end:_?H:C??H,progress:T?Dt(t,T):null,milestone:_,dependsOn:Array.isArray(pt)?pt.map(Nt=>String(Nt)):[],group:$?t[$]??null:null,datum:t}}),[k,d.key,M,r,S,T,G,E,$,x]),p=N(()=>{let t=[];for(let u of i)u.group!==null&&!t.includes(u.group)&&t.push(u.group);return t},[i]),b=tt(t=>t.group===null?L??mt(0):mt(p.indexOf(t.group)),[p,L]),v=N(()=>{if(O){let C=B(O[0]),_=B(O[1]);if(C!==null&&_!==null)return[C,_]}let t=i.flatMap(C=>C.start===null?[]:[C.start,C.end??C.start]);if(t.length===0)return[0,1];let u=Math.min(...t),z=Math.max(...t),H=z-u||864e5;return[u-H*Tt,z+H*Tt]},[O,i]),y=N(()=>It(v[0],v[1],W),[v,W]),w=N(()=>F??(t=>new Intl.DateTimeFormat(l,{day:"numeric",month:"short",year:"numeric"}).format(new Date(t))),[F,l]),j=N(()=>I===!1?null:B(I??Date.now()),[I]),gt=N(()=>p.map((t,u)=>({key:t,label:t,color:mt(u),marker:"rect"})),[p]),dt=et??Math.max(120,i.length*U+48),wt=D===void 0?p.length>=2:D!==!1,ht=typeof D=="string"?D:"bottom";return e(Lt,{title:R,description:V,height:dt,width:rt,size:P,loading:n,empty:i.length===0,emptyState:nt,error:at,errorState:ot,onRetry:m,actions:o,tableView:c,legendPosition:ht,legend:wt&&gt.length>0?e(Rt,{items:gt,position:ht,marker:"rect",size:P}):void 0,table:c?e("div",{className:"w-full overflow-x-auto",children:g(Ht,{children:[typeof R=="string"?e("caption",{className:"sr-only",children:R}):null,g(Xt,{children:[e(J,{children:d.label??d.key}),e(J,{className:"text-right",children:lt??s.chartStart}),e(J,{className:"text-right",children:it??s.chartEnd}),T?e(J,{className:"text-right",children:A??s.chartProgress}):null]}),e(Wt,{children:i.map(t=>g(Vt,{clickable:!1,children:[e(q,{className:"font-medium text-gray-900 dark:text-gray-100",children:t.label}),e(q,{className:ut,children:t.start===null?"\u2014":w(t.start)}),e(q,{className:ut,children:t.milestone||t.end===null?"\u2014":w(t.end)}),T?e(q,{className:ut,children:t.progress===null?"\u2014":vt(t.progress,{locale:l,maximumFractionDigits:0})}):null]},t.index))})]})}):void 0,className:ct,...a,children:({width:t})=>e(Kt,{width:t,height:dt,data:k,tasks:i,x:d,domain:v,unit:y.unit,timeTicks:y.values,today:j,grid:Y,size:P,barSize:K,colorOf:b,margin:h,tooltip:X,plotLabel:f,todayLabel:st??s.chartToday,locale:l,formatDate:w,formatX:x,onTaskClick:Z})})}export{de as GanttChart};
1
+ "use client";import{memo as St,useCallback as et,useMemo as v,useState as $t}from"react";import{useUILabels as xt}from"../../lib/i18n.js";import{ChartAxis as ft}from"../chart/ChartAxis.js";import{ChartContainer as Lt}from"../chart/ChartContainer.js";import{ChartGrid as Pt}from"../chart/ChartGrid.js";import{ChartLegend as Rt}from"../chart/ChartLegend.js";import{ChartTooltip as Mt}from"../chart/ChartTooltip.js";import{getSeriesColor as ut}from"../chart/palette.js";import{buildCartesianGeometry as Gt}from"../chart/utils/cartesian.js";import{readNumber as Dt,readXValue as At}from"../chart/utils/data.js";import{formatPercent as vt,formatXValue as Ot}from"../chart/utils/format.js";import{buildBarPath as bt}from"../chart/utils/path.js";import{nearestIndex as Et}from"../chart/utils/scales.js";import{formatTimeTick as yt,niceTimeTicks as It,toTimestamp as U}from"../chart/utils/time.js";import{CHART_TOUCH as Ht}from"../chart/utils/touch.js";import{Table as Wt}from"../table/Table.js";import{TableBody as Xt}from"../table/TableBody.js";import{TableCell as J}from"../table/TableCell.js";import{TableHeader as Vt}from"../table/TableHeader.js";import{TableHeaderCell as Q}from"../table/TableHeaderCell.js";import{TableRow as zt}from"../table/TableRow.js";import{Fragment as Yt,jsx as e,jsxs as h}from"react/jsx-runtime";var _t=18,Ct=.5,Bt=.3,tt=7,Tt=10,kt=.02,gt="text-right [font-variant-numeric:tabular-nums]",Kt=St(function({tasks:p,arrows:P}){return h("g",{children:[e("g",{className:"fill-gray-400 stroke-gray-400 dark:fill-gray-500 dark:stroke-gray-500",children:P.map(r=>h("g",{children:[e("path",{d:r.d,fill:"none",strokeWidth:1}),e("path",{d:r.head,strokeWidth:0})]},r.key))}),p.map(r=>h("g",{children:[r.track?e("path",{d:r.track,fill:r.color,fillOpacity:r.trackOpacity}):null,r.progress?e("path",{d:r.progress,fill:r.color}):null,r.milestone?e("path",{d:r.milestone,fill:r.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"}):null]},r.key))]})});function Ut({width:T,height:p,data:P,tasks:r,x:w,domain:k,unit:R,timeTicks:O,today:N,grid:E,size:I,barSize:X,colorOf:Y,margin:F,tooltip:S,plotLabel:rt,todayLabel:nt,locale:$,formatDate:Z,formatX:M,onTaskClick:V}){let[H,L]=$t(null),f=H!==null&&H<r.length?H:null,z=xt(),n=v(()=>{let o=Gt({width:T,height:p,data:P,x:w,y:{domain:k},bounds:k,margin:F,orientation:"horizontal",placement:"band",formatValue:a=>yt(a,R,$),formatX:M}),{valueScale:l,bandwidth:c,categoryPositions:b,innerWidth:it,innerHeight:st}=o,G=Math.min(X??_t,c),j=new Map(r.map((a,i)=>[a.id,i])),ct=r.map((a,i)=>{let g=b[i]+(c-G)/2,s=g+G/2,x=Y(a);if(a.start===null)return{key:`${i}`,color:x,track:null,trackOpacity:1,progress:null,milestone:null,top:b[i],height:c};let m=l(a.start);if(a.milestone)return{key:`${i}`,color:x,track:null,trackOpacity:1,progress:null,milestone:`M${m},${s-tt} L${m+tt},${s} L${m},${s+tt} L${m-tt},${s} Z`,top:b[i],height:c};let D=l(a.end??a.start),y=Math.max(2,D-m);return{key:`${i}`,color:x,track:bt({x:m,y:g,width:y,height:G,radius:3}),trackOpacity:a.progress===null?1:Bt,progress:a.progress===null?null:bt({x:m,y:s-G*Ct/2,width:Math.max(0,y*Math.min(1,Math.max(0,a.progress))),height:G*Ct,radius:2,round:"right"}),milestone:null,top:b[i],height:c}}),q=[];r.forEach((a,i)=>{if(a.start!==null)for(let g of a.dependsOn){let s=j.get(g);if(s===void 0||s===i)continue;let x=r[s];if(x.start===null)continue;let m=l(x.end??x.start),D=b[s]+c/2,y=l(a.start),A=b[i]+c/2,_=Math.max(m+Tt,y-Tt);q.push({key:`${g}-${a.id}`,d:`M${m},${D} L${_},${D} L${_},${A} L${y-5},${A}`,head:`M${y},${A} L${y-5},${A-3.5} L${y-5},${A+3.5} Z`})}});let mt=O.map(a=>({value:a,offset:l(a),label:yt(a,R,$)}));return{rendered:ct,arrows:q,categoryPositions:b,categoryCenters:o.categoryCenters,bandwidth:c,categoryTicks:o.categoryTicks,valueTicks:mt,valueScale:l,innerWidth:it,innerHeight:st,margin:o.margin}},[r,P,w,k,R,O,T,p,F,X,Y,$,M]),at=et(o=>{if(S===!1||r.length===0)return;let l=o.currentTarget.getBoundingClientRect(),c=o.clientY-l.top-n.margin.top;L(Et(n.categoryCenters,c))},[S,r.length,n.margin.top,n.categoryCenters]),ot=et(o=>{if(r.length===0)return;let l=r.length-1,c=f??0,b=o.key==="ArrowDown"?Math.min(l,c+1):o.key==="ArrowUp"?Math.max(0,c-1):o.key==="Home"?0:o.key==="End"?l:o.key==="Escape"?null:void 0;b!==void 0&&(o.preventDefault(),L(b))},[r.length,f]),lt=et(()=>{!V||f===null||V(r[f])},[V,f,r]),u=f===null?null:r[f];return h(Yt,{children:[h("svg",{width:T,height:p,role:"img","aria-label":rt??r.map(o=>o.label).join(", "),tabIndex:0,className:`${Ht} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500`,onPointerMove:at,onPointerLeave:()=>L(null),onKeyDown:ot,onBlur:()=>L(null),onClick:lt,children:[h("g",{transform:`translate(${n.margin.left}, ${n.margin.top})`,children:[e(Pt,{width:n.innerWidth,height:n.innerHeight,vertical:E?n.valueTicks.map(o=>o.offset):void 0}),f!==null?e("rect",{x:0,y:n.categoryPositions[f],width:n.innerWidth,height:n.bandwidth,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,e(Kt,{tasks:n.rendered,arrows:n.arrows}),N!==null?h("g",{children:[e("line",{x1:n.valueScale(N),y1:0,x2:n.valueScale(N),y2:n.innerHeight,className:"stroke-gray-900 dark:stroke-white",strokeWidth:1,strokeDasharray:"4 4"}),e("text",{x:n.valueScale(N)+4,y:8,className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:nt})]}):null]}),e("g",{transform:`translate(${n.margin.left}, ${n.margin.top+n.innerHeight})`,children:e(ft,{orientation:"bottom",ticks:n.valueTicks,length:n.innerWidth,size:I})}),e("g",{transform:`translate(${n.margin.left}, ${n.margin.top})`,children:w.hidden?null:e(ft,{orientation:"left",ticks:n.categoryTicks,length:n.innerHeight,showLine:!1,tickSize:0,label:w.label,size:I})})]}),u&&f!==null&&S!==!1?e(Mt,{x:n.margin.left+(u.start===null?n.innerWidth/2:n.valueScale(u.start)),y:n.margin.top+n.categoryCenters[f],containerWidth:T,children:typeof S=="function"?S(u):h("div",{className:"flex flex-col gap-1",children:[e("div",{className:"font-medium text-gray-900 dark:text-gray-100",children:u.label}),h("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[e("span",{children:z.chartStart}),e("span",{className:"[font-variant-numeric:tabular-nums] text-gray-900 dark:text-gray-100",children:u.start===null?"\u2014":Z(u.start)})]}),u.milestone?null:h("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[e("span",{children:z.chartEnd}),e("span",{className:"[font-variant-numeric:tabular-nums] text-gray-900 dark:text-gray-100",children:u.end===null?"\u2014":Z(u.end)})]}),u.progress===null?null:h("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[e("span",{children:z.chartProgress}),e("span",{className:"[font-variant-numeric:tabular-nums] text-gray-900 dark:text-gray-100",children:vt(u.progress,{locale:$,maximumFractionDigits:0})})]})]})}):null]})}function pe({data:T,x:p,start:P,end:r,id:w,progress:k,milestone:R,dependencies:O,group:N,domain:E,today:I,ticks:X=6,barSize:Y,rowSize:F=30,color:S,height:rt,width:nt,size:$="md",grid:Z=!0,legend:M,tooltip:V=!0,tableView:H=!1,title:L,description:f,loading:z=!1,emptyState:n,error:at=!1,errorState:ot,onRetry:lt,actions:u,margin:o,locale:l,plotLabel:c,startLabel:b,endLabel:it,progressLabel:st,todayLabel:G,formatDate:j,onTaskClick:ct,className:q,...mt}){let a=xt(),i=v(()=>p.format??(t=>Ot(t,l)),[p.format,l]),g=v(()=>T.map((t,d)=>{let B=At(t,p.key,d),W=U(t[P]),C=r?U(t[r]):null,K=R?!!t[R]:C===null,pt=O?t[O]:void 0;return{index:d,id:String(w?t[w]??d:d),x:B,label:i(B,d),start:W,end:K?W:C??W,progress:k?Dt(t,k):null,milestone:K,dependsOn:Array.isArray(pt)?pt.map(Nt=>String(Nt)):[],group:N?t[N]??null:null,datum:t}}),[T,p.key,P,r,w,k,R,O,N,i]),s=v(()=>{let t=[];for(let d of g)d.group!==null&&!t.includes(d.group)&&t.push(d.group);return t},[g]),x=et(t=>t.group===null?S??ut(0):ut(s.indexOf(t.group)),[s,S]),m=v(()=>{if(E){let C=U(E[0]),K=U(E[1]);if(C!==null&&K!==null)return[C,K]}let t=g.flatMap(C=>C.start===null?[]:[C.start,C.end??C.start]);if(t.length===0)return[0,1];let d=Math.min(...t),B=Math.max(...t),W=B-d||864e5;return[d-W*kt,B+W*kt]},[E,g]),D=v(()=>It(m[0],m[1],X),[m,X]),y=v(()=>j??(t=>new Intl.DateTimeFormat(l,{day:"numeric",month:"short",year:"numeric"}).format(new Date(t))),[j,l]),A=v(()=>I===!1?null:U(I??Date.now()),[I]),_=v(()=>s.map((t,d)=>({key:t,label:t,color:ut(d),marker:"rect"})),[s]),dt=rt??Math.max(120,g.length*F+48),wt=M===void 0?s.length>=2:M!==!1,ht=typeof M=="string"?M:"bottom";return e(Lt,{title:L,description:f,height:dt,width:nt,size:$,loading:z,empty:g.length===0,emptyState:n,error:at,errorState:ot,onRetry:lt,actions:u,tableView:H,legendPosition:ht,legend:wt&&_.length>0?e(Rt,{items:_,position:ht,marker:"rect",size:$}):void 0,table:H?e("div",{className:"w-full overflow-x-auto",children:h(Wt,{children:[typeof L=="string"?e("caption",{className:"sr-only",children:L}):null,h(Vt,{children:[e(Q,{children:p.label??p.key}),e(Q,{className:"text-right",children:b??a.chartStart}),e(Q,{className:"text-right",children:it??a.chartEnd}),k?e(Q,{className:"text-right",children:st??a.chartProgress}):null]}),e(Xt,{children:g.map(t=>h(zt,{clickable:!1,children:[e(J,{className:"font-medium text-gray-900 dark:text-gray-100",children:t.label}),e(J,{className:gt,children:t.start===null?"\u2014":y(t.start)}),e(J,{className:gt,children:t.milestone||t.end===null?"\u2014":y(t.end)}),k?e(J,{className:gt,children:t.progress===null?"\u2014":vt(t.progress,{locale:l,maximumFractionDigits:0})}):null]},t.index))})]})}):void 0,className:q,...mt,children:({width:t})=>e(Ut,{width:t,height:dt,data:T,tasks:g,x:p,domain:m,unit:D.unit,timeTicks:D.values,today:A,grid:Z,size:$,barSize:Y,colorOf:x,margin:o,tooltip:V,plotLabel:c,todayLabel:G??a.chartToday,locale:l,formatDate:y,formatX:i,onTaskClick:ct})})}export{pe as GanttChart};
@@ -1 +1 @@
1
- "use strict";"use client";var te=Object.defineProperty;var be=Object.getOwnPropertyDescriptor;var pe=Object.getOwnPropertyNames;var Ce=Object.prototype.hasOwnProperty;var ke=(i,r)=>{for(var t in r)te(i,t,{get:r[t],enumerable:!0})},ye=(i,r,t,e)=>{if(r&&typeof r=="object"||typeof r=="function")for(let f of pe(r))!Ce.call(i,f)&&f!==t&&te(i,f,{get:()=>r[f],enumerable:!(e=be(r,f))||e.enumerable});return i};var we=i=>ye(te({},"__esModule",{value:!0}),i);var Re={};ke(Re,{Heatmap:()=>He,resetHeatmapWarnings:()=>Xe});module.exports=we(Re);var c=require("react"),se=require("../../lib/cn.cjs"),ae=require("../chart/ChartAxis.cjs"),ue=require("../chart/ChartContainer.cjs"),ce=require("../chart/ChartScaleLegend.cjs"),me=require("../chart/ChartTableView.cjs"),he=require("../chart/ChartTooltip.cjs"),M=require("../chart/palette.cjs"),z=require("../chart/utils/data.cjs"),G=require("../chart/utils/format.cjs"),k=require("../chart/utils/scales.cjs"),L=require("../chart/utils/text.cjs"),de=require("../chart/utils/ticks.cjs"),n=require("react/jsx-runtime"),ve=2,Se=2,xe=12,Le=16,oe="cell:",ne=!1,Ve=(0,c.memo)(function({cells:r,radius:t}){return(0,n.jsx)("g",{children:r.map(e=>(0,n.jsxs)("g",{children:[(0,n.jsx)("rect",{x:e.x,y:e.y,width:e.width,height:e.height,rx:t,fill:e.missing?void 0:e.color,className:e.missing?"fill-gray-100 dark:fill-gray-800":void 0}),e.label?(0,n.jsx)("text",{x:e.x+e.width/2,y:e.y+e.height/2,textAnchor:"middle",dominantBaseline:"central",className:(0,se.cn)("text-[10px] [font-variant-numeric:tabular-nums]",e.onDark?"fill-gray-50 dark:fill-gray-900":"fill-gray-900 dark:fill-gray-50"),children:e.label}):null]},e.key))})});function Ee({width:i,height:r,columns:t,rows:e,lookup:f,colorScale:S,x:b,y:p,size:V,cellGap:w,cellRadius:W,showValues:I,tooltip:$,plotLabel:J,formatValue:N,formatX:A,formatY:T,onCellClick:P}){let[m,D]=(0,c.useState)(null),a=(0,c.useMemo)(()=>{let C=t.map((g,o)=>A(g,o)),s=e.map((g,o)=>T(g,o)),l={top:8,right:8,bottom:b.hidden?8:b.height??24+(b.label?16:0),left:p.hidden?8:p.height??(0,L.widestLabel)(s)+xe+(p.label?16:0)},v=Math.max(0,i-l.left-l.right),h=Math.max(0,r-l.top-l.bottom),d=(0,k.createBandScale)(t.map((g,o)=>o),[0,v],{paddingInner:0,paddingOuter:0}),x=(0,k.createBandScale)(e.map((g,o)=>o),[0,h],{paddingInner:0,paddingOuter:0}),Y=Math.max(0,d.bandwidth-w),Z=Math.max(0,x.bandwidth-w),X=[];e.forEach((g,o)=>{t.forEach((ee,q)=>{let E=f.get(`${(0,k.toKey)(ee)}|${(0,k.toKey)(g)}`)?.value??null,u=null;if(I&&E!==null&&Z>=Le){let y=N(E);(0,L.estimateTextWidth)(y,10)+6<=Y&&(u=y)}X.push({key:`${q}-${o}`,column:q,row:o,x:d(q)+w/2,y:x(o)+w/2,width:Y,height:Z,color:E===null?"transparent":S(E),label:u,onDark:E!==null&&S.onDark(E),missing:E===null})})});let B=(0,L.labelStride)(C.length,v,(0,L.widestLabel)(C)),R=(0,L.labelStride)(s.length,h,L.AXIS_FONT_SIZE+4),O=b.hidden?[]:C.map((g,o)=>({value:t[o],offset:d.center(o),label:g})).filter((g,o)=>o%B===0),U=p.hidden?[]:s.map((g,o)=>({value:e[o],offset:x.center(o),label:g})).filter((g,o)=>o%R===0);return{margin:l,innerWidth:v,innerHeight:h,columnScale:d,rowScale:x,cells:X,columnTicks:O,rowTicks:U}},[t,e,f,S,b,p,i,r,w,I,N,A,T]),_=(0,c.useCallback)((C,s)=>{let l=t[C],v=e[s],h=f.get(`${(0,k.toKey)(l)}|${(0,k.toKey)(v)}`),d=h?.value??null;return{x:l,y:v,xLabel:A(l,C),yLabel:T(v,s),value:d,formattedValue:d===null?"\u2014":N(d),color:d===null?"transparent":S(d),datum:h?.datum}},[t,e,f,S,N,A,T]),K=(0,c.useCallback)(C=>{if($===!1||t.length===0||e.length===0)return;let s=C.currentTarget.getBoundingClientRect(),l=C.clientX-s.left-a.margin.left,v=C.clientY-s.top-a.margin.top,h=Math.floor(l/(a.columnScale.step||1)),d=Math.floor(v/(a.rowScale.step||1));if(h<0||h>=t.length||d<0||d>=e.length){D(null);return}D(x=>x?.column===h&&x.row===d?x:{column:h,row:d})},[$,t.length,e.length,a.margin,a.columnScale,a.rowScale]),Q=(0,c.useCallback)(C=>{if(t.length===0||e.length===0)return;let s=m??{column:0,row:0},l;switch(C.key){case"ArrowRight":l={...s,column:Math.min(t.length-1,s.column+1)};break;case"ArrowLeft":l={...s,column:Math.max(0,s.column-1)};break;case"ArrowDown":l={...s,row:Math.min(e.length-1,s.row+1)};break;case"ArrowUp":l={...s,row:Math.max(0,s.row-1)};break;case"Home":l={...s,column:0};break;case"End":l={...s,column:t.length-1};break;case"Escape":l=null;break;default:l=void 0}l!==void 0&&(C.preventDefault(),D(l))},[t.length,e.length,m]),j=(0,c.useCallback)(()=>{!P||!m||P(_(m.column,m.row))},[P,m,_]),H=m?_(m.column,m.row):null;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("svg",{width:i,height:r,role:"img","aria-label":J??`${b.label??b.key} / ${p.label??p.key}`,tabIndex:0,className:"touch-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500",onPointerMove:K,onPointerLeave:()=>D(null),onKeyDown:Q,onBlur:()=>D(null),onClick:j,children:[(0,n.jsxs)("g",{transform:`translate(${a.margin.left}, ${a.margin.top})`,children:[(0,n.jsx)(Ve,{cells:a.cells,radius:W}),m?(0,n.jsx)("rect",{x:a.columnScale(m.column)+w/2,y:a.rowScale(m.row)+w/2,width:Math.max(0,a.columnScale.bandwidth-w),height:Math.max(0,a.rowScale.bandwidth-w),rx:W,fill:"none",strokeWidth:2,className:"stroke-gray-900 dark:stroke-white","aria-hidden":"true"}):null]}),(0,n.jsx)("g",{transform:`translate(${a.margin.left}, ${a.margin.top+a.innerHeight})`,children:b.hidden?null:(0,n.jsx)(ae.ChartAxis,{orientation:"bottom",ticks:a.columnTicks,length:a.innerWidth,showLine:!1,tickSize:0,label:b.label,size:V})}),(0,n.jsx)("g",{transform:`translate(${a.margin.left}, ${a.margin.top})`,children:p.hidden?null:(0,n.jsx)(ae.ChartAxis,{orientation:"left",ticks:a.rowTicks,length:a.innerHeight,showLine:!1,tickSize:0,label:p.label,size:V})})]}),m&&H&&$!==!1?(0,n.jsx)(he.ChartTooltip,{x:a.margin.left+a.columnScale.center(m.column),y:a.margin.top+a.rowScale.center(m.row),containerWidth:i,children:typeof $=="function"?$(H):(0,n.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,n.jsxs)("div",{className:"font-medium text-gray-900 dark:text-gray-100",children:[H.yLabel," \xB7 ",H.xLabel]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"h-2.5 w-2.5 shrink-0 rounded-sm",style:{backgroundColor:H.color},"aria-hidden":"true"}),(0,n.jsx)("span",{className:"font-semibold text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:H.formattedValue})]})]})}):null]})}function ie(i,r,t){if(t)return t;let e=new Map;return i.forEach((f,S)=>{let b=(0,z.readXValue)(f,r,S),p=(0,k.toKey)(b);e.has(p)||e.set(p,b)}),[...e.values()]}function He({data:i,x:r,y:t,value:e,format:f,domain:S,scale:b="sequential",center:p=0,steps:V,colors:w,xDomain:W,yDomain:I,cellGap:$=ve,cellRadius:J=Se,showValues:N=!1,height:A=280,width:T,size:P="md",legend:m=!0,legendLabel:D,tooltip:a=!0,tableView:_=!1,title:K,description:Q,loading:j=!1,emptyState:H,error:C=!1,errorState:s,onRetry:l,actions:v,locale:h,plotLabel:d,onCellClick:x,className:Y,...Z}){V!==void 0&&V>M.CHART_MAX_COLOR_CLASSES&&!ne&&(ne=!0,console.warn(`[@synertech/ui] A Heatmap was cut into ${V} colour classes. Past ${M.CHART_MAX_COLOR_CLASSES} two neighbouring cells stop being tellable apart: leave \`steps\` unset and let the ramp stay continuous.`));let X=(0,c.useMemo)(()=>ie(i,r.key,W),[i,r.key,W]),B=(0,c.useMemo)(()=>ie(i,t.key,I),[i,t.key,I]),R=(0,c.useMemo)(()=>{let u=new Map;return i.forEach((y,F)=>{let le=(0,z.readNumber)(y,e);if(le===null)return;let ge=(0,z.readXValue)(y,r.key,F),fe=(0,z.readXValue)(y,t.key,F);u.set(`${(0,k.toKey)(ge)}|${(0,k.toKey)(fe)}`,{value:le,datum:y})}),u},[i,r.key,t.key,e]),O=(0,c.useMemo)(()=>f??(u=>(0,G.formatAuto)(u,h)),[f,h]),U=(0,c.useMemo)(()=>r.format??(u=>(0,G.formatXValue)(u,h)),[r.format,h]),g=(0,c.useMemo)(()=>t.format??(u=>(0,G.formatXValue)(u,h)),[t.format,h]),o=(0,c.useMemo)(()=>{let u=S??(0,de.extent)([...R.values()].map(y=>y.value))??[0,1];return b==="diverging"?(0,M.createDivergingScale)(u,{center:p,steps:V,colors:w}):(0,M.createSequentialScale)(u,{steps:V,colors:w})},[S,R,b,p,V,w]),ee=(0,c.useMemo)(()=>B.map(u=>{let y={[t.key]:u};return X.forEach(F=>{y[`${oe}${(0,k.toKey)(F)}`]=R.get(`${(0,k.toKey)(F)}|${(0,k.toKey)(u)}`)?.value??null}),y}),[B,X,R,t.key]),q=(0,c.useMemo)(()=>X.map((u,y)=>({key:`${oe}${(0,k.toKey)(u)}`,label:U(u,y)})),[X,U]),re=m!==!1,E=typeof m=="string"?m:"bottom";return(0,n.jsx)(ue.ChartContainer,{title:K,description:Q,height:A,width:T,size:P,loading:j,empty:R.size===0,emptyState:H,error:C,errorState:s,onRetry:l,actions:v,tableView:_,legendPosition:E,legend:re?(0,n.jsx)(ce.ChartScaleLegend,{scale:o,label:D,format:O,size:P,locale:h}):void 0,table:_?(0,n.jsx)(me.ChartTableView,{data:ee,series:q,xKey:t.key,xLabel:t.label??t.key,formatX:g,formatValue:O,caption:typeof K=="string"?K:void 0}):void 0,className:Y,...Z,children:({width:u})=>(0,n.jsx)(Ee,{width:u,height:A,columns:X,rows:B,lookup:R,colorScale:o,x:r,y:t,size:P,cellGap:$,cellRadius:J,showValues:N,tooltip:a,plotLabel:d,formatValue:O,formatX:U,formatY:g,onCellClick:x})})}function Xe(){ne=!1}0&&(module.exports={Heatmap,resetHeatmapWarnings});
1
+ "use strict";"use client";var te=Object.defineProperty;var pe=Object.getOwnPropertyDescriptor;var Ce=Object.getOwnPropertyNames;var ke=Object.prototype.hasOwnProperty;var ye=(s,l)=>{for(var t in l)te(s,t,{get:l[t],enumerable:!0})},we=(s,l,t,e)=>{if(l&&typeof l=="object"||typeof l=="function")for(let f of Ce(l))!ke.call(s,f)&&f!==t&&te(s,f,{get:()=>l[f],enumerable:!(e=pe(l,f))||e.enumerable});return s};var ve=s=>we(te({},"__esModule",{value:!0}),s);var $e={};ye($e,{Heatmap:()=>Re,resetHeatmapWarnings:()=>Xe});module.exports=ve($e);var m=require("react"),se=require("../../lib/cn.cjs"),ne=require("../chart/ChartAxis.cjs"),ue=require("../chart/ChartContainer.cjs"),me=require("../chart/ChartScaleLegend.cjs"),ce=require("../chart/ChartTableView.cjs"),he=require("../chart/ChartTooltip.cjs"),N=require("../chart/palette.cjs"),I=require("../chart/utils/data.cjs"),F=require("../chart/utils/format.cjs"),k=require("../chart/utils/scales.cjs"),L=require("../chart/utils/text.cjs"),de=require("../chart/utils/ticks.cjs"),ge=require("../chart/utils/touch.cjs"),r=require("react/jsx-runtime"),Se=2,xe=2,Le=12,Ve=16,oe="cell:",ae=!1,He=(0,m.memo)(function({cells:l,radius:t}){return(0,r.jsx)("g",{children:l.map(e=>(0,r.jsxs)("g",{children:[(0,r.jsx)("rect",{x:e.x,y:e.y,width:e.width,height:e.height,rx:t,fill:e.missing?void 0:e.color,className:e.missing?"fill-gray-100 dark:fill-gray-800":void 0}),e.label?(0,r.jsx)("text",{x:e.x+e.width/2,y:e.y+e.height/2,textAnchor:"middle",dominantBaseline:"central",className:(0,se.cn)("text-[10px] [font-variant-numeric:tabular-nums]",e.onDark?"fill-gray-50 dark:fill-gray-900":"fill-gray-900 dark:fill-gray-50"),children:e.label}):null]},e.key))})});function Ee({width:s,height:l,columns:t,rows:e,lookup:f,colorScale:S,x:b,y:p,size:V,cellGap:w,cellRadius:K,showValues:O,tooltip:A,plotLabel:Z,formatValue:_,formatX:P,formatY:z,onCellClick:T}){let[H,D]=(0,m.useState)(null),c=H!==null&&H.column<t.length&&H.row<e.length?H:null,n=(0,m.useMemo)(()=>{let C=t.map((g,i)=>P(g,i)),u=e.map((g,i)=>z(g,i)),o={top:8,right:8,bottom:b.hidden?8:b.height??24+(b.label?16:0),left:p.hidden?8:p.height??(0,L.widestLabel)(u)+Le+(p.label?16:0)},h=Math.max(0,s-o.left-o.right),v=Math.max(0,l-o.top-o.bottom),d=(0,k.createBandScale)(t.map((g,i)=>i),[0,h],{paddingInner:0,paddingOuter:0}),x=(0,k.createBandScale)(e.map((g,i)=>i),[0,v],{paddingInner:0,paddingOuter:0}),G=Math.max(0,d.bandwidth-w),R=Math.max(0,x.bandwidth-w),W=[];e.forEach((g,i)=>{t.forEach((ee,q)=>{let a=f.get(`${(0,k.toKey)(ee)}|${(0,k.toKey)(g)}`)?.value??null,y=null;if(O&&a!==null&&R>=Ve){let $=_(a);(0,L.estimateTextWidth)($,10)+6<=G&&(y=$)}W.push({key:`${q}-${i}`,column:q,row:i,x:d(q)+w/2,y:x(i)+w/2,width:G,height:R,color:a===null?"transparent":S(a),label:y,onDark:a!==null&&S.onDark(a),missing:a===null})})});let X=(0,L.labelStride)(C.length,h,(0,L.widestLabel)(C)),B=(0,L.labelStride)(u.length,v,L.AXIS_FONT_SIZE+4),U=b.hidden?[]:C.map((g,i)=>({value:t[i],offset:d.center(i),label:g})).filter((g,i)=>i%X===0),Y=p.hidden?[]:u.map((g,i)=>({value:e[i],offset:x.center(i),label:g})).filter((g,i)=>i%B===0);return{margin:o,innerWidth:h,innerHeight:v,columnScale:d,rowScale:x,cells:W,columnTicks:U,rowTicks:Y}},[t,e,f,S,b,p,s,l,w,O,_,P,z]),M=(0,m.useCallback)((C,u)=>{let o=t[C],h=e[u],v=f.get(`${(0,k.toKey)(o)}|${(0,k.toKey)(h)}`),d=v?.value??null;return{x:o,y:h,xLabel:P(o,C),yLabel:z(h,u),value:d,formattedValue:d===null?"\u2014":_(d),color:d===null?"transparent":S(d),datum:v?.datum}},[t,e,f,S,_,P,z]),J=(0,m.useCallback)(C=>{if(A===!1||t.length===0||e.length===0)return;let u=C.currentTarget.getBoundingClientRect(),o=C.clientX-u.left-n.margin.left,h=C.clientY-u.top-n.margin.top,v=Math.floor(o/(n.columnScale.step||1)),d=Math.floor(h/(n.rowScale.step||1));if(v<0||v>=t.length||d<0||d>=e.length){D(null);return}D(x=>x?.column===v&&x.row===d?x:{column:v,row:d})},[A,t.length,e.length,n.margin,n.columnScale,n.rowScale]),Q=(0,m.useCallback)(C=>{if(t.length===0||e.length===0)return;let u=c??{column:0,row:0},o;switch(C.key){case"ArrowRight":o={...u,column:Math.min(t.length-1,u.column+1)};break;case"ArrowLeft":o={...u,column:Math.max(0,u.column-1)};break;case"ArrowDown":o={...u,row:Math.min(e.length-1,u.row+1)};break;case"ArrowUp":o={...u,row:Math.max(0,u.row-1)};break;case"Home":o={...u,column:0};break;case"End":o={...u,column:t.length-1};break;case"Escape":o=null;break;default:o=void 0}o!==void 0&&(C.preventDefault(),D(o))},[t.length,e.length,c]),j=(0,m.useCallback)(()=>{!T||!c||T(M(c.column,c.row))},[T,c,M]),E=c?M(c.column,c.row):null;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("svg",{width:s,height:l,role:"img","aria-label":Z??`${b.label??b.key} / ${p.label??p.key}`,tabIndex:0,className:`${ge.CHART_TOUCH} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500`,onPointerMove:J,onPointerLeave:()=>D(null),onKeyDown:Q,onBlur:()=>D(null),onClick:j,children:[(0,r.jsxs)("g",{transform:`translate(${n.margin.left}, ${n.margin.top})`,children:[(0,r.jsx)(He,{cells:n.cells,radius:K}),c?(0,r.jsx)("rect",{x:n.columnScale(c.column)+w/2,y:n.rowScale(c.row)+w/2,width:Math.max(0,n.columnScale.bandwidth-w),height:Math.max(0,n.rowScale.bandwidth-w),rx:K,fill:"none",strokeWidth:2,className:"stroke-gray-900 dark:stroke-white","aria-hidden":"true"}):null]}),(0,r.jsx)("g",{transform:`translate(${n.margin.left}, ${n.margin.top+n.innerHeight})`,children:b.hidden?null:(0,r.jsx)(ne.ChartAxis,{orientation:"bottom",ticks:n.columnTicks,length:n.innerWidth,showLine:!1,tickSize:0,label:b.label,size:V})}),(0,r.jsx)("g",{transform:`translate(${n.margin.left}, ${n.margin.top})`,children:p.hidden?null:(0,r.jsx)(ne.ChartAxis,{orientation:"left",ticks:n.rowTicks,length:n.innerHeight,showLine:!1,tickSize:0,label:p.label,size:V})})]}),c&&E&&A!==!1?(0,r.jsx)(he.ChartTooltip,{x:n.margin.left+n.columnScale.center(c.column),y:n.margin.top+n.rowScale.center(c.row),containerWidth:s,children:typeof A=="function"?A(E):(0,r.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,r.jsxs)("div",{className:"font-medium text-gray-900 dark:text-gray-100",children:[E.yLabel," \xB7 ",E.xLabel]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"h-2.5 w-2.5 shrink-0 rounded-sm",style:{backgroundColor:E.color},"aria-hidden":"true"}),(0,r.jsx)("span",{className:"font-semibold text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:E.formattedValue})]})]})}):null]})}function ie(s,l,t){if(t)return t;let e=new Map;return s.forEach((f,S)=>{let b=(0,I.readXValue)(f,l,S),p=(0,k.toKey)(b);e.has(p)||e.set(p,b)}),[...e.values()]}function Re({data:s,x:l,y:t,value:e,format:f,domain:S,scale:b="sequential",center:p=0,steps:V,colors:w,xDomain:K,yDomain:O,cellGap:A=Se,cellRadius:Z=xe,showValues:_=!1,height:P=280,width:z,size:T="md",legend:H=!0,legendLabel:D,tooltip:c=!0,tableView:n=!1,title:M,description:J,loading:Q=!1,emptyState:j,error:E=!1,errorState:C,onRetry:u,actions:o,locale:h,plotLabel:v,onCellClick:d,className:x,...G}){V!==void 0&&V>N.CHART_MAX_COLOR_CLASSES&&!ae&&(ae=!0,console.warn(`[@synertech/ui] A Heatmap was cut into ${V} colour classes. Past ${N.CHART_MAX_COLOR_CLASSES} two neighbouring cells stop being tellable apart: leave \`steps\` unset and let the ramp stay continuous.`));let R=(0,m.useMemo)(()=>ie(s,l.key,K),[s,l.key,K]),W=(0,m.useMemo)(()=>ie(s,t.key,O),[s,t.key,O]),X=(0,m.useMemo)(()=>{let a=new Map;return s.forEach((y,$)=>{let le=(0,I.readNumber)(y,e);if(le===null)return;let fe=(0,I.readXValue)(y,l.key,$),be=(0,I.readXValue)(y,t.key,$);a.set(`${(0,k.toKey)(fe)}|${(0,k.toKey)(be)}`,{value:le,datum:y})}),a},[s,l.key,t.key,e]),B=(0,m.useMemo)(()=>f??(a=>(0,F.formatAuto)(a,h)),[f,h]),U=(0,m.useMemo)(()=>l.format??(a=>(0,F.formatXValue)(a,h)),[l.format,h]),Y=(0,m.useMemo)(()=>t.format??(a=>(0,F.formatXValue)(a,h)),[t.format,h]),g=(0,m.useMemo)(()=>{let a=S??(0,de.extent)([...X.values()].map(y=>y.value))??[0,1];return b==="diverging"?(0,N.createDivergingScale)(a,{center:p,steps:V,colors:w}):(0,N.createSequentialScale)(a,{steps:V,colors:w})},[S,X,b,p,V,w]),i=(0,m.useMemo)(()=>W.map(a=>{let y={[t.key]:a};return R.forEach($=>{y[`${oe}${(0,k.toKey)($)}`]=X.get(`${(0,k.toKey)($)}|${(0,k.toKey)(a)}`)?.value??null}),y}),[W,R,X,t.key]),ee=(0,m.useMemo)(()=>R.map((a,y)=>({key:`${oe}${(0,k.toKey)(a)}`,label:U(a,y)})),[R,U]),q=H!==!1,re=typeof H=="string"?H:"bottom";return(0,r.jsx)(ue.ChartContainer,{title:M,description:J,height:P,width:z,size:T,loading:Q,empty:X.size===0,emptyState:j,error:E,errorState:C,onRetry:u,actions:o,tableView:n,legendPosition:re,legend:q?(0,r.jsx)(me.ChartScaleLegend,{scale:g,label:D,format:B,size:T,locale:h}):void 0,table:n?(0,r.jsx)(ce.ChartTableView,{data:i,series:ee,xKey:t.key,xLabel:t.label??t.key,formatX:Y,formatValue:B,caption:typeof M=="string"?M:void 0}):void 0,className:x,...G,children:({width:a})=>(0,r.jsx)(Ee,{width:a,height:P,columns:R,rows:W,lookup:X,colorScale:g,x:l,y:t,size:T,cellGap:A,cellRadius:Z,showValues:_,tooltip:c,plotLabel:v,formatValue:B,formatX:U,formatY:Y,onCellClick:d})})}function Xe(){ae=!1}0&&(module.exports={Heatmap,resetHeatmapWarnings});
@@ -1 +1 @@
1
- "use client";import{memo as de,useCallback as G,useMemo as S,useState as ge}from"react";import{cn as fe}from"../../lib/cn.js";import{ChartAxis as ne}from"../chart/ChartAxis.js";import{ChartContainer as be}from"../chart/ChartContainer.js";import{ChartScaleLegend as pe}from"../chart/ChartScaleLegend.js";import{ChartTableView as Ce}from"../chart/ChartTableView.js";import{ChartTooltip as ke}from"../chart/ChartTooltip.js";import{CHART_MAX_COLOR_CLASSES as re,createDivergingScale as ye,createSequentialScale as we}from"../chart/palette.js";import{readNumber as ve,readXValue as j}from"../chart/utils/data.js";import{formatAuto as Se,formatXValue as le}from"../chart/utils/format.js";import{createBandScale as oe,toKey as y}from"../chart/utils/scales.js";import{AXIS_FONT_SIZE as xe,estimateTextWidth as Le,labelStride as ie,widestLabel as se}from"../chart/utils/text.js";import{extent as Ve}from"../chart/utils/ticks.js";import{Fragment as Pe,jsx as m,jsxs as D}from"react/jsx-runtime";var Ee=2,He=2,Xe=12,Re=16,ue="cell:",ee=!1,$e=de(function({cells:h,radius:t}){return m("g",{children:h.map(e=>D("g",{children:[m("rect",{x:e.x,y:e.y,width:e.width,height:e.height,rx:t,fill:e.missing?void 0:e.color,className:e.missing?"fill-gray-100 dark:fill-gray-800":void 0}),e.label?m("text",{x:e.x+e.width/2,y:e.y+e.height/2,textAnchor:"middle",dominantBaseline:"central",className:fe("text-[10px] [font-variant-numeric:tabular-nums]",e.onDark?"fill-gray-50 dark:fill-gray-900":"fill-gray-900 dark:fill-gray-50"),children:e.label}):null]},e.key))})});function Ae({width:b,height:h,columns:t,rows:e,lookup:x,colorScale:w,x:d,y:g,size:L,cellGap:C,cellRadius:_,showValues:z,tooltip:R,plotLabel:Y,formatValue:M,formatX:$,formatY:N,onCellClick:A}){let[i,P]=ge(null),a=S(()=>{let f=t.map((c,r)=>$(c,r)),l=e.map((c,r)=>N(c,r)),n={top:8,right:8,bottom:d.hidden?8:d.height??24+(d.label?16:0),left:g.hidden?8:g.height??se(l)+Xe+(g.label?16:0)},k=Math.max(0,b-n.left-n.right),s=Math.max(0,h-n.top-n.bottom),u=oe(t.map((c,r)=>r),[0,k],{paddingInner:0,paddingOuter:0}),v=oe(e.map((c,r)=>r),[0,s],{paddingInner:0,paddingOuter:0}),q=Math.max(0,u.bandwidth-C),F=Math.max(0,v.bandwidth-C),H=[];e.forEach((c,r)=>{t.forEach((Q,O)=>{let V=x.get(`${y(Q)}|${y(c)}`)?.value??null,o=null;if(z&&V!==null&&F>=Re){let p=M(V);Le(p,10)+6<=q&&(o=p)}H.push({key:`${O}-${r}`,column:O,row:r,x:u(O)+C/2,y:v(r)+C/2,width:q,height:F,color:V===null?"transparent":w(V),label:o,onDark:V!==null&&w.onDark(V),missing:V===null})})});let I=ie(f.length,k,se(f)),X=ie(l.length,s,xe+4),K=d.hidden?[]:f.map((c,r)=>({value:t[r],offset:u.center(r),label:c})).filter((c,r)=>r%I===0),B=g.hidden?[]:l.map((c,r)=>({value:e[r],offset:v.center(r),label:c})).filter((c,r)=>r%X===0);return{margin:n,innerWidth:k,innerHeight:s,columnScale:u,rowScale:v,cells:H,columnTicks:K,rowTicks:B}},[t,e,x,w,d,g,b,h,C,z,M,$,N]),T=G((f,l)=>{let n=t[f],k=e[l],s=x.get(`${y(n)}|${y(k)}`),u=s?.value??null;return{x:n,y:k,xLabel:$(n,f),yLabel:N(k,l),value:u,formattedValue:u===null?"\u2014":M(u),color:u===null?"transparent":w(u),datum:s?.datum}},[t,e,x,w,M,$,N]),W=G(f=>{if(R===!1||t.length===0||e.length===0)return;let l=f.currentTarget.getBoundingClientRect(),n=f.clientX-l.left-a.margin.left,k=f.clientY-l.top-a.margin.top,s=Math.floor(n/(a.columnScale.step||1)),u=Math.floor(k/(a.rowScale.step||1));if(s<0||s>=t.length||u<0||u>=e.length){P(null);return}P(v=>v?.column===s&&v.row===u?v:{column:s,row:u})},[R,t.length,e.length,a.margin,a.columnScale,a.rowScale]),Z=G(f=>{if(t.length===0||e.length===0)return;let l=i??{column:0,row:0},n;switch(f.key){case"ArrowRight":n={...l,column:Math.min(t.length-1,l.column+1)};break;case"ArrowLeft":n={...l,column:Math.max(0,l.column-1)};break;case"ArrowDown":n={...l,row:Math.min(e.length-1,l.row+1)};break;case"ArrowUp":n={...l,row:Math.max(0,l.row-1)};break;case"Home":n={...l,column:0};break;case"End":n={...l,column:t.length-1};break;case"Escape":n=null;break;default:n=void 0}n!==void 0&&(f.preventDefault(),P(n))},[t.length,e.length,i]),J=G(()=>{!A||!i||A(T(i.column,i.row))},[A,i,T]),E=i?T(i.column,i.row):null;return D(Pe,{children:[D("svg",{width:b,height:h,role:"img","aria-label":Y??`${d.label??d.key} / ${g.label??g.key}`,tabIndex:0,className:"touch-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500",onPointerMove:W,onPointerLeave:()=>P(null),onKeyDown:Z,onBlur:()=>P(null),onClick:J,children:[D("g",{transform:`translate(${a.margin.left}, ${a.margin.top})`,children:[m($e,{cells:a.cells,radius:_}),i?m("rect",{x:a.columnScale(i.column)+C/2,y:a.rowScale(i.row)+C/2,width:Math.max(0,a.columnScale.bandwidth-C),height:Math.max(0,a.rowScale.bandwidth-C),rx:_,fill:"none",strokeWidth:2,className:"stroke-gray-900 dark:stroke-white","aria-hidden":"true"}):null]}),m("g",{transform:`translate(${a.margin.left}, ${a.margin.top+a.innerHeight})`,children:d.hidden?null:m(ne,{orientation:"bottom",ticks:a.columnTicks,length:a.innerWidth,showLine:!1,tickSize:0,label:d.label,size:L})}),m("g",{transform:`translate(${a.margin.left}, ${a.margin.top})`,children:g.hidden?null:m(ne,{orientation:"left",ticks:a.rowTicks,length:a.innerHeight,showLine:!1,tickSize:0,label:g.label,size:L})})]}),i&&E&&R!==!1?m(ke,{x:a.margin.left+a.columnScale.center(i.column),y:a.margin.top+a.rowScale.center(i.row),containerWidth:b,children:typeof R=="function"?R(E):D("div",{className:"flex flex-col gap-1",children:[D("div",{className:"font-medium text-gray-900 dark:text-gray-100",children:[E.yLabel," \xB7 ",E.xLabel]}),D("div",{className:"flex items-center gap-2",children:[m("span",{className:"h-2.5 w-2.5 shrink-0 rounded-sm",style:{backgroundColor:E.color},"aria-hidden":"true"}),m("span",{className:"font-semibold text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:E.formattedValue})]})]})}):null]})}function ce(b,h,t){if(t)return t;let e=new Map;return b.forEach((x,w)=>{let d=j(x,h,w),g=y(d);e.has(g)||e.set(g,d)}),[...e.values()]}function Fe({data:b,x:h,y:t,value:e,format:x,domain:w,scale:d="sequential",center:g=0,steps:L,colors:C,xDomain:_,yDomain:z,cellGap:R=Ee,cellRadius:Y=He,showValues:M=!1,height:$=280,width:N,size:A="md",legend:i=!0,legendLabel:P,tooltip:a=!0,tableView:T=!1,title:W,description:Z,loading:J=!1,emptyState:E,error:f=!1,errorState:l,onRetry:n,actions:k,locale:s,plotLabel:u,onCellClick:v,className:q,...F}){L!==void 0&&L>re&&!ee&&(ee=!0,console.warn(`[@synertech/ui] A Heatmap was cut into ${L} colour classes. Past ${re} two neighbouring cells stop being tellable apart: leave \`steps\` unset and let the ramp stay continuous.`));let H=S(()=>ce(b,h.key,_),[b,h.key,_]),I=S(()=>ce(b,t.key,z),[b,t.key,z]),X=S(()=>{let o=new Map;return b.forEach((p,U)=>{let ae=ve(p,e);if(ae===null)return;let me=j(p,h.key,U),he=j(p,t.key,U);o.set(`${y(me)}|${y(he)}`,{value:ae,datum:p})}),o},[b,h.key,t.key,e]),K=S(()=>x??(o=>Se(o,s)),[x,s]),B=S(()=>h.format??(o=>le(o,s)),[h.format,s]),c=S(()=>t.format??(o=>le(o,s)),[t.format,s]),r=S(()=>{let o=w??Ve([...X.values()].map(p=>p.value))??[0,1];return d==="diverging"?ye(o,{center:g,steps:L,colors:C}):we(o,{steps:L,colors:C})},[w,X,d,g,L,C]),Q=S(()=>I.map(o=>{let p={[t.key]:o};return H.forEach(U=>{p[`${ue}${y(U)}`]=X.get(`${y(U)}|${y(o)}`)?.value??null}),p}),[I,H,X,t.key]),O=S(()=>H.map((o,p)=>({key:`${ue}${y(o)}`,label:B(o,p)})),[H,B]),te=i!==!1,V=typeof i=="string"?i:"bottom";return m(be,{title:W,description:Z,height:$,width:N,size:A,loading:J,empty:X.size===0,emptyState:E,error:f,errorState:l,onRetry:n,actions:k,tableView:T,legendPosition:V,legend:te?m(pe,{scale:r,label:P,format:K,size:A,locale:s}):void 0,table:T?m(Ce,{data:Q,series:O,xKey:t.key,xLabel:t.label??t.key,formatX:c,formatValue:K,caption:typeof W=="string"?W:void 0}):void 0,className:q,...F,children:({width:o})=>m(Ae,{width:o,height:$,columns:H,rows:I,lookup:X,colorScale:r,x:h,y:t,size:A,cellGap:R,cellRadius:Y,showValues:M,tooltip:a,plotLabel:u,formatValue:K,formatX:B,formatY:c,onCellClick:v})})}function Ge(){ee=!1}export{Fe as Heatmap,Ge as resetHeatmapWarnings};
1
+ "use client";import{memo as de,useCallback as F,useMemo as S,useState as ge}from"react";import{cn as fe}from"../../lib/cn.js";import{ChartAxis as ae}from"../chart/ChartAxis.js";import{ChartContainer as be}from"../chart/ChartContainer.js";import{ChartScaleLegend as pe}from"../chart/ChartScaleLegend.js";import{ChartTableView as Ce}from"../chart/ChartTableView.js";import{ChartTooltip as ke}from"../chart/ChartTooltip.js";import{CHART_MAX_COLOR_CLASSES as re,createDivergingScale as ye,createSequentialScale as we}from"../chart/palette.js";import{readNumber as ve,readXValue as j}from"../chart/utils/data.js";import{formatAuto as Se,formatXValue as le}from"../chart/utils/format.js";import{createBandScale as oe,toKey as y}from"../chart/utils/scales.js";import{AXIS_FONT_SIZE as xe,estimateTextWidth as Le,labelStride as ie,widestLabel as se}from"../chart/utils/text.js";import{extent as Ve}from"../chart/utils/ticks.js";import{CHART_TOUCH as He}from"../chart/utils/touch.js";import{Fragment as Te,jsx as c,jsxs as M}from"react/jsx-runtime";var Ee=2,Re=2,Xe=12,$e=16,ue="cell:",ee=!1,Ae=de(function({cells:h,radius:t}){return c("g",{children:h.map(e=>M("g",{children:[c("rect",{x:e.x,y:e.y,width:e.width,height:e.height,rx:t,fill:e.missing?void 0:e.color,className:e.missing?"fill-gray-100 dark:fill-gray-800":void 0}),e.label?c("text",{x:e.x+e.width/2,y:e.y+e.height/2,textAnchor:"middle",dominantBaseline:"central",className:fe("text-[10px] [font-variant-numeric:tabular-nums]",e.onDark?"fill-gray-50 dark:fill-gray-900":"fill-gray-900 dark:fill-gray-50"),children:e.label}):null]},e.key))})});function Pe({width:b,height:h,columns:t,rows:e,lookup:x,colorScale:w,x:d,y:g,size:L,cellGap:C,cellRadius:W,showValues:I,tooltip:$,plotLabel:G,formatValue:N,formatX:A,formatY:_,onCellClick:P}){let[V,T]=ge(null),i=V!==null&&V.column<t.length&&V.row<e.length?V:null,n=S(()=>{let f=t.map((m,l)=>A(m,l)),o=e.map((m,l)=>_(m,l)),r={top:8,right:8,bottom:d.hidden?8:d.height??24+(d.label?16:0),left:g.hidden?8:g.height??se(o)+Xe+(g.label?16:0)},s=Math.max(0,b-r.left-r.right),k=Math.max(0,h-r.top-r.bottom),u=oe(t.map((m,l)=>l),[0,s],{paddingInner:0,paddingOuter:0}),v=oe(e.map((m,l)=>l),[0,k],{paddingInner:0,paddingOuter:0}),U=Math.max(0,u.bandwidth-C),E=Math.max(0,v.bandwidth-C),z=[];e.forEach((m,l)=>{t.forEach((Q,B)=>{let a=x.get(`${y(Q)}|${y(m)}`)?.value??null,p=null;if(I&&a!==null&&E>=$e){let X=N(a);Le(X,10)+6<=U&&(p=X)}z.push({key:`${B}-${l}`,column:B,row:l,x:u(B)+C/2,y:v(l)+C/2,width:U,height:E,color:a===null?"transparent":w(a),label:p,onDark:a!==null&&w.onDark(a),missing:a===null})})});let R=ie(f.length,s,se(f)),K=ie(o.length,k,xe+4),O=d.hidden?[]:f.map((m,l)=>({value:t[l],offset:u.center(l),label:m})).filter((m,l)=>l%R===0),q=g.hidden?[]:o.map((m,l)=>({value:e[l],offset:v.center(l),label:m})).filter((m,l)=>l%K===0);return{margin:r,innerWidth:s,innerHeight:k,columnScale:u,rowScale:v,cells:z,columnTicks:O,rowTicks:q}},[t,e,x,w,d,g,b,h,C,I,N,A,_]),D=F((f,o)=>{let r=t[f],s=e[o],k=x.get(`${y(r)}|${y(s)}`),u=k?.value??null;return{x:r,y:s,xLabel:A(r,f),yLabel:_(s,o),value:u,formattedValue:u===null?"\u2014":N(u),color:u===null?"transparent":w(u),datum:k?.datum}},[t,e,x,w,N,A,_]),Y=F(f=>{if($===!1||t.length===0||e.length===0)return;let o=f.currentTarget.getBoundingClientRect(),r=f.clientX-o.left-n.margin.left,s=f.clientY-o.top-n.margin.top,k=Math.floor(r/(n.columnScale.step||1)),u=Math.floor(s/(n.rowScale.step||1));if(k<0||k>=t.length||u<0||u>=e.length){T(null);return}T(v=>v?.column===k&&v.row===u?v:{column:k,row:u})},[$,t.length,e.length,n.margin,n.columnScale,n.rowScale]),Z=F(f=>{if(t.length===0||e.length===0)return;let o=i??{column:0,row:0},r;switch(f.key){case"ArrowRight":r={...o,column:Math.min(t.length-1,o.column+1)};break;case"ArrowLeft":r={...o,column:Math.max(0,o.column-1)};break;case"ArrowDown":r={...o,row:Math.min(e.length-1,o.row+1)};break;case"ArrowUp":r={...o,row:Math.max(0,o.row-1)};break;case"Home":r={...o,column:0};break;case"End":r={...o,column:t.length-1};break;case"Escape":r=null;break;default:r=void 0}r!==void 0&&(f.preventDefault(),T(r))},[t.length,e.length,i]),J=F(()=>{!P||!i||P(D(i.column,i.row))},[P,i,D]),H=i?D(i.column,i.row):null;return M(Te,{children:[M("svg",{width:b,height:h,role:"img","aria-label":G??`${d.label??d.key} / ${g.label??g.key}`,tabIndex:0,className:`${He} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500`,onPointerMove:Y,onPointerLeave:()=>T(null),onKeyDown:Z,onBlur:()=>T(null),onClick:J,children:[M("g",{transform:`translate(${n.margin.left}, ${n.margin.top})`,children:[c(Ae,{cells:n.cells,radius:W}),i?c("rect",{x:n.columnScale(i.column)+C/2,y:n.rowScale(i.row)+C/2,width:Math.max(0,n.columnScale.bandwidth-C),height:Math.max(0,n.rowScale.bandwidth-C),rx:W,fill:"none",strokeWidth:2,className:"stroke-gray-900 dark:stroke-white","aria-hidden":"true"}):null]}),c("g",{transform:`translate(${n.margin.left}, ${n.margin.top+n.innerHeight})`,children:d.hidden?null:c(ae,{orientation:"bottom",ticks:n.columnTicks,length:n.innerWidth,showLine:!1,tickSize:0,label:d.label,size:L})}),c("g",{transform:`translate(${n.margin.left}, ${n.margin.top})`,children:g.hidden?null:c(ae,{orientation:"left",ticks:n.rowTicks,length:n.innerHeight,showLine:!1,tickSize:0,label:g.label,size:L})})]}),i&&H&&$!==!1?c(ke,{x:n.margin.left+n.columnScale.center(i.column),y:n.margin.top+n.rowScale.center(i.row),containerWidth:b,children:typeof $=="function"?$(H):M("div",{className:"flex flex-col gap-1",children:[M("div",{className:"font-medium text-gray-900 dark:text-gray-100",children:[H.yLabel," \xB7 ",H.xLabel]}),M("div",{className:"flex items-center gap-2",children:[c("span",{className:"h-2.5 w-2.5 shrink-0 rounded-sm",style:{backgroundColor:H.color},"aria-hidden":"true"}),c("span",{className:"font-semibold text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:H.formattedValue})]})]})}):null]})}function me(b,h,t){if(t)return t;let e=new Map;return b.forEach((x,w)=>{let d=j(x,h,w),g=y(d);e.has(g)||e.set(g,d)}),[...e.values()]}function Ye({data:b,x:h,y:t,value:e,format:x,domain:w,scale:d="sequential",center:g=0,steps:L,colors:C,xDomain:W,yDomain:I,cellGap:$=Ee,cellRadius:G=Re,showValues:N=!1,height:A=280,width:_,size:P="md",legend:V=!0,legendLabel:T,tooltip:i=!0,tableView:n=!1,title:D,description:Y,loading:Z=!1,emptyState:J,error:H=!1,errorState:f,onRetry:o,actions:r,locale:s,plotLabel:k,onCellClick:u,className:v,...U}){L!==void 0&&L>re&&!ee&&(ee=!0,console.warn(`[@synertech/ui] A Heatmap was cut into ${L} colour classes. Past ${re} two neighbouring cells stop being tellable apart: leave \`steps\` unset and let the ramp stay continuous.`));let E=S(()=>me(b,h.key,W),[b,h.key,W]),z=S(()=>me(b,t.key,I),[b,t.key,I]),R=S(()=>{let a=new Map;return b.forEach((p,X)=>{let ne=ve(p,e);if(ne===null)return;let ce=j(p,h.key,X),he=j(p,t.key,X);a.set(`${y(ce)}|${y(he)}`,{value:ne,datum:p})}),a},[b,h.key,t.key,e]),K=S(()=>x??(a=>Se(a,s)),[x,s]),O=S(()=>h.format??(a=>le(a,s)),[h.format,s]),q=S(()=>t.format??(a=>le(a,s)),[t.format,s]),m=S(()=>{let a=w??Ve([...R.values()].map(p=>p.value))??[0,1];return d==="diverging"?ye(a,{center:g,steps:L,colors:C}):we(a,{steps:L,colors:C})},[w,R,d,g,L,C]),l=S(()=>z.map(a=>{let p={[t.key]:a};return E.forEach(X=>{p[`${ue}${y(X)}`]=R.get(`${y(X)}|${y(a)}`)?.value??null}),p}),[z,E,R,t.key]),Q=S(()=>E.map((a,p)=>({key:`${ue}${y(a)}`,label:O(a,p)})),[E,O]),B=V!==!1,te=typeof V=="string"?V:"bottom";return c(be,{title:D,description:Y,height:A,width:_,size:P,loading:Z,empty:R.size===0,emptyState:J,error:H,errorState:f,onRetry:o,actions:r,tableView:n,legendPosition:te,legend:B?c(pe,{scale:m,label:T,format:K,size:P,locale:s}):void 0,table:n?c(Ce,{data:l,series:Q,xKey:t.key,xLabel:t.label??t.key,formatX:q,formatValue:K,caption:typeof D=="string"?D:void 0}):void 0,className:v,...U,children:({width:a})=>c(Pe,{width:a,height:A,columns:E,rows:z,lookup:R,colorScale:m,x:h,y:t,size:P,cellGap:$,cellRadius:G,showValues:N,tooltip:i,plotLabel:k,formatValue:K,formatX:O,formatY:q,onCellClick:u})})}function Ze(){ee=!1}export{Ye as Heatmap,Ze as resetHeatmapWarnings};
@@ -1 +1 @@
1
- "use strict";"use client";var xe=Object.defineProperty;var De=Object.getOwnPropertyDescriptor;var Me=Object.getOwnPropertyNames;var Ke=Object.prototype.hasOwnProperty;var Xe=(h,s)=>{for(var o in s)xe(h,o,{get:s[o],enumerable:!0})},$e=(h,s,o,i)=>{if(s&&typeof s=="object"||typeof s=="function")for(let u of Me(s))!Ke.call(h,u)&&u!==o&&xe(h,u,{get:()=>s[u],enumerable:!(i=De(s,u))||i.enumerable});return h};var Ge=h=>$e(xe({},"__esModule",{value:!0}),h);var Ye={};Xe(Ye,{LineChart:()=>Fe});module.exports=Ge(Ye);var l=require("react"),Re=require("../../lib/cn.cjs"),we=require("../../lib/i18n.cjs"),j=require("../chart/ChartAnnotations.cjs"),ke=require("../chart/ChartAxis.cjs"),re=require("../chart/ChartBrush.cjs"),Ae=require("../chart/ChartContainer.cjs"),Ve=require("../chart/ChartGrid.cjs"),Ee=require("../chart/ChartLegend.cjs"),Be=require("../chart/ChartSync.cjs"),Te=require("../chart/ChartTableView.cjs"),oe=require("../chart/ChartTooltip.cjs"),E=require("../chart/palette.cjs"),v=require("../chart/utils/cartesian.cjs"),U=require("../chart/utils/data.cjs"),ae=require("../chart/utils/decimate.cjs"),F=require("../chart/utils/format.cjs"),Pe=require("../chart/utils/path.cjs"),x=require("../chart/utils/scales.cjs"),He=require("../chart/utils/ticks.cjs"),n=require("react/jsx-runtime"),Oe=24,ze=10,_e=10,je=(0,l.memo)(function({lines:s,showMarkers:o}){return(0,n.jsx)("g",{children:s.map(i=>(0,n.jsxs)("g",{children:[i.solid?(0,n.jsx)("path",{d:i.solid,fill:"none",stroke:i.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}):null,i.dashed?(0,n.jsx)("path",{d:i.dashed,fill:"none",stroke:i.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"5 4"}):null,o?i.markers.map(u=>(0,n.jsx)("circle",{cx:u.x,cy:u.y,r:3,fill:i.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},`${u.x}-${u.y}`)):null]},i.key))})});function Ue({width:h,height:s,data:o,resolvedSeries:i,x:u,y:B,grid:k,size:Y,curve:P,forecastFrom:D,forecastLabel:L,markers:S,connectNulls:T,referenceLines:se,annotations:R,annotationsLabel:ie,overlay:le,maxPoints:w,brush:q,onBrush:J,brushLabel:he,syncEnabled:ue,margin:Q,tooltip:A,onPointClick:M,plotLabel:ce,formatValue:V,formatX:H}){let[K,X]=(0,l.useState)(null),c=K!==null&&K<o.length?K:null,[de,me]=(0,l.useState)(null),fe=(0,Be.useChartSync)(),m=ue?fe:null,e=(0,l.useMemo)(()=>{let t=i.filter(g=>!g.hidden),r=(0,v.buildCartesianGeometry)({width:h,height:s,data:o,x:u,y:B,bounds:(0,He.extent)((0,U.collectAllValues)(o,t.map(g=>g.key))),margin:Q,placement:"point",formatValue:V,formatX:H,extraTop:L?ze:0}),d=r.categoryCenters,y=r.valueScale,ne=D===void 0?-1:r.xValues.findIndex(g=>(0,x.toKey)(g)===(0,x.toKey)(D)),Ne=t.map(g=>{let _=o.map((I,Ie)=>{let be=(0,U.readNumber)(I,g.key);return{x:d[Ie],y:be===null?Number.NaN:y(be),defined:be!==null}}),ve={connectNulls:T},pe=ne>=0,Ce=I=>w&&w>0?(0,ae.decimatePath)(I,w):I,Le=Ce(pe?_.slice(0,ne+1):_),Se=g.dashed?Ce(_):pe?Ce(_.slice(ne)):[];return w||(0,ae.warnPointBudget)("LineChart",_.length),{key:g.key,color:g.color,solid:g.dashed?"":(0,Pe.buildLinePath)(Le,P,ve),dashed:g.dashed||pe?(0,Pe.buildLinePath)(Se,P,ve):"",markers:[...Le,...g.dashed?[]:Se].filter(I=>I.defined!==!1)}}),We=o.length>1?r.innerWidth/(o.length-1):0;return{visible:t,locate:(0,v.createCategoryLocator)(r),plot:(0,v.createPlotContext)({geometry:r,width:h,height:s,data:o,series:t,formatValue:V,formatX:H}),xValues:r.xValues,xPositions:d,xTicks:r.categoryTicks,yTicks:r.valueTicks,yScale:y,innerWidth:r.innerWidth,innerHeight:r.innerHeight,margin:r.margin,lines:Ne,forecastIndex:ne,showMarkers:S==="always"||S==="auto"&&We>=Oe&&o.length>1}},[o,i,u,B,h,s,Q,P,T,D,L,S,w,V,H]),p=(0,l.useCallback)(t=>e.visible.map(r=>{let d=(0,U.readNumber)(o[t],r.key);return{seriesKey:r.key,seriesLabel:(0,E.getSeriesLabel)(r),color:r.color,value:d,formattedValue:d===null?"\u2014":V(d),datum:o[t]}}),[o,e.visible,V]),Z=m?m.brush:de,ge=(0,l.useCallback)(t=>{me(t),m?.setBrush(t),J?.(t)},[m,J]),f=(0,re.useChartBrush)({enabled:q,active:Z!==null,centers:e.xPositions,xValues:e.xValues,offset:e.margin.left,orientation:"vertical",onCommit:ge}),ee=(0,l.useCallback)(t=>{if(f.onPointerMove(t),A===!1||o.length===0)return;let r=t.currentTarget.getBoundingClientRect(),d=t.clientX-r.left-e.margin.left,y=(0,x.nearestIndex)(e.xPositions,d);X(y>=0?y:null),m?.setHovered(y>=0?e.xValues[y]:null)},[f,A,o.length,e.margin.left,e.xPositions,e.xValues,m]),$=(0,l.useCallback)(()=>{X(null),m?.setHovered(null)},[m]),ye=(0,l.useCallback)(t=>{if(o.length===0)return;f.onKeyDown(t,c);let r=o.length-1,d=c??0,y=t.key==="ArrowRight"?Math.min(r,d+1):t.key==="ArrowLeft"?Math.max(0,d-1):t.key==="Home"?0:t.key==="End"?r:t.key==="Escape"?null:void 0;y!==void 0&&(t.preventDefault(),X(y),m?.setHovered(y===null?null:e.xValues[y]))},[o.length,c,f,m,e.xValues]),N=(0,l.useCallback)(()=>{if(f.consumedClick()||!M||c===null)return;let[t]=p(c);t&&M({...t,index:c,x:e.xValues[c]})},[f,M,c,p,e.xValues]),te=c!==null||!m?.hovered?null:(()=>{let t=(0,x.toKey)(m.hovered),r=e.xValues.findIndex(d=>(0,x.toKey)(d)===t);return r<0?null:r})(),C=c??te,G=C===null?null:p(C),O=(G??[]).filter(t=>t.value!==null),W=f.dragging??Z,z=(()=>{if(!W)return null;let t=e.locate(W.from),r=e.locate(W.to);return t===null||r===null?null:{from:t,to:r}})(),a=(0,v.splitOverlay)(le),b=c===null||G===null?null:{x:e.xValues[c],xLabel:H(e.xValues[c],c),index:c,points:G};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("svg",{width:h,height:s,role:"img","aria-label":ce??[e.visible.map(t=>(0,E.getSeriesLabel)(t)).join(", "),(0,j.describeAnnotations)(R,ie)].filter(Boolean).join(". "),tabIndex:0,className:(0,Re.cn)("touch-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500",q&&"select-none"),onPointerDown:f.onPointerDown,onPointerMove:ee,onPointerUp:f.onPointerUp,onPointerCancel:f.onPointerUp,onPointerLeave:$,onKeyDown:ye,onBlur:$,onClick:N,children:[(0,n.jsxs)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[(0,n.jsx)(Ve.ChartGrid,{width:e.innerWidth,height:e.innerHeight,horizontal:k==="y"||k==="both"?e.yTicks.map(t=>t.offset):void 0,vertical:k==="x"||k==="both"?e.xTicks.map(t=>t.offset):void 0}),R?(0,n.jsx)(j.ChartAnnotationLayer,{layer:"under",annotations:R,xAt:e.locate,yAt:e.yScale,width:e.innerWidth,height:e.innerHeight}):null,z?(0,n.jsx)(re.ChartBrushLayer,{from:z.from,to:z.to,width:e.innerWidth,height:e.innerHeight,live:f.dragging!==null,label:he}):null,a.under?.(e.plot),se?.map(t=>{let r=e.yScale(t.value),d=r<_e?r+12:r-4;return(0,n.jsxs)("g",{children:[(0,n.jsx)("line",{x1:0,y1:r,x2:e.innerWidth,y2:r,stroke:t.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:t.dashed===!1?void 0:"4 4"}),t.label?(0,n.jsx)("text",{x:e.innerWidth,y:d,textAnchor:"end",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)}),e.forecastIndex>=0?(0,n.jsxs)("g",{children:[(0,n.jsx)("line",{x1:e.xPositions[e.forecastIndex],y1:0,x2:e.xPositions[e.forecastIndex],y2:e.innerHeight,className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1,strokeDasharray:"3 3"}),L?(0,n.jsx)("text",{x:e.xPositions[e.forecastIndex]+4,y:-2,className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:L}):null]}):null,(0,n.jsx)(je,{lines:e.lines,showMarkers:e.showMarkers}),R?(0,n.jsx)(j.ChartAnnotationLayer,{annotations:R,xAt:e.locate,yAt:e.yScale,width:e.innerWidth,height:e.innerHeight}):null,a.over?.(e.plot),C!==null?(0,n.jsxs)("g",{"aria-hidden":"true",children:[(0,n.jsx)("line",{x1:e.xPositions[C],y1:0,x2:e.xPositions[C],y2:e.innerHeight,className:"stroke-gray-400 dark:stroke-gray-500",strokeWidth:1,strokeDasharray:c===null?"3 3":void 0}),O.map(t=>(0,n.jsx)("circle",{cx:e.xPositions[C],cy:e.yScale(t.value),r:4,fill:t.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},t.seriesKey))]}):null]}),(0,n.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:u.hidden?null:(0,n.jsx)(ke.ChartAxis,{orientation:"bottom",ticks:e.xTicks,length:e.innerWidth,label:u.label,size:Y})}),(0,n.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:B?.hidden?null:(0,n.jsx)(ke.ChartAxis,{orientation:"left",ticks:e.yTicks,length:e.innerHeight,showLine:!1,label:B?.label,size:Y})})]}),b&&A!==!1?(0,n.jsx)(oe.ChartTooltip,{x:e.margin.left+e.xPositions[b.index],y:e.margin.top+(O.length>0?Math.min(...O.map(t=>e.yScale(t.value))):e.innerHeight/2),containerWidth:h,children:typeof A=="function"?A(b):(0,n.jsx)(oe.ChartTooltipContent,{title:b.xLabel,points:b.points})}):null]})}function Fe({data:h,series:s,x:o,y:i,height:u=240,width:B,size:k="md",grid:Y="y",legend:P,tooltip:D=!0,tableView:L=!1,emphasis:S,title:T,description:se,loading:R=!1,emptyState:ie,error:le=!1,errorState:w,onRetry:q,actions:J,onPointClick:he,curve:ue="monotone",forecastFrom:Q,forecastLabel:A,markers:M="auto",connectNulls:ce=!1,referenceLines:V,annotations:H,overlay:K,legendToggle:X=!0,maxPoints:c,brush:de=!1,onBrush:me,brushLabel:fe,sync:m=!0,margin:e,locale:p,plotLabel:Z,className:ge,...f}){let ee=(0,we.useUILabels)(),[$,ye]=(0,l.useState)(()=>new Set),N=(0,l.useMemo)(()=>s.map((a,b)=>({...a,hidden:a.hidden||$.has(a.key),color:(0,E.resolveSeriesColor)(a,b,S)})),[s,$,S]),te=(0,l.useMemo)(()=>i?.format??(a=>(0,F.formatAuto)(a,p)),[i?.format,p]),C=(0,l.useMemo)(()=>o.format??(a=>o.scale==="time"?(0,F.formatXValue)(a instanceof Date?a:new Date((0,x.toNumber)(a)),p):(0,F.formatXValue)(a,p)),[o.format,o.scale,p]),G=(0,l.useCallback)(a=>{ye(b=>{let t=new Set(b);return t.has(a)?t.delete(a):t.add(a),t})},[]),O=P===void 0?s.length>=2:P!==!1,W=typeof P=="string"?P:"bottom",z=N.filter(a=>!a.hidden).length;return(0,n.jsx)(Ae.ChartContainer,{title:T,description:se,height:u,width:B,size:k,loading:R,empty:h.length===0||z===0,emptyState:ie,error:le,errorState:w,onRetry:q,actions:J,tableView:L,legendPosition:W,legend:O?(0,n.jsx)(Ee.ChartLegend,{items:(0,E.toLegendItems)(N,S),position:W,marker:"line",size:k,onToggle:X?G:void 0}):void 0,table:L?(0,n.jsx)(Te.ChartTableView,{data:h,series:N,xKey:o.key,xLabel:o.label??o.key,formatX:C,formatValue:te,caption:typeof T=="string"?T:void 0}):void 0,className:ge,...f,children:({width:a})=>(0,n.jsx)(Ue,{width:a,height:u,data:h,resolvedSeries:N,x:o,y:i,grid:Y,size:k,curve:ue,forecastFrom:Q,forecastLabel:A,markers:M,connectNulls:ce,referenceLines:V,annotations:H,annotationsLabel:ee.chartAnnotations,overlay:K,maxPoints:c,brush:de,onBrush:me,brushLabel:fe??ee.chartBrush,syncEnabled:m,margin:e,tooltip:D,onPointClick:he,plotLabel:Z,formatValue:te,formatX:C})})}0&&(module.exports={LineChart});
1
+ "use strict";"use client";var Pe=Object.defineProperty;var Xe=Object.getOwnPropertyDescriptor;var $e=Object.getOwnPropertyNames;var Ge=Object.prototype.hasOwnProperty;var Oe=(h,a)=>{for(var o in a)Pe(h,o,{get:a[o],enumerable:!0})},_e=(h,a,o,s)=>{if(a&&typeof a=="object"||typeof a=="function")for(let u of $e(a))!Ge.call(h,u)&&u!==o&&Pe(h,u,{get:()=>a[u],enumerable:!(s=Xe(a,u))||s.enumerable});return h};var ze=h=>_e(Pe({},"__esModule",{value:!0}),h);var Qe={};Oe(Qe,{LineChart:()=>Je});module.exports=ze(Qe);var l=require("react"),Re=require("../../lib/cn.cjs"),we=require("../../lib/i18n.cjs"),U=require("../chart/ChartAnnotations.cjs"),Le=require("../chart/ChartAxis.cjs"),se=require("../chart/ChartBrush.cjs"),Ae=require("../chart/ChartContainer.cjs"),Ve=require("../chart/ChartGrid.cjs"),Te=require("../chart/ChartLegend.cjs"),Ee=require("../chart/ChartSync.cjs"),Be=require("../chart/ChartTableView.cjs"),ie=require("../chart/ChartTooltip.cjs"),E=require("../chart/palette.cjs"),v=require("../chart/utils/cartesian.cjs"),j=require("../chart/utils/data.cjs"),le=require("../chart/utils/decimate.cjs"),he=require("../chart/utils/format.cjs"),B=require("../chart/utils/path.cjs"),T=require("../chart/utils/scales.cjs"),He=require("../chart/utils/ticks.cjs"),We=require("../chart/utils/timestamp.cjs"),Ie=require("../chart/utils/touch.cjs"),n=require("react/jsx-runtime"),Ue=24,je=10,Fe=10,Ye=(0,l.memo)(function({lines:a,showMarkers:o}){return(0,n.jsx)("g",{children:a.map(s=>(0,n.jsxs)("g",{children:[s.solid?(0,n.jsx)("path",{d:s.solid,fill:"none",stroke:s.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}):null,s.dashed?(0,n.jsx)("path",{d:s.dashed,fill:"none",stroke:s.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"5 4"}):null,(o?s.markers:s.isolated).map(u=>(0,n.jsx)("circle",{cx:u.x,cy:u.y,r:3,fill:s.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},`${u.x}-${u.y}`))]},s.key))})});function qe({width:h,height:a,data:o,resolvedSeries:s,x:u,y:H,grid:x,size:F,curve:k,forecastFrom:D,forecastLabel:P,markers:L,connectNulls:S,referenceLines:ue,annotations:R,annotationsLabel:ce,overlay:de,maxPoints:w,brush:Y,onBrush:q,brushLabel:me,syncEnabled:fe,margin:J,tooltip:A,onPointClick:M,plotLabel:ge,formatValue:V,formatX:W}){let[K,X]=(0,l.useState)(null),c=K!==null&&K<o.length?K:null,[ye,pe]=(0,l.useState)(null),Ce=(0,Ee.useChartSync)(),m=fe?Ce:null,e=(0,l.useMemo)(()=>{let t=s.filter(f=>!f.hidden),r=(0,v.buildCartesianGeometry)({width:h,height:a,data:o,x:u,y:H,bounds:(0,He.extent)((0,j.collectAllValues)(o,t.map(f=>f.key))),margin:J,placement:"point",formatValue:V,formatX:W,extraTop:P?je:0}),d=r.categoryCenters,y=r.valueScale,te=D===void 0?-1:r.xValues.findIndex(f=>(0,T.toKey)(f)===(0,T.toKey)(D)),Ne=t.map(f=>{let z=o.map((ae,Ke)=>{let ve=(0,j.readNumber)(ae,f.key);return{x:d[Ke],y:ve===null?Number.NaN:y(ve),defined:ve!==null}}),Se={connectNulls:S},ne=te>=0,ke=ae=>w&&w>0?(0,le.decimatePath)(ae,w):ae,re=ke(ne?z.slice(0,te+1):z),oe=f.dashed?ke(z):ne?ke(z.slice(te)):[];w||(0,le.warnPointBudget)("LineChart",z.length);let Me=f.dashed?oe:ne?[...re,...oe.slice(1)]:re;return{key:f.key,color:f.color,solid:f.dashed?"":(0,B.buildLinePath)(re,k,Se),dashed:f.dashed||ne?(0,B.buildLinePath)(oe,k,Se):"",markers:[...re,...f.dashed?[]:oe].filter(B.isDrawable),isolated:(0,B.isolatedPoints)(Me,S)}}),De=o.length>1?r.innerWidth/(o.length-1):0;return{visible:t,locate:(0,v.createCategoryLocator)(r),plot:(0,v.createPlotContext)({geometry:r,width:h,height:a,data:o,series:t,formatValue:V,formatX:W}),xValues:r.xValues,xPositions:d,xTicks:r.categoryTicks,yTicks:r.valueTicks,yScale:y,innerWidth:r.innerWidth,innerHeight:r.innerHeight,margin:r.margin,lines:Ne,forecastIndex:te,showMarkers:L==="always"||L==="auto"&&De>=Ue&&o.length>1}},[o,s,u,H,h,a,J,k,S,D,P,L,w,V,W]),p=(0,l.useCallback)(t=>e.visible.map(r=>{let d=(0,j.readNumber)(o[t],r.key);return{seriesKey:r.key,seriesLabel:(0,E.getSeriesLabel)(r),color:r.color,value:d,formattedValue:d===null?"\u2014":V(d),datum:o[t]}}),[o,e.visible,V]),Q=m?m.brush:ye,be=(0,l.useCallback)(t=>{pe(t),m?.setBrush(t),q?.(t)},[m,q]),g=(0,se.useChartBrush)({enabled:Y,active:Q!==null,centers:e.xPositions,xValues:e.xValues,offset:e.margin.left,orientation:"vertical",onCommit:be}),Z=(0,l.useCallback)(t=>{if(g.onPointerMove(t),A===!1||o.length===0)return;let r=t.currentTarget.getBoundingClientRect(),d=t.clientX-r.left-e.margin.left,y=(0,T.nearestIndex)(e.xPositions,d);X(y>=0?y:null),m?.setHovered(y>=0?e.xValues[y]:null)},[g,A,o.length,e.margin.left,e.xPositions,e.xValues,m]),$=(0,l.useCallback)(()=>{X(null),m?.setHovered(null)},[m]),xe=(0,l.useCallback)(t=>{if(o.length===0)return;g.onKeyDown(t,c);let r=o.length-1,d=c??0,y=t.key==="ArrowRight"?Math.min(r,d+1):t.key==="ArrowLeft"?Math.max(0,d-1):t.key==="Home"?0:t.key==="End"?r:t.key==="Escape"?null:void 0;y!==void 0&&(t.preventDefault(),X(y),m?.setHovered(y===null?null:e.xValues[y]))},[o.length,c,g,m,e.xValues]),I=(0,l.useCallback)(()=>{if(g.consumedClick()||!M||c===null)return;let[t]=p(c);t&&M({...t,index:c,x:e.xValues[c]})},[g,M,c,p,e.xValues]),ee=c!==null||!m?.hovered?null:(()=>{let t=(0,T.toKey)(m.hovered),r=e.xValues.findIndex(d=>(0,T.toKey)(d)===t);return r<0?null:r})(),C=c??ee,G=C===null?null:p(C),O=(G??[]).filter(t=>t.value!==null),N=g.dragging??Q,_=(()=>{if(!N)return null;let t=e.locate(N.from),r=e.locate(N.to);return t===null||r===null?null:{from:t,to:r}})(),i=(0,v.splitOverlay)(de),b=c===null||G===null?null:{x:e.xValues[c],xLabel:W(e.xValues[c],c),index:c,points:G};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("svg",{width:h,height:a,role:"img","aria-label":ge??[e.visible.map(t=>(0,E.getSeriesLabel)(t)).join(", "),(0,U.describeAnnotations)(R,ce)].filter(Boolean).join(". "),tabIndex:0,className:(0,Re.cn)(Ie.CHART_TOUCH,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500",Y&&"select-none"),onPointerDown:g.onPointerDown,onPointerMove:Z,onPointerUp:g.onPointerUp,onPointerCancel:g.onPointerUp,onPointerLeave:$,onKeyDown:xe,onBlur:$,onClick:I,children:[(0,n.jsxs)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[(0,n.jsx)(Ve.ChartGrid,{width:e.innerWidth,height:e.innerHeight,horizontal:x==="y"||x==="both"?e.yTicks.map(t=>t.offset):void 0,vertical:x==="x"||x==="both"?e.xTicks.map(t=>t.offset):void 0}),R?(0,n.jsx)(U.ChartAnnotationLayer,{layer:"under",annotations:R,xAt:e.locate,yAt:e.yScale,width:e.innerWidth,height:e.innerHeight}):null,_?(0,n.jsx)(se.ChartBrushLayer,{from:_.from,to:_.to,width:e.innerWidth,height:e.innerHeight,live:g.dragging!==null,label:me}):null,i.under?.(e.plot),ue?.map(t=>{let r=e.yScale(t.value),d=r<Fe?r+12:r-4;return(0,n.jsxs)("g",{children:[(0,n.jsx)("line",{x1:0,y1:r,x2:e.innerWidth,y2:r,stroke:t.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:t.dashed===!1?void 0:"4 4"}),t.label?(0,n.jsx)("text",{x:e.innerWidth,y:d,textAnchor:"end",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)}),e.forecastIndex>=0?(0,n.jsxs)("g",{children:[(0,n.jsx)("line",{x1:e.xPositions[e.forecastIndex],y1:0,x2:e.xPositions[e.forecastIndex],y2:e.innerHeight,className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1,strokeDasharray:"3 3"}),P?(0,n.jsx)("text",{x:e.xPositions[e.forecastIndex]+4,y:-2,className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:P}):null]}):null,(0,n.jsx)(Ye,{lines:e.lines,showMarkers:e.showMarkers}),R?(0,n.jsx)(U.ChartAnnotationLayer,{annotations:R,xAt:e.locate,yAt:e.yScale,width:e.innerWidth,height:e.innerHeight}):null,i.over?.(e.plot),C!==null?(0,n.jsxs)("g",{"aria-hidden":"true",children:[(0,n.jsx)("line",{x1:e.xPositions[C],y1:0,x2:e.xPositions[C],y2:e.innerHeight,className:"stroke-gray-400 dark:stroke-gray-500",strokeWidth:1,strokeDasharray:c===null?"3 3":void 0}),O.map(t=>(0,n.jsx)("circle",{cx:e.xPositions[C],cy:e.yScale(t.value),r:4,fill:t.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},t.seriesKey))]}):null]}),(0,n.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:u.hidden?null:(0,n.jsx)(Le.ChartAxis,{orientation:"bottom",ticks:e.xTicks,length:e.innerWidth,label:u.label,size:F})}),(0,n.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:H?.hidden?null:(0,n.jsx)(Le.ChartAxis,{orientation:"left",ticks:e.yTicks,length:e.innerHeight,showLine:!1,label:H?.label,size:F})})]}),b&&A!==!1?(0,n.jsx)(ie.ChartTooltip,{x:e.margin.left+e.xPositions[b.index],y:e.margin.top+(O.length>0?Math.min(...O.map(t=>e.yScale(t.value))):e.innerHeight/2),containerWidth:h,children:typeof A=="function"?A(b):(0,n.jsx)(ie.ChartTooltipContent,{title:b.xLabel,points:b.points})}):null]})}function Je({data:h,series:a,x:o,y:s,height:u=240,width:H,size:x="md",grid:F="y",legend:k,tooltip:D=!0,tableView:P=!1,emphasis:L,title:S,description:ue,loading:R=!1,emptyState:ce,error:de=!1,errorState:w,onRetry:Y,actions:q,onPointClick:me,curve:fe="monotone",forecastFrom:J,forecastLabel:A,markers:M="auto",connectNulls:ge=!1,referenceLines:V,annotations:W,overlay:K,legendToggle:X=!0,maxPoints:c,brush:ye=!1,onBrush:pe,brushLabel:Ce,sync:m=!0,margin:e,locale:p,plotLabel:Q,className:be,...g}){let Z=(0,we.useUILabels)(),[$,xe]=(0,l.useState)(()=>new Set),I=(0,l.useMemo)(()=>a.map((i,b)=>({...i,hidden:i.hidden||$.has(i.key),color:(0,E.resolveSeriesColor)(i,b,L)})),[a,$,L]),ee=(0,l.useMemo)(()=>s?.format??(i=>(0,he.formatAuto)(i,p)),[s?.format,p]),C=(0,l.useMemo)(()=>o.format??(i=>o.scale==="time"?(0,We.formatTimeValue)(i,p):(0,he.formatXValue)(i,p)),[o.format,o.scale,p]),G=(0,l.useCallback)(i=>{xe(b=>{let t=new Set(b);return t.has(i)?t.delete(i):t.add(i),t})},[]),O=k===void 0?a.length>=2:k!==!1,N=typeof k=="string"?k:"bottom",_=I.filter(i=>!i.hidden).length;return(0,n.jsx)(Ae.ChartContainer,{title:S,description:ue,height:u,width:H,size:x,loading:R,empty:h.length===0||_===0,emptyState:ce,error:de,errorState:w,onRetry:Y,actions:q,tableView:P,legendPosition:N,legend:O?(0,n.jsx)(Te.ChartLegend,{items:(0,E.toLegendItems)(I,L),position:N,marker:"line",size:x,onToggle:X?G:void 0}):void 0,table:P?(0,n.jsx)(Be.ChartTableView,{data:h,series:I,xKey:o.key,xLabel:o.label??o.key,formatX:C,formatValue:ee,caption:typeof S=="string"?S:void 0}):void 0,className:be,...g,children:({width:i})=>(0,n.jsx)(qe,{width:i,height:u,data:h,resolvedSeries:I,x:o,y:s,grid:F,size:x,curve:fe,forecastFrom:J,forecastLabel:A,markers:M,connectNulls:ge,referenceLines:V,annotations:W,annotationsLabel:Z.chartAnnotations,overlay:K,maxPoints:c,brush:ye,onBrush:pe,brushLabel:Ce??Z.chartBrush,syncEnabled:m,margin:e,tooltip:D,onPointClick:me,plotLabel:Q,formatValue:ee,formatX:C})})}0&&(module.exports={LineChart});
@@ -1 +1 @@
1
- "use client";import{memo as we,useCallback as w,useMemo as Z,useState as fe}from"react";import{cn as Ae}from"../../lib/cn.js";import{useUILabels as Ve}from"../../lib/i18n.js";import{ChartAnnotationLayer as Ce,describeAnnotations as Ee}from"../chart/ChartAnnotations.js";import{ChartAxis as be}from"../chart/ChartAxis.js";import{ChartBrushLayer as Be,useChartBrush as Te}from"../chart/ChartBrush.js";import{ChartContainer as He}from"../chart/ChartContainer.js";import{ChartGrid as Ne}from"../chart/ChartGrid.js";import{ChartLegend as We}from"../chart/ChartLegend.js";import{useChartSync as Ie}from"../chart/ChartSync.js";import{ChartTableView as De}from"../chart/ChartTableView.js";import{ChartTooltip as Me,ChartTooltipContent as Ke}from"../chart/ChartTooltip.js";import{getSeriesLabel as xe,resolveSeriesColor as Xe,toLegendItems as $e}from"../chart/palette.js";import{buildCartesianGeometry as Ge,createCategoryLocator as Oe,createPlotContext as ze,splitOverlay as _e}from"../chart/utils/cartesian.js";import{collectAllValues as je,readNumber as ke}from"../chart/utils/data.js";import{decimatePath as Ue,warnPointBudget as Fe}from"../chart/utils/decimate.js";import{formatAuto as Ye,formatXValue as Pe}from"../chart/utils/format.js";import{buildLinePath as ve}from"../chart/utils/path.js";import{nearestIndex as qe,toKey as Q,toNumber as Je}from"../chart/utils/scales.js";import{extent as Qe}from"../chart/utils/ticks.js";import{Fragment as ot,jsx as o,jsxs as A}from"react/jsx-runtime";var Ze=24,et=10,tt=10,nt=we(function({lines:g,showMarkers:r}){return o("g",{children:g.map(i=>A("g",{children:[i.solid?o("path",{d:i.solid,fill:"none",stroke:i.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}):null,i.dashed?o("path",{d:i.dashed,fill:"none",stroke:i.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"5 4"}):null,r?i.markers.map(d=>o("circle",{cx:d.x,cy:d.y,r:3,fill:i.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},`${d.x}-${d.y}`)):null]},i.key))})});function rt({width:f,height:g,data:r,resolvedSeries:i,x:d,y:V,grid:b,size:z,curve:x,forecastFrom:W,forecastLabel:k,markers:P,connectNulls:E,referenceLines:ee,annotations:v,annotationsLabel:te,overlay:ne,maxPoints:L,brush:_,onBrush:j,brushLabel:re,syncEnabled:oe,margin:U,tooltip:S,onPointClick:I,plotLabel:ae,formatValue:R,formatX:B}){let[D,M]=fe(null),s=D!==null&&D<r.length?D:null,[se,ie]=fe(null),le=Ie(),h=oe?le:null,e=Z(()=>{let t=i.filter(c=>!c.hidden),n=Ge({width:f,height:g,data:r,x:d,y:V,bounds:Qe(je(r,t.map(c=>c.key))),margin:U,placement:"point",formatValue:R,formatX:B,extraTop:k?et:0}),l=n.categoryCenters,m=n.valueScale,J=W===void 0?-1:n.xValues.findIndex(c=>Q(c)===Q(W)),Le=t.map(c=>{let O=r.map((N,Re)=>{let me=ke(N,c.key);return{x:l[Re],y:me===null?Number.NaN:m(me),defined:me!==null}}),ge={connectNulls:E},ce=J>=0,de=N=>L&&L>0?Ue(N,L):N,ye=de(ce?O.slice(0,J+1):O),pe=c.dashed?de(O):ce?de(O.slice(J)):[];return L||Fe("LineChart",O.length),{key:c.key,color:c.color,solid:c.dashed?"":ve(ye,x,ge),dashed:c.dashed||ce?ve(pe,x,ge):"",markers:[...ye,...c.dashed?[]:pe].filter(N=>N.defined!==!1)}}),Se=r.length>1?n.innerWidth/(r.length-1):0;return{visible:t,locate:Oe(n),plot:ze({geometry:n,width:f,height:g,data:r,series:t,formatValue:R,formatX:B}),xValues:n.xValues,xPositions:l,xTicks:n.categoryTicks,yTicks:n.valueTicks,yScale:m,innerWidth:n.innerWidth,innerHeight:n.innerHeight,margin:n.margin,lines:Le,forecastIndex:J,showMarkers:P==="always"||P==="auto"&&Se>=Ze&&r.length>1}},[r,i,d,V,f,g,U,x,E,W,k,P,L,R,B]),y=w(t=>e.visible.map(n=>{let l=ke(r[t],n.key);return{seriesKey:n.key,seriesLabel:xe(n),color:n.color,value:l,formattedValue:l===null?"\u2014":R(l),datum:r[t]}}),[r,e.visible,R]),F=h?h.brush:se,he=w(t=>{ie(t),h?.setBrush(t),j?.(t)},[h,j]),u=Te({enabled:_,active:F!==null,centers:e.xPositions,xValues:e.xValues,offset:e.margin.left,orientation:"vertical",onCommit:he}),Y=w(t=>{if(u.onPointerMove(t),S===!1||r.length===0)return;let n=t.currentTarget.getBoundingClientRect(),l=t.clientX-n.left-e.margin.left,m=qe(e.xPositions,l);M(m>=0?m:null),h?.setHovered(m>=0?e.xValues[m]:null)},[u,S,r.length,e.margin.left,e.xPositions,e.xValues,h]),K=w(()=>{M(null),h?.setHovered(null)},[h]),ue=w(t=>{if(r.length===0)return;u.onKeyDown(t,s);let n=r.length-1,l=s??0,m=t.key==="ArrowRight"?Math.min(n,l+1):t.key==="ArrowLeft"?Math.max(0,l-1):t.key==="Home"?0:t.key==="End"?n:t.key==="Escape"?null:void 0;m!==void 0&&(t.preventDefault(),M(m),h?.setHovered(m===null?null:e.xValues[m]))},[r.length,s,u,h,e.xValues]),T=w(()=>{if(u.consumedClick()||!I||s===null)return;let[t]=y(s);t&&I({...t,index:s,x:e.xValues[s]})},[u,I,s,y,e.xValues]),q=s!==null||!h?.hovered?null:(()=>{let t=Q(h.hovered),n=e.xValues.findIndex(l=>Q(l)===t);return n<0?null:n})(),p=s??q,X=p===null?null:y(p),$=(X??[]).filter(t=>t.value!==null),H=u.dragging??F,G=(()=>{if(!H)return null;let t=e.locate(H.from),n=e.locate(H.to);return t===null||n===null?null:{from:t,to:n}})(),a=_e(ne),C=s===null||X===null?null:{x:e.xValues[s],xLabel:B(e.xValues[s],s),index:s,points:X};return A(ot,{children:[A("svg",{width:f,height:g,role:"img","aria-label":ae??[e.visible.map(t=>xe(t)).join(", "),Ee(v,te)].filter(Boolean).join(". "),tabIndex:0,className:Ae("touch-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500",_&&"select-none"),onPointerDown:u.onPointerDown,onPointerMove:Y,onPointerUp:u.onPointerUp,onPointerCancel:u.onPointerUp,onPointerLeave:K,onKeyDown:ue,onBlur:K,onClick:T,children:[A("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[o(Ne,{width:e.innerWidth,height:e.innerHeight,horizontal:b==="y"||b==="both"?e.yTicks.map(t=>t.offset):void 0,vertical:b==="x"||b==="both"?e.xTicks.map(t=>t.offset):void 0}),v?o(Ce,{layer:"under",annotations:v,xAt:e.locate,yAt:e.yScale,width:e.innerWidth,height:e.innerHeight}):null,G?o(Be,{from:G.from,to:G.to,width:e.innerWidth,height:e.innerHeight,live:u.dragging!==null,label:re}):null,a.under?.(e.plot),ee?.map(t=>{let n=e.yScale(t.value),l=n<tt?n+12:n-4;return A("g",{children:[o("line",{x1:0,y1:n,x2:e.innerWidth,y2:n,stroke:t.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:t.dashed===!1?void 0:"4 4"}),t.label?o("text",{x:e.innerWidth,y:l,textAnchor:"end",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)}),e.forecastIndex>=0?A("g",{children:[o("line",{x1:e.xPositions[e.forecastIndex],y1:0,x2:e.xPositions[e.forecastIndex],y2:e.innerHeight,className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1,strokeDasharray:"3 3"}),k?o("text",{x:e.xPositions[e.forecastIndex]+4,y:-2,className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:k}):null]}):null,o(nt,{lines:e.lines,showMarkers:e.showMarkers}),v?o(Ce,{annotations:v,xAt:e.locate,yAt:e.yScale,width:e.innerWidth,height:e.innerHeight}):null,a.over?.(e.plot),p!==null?A("g",{"aria-hidden":"true",children:[o("line",{x1:e.xPositions[p],y1:0,x2:e.xPositions[p],y2:e.innerHeight,className:"stroke-gray-400 dark:stroke-gray-500",strokeWidth:1,strokeDasharray:s===null?"3 3":void 0}),$.map(t=>o("circle",{cx:e.xPositions[p],cy:e.yScale(t.value),r:4,fill:t.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},t.seriesKey))]}):null]}),o("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:d.hidden?null:o(be,{orientation:"bottom",ticks:e.xTicks,length:e.innerWidth,label:d.label,size:z})}),o("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:V?.hidden?null:o(be,{orientation:"left",ticks:e.yTicks,length:e.innerHeight,showLine:!1,label:V?.label,size:z})})]}),C&&S!==!1?o(Me,{x:e.margin.left+e.xPositions[C.index],y:e.margin.top+($.length>0?Math.min(...$.map(t=>e.yScale(t.value))):e.innerHeight/2),containerWidth:f,children:typeof S=="function"?S(C):o(Ke,{title:C.xLabel,points:C.points})}):null]})}function St({data:f,series:g,x:r,y:i,height:d=240,width:V,size:b="md",grid:z="y",legend:x,tooltip:W=!0,tableView:k=!1,emphasis:P,title:E,description:ee,loading:v=!1,emptyState:te,error:ne=!1,errorState:L,onRetry:_,actions:j,onPointClick:re,curve:oe="monotone",forecastFrom:U,forecastLabel:S,markers:I="auto",connectNulls:ae=!1,referenceLines:R,annotations:B,overlay:D,legendToggle:M=!0,maxPoints:s,brush:se=!1,onBrush:ie,brushLabel:le,sync:h=!0,margin:e,locale:y,plotLabel:F,className:he,...u}){let Y=Ve(),[K,ue]=fe(()=>new Set),T=Z(()=>g.map((a,C)=>({...a,hidden:a.hidden||K.has(a.key),color:Xe(a,C,P)})),[g,K,P]),q=Z(()=>i?.format??(a=>Ye(a,y)),[i?.format,y]),p=Z(()=>r.format??(a=>r.scale==="time"?Pe(a instanceof Date?a:new Date(Je(a)),y):Pe(a,y)),[r.format,r.scale,y]),X=w(a=>{ue(C=>{let t=new Set(C);return t.has(a)?t.delete(a):t.add(a),t})},[]),$=x===void 0?g.length>=2:x!==!1,H=typeof x=="string"?x:"bottom",G=T.filter(a=>!a.hidden).length;return o(He,{title:E,description:ee,height:d,width:V,size:b,loading:v,empty:f.length===0||G===0,emptyState:te,error:ne,errorState:L,onRetry:_,actions:j,tableView:k,legendPosition:H,legend:$?o(We,{items:$e(T,P),position:H,marker:"line",size:b,onToggle:M?X:void 0}):void 0,table:k?o(De,{data:f,series:T,xKey:r.key,xLabel:r.label??r.key,formatX:p,formatValue:q,caption:typeof E=="string"?E:void 0}):void 0,className:he,...u,children:({width:a})=>o(rt,{width:a,height:d,data:f,resolvedSeries:T,x:r,y:i,grid:z,size:b,curve:oe,forecastFrom:U,forecastLabel:S,markers:I,connectNulls:ae,referenceLines:R,annotations:B,annotationsLabel:Y.chartAnnotations,overlay:D,maxPoints:s,brush:se,onBrush:ie,brushLabel:le??Y.chartBrush,syncEnabled:h,margin:e,tooltip:W,onPointClick:re,plotLabel:F,formatValue:q,formatX:p})})}export{St as LineChart};
1
+ "use client";import{memo as we,useCallback as A,useMemo as ne,useState as ye}from"react";import{cn as Ae}from"../../lib/cn.js";import{useUILabels as Ve}from"../../lib/i18n.js";import{ChartAnnotationLayer as Ce,describeAnnotations as Te}from"../chart/ChartAnnotations.js";import{ChartAxis as be}from"../chart/ChartAxis.js";import{ChartBrushLayer as Ee,useChartBrush as Be}from"../chart/ChartBrush.js";import{ChartContainer as He}from"../chart/ChartContainer.js";import{ChartGrid as We}from"../chart/ChartGrid.js";import{ChartLegend as Ie}from"../chart/ChartLegend.js";import{useChartSync as Ne}from"../chart/ChartSync.js";import{ChartTableView as De}from"../chart/ChartTableView.js";import{ChartTooltip as Me,ChartTooltipContent as Ke}from"../chart/ChartTooltip.js";import{getSeriesLabel as xe,resolveSeriesColor as Xe,toLegendItems as $e}from"../chart/palette.js";import{buildCartesianGeometry as Ge,createCategoryLocator as Oe,createPlotContext as _e,splitOverlay as ze}from"../chart/utils/cartesian.js";import{collectAllValues as Ue,readNumber as ke}from"../chart/utils/data.js";import{decimatePath as je,warnPointBudget as Fe}from"../chart/utils/decimate.js";import{formatAuto as Ye,formatXValue as qe}from"../chart/utils/format.js";import{buildLinePath as ve,isDrawable as Je,isolatedPoints as Qe}from"../chart/utils/path.js";import{nearestIndex as Ze,toKey as te}from"../chart/utils/scales.js";import{extent as et}from"../chart/utils/ticks.js";import{formatTimeValue as tt}from"../chart/utils/timestamp.js";import{CHART_TOUCH as nt}from"../chart/utils/touch.js";import{Fragment as lt,jsx as o,jsxs as V}from"react/jsx-runtime";var rt=24,ot=10,at=10,st=we(function({lines:g,showMarkers:r}){return o("g",{children:g.map(i=>V("g",{children:[i.solid?o("path",{d:i.solid,fill:"none",stroke:i.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}):null,i.dashed?o("path",{d:i.dashed,fill:"none",stroke:i.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"5 4"}):null,(r?i.markers:i.isolated).map(d=>o("circle",{cx:d.x,cy:d.y,r:3,fill:i.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},`${d.x}-${d.y}`))]},i.key))})});function it({width:f,height:g,data:r,resolvedSeries:i,x:d,y:T,grid:b,size:O,curve:x,forecastFrom:W,forecastLabel:k,markers:v,connectNulls:P,referenceLines:re,annotations:L,annotationsLabel:oe,overlay:ae,maxPoints:S,brush:_,onBrush:z,brushLabel:se,syncEnabled:ie,margin:U,tooltip:R,onPointClick:I,plotLabel:le,formatValue:w,formatX:E}){let[N,D]=ye(null),s=N!==null&&N<r.length?N:null,[he,ue]=ye(null),ce=Ne(),h=ie?ce:null,e=ne(()=>{let t=i.filter(u=>!u.hidden),n=Ge({width:f,height:g,data:r,x:d,y:T,bounds:et(Ue(r,t.map(u=>u.key))),margin:U,placement:"point",formatValue:w,formatX:E,extraTop:k?ot:0}),l=n.categoryCenters,m=n.valueScale,q=W===void 0?-1:n.xValues.findIndex(u=>te(u)===te(W)),Pe=t.map(u=>{let G=r.map((ee,Re)=>{let ge=ke(ee,u.key);return{x:l[Re],y:ge===null?Number.NaN:m(ge),defined:ge!==null}}),pe={connectNulls:P},J=q>=0,fe=ee=>S&&S>0?je(ee,S):ee,Q=fe(J?G.slice(0,q+1):G),Z=u.dashed?fe(G):J?fe(G.slice(q)):[];S||Fe("LineChart",G.length);let Se=u.dashed?Z:J?[...Q,...Z.slice(1)]:Q;return{key:u.key,color:u.color,solid:u.dashed?"":ve(Q,x,pe),dashed:u.dashed||J?ve(Z,x,pe):"",markers:[...Q,...u.dashed?[]:Z].filter(Je),isolated:Qe(Se,P)}}),Le=r.length>1?n.innerWidth/(r.length-1):0;return{visible:t,locate:Oe(n),plot:_e({geometry:n,width:f,height:g,data:r,series:t,formatValue:w,formatX:E}),xValues:n.xValues,xPositions:l,xTicks:n.categoryTicks,yTicks:n.valueTicks,yScale:m,innerWidth:n.innerWidth,innerHeight:n.innerHeight,margin:n.margin,lines:Pe,forecastIndex:q,showMarkers:v==="always"||v==="auto"&&Le>=rt&&r.length>1}},[r,i,d,T,f,g,U,x,P,W,k,v,S,w,E]),y=A(t=>e.visible.map(n=>{let l=ke(r[t],n.key);return{seriesKey:n.key,seriesLabel:xe(n),color:n.color,value:l,formattedValue:l===null?"\u2014":w(l),datum:r[t]}}),[r,e.visible,w]),j=h?h.brush:he,de=A(t=>{ue(t),h?.setBrush(t),z?.(t)},[h,z]),c=Be({enabled:_,active:j!==null,centers:e.xPositions,xValues:e.xValues,offset:e.margin.left,orientation:"vertical",onCommit:de}),F=A(t=>{if(c.onPointerMove(t),R===!1||r.length===0)return;let n=t.currentTarget.getBoundingClientRect(),l=t.clientX-n.left-e.margin.left,m=Ze(e.xPositions,l);D(m>=0?m:null),h?.setHovered(m>=0?e.xValues[m]:null)},[c,R,r.length,e.margin.left,e.xPositions,e.xValues,h]),M=A(()=>{D(null),h?.setHovered(null)},[h]),me=A(t=>{if(r.length===0)return;c.onKeyDown(t,s);let n=r.length-1,l=s??0,m=t.key==="ArrowRight"?Math.min(n,l+1):t.key==="ArrowLeft"?Math.max(0,l-1):t.key==="Home"?0:t.key==="End"?n:t.key==="Escape"?null:void 0;m!==void 0&&(t.preventDefault(),D(m),h?.setHovered(m===null?null:e.xValues[m]))},[r.length,s,c,h,e.xValues]),B=A(()=>{if(c.consumedClick()||!I||s===null)return;let[t]=y(s);t&&I({...t,index:s,x:e.xValues[s]})},[c,I,s,y,e.xValues]),Y=s!==null||!h?.hovered?null:(()=>{let t=te(h.hovered),n=e.xValues.findIndex(l=>te(l)===t);return n<0?null:n})(),p=s??Y,K=p===null?null:y(p),X=(K??[]).filter(t=>t.value!==null),H=c.dragging??j,$=(()=>{if(!H)return null;let t=e.locate(H.from),n=e.locate(H.to);return t===null||n===null?null:{from:t,to:n}})(),a=ze(ae),C=s===null||K===null?null:{x:e.xValues[s],xLabel:E(e.xValues[s],s),index:s,points:K};return V(lt,{children:[V("svg",{width:f,height:g,role:"img","aria-label":le??[e.visible.map(t=>xe(t)).join(", "),Te(L,oe)].filter(Boolean).join(". "),tabIndex:0,className:Ae(nt,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500",_&&"select-none"),onPointerDown:c.onPointerDown,onPointerMove:F,onPointerUp:c.onPointerUp,onPointerCancel:c.onPointerUp,onPointerLeave:M,onKeyDown:me,onBlur:M,onClick:B,children:[V("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[o(We,{width:e.innerWidth,height:e.innerHeight,horizontal:b==="y"||b==="both"?e.yTicks.map(t=>t.offset):void 0,vertical:b==="x"||b==="both"?e.xTicks.map(t=>t.offset):void 0}),L?o(Ce,{layer:"under",annotations:L,xAt:e.locate,yAt:e.yScale,width:e.innerWidth,height:e.innerHeight}):null,$?o(Ee,{from:$.from,to:$.to,width:e.innerWidth,height:e.innerHeight,live:c.dragging!==null,label:se}):null,a.under?.(e.plot),re?.map(t=>{let n=e.yScale(t.value),l=n<at?n+12:n-4;return V("g",{children:[o("line",{x1:0,y1:n,x2:e.innerWidth,y2:n,stroke:t.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:t.dashed===!1?void 0:"4 4"}),t.label?o("text",{x:e.innerWidth,y:l,textAnchor:"end",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)}),e.forecastIndex>=0?V("g",{children:[o("line",{x1:e.xPositions[e.forecastIndex],y1:0,x2:e.xPositions[e.forecastIndex],y2:e.innerHeight,className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1,strokeDasharray:"3 3"}),k?o("text",{x:e.xPositions[e.forecastIndex]+4,y:-2,className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:k}):null]}):null,o(st,{lines:e.lines,showMarkers:e.showMarkers}),L?o(Ce,{annotations:L,xAt:e.locate,yAt:e.yScale,width:e.innerWidth,height:e.innerHeight}):null,a.over?.(e.plot),p!==null?V("g",{"aria-hidden":"true",children:[o("line",{x1:e.xPositions[p],y1:0,x2:e.xPositions[p],y2:e.innerHeight,className:"stroke-gray-400 dark:stroke-gray-500",strokeWidth:1,strokeDasharray:s===null?"3 3":void 0}),X.map(t=>o("circle",{cx:e.xPositions[p],cy:e.yScale(t.value),r:4,fill:t.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},t.seriesKey))]}):null]}),o("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:d.hidden?null:o(be,{orientation:"bottom",ticks:e.xTicks,length:e.innerWidth,label:d.label,size:O})}),o("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:T?.hidden?null:o(be,{orientation:"left",ticks:e.yTicks,length:e.innerHeight,showLine:!1,label:T?.label,size:O})})]}),C&&R!==!1?o(Me,{x:e.margin.left+e.xPositions[C.index],y:e.margin.top+(X.length>0?Math.min(...X.map(t=>e.yScale(t.value))):e.innerHeight/2),containerWidth:f,children:typeof R=="function"?R(C):o(Ke,{title:C.xLabel,points:C.points})}):null]})}function Et({data:f,series:g,x:r,y:i,height:d=240,width:T,size:b="md",grid:O="y",legend:x,tooltip:W=!0,tableView:k=!1,emphasis:v,title:P,description:re,loading:L=!1,emptyState:oe,error:ae=!1,errorState:S,onRetry:_,actions:z,onPointClick:se,curve:ie="monotone",forecastFrom:U,forecastLabel:R,markers:I="auto",connectNulls:le=!1,referenceLines:w,annotations:E,overlay:N,legendToggle:D=!0,maxPoints:s,brush:he=!1,onBrush:ue,brushLabel:ce,sync:h=!0,margin:e,locale:y,plotLabel:j,className:de,...c}){let F=Ve(),[M,me]=ye(()=>new Set),B=ne(()=>g.map((a,C)=>({...a,hidden:a.hidden||M.has(a.key),color:Xe(a,C,v)})),[g,M,v]),Y=ne(()=>i?.format??(a=>Ye(a,y)),[i?.format,y]),p=ne(()=>r.format??(a=>r.scale==="time"?tt(a,y):qe(a,y)),[r.format,r.scale,y]),K=A(a=>{me(C=>{let t=new Set(C);return t.has(a)?t.delete(a):t.add(a),t})},[]),X=x===void 0?g.length>=2:x!==!1,H=typeof x=="string"?x:"bottom",$=B.filter(a=>!a.hidden).length;return o(He,{title:P,description:re,height:d,width:T,size:b,loading:L,empty:f.length===0||$===0,emptyState:oe,error:ae,errorState:S,onRetry:_,actions:z,tableView:k,legendPosition:H,legend:X?o(Ie,{items:$e(B,v),position:H,marker:"line",size:b,onToggle:D?K:void 0}):void 0,table:k?o(De,{data:f,series:B,xKey:r.key,xLabel:r.label??r.key,formatX:p,formatValue:Y,caption:typeof P=="string"?P:void 0}):void 0,className:de,...c,children:({width:a})=>o(it,{width:a,height:d,data:f,resolvedSeries:B,x:r,y:i,grid:O,size:b,curve:ie,forecastFrom:U,forecastLabel:R,markers:I,connectNulls:le,referenceLines:w,annotations:E,annotationsLabel:F.chartAnnotations,overlay:N,maxPoints:s,brush:he,onBrush:ue,brushLabel:ce??F.chartBrush,syncEnabled:h,margin:e,tooltip:W,onPointClick:se,plotLabel:j,formatValue:Y,formatX:p})})}export{Et as LineChart};
@@ -1 +1 @@
1
- "use strict";"use client";var H=Object.defineProperty;var ue=Object.getOwnPropertyDescriptor;var ce=Object.getOwnPropertyNames;var de=Object.prototype.hasOwnProperty;var he=(i,t)=>{for(var a in t)H(i,a,{get:t[a],enumerable:!0})},me=(i,t,a,C)=>{if(t&&typeof t=="object"||typeof t=="function")for(let m of ce(t))!de.call(i,m)&&m!==a&&H(i,m,{get:()=>t[m],enumerable:!(C=ue(t,m))||C.enumerable});return i};var ge=i=>me(H({},"__esModule",{value:!0}),i);var ve={};he(ve,{PieChart:()=>Pe,resetPieWarnings:()=>xe});module.exports=ge(ve);var h=require("react"),Z=require("../../lib/i18n.cjs"),ee=require("../chart/ChartContainer.cjs"),te=require("../chart/ChartLegend.cjs"),B=require("../chart/ChartPatterns.cjs"),ae=require("../chart/ChartTableView.cjs"),T=require("../chart/ChartTooltip.cjs"),$=require("../chart/palette.cjs"),N=require("../chart/utils/data.cjs"),x=require("../chart/utils/format.cjs"),oe=require("../chart/utils/path.cjs"),o=require("react/jsx-runtime"),pe=.62,fe=2,be=3,ye=.16,Ce=64,ke=22,U=6,F=!1;function Ae({width:i,height:t,slices:a,variant:C,innerRadius:m,showLabels:k,centerLabel:A,tooltip:P,patterns:w,patternBaseId:M,plotLabel:E,formatValue:L,locale:D,onSliceClick:_}){let[p,v]=(0,h.useState)(null),V=(0,h.useMemo)(()=>{let e=k?Ce:8,n=k?ke:8,l=Math.max(0,Math.min((i-e*2)/2,(t-n*2)/2));return{cx:i/2,cy:t/2,outerRadius:l,inner:C==="donut"?l*(m??pe):(m??0)*l,pad:l>0&&a.length>1?fe/l/2:0}},[i,t,C,m,k,a.length]),{cx:g,cy:b,outerRadius:f,inner:O,pad:S}=V,K=(0,h.useCallback)(e=>{let n=(e.startAngle+e.endAngle)/2,l=Math.sin(n)>=0,d={x:g+Math.sin(n)*(f+4),y:b-Math.cos(n)*(f+4)},y={x:g+Math.sin(n)*(f+14),y:b-Math.cos(n)*(f+14)},I={x:l?y.x+10:y.x-10,y:y.y};return{from:d,elbow:y,end:I,anchor:l?"start":"end"}},[g,b,f]),X=(0,h.useCallback)(e=>{if(a.length===0)return;let n=a.length-1,l=p??0,d=e.key==="ArrowRight"||e.key==="ArrowDown"?Math.min(n,l+1):e.key==="ArrowLeft"||e.key==="ArrowUp"?Math.max(0,l-1):e.key==="Home"?0:e.key==="End"?n:e.key==="Escape"?null:void 0;d!==void 0&&(e.preventDefault(),v(d))},[a.length,p]),r=p===null?null:a[p];return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)("svg",{width:i,height:t,role:"img","aria-label":E??a.map(e=>e.label).join(", "),tabIndex:0,className:"touch-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500",onPointerLeave:()=>v(null),onBlur:()=>v(null),onKeyDown:X,children:[w?(0,o.jsx)(B.ChartPatternDefs,{id:M,entries:a.map(e=>({slot:e.slot,color:e.color}))}):null,a.map((e,n)=>(0,o.jsx)("path",{d:(0,oe.buildArcPath)({cx:g,cy:b,innerRadius:O,outerRadius:f+(p===n?be:0),startAngle:e.startAngle+S,endAngle:Math.max(e.startAngle+S,e.endAngle-S)}),fill:(0,B.patternFill)(w,M,e.slot,e.color),onPointerEnter:()=>P===!1?void 0:v(n),onClick:()=>_?.({key:e.key,label:e.label,value:e.value,share:e.share})},e.key)),k?a.filter(e=>e.endAngle-e.startAngle>=ye).map(e=>{let{from:n,elbow:l,end:d,anchor:y}=K(e);return(0,o.jsxs)("g",{"aria-hidden":"true",children:[(0,o.jsx)("polyline",{points:`${n.x},${n.y} ${l.x},${l.y} ${d.x},${d.y}`,fill:"none",className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1}),(0,o.jsx)("text",{x:y==="start"?d.x+3:d.x-3,y:d.y,textAnchor:y,dominantBaseline:"middle",className:"fill-gray-600 text-[10px] dark:fill-gray-300",children:e.label})]},`label-${e.key}`)}):null,C==="donut"&&A?(0,o.jsxs)("g",{"aria-hidden":"true",children:[(0,o.jsx)("text",{x:g,y:b-(A.label?2:0),textAnchor:"middle",dominantBaseline:"middle",className:"fill-gray-900 text-lg font-semibold dark:fill-gray-100",children:A.value}),A.label?(0,o.jsx)("text",{x:g,y:b+14,textAnchor:"middle",dominantBaseline:"middle",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:A.label}):null]}):null]}),r&&P!==!1?(0,o.jsx)(T.ChartTooltip,{x:g+Math.sin((r.startAngle+r.endAngle)/2)*(f*.7),y:b-Math.cos((r.startAngle+r.endAngle)/2)*(f*.7),containerWidth:i,children:typeof P=="function"?P({seriesKey:r.key,seriesLabel:r.label,color:r.color,value:r.value,formattedValue:L(r.value),datum:{},share:r.share}):(0,o.jsx)(T.ChartTooltipContent,{title:r.label,points:[{seriesKey:r.key,seriesLabel:(0,x.formatPercent)(r.share,{locale:D}),color:r.color,value:r.value,formattedValue:L(r.value),datum:{}}]})}):null]})}function Pe({data:i,x:t,value:a,variant:C="pie",innerRadius:m,maxSlices:k=U,otherLabel:A,sort:P="desc",showLabels:w=!0,centerLabel:M,patterns:E=!1,height:L=260,width:D,size:_="md",legend:p,tooltip:v=!0,tableView:V=!1,title:g,description:b,loading:f=!1,emptyState:O,error:S=!1,errorState:K,onRetry:X,actions:r,locale:e,plotLabel:n,onSliceClick:l,className:d,...y}){let I=(0,Z.useUILabels)(),re=(0,h.useId)(),j=(0,h.useCallback)(u=>(0,x.formatAuto)(u,e),[e]),q=(0,h.useCallback)(u=>t.format?t.format(u,0):(0,x.formatXValue)(u,e),[t,e]),{slices:W,total:ne,rows:le}=(0,h.useMemo)(()=>{let u=i.map((s,c)=>({key:String((0,N.readXValue)(s,t.key,c)),label:q((0,N.readXValue)(s,t.key,c)),value:(0,N.readNumber)(s,a)??0,color:(0,$.getSeriesColor)(c),slot:c,datum:s})),Q=P==="none"?u:[...u].sort((s,c)=>P==="asc"?s.value-c.value:c.value-s.value),R=Q.slice(0,k),Y=Q.slice(k);Y.length>0&&R.push({key:"__other__",label:A??I.chartOther,value:Y.reduce((s,c)=>s+c.value,0),color:$.CHART_MUTED_COLOR,slot:-1,datum:{}}),R.length>U&&!F&&(F=!0,console.warn(`[@synertech/ui] A PieChart is drawing ${R.length} slices. Past ${U} the slices stop being tellable apart: lower \`maxSlices\`, or use a BarChart, which compares lengths rather than angles.`));let z=R.reduce((s,c)=>s+Math.max(0,c.value),0),G=0;return{slices:R.map(s=>{let c=z===0?0:Math.max(0,s.value)/z,ie=G;return G+=c*Math.PI*2,{...s,share:c,startAngle:ie,endAngle:G}}),total:z,rows:R.map(s=>({[t.key]:s.label,[a]:s.value}))}},[i,t.key,a,P,k,A,I.chartOther,q]),se=p===void 0?!0:p!==!1,J=typeof p=="string"?p:"bottom";return(0,o.jsx)(ee.ChartContainer,{title:g,description:b,height:L,width:D,size:_,loading:f,empty:W.length===0||ne===0,emptyState:O,error:S,errorState:K,onRetry:X,actions:r,tableView:V,legendPosition:J,legend:se?(0,o.jsx)(te.ChartLegend,{items:W.map(u=>({key:u.key,label:`${u.label} \xB7 ${(0,x.formatPercent)(u.share,{locale:e})}`,color:u.color,...E?{pattern:u.slot}:{}})),position:J,marker:"rect",size:_}):void 0,table:V?(0,o.jsx)(ae.ChartTableView,{data:le,series:[{key:a,label:t.label??a}],xKey:t.key,xLabel:t.label??t.key,formatValue:j,caption:typeof g=="string"?g:void 0}):void 0,className:d,...y,children:({width:u})=>(0,o.jsx)(Ae,{width:u,height:L,slices:W,variant:C,innerRadius:m,showLabels:w,centerLabel:M,tooltip:v,patterns:E,patternBaseId:re,plotLabel:n,formatValue:j,locale:e,onSliceClick:l})})}function xe(){F=!1}0&&(module.exports={PieChart,resetPieWarnings});
1
+ "use strict";"use client";var G=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var de=Object.getOwnPropertyNames;var he=Object.prototype.hasOwnProperty;var me=(i,t)=>{for(var a in t)G(i,a,{get:t[a],enumerable:!0})},ge=(i,t,a,C)=>{if(t&&typeof t=="object"||typeof t=="function")for(let m of de(t))!he.call(i,m)&&m!==a&&G(i,m,{get:()=>t[m],enumerable:!(C=ce(t,m))||C.enumerable});return i};var pe=i=>ge(G({},"__esModule",{value:!0}),i);var ve={};me(ve,{PieChart:()=>xe,resetPieWarnings:()=>Re});module.exports=pe(ve);var h=require("react"),Z=require("../../lib/i18n.cjs"),ee=require("../chart/ChartContainer.cjs"),te=require("../chart/ChartLegend.cjs"),T=require("../chart/ChartPatterns.cjs"),ae=require("../chart/ChartTableView.cjs"),$=require("../chart/ChartTooltip.cjs"),B=require("../chart/palette.cjs"),N=require("../chart/utils/data.cjs"),x=require("../chart/utils/format.cjs"),oe=require("../chart/utils/path.cjs"),re=require("../chart/utils/touch.cjs"),o=require("react/jsx-runtime"),fe=.62,be=2,ye=3,Ce=.16,ke=64,Ae=22,U=6,F=!1;function Pe({width:i,height:t,slices:a,variant:C,innerRadius:m,showLabels:k,centerLabel:A,tooltip:P,patterns:w,patternBaseId:M,plotLabel:E,formatValue:L,locale:O,onSliceClick:_}){let[p,R]=(0,h.useState)(null),V=(0,h.useMemo)(()=>{let e=k?ke:8,n=k?Ae:8,l=Math.max(0,Math.min((i-e*2)/2,(t-n*2)/2));return{cx:i/2,cy:t/2,outerRadius:l,inner:C==="donut"?l*(m??fe):(m??0)*l,pad:l>0&&a.length>1?be/l/2:0}},[i,t,C,m,k,a.length]),{cx:g,cy:b,outerRadius:f,inner:D,pad:S}=V,K=(0,h.useCallback)(e=>{let n=(e.startAngle+e.endAngle)/2,l=Math.sin(n)>=0,d={x:g+Math.sin(n)*(f+4),y:b-Math.cos(n)*(f+4)},y={x:g+Math.sin(n)*(f+14),y:b-Math.cos(n)*(f+14)},I={x:l?y.x+10:y.x-10,y:y.y};return{from:d,elbow:y,end:I,anchor:l?"start":"end"}},[g,b,f]),X=(0,h.useCallback)(e=>{if(a.length===0)return;let n=a.length-1,l=p??0,d=e.key==="ArrowRight"||e.key==="ArrowDown"?Math.min(n,l+1):e.key==="ArrowLeft"||e.key==="ArrowUp"?Math.max(0,l-1):e.key==="Home"?0:e.key==="End"?n:e.key==="Escape"?null:void 0;d!==void 0&&(e.preventDefault(),R(d))},[a.length,p]),r=p===null?null:a[p];return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)("svg",{width:i,height:t,role:"img","aria-label":E??a.map(e=>e.label).join(", "),tabIndex:0,className:`${re.CHART_TOUCH} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500`,onPointerLeave:()=>R(null),onBlur:()=>R(null),onKeyDown:X,children:[w?(0,o.jsx)(T.ChartPatternDefs,{id:M,entries:a.map(e=>({slot:e.slot,color:e.color}))}):null,a.map((e,n)=>(0,o.jsx)("path",{d:(0,oe.buildArcPath)({cx:g,cy:b,innerRadius:D,outerRadius:f+(p===n?ye:0),startAngle:e.startAngle+S,endAngle:Math.max(e.startAngle+S,e.endAngle-S)}),fill:(0,T.patternFill)(w,M,e.slot,e.color),onPointerEnter:()=>P===!1?void 0:R(n),onClick:()=>_?.({key:e.key,label:e.label,value:e.value,share:e.share})},e.key)),k?a.filter(e=>e.endAngle-e.startAngle>=Ce).map(e=>{let{from:n,elbow:l,end:d,anchor:y}=K(e);return(0,o.jsxs)("g",{"aria-hidden":"true",children:[(0,o.jsx)("polyline",{points:`${n.x},${n.y} ${l.x},${l.y} ${d.x},${d.y}`,fill:"none",className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1}),(0,o.jsx)("text",{x:y==="start"?d.x+3:d.x-3,y:d.y,textAnchor:y,dominantBaseline:"middle",className:"fill-gray-600 text-[10px] dark:fill-gray-300",children:e.label})]},`label-${e.key}`)}):null,C==="donut"&&A?(0,o.jsxs)("g",{"aria-hidden":"true",children:[(0,o.jsx)("text",{x:g,y:b-(A.label?2:0),textAnchor:"middle",dominantBaseline:"middle",className:"fill-gray-900 text-lg font-semibold dark:fill-gray-100",children:A.value}),A.label?(0,o.jsx)("text",{x:g,y:b+14,textAnchor:"middle",dominantBaseline:"middle",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:A.label}):null]}):null]}),r&&P!==!1?(0,o.jsx)($.ChartTooltip,{x:g+Math.sin((r.startAngle+r.endAngle)/2)*(f*.7),y:b-Math.cos((r.startAngle+r.endAngle)/2)*(f*.7),containerWidth:i,children:typeof P=="function"?P({seriesKey:r.key,seriesLabel:r.label,color:r.color,value:r.value,formattedValue:L(r.value),datum:{},share:r.share}):(0,o.jsx)($.ChartTooltipContent,{title:r.label,points:[{seriesKey:r.key,seriesLabel:(0,x.formatPercent)(r.share,{locale:O}),color:r.color,value:r.value,formattedValue:L(r.value),datum:{}}]})}):null]})}function xe({data:i,x:t,value:a,variant:C="pie",innerRadius:m,maxSlices:k=U,otherLabel:A,sort:P="desc",showLabels:w=!0,centerLabel:M,patterns:E=!1,height:L=260,width:O,size:_="md",legend:p,tooltip:R=!0,tableView:V=!1,title:g,description:b,loading:f=!1,emptyState:D,error:S=!1,errorState:K,onRetry:X,actions:r,locale:e,plotLabel:n,onSliceClick:l,className:d,...y}){let I=(0,Z.useUILabels)(),ne=(0,h.useId)(),j=(0,h.useCallback)(u=>(0,x.formatAuto)(u,e),[e]),q=(0,h.useCallback)(u=>t.format?t.format(u,0):(0,x.formatXValue)(u,e),[t,e]),{slices:H,total:le,rows:se}=(0,h.useMemo)(()=>{let u=i.map((s,c)=>({key:String((0,N.readXValue)(s,t.key,c)),label:q((0,N.readXValue)(s,t.key,c)),value:(0,N.readNumber)(s,a)??0,color:(0,B.getSeriesColor)(c),slot:c,datum:s})),Q=P==="none"?u:[...u].sort((s,c)=>P==="asc"?s.value-c.value:c.value-s.value),v=Q.slice(0,k),Y=Q.slice(k);Y.length>0&&v.push({key:"__other__",label:A??I.chartOther,value:Y.reduce((s,c)=>s+c.value,0),color:B.CHART_MUTED_COLOR,slot:-1,datum:{}}),v.length>U&&!F&&(F=!0,console.warn(`[@synertech/ui] A PieChart is drawing ${v.length} slices. Past ${U} the slices stop being tellable apart: lower \`maxSlices\`, or use a BarChart, which compares lengths rather than angles.`));let W=v.reduce((s,c)=>s+Math.max(0,c.value),0),z=0;return{slices:v.map(s=>{let c=W===0?0:Math.max(0,s.value)/W,ue=z;return z+=c*Math.PI*2,{...s,share:c,startAngle:ue,endAngle:z}}),total:W,rows:v.map(s=>({[t.key]:s.label,[a]:s.value}))}},[i,t.key,a,P,k,A,I.chartOther,q]),ie=p===void 0?!0:p!==!1,J=typeof p=="string"?p:"bottom";return(0,o.jsx)(ee.ChartContainer,{title:g,description:b,height:L,width:O,size:_,loading:f,empty:H.length===0||le===0,emptyState:D,error:S,errorState:K,onRetry:X,actions:r,tableView:V,legendPosition:J,legend:ie?(0,o.jsx)(te.ChartLegend,{items:H.map(u=>({key:u.key,label:`${u.label} \xB7 ${(0,x.formatPercent)(u.share,{locale:e})}`,color:u.color,...E?{pattern:u.slot}:{}})),position:J,marker:"rect",size:_}):void 0,table:V?(0,o.jsx)(ae.ChartTableView,{data:se,series:[{key:a,label:t.label??a}],xKey:t.key,xLabel:t.label??t.key,formatValue:j,caption:typeof g=="string"?g:void 0}):void 0,className:d,...y,children:({width:u})=>(0,o.jsx)(Pe,{width:u,height:L,slices:H,variant:C,innerRadius:m,showLabels:w,centerLabel:M,tooltip:R,patterns:E,patternBaseId:ne,plotLabel:n,formatValue:j,locale:e,onSliceClick:l})})}function Re(){F=!1}0&&(module.exports={PieChart,resetPieWarnings});
@@ -1 +1 @@
1
- "use client";import{useCallback as V,useId as ae,useMemo as q,useState as oe}from"react";import{useUILabels as re}from"../../lib/i18n.js";import{ChartContainer as ne}from"../chart/ChartContainer.js";import{ChartLegend as le}from"../chart/ChartLegend.js";import{ChartPatternDefs as se,patternFill as ie}from"../chart/ChartPatterns.js";import{ChartTableView as ue}from"../chart/ChartTableView.js";import{ChartTooltip as ce,ChartTooltipContent as de}from"../chart/ChartTooltip.js";import{CHART_MUTED_COLOR as he,getSeriesColor as me}from"../chart/palette.js";import{readNumber as ge,readXValue as j}from"../chart/utils/data.js";import{formatAuto as pe,formatPercent as J,formatXValue as fe}from"../chart/utils/format.js";import{buildArcPath as be}from"../chart/utils/path.js";import{Fragment as Re,jsx as c,jsxs as _}from"react/jsx-runtime";var ye=.62,Ce=2,ke=3,Ae=.16,Pe=64,xe=22,X=6,W=!1;function ve({width:f,height:n,slices:l,variant:P,innerRadius:x,showLabels:b,centerLabel:y,tooltip:C,patterns:L,patternBaseId:S,plotLabel:N,formatValue:v,locale:I,onSliceClick:w}){let[h,k]=oe(null),M=q(()=>{let e=b?Pe:8,a=b?xe:8,o=Math.max(0,Math.min((f-e*2)/2,(n-a*2)/2));return{cx:f/2,cy:n/2,outerRadius:o,inner:P==="donut"?o*(x??ye):(x??0)*o,pad:o>0&&l.length>1?Ce/o/2:0}},[f,n,P,x,b,l.length]),{cx:d,cy:g,outerRadius:m,inner:B,pad:R}=M,T=V(e=>{let a=(e.startAngle+e.endAngle)/2,o=Math.sin(a)>=0,u={x:d+Math.sin(a)*(m+4),y:g-Math.cos(a)*(m+4)},p={x:d+Math.sin(a)*(m+14),y:g-Math.cos(a)*(m+14)},E={x:o?p.x+10:p.x-10,y:p.y};return{from:u,elbow:p,end:E,anchor:o?"start":"end"}},[d,g,m]),$=V(e=>{if(l.length===0)return;let a=l.length-1,o=h??0,u=e.key==="ArrowRight"||e.key==="ArrowDown"?Math.min(a,o+1):e.key==="ArrowLeft"||e.key==="ArrowUp"?Math.max(0,o-1):e.key==="Home"?0:e.key==="End"?a:e.key==="Escape"?null:void 0;u!==void 0&&(e.preventDefault(),k(u))},[l.length,h]),t=h===null?null:l[h];return _(Re,{children:[_("svg",{width:f,height:n,role:"img","aria-label":N??l.map(e=>e.label).join(", "),tabIndex:0,className:"touch-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500",onPointerLeave:()=>k(null),onBlur:()=>k(null),onKeyDown:$,children:[L?c(se,{id:S,entries:l.map(e=>({slot:e.slot,color:e.color}))}):null,l.map((e,a)=>c("path",{d:be({cx:d,cy:g,innerRadius:B,outerRadius:m+(h===a?ke:0),startAngle:e.startAngle+R,endAngle:Math.max(e.startAngle+R,e.endAngle-R)}),fill:ie(L,S,e.slot,e.color),onPointerEnter:()=>C===!1?void 0:k(a),onClick:()=>w?.({key:e.key,label:e.label,value:e.value,share:e.share})},e.key)),b?l.filter(e=>e.endAngle-e.startAngle>=Ae).map(e=>{let{from:a,elbow:o,end:u,anchor:p}=T(e);return _("g",{"aria-hidden":"true",children:[c("polyline",{points:`${a.x},${a.y} ${o.x},${o.y} ${u.x},${u.y}`,fill:"none",className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1}),c("text",{x:p==="start"?u.x+3:u.x-3,y:u.y,textAnchor:p,dominantBaseline:"middle",className:"fill-gray-600 text-[10px] dark:fill-gray-300",children:e.label})]},`label-${e.key}`)}):null,P==="donut"&&y?_("g",{"aria-hidden":"true",children:[c("text",{x:d,y:g-(y.label?2:0),textAnchor:"middle",dominantBaseline:"middle",className:"fill-gray-900 text-lg font-semibold dark:fill-gray-100",children:y.value}),y.label?c("text",{x:d,y:g+14,textAnchor:"middle",dominantBaseline:"middle",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:y.label}):null]}):null]}),t&&C!==!1?c(ce,{x:d+Math.sin((t.startAngle+t.endAngle)/2)*(m*.7),y:g-Math.cos((t.startAngle+t.endAngle)/2)*(m*.7),containerWidth:f,children:typeof C=="function"?C({seriesKey:t.key,seriesLabel:t.label,color:t.color,value:t.value,formattedValue:v(t.value),datum:{},share:t.share}):c(de,{title:t.label,points:[{seriesKey:t.key,seriesLabel:J(t.share,{locale:I}),color:t.color,value:t.value,formattedValue:v(t.value),datum:{}}]})}):null]})}function De({data:f,x:n,value:l,variant:P="pie",innerRadius:x,maxSlices:b=X,otherLabel:y,sort:C="desc",showLabels:L=!0,centerLabel:S,patterns:N=!1,height:v=260,width:I,size:w="md",legend:h,tooltip:k=!0,tableView:M=!1,title:d,description:g,loading:m=!1,emptyState:B,error:R=!1,errorState:T,onRetry:$,actions:t,locale:e,plotLabel:a,onSliceClick:o,className:u,...p}){let E=re(),Q=ae(),z=V(s=>pe(s,e),[e]),G=V(s=>n.format?n.format(s,0):fe(s,e),[n,e]),{slices:D,total:Y,rows:Z}=q(()=>{let s=f.map((r,i)=>({key:String(j(r,n.key,i)),label:G(j(r,n.key,i)),value:ge(r,l)??0,color:me(i),slot:i,datum:r})),U=C==="none"?s:[...s].sort((r,i)=>C==="asc"?r.value-i.value:i.value-r.value),A=U.slice(0,b),F=U.slice(b);F.length>0&&A.push({key:"__other__",label:y??E.chartOther,value:F.reduce((r,i)=>r+i.value,0),color:he,slot:-1,datum:{}}),A.length>X&&!W&&(W=!0,console.warn(`[@synertech/ui] A PieChart is drawing ${A.length} slices. Past ${X} the slices stop being tellable apart: lower \`maxSlices\`, or use a BarChart, which compares lengths rather than angles.`));let O=A.reduce((r,i)=>r+Math.max(0,i.value),0),K=0;return{slices:A.map(r=>{let i=O===0?0:Math.max(0,r.value)/O,te=K;return K+=i*Math.PI*2,{...r,share:i,startAngle:te,endAngle:K}}),total:O,rows:A.map(r=>({[n.key]:r.label,[l]:r.value}))}},[f,n.key,l,C,b,y,E.chartOther,G]),ee=h===void 0?!0:h!==!1,H=typeof h=="string"?h:"bottom";return c(ne,{title:d,description:g,height:v,width:I,size:w,loading:m,empty:D.length===0||Y===0,emptyState:B,error:R,errorState:T,onRetry:$,actions:t,tableView:M,legendPosition:H,legend:ee?c(le,{items:D.map(s=>({key:s.key,label:`${s.label} \xB7 ${J(s.share,{locale:e})}`,color:s.color,...N?{pattern:s.slot}:{}})),position:H,marker:"rect",size:w}):void 0,table:M?c(ue,{data:Z,series:[{key:l,label:n.label??l}],xKey:n.key,xLabel:n.label??n.key,formatValue:z,caption:typeof d=="string"?d:void 0}):void 0,className:u,...p,children:({width:s})=>c(ve,{width:s,height:v,slices:D,variant:P,innerRadius:x,showLabels:L,centerLabel:S,tooltip:k,patterns:N,patternBaseId:Q,plotLabel:a,formatValue:z,locale:e,onSliceClick:o})})}function Oe(){W=!1}export{De as PieChart,Oe as resetPieWarnings};
1
+ "use client";import{useCallback as V,useId as ae,useMemo as q,useState as oe}from"react";import{useUILabels as re}from"../../lib/i18n.js";import{ChartContainer as ne}from"../chart/ChartContainer.js";import{ChartLegend as le}from"../chart/ChartLegend.js";import{ChartPatternDefs as se,patternFill as ie}from"../chart/ChartPatterns.js";import{ChartTableView as ue}from"../chart/ChartTableView.js";import{ChartTooltip as ce,ChartTooltipContent as de}from"../chart/ChartTooltip.js";import{CHART_MUTED_COLOR as he,getSeriesColor as me}from"../chart/palette.js";import{readNumber as ge,readXValue as j}from"../chart/utils/data.js";import{formatAuto as pe,formatPercent as J,formatXValue as fe}from"../chart/utils/format.js";import{buildArcPath as be}from"../chart/utils/path.js";import{CHART_TOUCH as ye}from"../chart/utils/touch.js";import{Fragment as Le,jsx as c,jsxs as _}from"react/jsx-runtime";var Ce=.62,ke=2,Ae=3,Pe=.16,xe=64,Re=22,X=6,H=!1;function ve({width:f,height:n,slices:l,variant:P,innerRadius:x,showLabels:b,centerLabel:y,tooltip:C,patterns:L,patternBaseId:S,plotLabel:N,formatValue:R,locale:I,onSliceClick:w}){let[h,k]=oe(null),M=q(()=>{let e=b?xe:8,a=b?Re:8,o=Math.max(0,Math.min((f-e*2)/2,(n-a*2)/2));return{cx:f/2,cy:n/2,outerRadius:o,inner:P==="donut"?o*(x??Ce):(x??0)*o,pad:o>0&&l.length>1?ke/o/2:0}},[f,n,P,x,b,l.length]),{cx:d,cy:g,outerRadius:m,inner:T,pad:v}=M,$=V(e=>{let a=(e.startAngle+e.endAngle)/2,o=Math.sin(a)>=0,u={x:d+Math.sin(a)*(m+4),y:g-Math.cos(a)*(m+4)},p={x:d+Math.sin(a)*(m+14),y:g-Math.cos(a)*(m+14)},E={x:o?p.x+10:p.x-10,y:p.y};return{from:u,elbow:p,end:E,anchor:o?"start":"end"}},[d,g,m]),B=V(e=>{if(l.length===0)return;let a=l.length-1,o=h??0,u=e.key==="ArrowRight"||e.key==="ArrowDown"?Math.min(a,o+1):e.key==="ArrowLeft"||e.key==="ArrowUp"?Math.max(0,o-1):e.key==="Home"?0:e.key==="End"?a:e.key==="Escape"?null:void 0;u!==void 0&&(e.preventDefault(),k(u))},[l.length,h]),t=h===null?null:l[h];return _(Le,{children:[_("svg",{width:f,height:n,role:"img","aria-label":N??l.map(e=>e.label).join(", "),tabIndex:0,className:`${ye} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500`,onPointerLeave:()=>k(null),onBlur:()=>k(null),onKeyDown:B,children:[L?c(se,{id:S,entries:l.map(e=>({slot:e.slot,color:e.color}))}):null,l.map((e,a)=>c("path",{d:be({cx:d,cy:g,innerRadius:T,outerRadius:m+(h===a?Ae:0),startAngle:e.startAngle+v,endAngle:Math.max(e.startAngle+v,e.endAngle-v)}),fill:ie(L,S,e.slot,e.color),onPointerEnter:()=>C===!1?void 0:k(a),onClick:()=>w?.({key:e.key,label:e.label,value:e.value,share:e.share})},e.key)),b?l.filter(e=>e.endAngle-e.startAngle>=Pe).map(e=>{let{from:a,elbow:o,end:u,anchor:p}=$(e);return _("g",{"aria-hidden":"true",children:[c("polyline",{points:`${a.x},${a.y} ${o.x},${o.y} ${u.x},${u.y}`,fill:"none",className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1}),c("text",{x:p==="start"?u.x+3:u.x-3,y:u.y,textAnchor:p,dominantBaseline:"middle",className:"fill-gray-600 text-[10px] dark:fill-gray-300",children:e.label})]},`label-${e.key}`)}):null,P==="donut"&&y?_("g",{"aria-hidden":"true",children:[c("text",{x:d,y:g-(y.label?2:0),textAnchor:"middle",dominantBaseline:"middle",className:"fill-gray-900 text-lg font-semibold dark:fill-gray-100",children:y.value}),y.label?c("text",{x:d,y:g+14,textAnchor:"middle",dominantBaseline:"middle",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:y.label}):null]}):null]}),t&&C!==!1?c(ce,{x:d+Math.sin((t.startAngle+t.endAngle)/2)*(m*.7),y:g-Math.cos((t.startAngle+t.endAngle)/2)*(m*.7),containerWidth:f,children:typeof C=="function"?C({seriesKey:t.key,seriesLabel:t.label,color:t.color,value:t.value,formattedValue:R(t.value),datum:{},share:t.share}):c(de,{title:t.label,points:[{seriesKey:t.key,seriesLabel:J(t.share,{locale:I}),color:t.color,value:t.value,formattedValue:R(t.value),datum:{}}]})}):null]})}function Ke({data:f,x:n,value:l,variant:P="pie",innerRadius:x,maxSlices:b=X,otherLabel:y,sort:C="desc",showLabels:L=!0,centerLabel:S,patterns:N=!1,height:R=260,width:I,size:w="md",legend:h,tooltip:k=!0,tableView:M=!1,title:d,description:g,loading:m=!1,emptyState:T,error:v=!1,errorState:$,onRetry:B,actions:t,locale:e,plotLabel:a,onSliceClick:o,className:u,...p}){let E=re(),Q=ae(),W=V(s=>pe(s,e),[e]),z=V(s=>n.format?n.format(s,0):fe(s,e),[n,e]),{slices:O,total:Y,rows:Z}=q(()=>{let s=f.map((r,i)=>({key:String(j(r,n.key,i)),label:z(j(r,n.key,i)),value:ge(r,l)??0,color:me(i),slot:i,datum:r})),U=C==="none"?s:[...s].sort((r,i)=>C==="asc"?r.value-i.value:i.value-r.value),A=U.slice(0,b),F=U.slice(b);F.length>0&&A.push({key:"__other__",label:y??E.chartOther,value:F.reduce((r,i)=>r+i.value,0),color:he,slot:-1,datum:{}}),A.length>X&&!H&&(H=!0,console.warn(`[@synertech/ui] A PieChart is drawing ${A.length} slices. Past ${X} the slices stop being tellable apart: lower \`maxSlices\`, or use a BarChart, which compares lengths rather than angles.`));let D=A.reduce((r,i)=>r+Math.max(0,i.value),0),K=0;return{slices:A.map(r=>{let i=D===0?0:Math.max(0,r.value)/D,te=K;return K+=i*Math.PI*2,{...r,share:i,startAngle:te,endAngle:K}}),total:D,rows:A.map(r=>({[n.key]:r.label,[l]:r.value}))}},[f,n.key,l,C,b,y,E.chartOther,z]),ee=h===void 0?!0:h!==!1,G=typeof h=="string"?h:"bottom";return c(ne,{title:d,description:g,height:R,width:I,size:w,loading:m,empty:O.length===0||Y===0,emptyState:T,error:v,errorState:$,onRetry:B,actions:t,tableView:M,legendPosition:G,legend:ee?c(le,{items:O.map(s=>({key:s.key,label:`${s.label} \xB7 ${J(s.share,{locale:e})}`,color:s.color,...N?{pattern:s.slot}:{}})),position:G,marker:"rect",size:w}):void 0,table:M?c(ue,{data:Z,series:[{key:l,label:n.label??l}],xKey:n.key,xLabel:n.label??n.key,formatValue:W,caption:typeof d=="string"?d:void 0}):void 0,className:u,...p,children:({width:s})=>c(ve,{width:s,height:R,slices:O,variant:P,innerRadius:x,showLabels:L,centerLabel:S,tooltip:k,patterns:N,patternBaseId:Q,plotLabel:a,formatValue:W,locale:e,onSliceClick:o})})}function Xe(){H=!1}export{Ke as PieChart,Xe as resetPieWarnings};