@synertech/ui 0.47.0 → 0.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/.claude/skills/use-synertech-ui/SKILL.md +49 -1
  2. package/README.md +23 -0
  3. package/dist/components/area-chart/AreaChart.cjs +1 -1
  4. package/dist/components/area-chart/AreaChart.js +1 -1
  5. package/dist/components/bar-chart/BarChart.cjs +1 -1
  6. package/dist/components/bar-chart/BarChart.js +1 -1
  7. package/dist/components/box-plot/BoxPlot.cjs +1 -1
  8. package/dist/components/box-plot/BoxPlot.js +1 -1
  9. package/dist/components/breadcrumb/Breadcrumb.cjs +1 -1
  10. package/dist/components/breadcrumb/Breadcrumb.js +1 -1
  11. package/dist/components/bullet-chart/BulletChart.cjs +1 -1
  12. package/dist/components/bullet-chart/BulletChart.js +1 -1
  13. package/dist/components/calendar/Calendar.cjs +1 -1
  14. package/dist/components/calendar/Calendar.js +1 -1
  15. package/dist/components/candlestick-chart/CandlestickChart.cjs +1 -1
  16. package/dist/components/candlestick-chart/CandlestickChart.js +1 -1
  17. package/dist/components/chart/ChartPeriodPicker.cjs +1 -1
  18. package/dist/components/chart/ChartPeriodPicker.js +1 -1
  19. package/dist/components/datagrid/DataGrid.cjs +1 -1
  20. package/dist/components/datagrid/DataGrid.js +1 -1
  21. package/dist/components/dumbbell-chart/DumbbellChart.cjs +1 -1
  22. package/dist/components/dumbbell-chart/DumbbellChart.js +1 -1
  23. package/dist/components/footer/FooterLink.cjs +1 -1
  24. package/dist/components/footer/FooterLink.js +1 -1
  25. package/dist/components/footer/FooterSocial.cjs +1 -1
  26. package/dist/components/footer/FooterSocial.js +1 -1
  27. package/dist/components/form/number-input/NumberInput.cjs +1 -1
  28. package/dist/components/form/number-input/NumberInput.js +1 -1
  29. package/dist/components/funnel-chart/FunnelChart.cjs +1 -1
  30. package/dist/components/funnel-chart/FunnelChart.js +1 -1
  31. package/dist/components/gantt-chart/GanttChart.cjs +1 -1
  32. package/dist/components/gantt-chart/GanttChart.js +1 -1
  33. package/dist/components/header/Header.cjs +1 -1
  34. package/dist/components/header/Header.js +1 -1
  35. package/dist/components/heat-map/Heatmap.cjs +1 -1
  36. package/dist/components/heat-map/Heatmap.js +1 -1
  37. package/dist/components/help-button/HelpButton.cjs +5 -5
  38. package/dist/components/help-button/HelpButton.js +6 -6
  39. package/dist/components/help-button/sanitize-html.cjs +1 -0
  40. package/dist/components/help-button/sanitize-html.js +1 -0
  41. package/dist/components/line-chart/LineChart.cjs +1 -1
  42. package/dist/components/line-chart/LineChart.js +1 -1
  43. package/dist/components/pie-chart/PieChart.cjs +1 -1
  44. package/dist/components/pie-chart/PieChart.js +1 -1
  45. package/dist/components/scatter-chart/ScatterChart.cjs +1 -1
  46. package/dist/components/scatter-chart/ScatterChart.js +1 -1
  47. package/dist/components/sidebar/Sidebar.cjs +1 -1
  48. package/dist/components/sidebar/Sidebar.js +1 -1
  49. package/dist/components/stat-card/StatCard.cjs +1 -1
  50. package/dist/components/stat-card/StatCard.js +1 -1
  51. package/dist/components/waterfall-chart/WaterfallChart.cjs +1 -1
  52. package/dist/components/waterfall-chart/WaterfallChart.js +1 -1
  53. package/dist/index.cjs +1 -1
  54. package/dist/index.d.cts +187 -25
  55. package/dist/index.d.ts +187 -25
  56. package/dist/index.js +1 -1
  57. package/dist/lib/i18n.cjs +1 -1
  58. package/dist/lib/i18n.js +1 -1
  59. package/dist/lib/safe-href.cjs +1 -0
  60. package/dist/lib/safe-href.js +1 -0
  61. package/package.json +1 -1
@@ -402,6 +402,14 @@ import { Breadcrumb } from "@synertech/ui";
402
402
  />
403
403
  ```
404
404
 
405
+ Une adresse ne fait un lien que si elle est en `http:`, `https:`, `mailto:`,
406
+ `tel:` ou relative : le `href` d'un element de `Breadcrumb`, de `Header` (et
407
+ son `logoHref`), d'un `SidebarItem`, d'un `FooterLink` ou d'un
408
+ `FooterSocialLink`. Toute autre (`javascript:`, `data:`, `sms:`...) laisse le
409
+ texte sans lien, un `SidebarItem` devient un bouton, et la console le signale
410
+ une fois. Un `rel` passe a `FooterLink external` ou a `FooterSocialLink`
411
+ s'ajoute a `noopener noreferrer` au lieu de le remplacer.
412
+
405
413
  ### Pagination
406
414
 
407
415
  ```tsx
@@ -1067,7 +1075,13 @@ import { StatCard, StatCardGroup, Sparkline } from "@synertech/ui";
1067
1075
  ```
1068
1076
 
1069
1077
  `StatCard` et `Sparkline` n'utilisent aucun hook : ils fonctionnent en composant
1070
- serveur, sans `"use client"`.
1078
+ serveur, sans `"use client"`. C'est aussi pourquoi `StatCard` ne lit pas la
1079
+ `locale` de `UILabelsProvider` : passez-la en prop (`locale="fr-CA"`), sinon la
1080
+ carte s'écrit dans la langue du serveur puis change à l'hydratation.
1081
+
1082
+ Le sens de la variation se lit sur ce qui est écrit : une variation arrondie à
1083
+ « 0 % » est stable (tiret gris), jamais une flèche verte à côté d'un zéro.
1084
+ `delta.direction` l'emporte toujours.
1071
1085
 
1072
1086
  ### Rhabiller la palette
1073
1087
 
@@ -1434,6 +1448,14 @@ import { HelpButton, WithHelpButton } from "@synertech/ui";
1434
1448
  </WithHelpButton>
1435
1449
  ```
1436
1450
 
1451
+ Sans `markdown`, une chaine est du HTML reduit a sa mise en forme : titres,
1452
+ paragraphes, listes, liens, code, citations, tableaux. `<style>`, formulaires,
1453
+ champs, boutons et images sont retires, comme les attributs `class`, `style`,
1454
+ `id` et `name` ; un lien ne garde qu'une adresse `http:`, `https:`, `mailto:`,
1455
+ `tel:` ou relative. En Markdown non plus, une image (`![](url)`) n'est pas
1456
+ affichee. Une aide qui a besoin d'autre chose (une image, un composant) se
1457
+ passe en noeud React, rendu tel quel.
1458
+
1437
1459
  ### Detachable
1438
1460
 
1439
1461
  ```tsx
@@ -2169,6 +2191,32 @@ courant.
2169
2191
  <UILabelsProvider labels={{ dataGridPageOf: "Page {page} / {total}" }}>
2170
2192
  ```
2171
2193
 
2194
+ **Nombres et dates : la `locale` du provider.** `labels` est la langue des
2195
+ textes ; `locale` (une etiquette BCP 47 : `"fr-CA"`, `"en-US"`) est la facon
2196
+ d'ecrire les nombres et les dates. Le provider prend les deux :
2197
+
2198
+ ```tsx
2199
+ <UILabelsProvider labels={frenchUILabels} locale="fr-CA">
2200
+ {children}
2201
+ </UILabelsProvider>
2202
+ ```
2203
+
2204
+ - La lisent : les treize graphiques, `Calendar`, `ChartPeriodPicker`,
2205
+ `NumberInput` et les agregats du pied de `DataGrid`. La prop `locale` d'une
2206
+ instance gagne ; un provider imbrique sans `locale` garde celle du parent ;
2207
+ `useUILocale()` la lit pour vos propres composants (a passer a `Intl`).
2208
+ - Sans prop ni provider, ces composants suivent la langue de l'environnement :
2209
+ celle du serveur sur le serveur, celle du lecteur dans le navigateur.
2210
+ `NumberInput` fait exception : `en-US`.
2211
+ - `StatCard`, `ChartFacets` et `ChartScaleLegend` sont rendus cote serveur :
2212
+ le provider ne les atteint pas, leur `locale` est une prop.
2213
+ - `Calendar` prend `today` pour la meme raison (le serveur en UTC et le lecteur
2214
+ ne sont pas toujours le meme jour) ; `ChartPeriodPicker` a `now`.
2215
+
2216
+ **Anti-pattern** : dans une application rendue cote serveur (Next.js), laisser
2217
+ la `locale` a l'environnement. Le serveur ecrit « 1,284.5 », le navigateur
2218
+ « 1 284,5 », et le texte change a l'hydratation.
2219
+
2172
2220
  **Composants rendus cote serveur** : `Label`, `Breadcrumb` et `Avatar` n'ont
2173
2221
  aucun hook, le provider ne les atteint donc pas. Leur libelle est une prop,
2174
2222
  anglaise par defaut :
package/README.md CHANGED
@@ -269,6 +269,29 @@ import { UILabelsProvider, frenchUILabels } from "@synertech/ui";
269
269
  application spoke. They are English by default like the rest, and French
270
270
  under `frenchUILabels`.
271
271
 
272
+ #### Numbers and dates
273
+
274
+ `labels` is the language of the texts; `locale` is the way numbers and dates are
275
+ written, and the provider takes both:
276
+
277
+ ```tsx
278
+ <UILabelsProvider labels={frenchUILabels} locale="fr-CA">
279
+ <App />
280
+ </UILabelsProvider>
281
+ ```
282
+
283
+ - The charts, `Calendar`, `ChartPeriodPicker`, `NumberInput` and the footer
284
+ aggregates of `DataGrid` read it. A `locale` prop on one instance wins, and
285
+ `useUILocale()` reads it for your own components.
286
+ - Without either, they follow the language of the runtime — the server's on the
287
+ server, the reader's in the browser. **An application that renders on the
288
+ server sets `locale`**: otherwise "1,284.5" becomes "1 284,5" at hydration.
289
+ (`NumberInput` is the exception: `en-US` when nothing says otherwise.)
290
+ - `StatCard`, `ChartFacets` and `ChartScaleLegend` render on the server, where
291
+ the provider does not reach: pass them `locale` as a prop.
292
+ - `Calendar` takes a `today` for the same reason: late in the evening, a server
293
+ in UTC and its reader do not agree on the day. `ChartPeriodPicker` has `now`.
294
+
272
295
  ### Table
273
296
 
274
297
  ```tsx
@@ -1 +1 @@
1
- "use strict";"use client";var He=Object.defineProperty;var je=Object.getOwnPropertyDescriptor;var Ze=Object.getOwnPropertyNames;var qe=Object.prototype.hasOwnProperty;var Je=(h,c)=>{for(var r in c)He(h,r,{get:c[r],enumerable:!0})},Qe=(h,c,r,g)=>{if(c&&typeof c=="object"||typeof c=="function")for(let d of Ze(c))!qe.call(h,d)&&d!==r&&He(h,d,{get:()=>c[d],enumerable:!(g=je(c,d))||g.enumerable});return h};var et=h=>Qe(He({},"__esModule",{value:!0}),h);var lt={};Je(lt,{AreaChart:()=>st});module.exports=et(lt);var s=require("react"),De=require("../../lib/cn.cjs"),$e=require("../../lib/i18n.cjs"),q=require("../chart/ChartAnnotations.cjs"),Ie=require("../chart/ChartAxis.cjs"),ge=require("../chart/ChartBrush.cjs"),Ke=require("../chart/ChartContainer.cjs"),Me=require("../chart/ChartGrid.cjs"),Oe=require("../chart/ChartLegend.cjs"),fe=require("../chart/ChartPatterns.cjs"),Xe=require("../chart/ChartSync.cjs"),Ge=require("../chart/ChartTableView.cjs"),pe=require("../chart/ChartTooltip.cjs"),I=require("../chart/palette.cjs"),S=require("../chart/utils/cartesian.cjs"),Ce=require("../chart/utils/data.cjs"),be=require("../chart/utils/decimate.cjs"),N=require("../chart/utils/format.cjs"),ye=require("../chart/utils/keyboard.cjs"),L=require("../chart/utils/path.cjs"),J=require("../chart/utils/scales.cjs"),ve=require("../chart/utils/stack.cjs"),_e=require("../chart/utils/ticks.cjs"),ze=require("../chart/utils/timestamp.cjs"),Ye=require("../chart/utils/touch.cjs"),n=require("react/jsx-runtime"),tt=.12,nt=.9,rt=10,ot=(0,s.memo)(function({bands:c,stacked:r,patterns:g,patternBaseId:d}){return(0,n.jsx)("g",{children:c.map(m=>(0,n.jsxs)("g",{children:[(0,n.jsx)("path",{d:m.area,fill:(0,fe.patternFill)(g,d,m.slot,m.color),fillOpacity:r?nt:tt,stroke:"none"}),m.gap?(0,n.jsx)("path",{d:m.gap,fill:"none",strokeWidth:2,className:"stroke-white dark:stroke-gray-800"}):null,(0,n.jsx)("path",{d:m.edge,fill:"none",stroke:m.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}),m.isolated.map(C=>(0,n.jsx)("circle",{cx:C.x,cy:C.y,r:3,fill:m.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},`${C.x}-${C.y}`))]},m.key))})});function at({width:h,height:c,data:r,resolvedSeries:g,x:d,y:m,grid:C,size:Q,curve:y,stack:A,baseline:B,connectNulls:R,referenceLines:K,annotations:w,annotationsLabel:ke,patterns:ee,patternBaseId:te,overlay:xe,maxPoints:x,brush:ne,onBrush:re,brushLabel:Pe,syncEnabled:M,margin:oe,tooltip:T,onPointClick:V,plotLabel:Le,formatValue:P,formatRaw:O,formatX:W}){let[X,G]=(0,s.useState)(null),i=X!==null&&X<r.length?X:null,[Se,Ae]=(0,s.useState)(null),Be=(0,Xe.useChartSync)(),u=M?Be:null,e=(0,s.useMemo)(()=>{let t=g.filter(E=>!E.hidden),o=t.map(E=>E.key),l=A!=="none",p=(0,ve.stackSeries)(r,o,A),ue=l?(0,ve.stackExtent)(p):(0,_e.extent)([...(0,Ce.collectAllValues)(r,o),B]),b=(0,S.buildCartesianGeometry)({width:h,height:c,data:r,x:d,y:m,bounds:ue,margin:oe,placement:"point",formatValue:P,formatX:W,defaultIncludeZero:!0}),Ve=b.categoryCenters,ce=b.valueScale,Ue=ce(l?0:B),Fe=t.map((E,Ee)=>{let F=r.map((j,Z)=>{let H=p[Z].segments[Ee];return{x:Ve[Z],y:H.value===null?Number.NaN:ce(H.end),defined:H.value!==null}}),Ne=r.map((j,Z)=>{let H=p[Z].segments[Ee];return{x:Ve[Z],y:H.value===null?Number.NaN:ce(l?H.start:B),defined:H.value!==null}}),he={connectNulls:R},me=x&&x>0&&F.length>x?(0,be.decimateIndices)(F,x):null,de=me?me.map(j=>F[j]):F,We=me?me.map(j=>Ne[j]):Ne;return x||(0,be.warnPointBudget)("AreaChart",F.length),{key:E.key,color:E.color,slot:E.slot,area:l?(0,L.buildAreaPath)(de,We,y,he):(0,L.buildAreaPath)(de,Ue,y,he),edge:(0,L.buildLinePath)(de,y,he),gap:l&&Ee>0?(0,L.buildLinePath)(We,y,he):"",isolated:(0,L.isolatedPoints)(de,R)}});return{visible:t,locate:(0,S.createCategoryLocator)(b),plot:(0,S.createPlotContext)({geometry:b,width:h,height:c,data:r,series:t,formatValue:P,formatX:W}),rows:p,stacked:l,xValues:b.xValues,positions:Ve,xTicks:b.categoryTicks,yTicks:b.valueTicks,valueScale:ce,innerWidth:b.innerWidth,innerHeight:b.innerHeight,margin:b.margin,bands:Fe}},[r,g,d,m,h,c,oe,y,A,B,R,x,P,W]),_=(0,s.useCallback)(t=>e.visible.map((o,l)=>{let p=(0,Ce.readNumber)(r[t],o.key),ue=e.rows[t].segments[l],b=p===null?"\u2014":A==="percent"?`${O(p)} (${P(ue.end-ue.start)})`:P(p);return{seriesKey:o.key,seriesLabel:(0,I.getSeriesLabel)(o),color:o.color,value:p,formattedValue:b,datum:r[t]}}),[r,e.visible,e.rows,A,P,O]),ae=u?u.brush:Se,se=(0,s.useCallback)(t=>{Ae(t),u?.setBrush(t),re?.(t)},[u,re]),f=(0,ge.useChartBrush)({enabled:ne,active:ae!==null,centers:e.positions,xValues:e.xValues,offset:e.margin.left,orientation:"vertical",onCommit:se}),Re=(0,s.useCallback)(t=>{if(f.onPointerMove(t),T===!1||r.length===0)return;let o=t.currentTarget.getBoundingClientRect(),l=t.clientX-o.left-e.margin.left,p=(0,J.nearestIndex)(e.positions,l);G(p>=0?p:null),u?.setHovered(p>=0?e.xValues[p]:null)},[f,T,r.length,e.margin.left,e.positions,e.xValues,u]),le=(0,s.useCallback)(()=>{G(null),u?.setHovered(null)},[u]),v=(0,s.useCallback)(()=>{if(!V||i===null)return;let[t]=_(i);t&&V({...t,index:i,x:e.xValues[i]})},[V,i,_,e.xValues]),D=(0,s.useCallback)(t=>{if(r.length===0)return;let o=V&&i!==null&&e.visible.length>0;if((0,ye.pressChartMark)(t,o?v:null))return;f.onKeyDown(t,i);let l=(0,ye.chartCursorTarget)(t.key,i,r.length,"x");l!==void 0&&(t.preventDefault(),G(l),u?.setHovered(l===null?null:e.xValues[l]))},[r.length,i,f,u,e.xValues,e.visible.length,V,v]),we=(0,s.useCallback)(()=>{f.consumedClick()||v()},[f,v]),Te=i!==null||!u?.hovered?null:(()=>{let t=(0,J.toKey)(u.hovered),o=e.xValues.findIndex(l=>(0,J.toKey)(l)===t);return o<0?null:o})(),k=i??Te,z=i===null?null:_(i),Y=k===null?[]:e.visible.map((t,o)=>{let l=e.rows[k].segments[o];return l.value===null?null:{key:t.key,color:t.color,y:e.valueScale(l.end)}}).filter(t=>t!==null),U=f.dragging??ae,$=(()=>{if(!U)return null;let t=e.locate(U.from),o=e.locate(U.to);return t===null||o===null?null:{from:t,to:o}})(),ie=(0,S.splitOverlay)(xe),a=i===null||z===null?null:{x:e.xValues[i],xLabel:W(e.xValues[i],i),index:i,points:z};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("svg",{width:h,height:c,role:"img","aria-label":Le??[e.visible.map(t=>(0,I.getSeriesLabel)(t)).join(", "),(0,q.describeAnnotations)(w,ke)].filter(Boolean).join(". "),tabIndex:0,className:(0,De.cn)(Ye.CHART_TOUCH,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500",ne&&"select-none"),onPointerDown:f.onPointerDown,onPointerMove:Re,onPointerUp:f.onPointerUp,onPointerCancel:f.onPointerUp,onPointerLeave:le,onKeyDown:D,onBlur:le,onClick:we,children:[ee?(0,n.jsx)(fe.ChartPatternDefs,{id:te,entries:g.map(t=>({slot:t.slot,color:t.color}))}):null,(0,n.jsxs)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[(0,n.jsx)(Me.ChartGrid,{width:e.innerWidth,height:e.innerHeight,horizontal:C==="y"||C==="both"?e.yTicks.map(t=>t.offset):void 0,vertical:C==="x"||C==="both"?e.xTicks.map(t=>t.offset):void 0}),w?(0,n.jsx)(q.ChartAnnotationLayer,{layer:"under",annotations:w,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight}):null,$?(0,n.jsx)(ge.ChartBrushLayer,{from:$.from,to:$.to,width:e.innerWidth,height:e.innerHeight,live:f.dragging!==null,label:Pe}):null,ie.under?.(e.plot),(0,n.jsx)(ot,{bands:e.bands,stacked:e.stacked,patterns:ee&&e.stacked,patternBaseId:te}),w?(0,n.jsx)(q.ChartAnnotationLayer,{annotations:w,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight}):null,K?.map(t=>{let o=e.valueScale(t.value),l=o<rt?o+12:o-4;return(0,n.jsxs)("g",{children:[(0,n.jsx)("line",{x1:0,y1:o,x2:e.innerWidth,y2:o,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:l,textAnchor:"end",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)}),ie.over?.(e.plot),k!==null?(0,n.jsxs)("g",{"aria-hidden":"true",children:[(0,n.jsx)("line",{x1:e.positions[k],y1:0,x2:e.positions[k],y2:e.innerHeight,className:"stroke-gray-400 dark:stroke-gray-500",strokeWidth:1,strokeDasharray:i===null?"3 3":void 0}),Y.map(t=>(0,n.jsx)("circle",{cx:e.positions[k],cy:t.y,r:4,fill:t.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},t.key))]}):null]}),(0,n.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:d.hidden?null:(0,n.jsx)(Ie.ChartAxis,{orientation:"bottom",ticks:e.xTicks,length:e.innerWidth,label:d.label,size:Q})}),(0,n.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:m?.hidden?null:(0,n.jsx)(Ie.ChartAxis,{orientation:"left",ticks:e.yTicks,length:e.innerHeight,showLine:!1,label:m?.label,size:Q})})]}),a&&T!==!1?(0,n.jsx)(pe.ChartTooltip,{x:e.margin.left+e.positions[a.index],y:e.margin.top+(Y.length>0?Math.min(...Y.map(t=>t.y)):e.innerHeight/2),containerWidth:h,children:typeof T=="function"?T(a):(0,n.jsx)(pe.ChartTooltipContent,{title:a.xLabel,points:a.points})}):null]})}function st({data:h,series:c,x:r,y:g,height:d=240,width:m,size:C="md",grid:Q="y",legend:y,tooltip:A=!0,tableView:B=!1,emphasis:R,title:K,description:w,loading:ke=!1,emptyState:ee,error:te=!1,errorState:xe,onRetry:x,actions:ne,onPointClick:re,curve:Pe="monotone",stack:M="none",baseline:oe=0,connectNulls:T=!1,referenceLines:V,annotations:Le,overlay:P,patterns:O=!1,legendToggle:W=!0,maxPoints:X,brush:G=!1,onBrush:i,brushLabel:Se,sync:Ae=!0,margin:Be,locale:u,plotLabel:e,className:_,...ae}){let se=(0,$e.useUILabels)(),[f,Re]=(0,s.useState)(()=>new Set),le=(0,s.useId)(),v=(0,s.useMemo)(()=>c.map((a,t)=>({...a,slot:t,hidden:a.hidden||f.has(a.key),color:(0,I.resolveSeriesColor)(a,t,R)})),[c,f,R]),D=M==="percent",we=(0,s.useMemo)(()=>D?{domain:[0,100],...g}:g,[D,g]),Te=(0,s.useMemo)(()=>g?.format??(D?a=>(0,N.formatPercent)(a,{locale:u,alreadyScaled:!0,maximumFractionDigits:0}):a=>(0,N.formatAuto)(a,u)),[g?.format,D,u]),k=(0,s.useMemo)(()=>a=>(0,N.formatAuto)(a,u),[u]),z=(0,s.useMemo)(()=>r.format??(a=>r.scale==="time"?(0,ze.formatTimeValue)(a,u):(0,N.formatXValue)(a,u)),[r.format,r.scale,u]),Y=(0,s.useCallback)(a=>{Re(t=>{let o=new Set(t);return o.has(a)?o.delete(a):o.add(a),o})},[]),U=y===void 0?c.length>=2:y!==!1,$=typeof y=="string"?y:"bottom",ie=v.filter(a=>!a.hidden).length;return(0,n.jsx)(Ke.ChartContainer,{title:K,description:w,height:d,width:m,size:C,loading:ke,empty:h.length===0||ie===0,emptyState:ee,error:te,errorState:xe,onRetry:x,actions:ne,tableView:B,legendPosition:$,legend:U?(0,n.jsx)(Oe.ChartLegend,{items:(0,I.toLegendItems)(v,R,O&&M!=="none"),position:$,marker:"rect",size:C,onToggle:W?Y:void 0}):void 0,table:B?(0,n.jsx)(Ge.ChartTableView,{data:h,series:v,xKey:r.key,xLabel:r.label??r.key,formatX:z,formatValue:k,caption:typeof K=="string"?K:void 0}):void 0,className:_,...ae,children:({width:a})=>(0,n.jsx)(at,{width:a,height:d,data:h,resolvedSeries:v,x:r,y:we,grid:Q,size:C,curve:Pe,stack:M,baseline:oe,connectNulls:T,referenceLines:V,annotations:Le,annotationsLabel:se.chartAnnotations,patterns:O,patternBaseId:le,overlay:P,maxPoints:X,brush:G,onBrush:i,brushLabel:Se??se.chartBrush,syncEnabled:Ae,margin:Be,tooltip:A,onPointClick:re,plotLabel:e,formatValue:Te,formatRaw:k,formatX:z})})}0&&(module.exports={AreaChart});
1
+ "use strict";"use client";var He=Object.defineProperty;var je=Object.getOwnPropertyDescriptor;var Ze=Object.getOwnPropertyNames;var qe=Object.prototype.hasOwnProperty;var Je=(u,i)=>{for(var r in i)He(u,r,{get:i[r],enumerable:!0})},Qe=(u,i,r,m)=>{if(i&&typeof i=="object"||typeof i=="function")for(let h of Ze(i))!qe.call(u,h)&&h!==r&&He(u,h,{get:()=>i[h],enumerable:!(m=je(i,h))||m.enumerable});return u};var et=u=>Qe(He({},"__esModule",{value:!0}),u);var st={};Je(st,{AreaChart:()=>lt});module.exports=et(st);var l=require("react"),$e=require("../../lib/cn.cjs"),pe=require("../../lib/i18n.cjs"),ee=require("../chart/ChartAnnotations.cjs"),Ne=require("../chart/ChartAxis.cjs"),Ce=require("../chart/ChartBrush.cjs"),Ke=require("../chart/ChartContainer.cjs"),Me=require("../chart/ChartGrid.cjs"),Oe=require("../chart/ChartLegend.cjs"),be=require("../chart/ChartPatterns.cjs"),Xe=require("../chart/ChartSync.cjs"),Ge=require("../chart/ChartTableView.cjs"),ye=require("../chart/ChartTooltip.cjs"),H=require("../chart/palette.cjs"),L=require("../chart/utils/cartesian.cjs"),ve=require("../chart/utils/data.cjs"),ke=require("../chart/utils/decimate.cjs"),N=require("../chart/utils/format.cjs"),xe=require("../chart/utils/keyboard.cjs"),P=require("../chart/utils/path.cjs"),te=require("../chart/utils/scales.cjs"),Pe=require("../chart/utils/stack.cjs"),_e=require("../chart/utils/ticks.cjs"),ze=require("../chart/utils/timestamp.cjs"),Ue=require("../chart/utils/touch.cjs"),n=require("react/jsx-runtime"),tt=.12,nt=.9,rt=10,ot=(0,l.memo)(function({bands:i,stacked:r,patterns:m,patternBaseId:h}){return(0,n.jsx)("g",{children:i.map(c=>(0,n.jsxs)("g",{children:[(0,n.jsx)("path",{d:c.area,fill:(0,be.patternFill)(m,h,c.slot,c.color),fillOpacity:r?nt:tt,stroke:"none"}),c.gap?(0,n.jsx)("path",{d:c.gap,fill:"none",strokeWidth:2,className:"stroke-white dark:stroke-gray-800"}):null,(0,n.jsx)("path",{d:c.edge,fill:"none",stroke:c.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}),c.isolated.map(p=>(0,n.jsx)("circle",{cx:p.x,cy:p.y,r:3,fill:c.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},`${p.x}-${p.y}`))]},c.key))})});function at({width:u,height:i,data:r,resolvedSeries:m,x:h,y:c,grid:p,size:ne,curve:b,stack:S,baseline:A,connectNulls:B,referenceLines:O,annotations:R,annotationsLabel:Le,patterns:re,patternBaseId:oe,overlay:Se,maxPoints:v,brush:ae,onBrush:le,brushLabel:Ae,syncEnabled:X,margin:se,tooltip:w,onPointClick:T,plotLabel:Be,formatValue:k,formatRaw:G,formatX:W}){let[_,z]=(0,l.useState)(null),s=_!==null&&_<r.length?_:null,[Re,we]=(0,l.useState)(null),Te=(0,Xe.useChartSync)(),d=X?Te:null,t=(0,l.useMemo)(()=>{let e=m.filter(E=>!E.hidden),o=e.map(E=>E.key),a=S!=="none",f=(0,Pe.stackSeries)(r,o,S),he=a?(0,Pe.stackExtent)(f):(0,_e.extent)([...(0,ve.collectAllValues)(r,o),A]),C=(0,L.buildCartesianGeometry)({width:u,height:i,data:r,x:h,y:c,bounds:he,margin:se,placement:"point",formatValue:k,formatX:W,defaultIncludeZero:!0}),Ee=C.categoryCenters,me=C.valueScale,Ye=me(a?0:A),Fe=e.map((E,Ie)=>{let q=r.map((J,Q)=>{let I=f[Q].segments[Ie];return{x:Ee[Q],y:I.value===null?Number.NaN:me(I.end),defined:I.value!==null}}),We=r.map((J,Q)=>{let I=f[Q].segments[Ie];return{x:Ee[Q],y:I.value===null?Number.NaN:me(a?I.start:A),defined:I.value!==null}}),de={connectNulls:B},ge=v&&v>0&&q.length>v?(0,ke.decimateIndices)(q,v):null,fe=ge?ge.map(J=>q[J]):q,De=ge?ge.map(J=>We[J]):We;return v||(0,ke.warnPointBudget)("AreaChart",q.length),{key:E.key,color:E.color,slot:E.slot,area:a?(0,P.buildAreaPath)(fe,De,b,de):(0,P.buildAreaPath)(fe,Ye,b,de),edge:(0,P.buildLinePath)(fe,b,de),gap:a&&Ie>0?(0,P.buildLinePath)(De,b,de):"",isolated:(0,P.isolatedPoints)(fe,B)}});return{visible:e,locate:(0,L.createCategoryLocator)(C),plot:(0,L.createPlotContext)({geometry:C,width:u,height:i,data:r,series:e,formatValue:k,formatX:W}),rows:f,stacked:a,xValues:C.xValues,positions:Ee,xTicks:C.categoryTicks,yTicks:C.valueTicks,valueScale:me,innerWidth:C.innerWidth,innerHeight:C.innerHeight,margin:C.margin,bands:Fe}},[r,m,h,c,u,i,se,b,S,A,B,v,k,W]),U=(0,l.useCallback)(e=>t.visible.map((o,a)=>{let f=(0,ve.readNumber)(r[e],o.key),he=t.rows[e].segments[a],C=f===null?"\u2014":S==="percent"?`${G(f)} (${k(he.end-he.start)})`:k(f);return{seriesKey:o.key,seriesLabel:(0,H.getSeriesLabel)(o),color:o.color,value:f,formattedValue:C,datum:r[e]}}),[r,t.visible,t.rows,S,k,G]),ie=d?d.brush:Re,y=(0,l.useCallback)(e=>{we(e),d?.setBrush(e),le?.(e)},[d,le]),g=(0,Ce.useChartBrush)({enabled:ae,active:ie!==null,centers:t.positions,xValues:t.xValues,offset:t.margin.left,orientation:"vertical",onCommit:y}),ue=(0,l.useCallback)(e=>{if(g.onPointerMove(e),w===!1||r.length===0)return;let o=e.currentTarget.getBoundingClientRect(),a=e.clientX-o.left-t.margin.left,f=(0,te.nearestIndex)(t.positions,a);z(f>=0?f:null),d?.setHovered(f>=0?t.xValues[f]:null)},[g,w,r.length,t.margin.left,t.positions,t.xValues,d]),ce=(0,l.useCallback)(()=>{z(null),d?.setHovered(null)},[d]),D=(0,l.useCallback)(()=>{if(!T||s===null)return;let[e]=U(s);e&&T({...e,index:s,x:t.xValues[s]})},[T,s,U,t.xValues]),$=(0,l.useCallback)(e=>{if(r.length===0)return;let o=T&&s!==null&&t.visible.length>0;if((0,xe.pressChartMark)(e,o?D:null))return;g.onKeyDown(e,s);let a=(0,xe.chartCursorTarget)(e.key,s,r.length,"x");a!==void 0&&(e.preventDefault(),z(a),d?.setHovered(a===null?null:t.xValues[a]))},[r.length,s,g,d,t.xValues,t.visible.length,T,D]),K=(0,l.useCallback)(()=>{g.consumedClick()||D()},[g,D]),Ve=s!==null||!d?.hovered?null:(()=>{let e=(0,te.toKey)(d.hovered),o=t.xValues.findIndex(a=>(0,te.toKey)(a)===e);return o<0?null:o})(),x=s??Ve,Y=s===null?null:U(s),M=x===null?[]:t.visible.map((e,o)=>{let a=t.rows[x].segments[o];return a.value===null?null:{key:e.key,color:e.color,y:t.valueScale(a.end)}}).filter(e=>e!==null),F=g.dragging??ie,j=(()=>{if(!F)return null;let e=t.locate(F.from),o=t.locate(F.to);return e===null||o===null?null:{from:e,to:o}})(),Z=(0,L.splitOverlay)(Se),V=s===null||Y===null?null:{x:t.xValues[s],xLabel:W(t.xValues[s],s),index:s,points:Y};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("svg",{width:u,height:i,role:"img","aria-label":Be??[t.visible.map(e=>(0,H.getSeriesLabel)(e)).join(", "),(0,ee.describeAnnotations)(R,Le)].filter(Boolean).join(". "),tabIndex:0,className:(0,$e.cn)(Ue.CHART_TOUCH,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500",ae&&"select-none"),onPointerDown:g.onPointerDown,onPointerMove:ue,onPointerUp:g.onPointerUp,onPointerCancel:g.onPointerUp,onPointerLeave:ce,onKeyDown:$,onBlur:ce,onClick:K,children:[re?(0,n.jsx)(be.ChartPatternDefs,{id:oe,entries:m.map(e=>({slot:e.slot,color:e.color}))}):null,(0,n.jsxs)("g",{transform:`translate(${t.margin.left}, ${t.margin.top})`,children:[(0,n.jsx)(Me.ChartGrid,{width:t.innerWidth,height:t.innerHeight,horizontal:p==="y"||p==="both"?t.yTicks.map(e=>e.offset):void 0,vertical:p==="x"||p==="both"?t.xTicks.map(e=>e.offset):void 0}),R?(0,n.jsx)(ee.ChartAnnotationLayer,{layer:"under",annotations:R,xAt:t.locate,yAt:t.valueScale,width:t.innerWidth,height:t.innerHeight}):null,j?(0,n.jsx)(Ce.ChartBrushLayer,{from:j.from,to:j.to,width:t.innerWidth,height:t.innerHeight,live:g.dragging!==null,label:Ae}):null,Z.under?.(t.plot),(0,n.jsx)(ot,{bands:t.bands,stacked:t.stacked,patterns:re&&t.stacked,patternBaseId:oe}),R?(0,n.jsx)(ee.ChartAnnotationLayer,{annotations:R,xAt:t.locate,yAt:t.valueScale,width:t.innerWidth,height:t.innerHeight}):null,O?.map(e=>{let o=t.valueScale(e.value),a=o<rt?o+12:o-4;return(0,n.jsxs)("g",{children:[(0,n.jsx)("line",{x1:0,y1:o,x2:t.innerWidth,y2:o,stroke:e.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:e.dashed===!1?void 0:"4 4"}),e.label?(0,n.jsx)("text",{x:t.innerWidth,y:a,textAnchor:"end",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:e.label}):null]},`${e.value}-${e.label??""}`)}),Z.over?.(t.plot),x!==null?(0,n.jsxs)("g",{"aria-hidden":"true",children:[(0,n.jsx)("line",{x1:t.positions[x],y1:0,x2:t.positions[x],y2:t.innerHeight,className:"stroke-gray-400 dark:stroke-gray-500",strokeWidth:1,strokeDasharray:s===null?"3 3":void 0}),M.map(e=>(0,n.jsx)("circle",{cx:t.positions[x],cy:e.y,r:4,fill:e.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},e.key))]}):null]}),(0,n.jsx)("g",{transform:`translate(${t.margin.left}, ${t.margin.top+t.innerHeight})`,children:h.hidden?null:(0,n.jsx)(Ne.ChartAxis,{orientation:"bottom",ticks:t.xTicks,length:t.innerWidth,label:h.label,size:ne})}),(0,n.jsx)("g",{transform:`translate(${t.margin.left}, ${t.margin.top})`,children:c?.hidden?null:(0,n.jsx)(Ne.ChartAxis,{orientation:"left",ticks:t.yTicks,length:t.innerHeight,showLine:!1,label:c?.label,size:ne})})]}),V&&w!==!1?(0,n.jsx)(ye.ChartTooltip,{x:t.margin.left+t.positions[V.index],y:t.margin.top+(M.length>0?Math.min(...M.map(e=>e.y)):t.innerHeight/2),containerWidth:u,children:typeof w=="function"?w(V):(0,n.jsx)(ye.ChartTooltipContent,{title:V.xLabel,points:V.points})}):null]})}function lt({data:u,series:i,x:r,y:m,height:h=240,width:c,size:p="md",grid:ne="y",legend:b,tooltip:S=!0,tableView:A=!1,emphasis:B,title:O,description:R,loading:Le=!1,emptyState:re,error:oe=!1,errorState:Se,onRetry:v,actions:ae,onPointClick:le,curve:Ae="monotone",stack:X="none",baseline:se=0,connectNulls:w=!1,referenceLines:T,annotations:Be,overlay:k,patterns:G=!1,legendToggle:W=!0,maxPoints:_,brush:z=!1,onBrush:s,brushLabel:Re,sync:we=!0,margin:Te,locale:d,plotLabel:t,className:U,...ie}){let y=(0,pe.useUILocale)(d),g=(0,pe.useUILabels)(),[ue,ce]=(0,l.useState)(()=>new Set),D=(0,l.useId)(),$=(0,l.useMemo)(()=>i.map((e,o)=>({...e,slot:o,hidden:e.hidden||ue.has(e.key),color:(0,H.resolveSeriesColor)(e,o,B)})),[i,ue,B]),K=X==="percent",Ve=(0,l.useMemo)(()=>K?{domain:[0,100],...m}:m,[K,m]),x=(0,l.useMemo)(()=>m?.format??(K?e=>(0,N.formatPercent)(e,{locale:y,alreadyScaled:!0,maximumFractionDigits:0}):e=>(0,N.formatAuto)(e,y)),[m?.format,K,y]),Y=(0,l.useMemo)(()=>e=>(0,N.formatAuto)(e,y),[y]),M=(0,l.useMemo)(()=>r.format??(e=>r.scale==="time"?(0,ze.formatTimeValue)(e,y):(0,N.formatXValue)(e,y)),[r.format,r.scale,y]),F=(0,l.useCallback)(e=>{ce(o=>{let a=new Set(o);return a.has(e)?a.delete(e):a.add(e),a})},[]),j=b===void 0?i.length>=2:b!==!1,Z=typeof b=="string"?b:"bottom",V=$.filter(e=>!e.hidden).length;return(0,n.jsx)(Ke.ChartContainer,{title:O,description:R,height:h,width:c,size:p,loading:Le,empty:u.length===0||V===0,emptyState:re,error:oe,errorState:Se,onRetry:v,actions:ae,tableView:A,legendPosition:Z,legend:j?(0,n.jsx)(Oe.ChartLegend,{items:(0,H.toLegendItems)($,B,G&&X!=="none"),position:Z,marker:"rect",size:p,onToggle:W?F:void 0}):void 0,table:A?(0,n.jsx)(Ge.ChartTableView,{data:u,series:$,xKey:r.key,xLabel:r.label??r.key,formatX:M,formatValue:Y,caption:typeof O=="string"?O:void 0}):void 0,className:U,...ie,children:({width:e})=>(0,n.jsx)(at,{width:e,height:h,data:u,resolvedSeries:$,x:r,y:Ve,grid:ne,size:p,curve:Ae,stack:X,baseline:se,connectNulls:w,referenceLines:T,annotations:Be,annotationsLabel:g.chartAnnotations,patterns:G,patternBaseId:D,overlay:k,maxPoints:_,brush:z,onBrush:s,brushLabel:Re??g.chartBrush,syncEnabled:we,margin:Te,tooltip:S,onPointClick:le,plotLabel:t,formatValue:x,formatRaw:Y,formatX:M})})}0&&(module.exports={AreaChart});
@@ -1 +1 @@
1
- "use client";import{memo as Ie,useCallback as P,useId as Ne,useMemo as N,useState as xe}from"react";import{cn as We}from"../../lib/cn.js";import{useUILabels as De}from"../../lib/i18n.js";import{ChartAnnotationLayer as Se,describeAnnotations as $e}from"../chart/ChartAnnotations.js";import{ChartAxis as Ae}from"../chart/ChartAxis.js";import{ChartBrushLayer as Ke,useChartBrush as Me}from"../chart/ChartBrush.js";import{ChartContainer as Oe}from"../chart/ChartContainer.js";import{ChartGrid as Xe}from"../chart/ChartGrid.js";import{ChartLegend as Ge}from"../chart/ChartLegend.js";import{ChartPatternDefs as _e,patternFill as ze}from"../chart/ChartPatterns.js";import{useChartSync as Ye}from"../chart/ChartSync.js";import{ChartTableView as Ue}from"../chart/ChartTableView.js";import{ChartTooltip as Fe,ChartTooltipContent as je}from"../chart/ChartTooltip.js";import{getSeriesLabel as Be,resolveSeriesColor as Ze,toLegendItems as qe}from"../chart/palette.js";import{buildCartesianGeometry as Je,createCategoryLocator as Qe,createPlotContext as et,splitOverlay as tt}from"../chart/utils/cartesian.js";import{collectAllValues as nt,readNumber as rt}from"../chart/utils/data.js";import{decimateIndices as ot,warnPointBudget as at}from"../chart/utils/decimate.js";import{formatAuto as Re,formatPercent as st,formatXValue as lt}from"../chart/utils/format.js";import{chartCursorTarget as it,pressChartMark as ut}from"../chart/utils/keyboard.js";import{buildAreaPath as we,buildLinePath as Te,isolatedPoints as ct}from"../chart/utils/path.js";import{nearestIndex as ht,toKey as Ve}from"../chart/utils/scales.js";import{stackExtent as mt,stackSeries as dt}from"../chart/utils/stack.js";import{extent as gt}from"../chart/utils/ticks.js";import{formatTimeValue as ft}from"../chart/utils/timestamp.js";import{CHART_TOUCH as pt}from"../chart/utils/touch.js";import{Fragment as xt,jsx as a,jsxs as W}from"react/jsx-runtime";var Ct=.12,bt=.9,yt=10,vt=Ie(function({bands:p,stacked:r,patterns:g,patternBaseId:b}){return a("g",{children:p.map(u=>W("g",{children:[a("path",{d:u.area,fill:ze(g,b,u.slot,u.color),fillOpacity:r?bt:Ct,stroke:"none"}),u.gap?a("path",{d:u.gap,fill:"none",strokeWidth:2,className:"stroke-white dark:stroke-gray-800"}):null,a("path",{d:u.edge,fill:"none",stroke:u.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}),u.isolated.map(m=>a("circle",{cx:m.x,cy:m.y,r:3,fill:u.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},`${m.x}-${m.y}`))]},u.key))})});function kt({width:f,height:p,data:r,resolvedSeries:g,x:b,y:u,grid:m,size:j,curve:C,stack:L,baseline:S,connectNulls:A,referenceLines:D,annotations:B,annotationsLabel:ce,patterns:Z,patternBaseId:q,overlay:he,maxPoints:k,brush:J,onBrush:Q,brushLabel:me,syncEnabled:$,margin:ee,tooltip:R,onPointClick:w,plotLabel:de,formatValue:x,formatRaw:K,formatX:E}){let[M,O]=xe(null),l=M!==null&&M<r.length?M:null,[ge,fe]=xe(null),pe=Ye(),i=$?pe:null,e=N(()=>{let t=g.filter(T=>!T.hidden),n=t.map(T=>T.key),s=L!=="none",h=dt(r,n,L),ae=s?mt(h):gt([...nt(r,n),S]),d=Je({width:f,height:p,data:r,x:b,y:u,bounds:ae,margin:ee,placement:"point",formatValue:x,formatX:E,defaultIncludeZero:!0}),ve=d.categoryCenters,se=d.valueScale,Ee=se(s?0:S),He=t.map((T,ke)=>{let Y=r.map((U,F)=>{let V=h[F].segments[ke];return{x:ve[F],y:V.value===null?Number.NaN:se(V.end),defined:V.value!==null}}),Pe=r.map((U,F)=>{let V=h[F].segments[ke];return{x:ve[F],y:V.value===null?Number.NaN:se(s?V.start:S),defined:V.value!==null}}),le={connectNulls:A},ie=k&&k>0&&Y.length>k?ot(Y,k):null,ue=ie?ie.map(U=>Y[U]):Y,Le=ie?ie.map(U=>Pe[U]):Pe;return k||at("AreaChart",Y.length),{key:T.key,color:T.color,slot:T.slot,area:s?we(ue,Le,C,le):we(ue,Ee,C,le),edge:Te(ue,C,le),gap:s&&ke>0?Te(Le,C,le):"",isolated:ct(ue,A)}});return{visible:t,locate:Qe(d),plot:et({geometry:d,width:f,height:p,data:r,series:t,formatValue:x,formatX:E}),rows:h,stacked:s,xValues:d.xValues,positions:ve,xTicks:d.categoryTicks,yTicks:d.valueTicks,valueScale:se,innerWidth:d.innerWidth,innerHeight:d.innerHeight,margin:d.margin,bands:He}},[r,g,b,u,f,p,ee,C,L,S,A,k,x,E]),X=P(t=>e.visible.map((n,s)=>{let h=rt(r[t],n.key),ae=e.rows[t].segments[s],d=h===null?"\u2014":L==="percent"?`${K(h)} (${x(ae.end-ae.start)})`:x(h);return{seriesKey:n.key,seriesLabel:Be(n),color:n.color,value:h,formattedValue:d,datum:r[t]}}),[r,e.visible,e.rows,L,x,K]),te=i?i.brush:ge,ne=P(t=>{fe(t),i?.setBrush(t),Q?.(t)},[i,Q]),c=Me({enabled:J,active:te!==null,centers:e.positions,xValues:e.xValues,offset:e.margin.left,orientation:"vertical",onCommit:ne}),Ce=P(t=>{if(c.onPointerMove(t),R===!1||r.length===0)return;let n=t.currentTarget.getBoundingClientRect(),s=t.clientX-n.left-e.margin.left,h=ht(e.positions,s);O(h>=0?h:null),i?.setHovered(h>=0?e.xValues[h]:null)},[c,R,r.length,e.margin.left,e.positions,e.xValues,i]),re=P(()=>{O(null),i?.setHovered(null)},[i]),y=P(()=>{if(!w||l===null)return;let[t]=X(l);t&&w({...t,index:l,x:e.xValues[l]})},[w,l,X,e.xValues]),H=P(t=>{if(r.length===0)return;let n=w&&l!==null&&e.visible.length>0;if(ut(t,n?y:null))return;c.onKeyDown(t,l);let s=it(t.key,l,r.length,"x");s!==void 0&&(t.preventDefault(),O(s),i?.setHovered(s===null?null:e.xValues[s]))},[r.length,l,c,i,e.xValues,e.visible.length,w,y]),be=P(()=>{c.consumedClick()||y()},[c,y]),ye=l!==null||!i?.hovered?null:(()=>{let t=Ve(i.hovered),n=e.xValues.findIndex(s=>Ve(s)===t);return n<0?null:n})(),v=l??ye,G=l===null?null:X(l),_=v===null?[]:e.visible.map((t,n)=>{let s=e.rows[v].segments[n];return s.value===null?null:{key:t.key,color:t.color,y:e.valueScale(s.end)}}).filter(t=>t!==null),z=c.dragging??te,I=(()=>{if(!z)return null;let t=e.locate(z.from),n=e.locate(z.to);return t===null||n===null?null:{from:t,to:n}})(),oe=tt(he),o=l===null||G===null?null:{x:e.xValues[l],xLabel:E(e.xValues[l],l),index:l,points:G};return W(xt,{children:[W("svg",{width:f,height:p,role:"img","aria-label":de??[e.visible.map(t=>Be(t)).join(", "),$e(B,ce)].filter(Boolean).join(". "),tabIndex:0,className:We(pt,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500",J&&"select-none"),onPointerDown:c.onPointerDown,onPointerMove:Ce,onPointerUp:c.onPointerUp,onPointerCancel:c.onPointerUp,onPointerLeave:re,onKeyDown:H,onBlur:re,onClick:be,children:[Z?a(_e,{id:q,entries:g.map(t=>({slot:t.slot,color:t.color}))}):null,W("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[a(Xe,{width:e.innerWidth,height:e.innerHeight,horizontal:m==="y"||m==="both"?e.yTicks.map(t=>t.offset):void 0,vertical:m==="x"||m==="both"?e.xTicks.map(t=>t.offset):void 0}),B?a(Se,{layer:"under",annotations:B,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight}):null,I?a(Ke,{from:I.from,to:I.to,width:e.innerWidth,height:e.innerHeight,live:c.dragging!==null,label:me}):null,oe.under?.(e.plot),a(vt,{bands:e.bands,stacked:e.stacked,patterns:Z&&e.stacked,patternBaseId:q}),B?a(Se,{annotations:B,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight}):null,D?.map(t=>{let n=e.valueScale(t.value),s=n<yt?n+12:n-4;return W("g",{children:[a("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?a("text",{x:e.innerWidth,y:s,textAnchor:"end",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)}),oe.over?.(e.plot),v!==null?W("g",{"aria-hidden":"true",children:[a("line",{x1:e.positions[v],y1:0,x2:e.positions[v],y2:e.innerHeight,className:"stroke-gray-400 dark:stroke-gray-500",strokeWidth:1,strokeDasharray:l===null?"3 3":void 0}),_.map(t=>a("circle",{cx:e.positions[v],cy:t.y,r:4,fill:t.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},t.key))]}):null]}),a("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:b.hidden?null:a(Ae,{orientation:"bottom",ticks:e.xTicks,length:e.innerWidth,label:b.label,size:j})}),a("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:u?.hidden?null:a(Ae,{orientation:"left",ticks:e.yTicks,length:e.innerHeight,showLine:!1,label:u?.label,size:j})})]}),o&&R!==!1?a(Fe,{x:e.margin.left+e.positions[o.index],y:e.margin.top+(_.length>0?Math.min(..._.map(t=>t.y)):e.innerHeight/2),containerWidth:f,children:typeof R=="function"?R(o):a(je,{title:o.xLabel,points:o.points})}):null]})}function Ft({data:f,series:p,x:r,y:g,height:b=240,width:u,size:m="md",grid:j="y",legend:C,tooltip:L=!0,tableView:S=!1,emphasis:A,title:D,description:B,loading:ce=!1,emptyState:Z,error:q=!1,errorState:he,onRetry:k,actions:J,onPointClick:Q,curve:me="monotone",stack:$="none",baseline:ee=0,connectNulls:R=!1,referenceLines:w,annotations:de,overlay:x,patterns:K=!1,legendToggle:E=!0,maxPoints:M,brush:O=!1,onBrush:l,brushLabel:ge,sync:fe=!0,margin:pe,locale:i,plotLabel:e,className:X,...te}){let ne=De(),[c,Ce]=xe(()=>new Set),re=Ne(),y=N(()=>p.map((o,t)=>({...o,slot:t,hidden:o.hidden||c.has(o.key),color:Ze(o,t,A)})),[p,c,A]),H=$==="percent",be=N(()=>H?{domain:[0,100],...g}:g,[H,g]),ye=N(()=>g?.format??(H?o=>st(o,{locale:i,alreadyScaled:!0,maximumFractionDigits:0}):o=>Re(o,i)),[g?.format,H,i]),v=N(()=>o=>Re(o,i),[i]),G=N(()=>r.format??(o=>r.scale==="time"?ft(o,i):lt(o,i)),[r.format,r.scale,i]),_=P(o=>{Ce(t=>{let n=new Set(t);return n.has(o)?n.delete(o):n.add(o),n})},[]),z=C===void 0?p.length>=2:C!==!1,I=typeof C=="string"?C:"bottom",oe=y.filter(o=>!o.hidden).length;return a(Oe,{title:D,description:B,height:b,width:u,size:m,loading:ce,empty:f.length===0||oe===0,emptyState:Z,error:q,errorState:he,onRetry:k,actions:J,tableView:S,legendPosition:I,legend:z?a(Ge,{items:qe(y,A,K&&$!=="none"),position:I,marker:"rect",size:m,onToggle:E?_:void 0}):void 0,table:S?a(Ue,{data:f,series:y,xKey:r.key,xLabel:r.label??r.key,formatX:G,formatValue:v,caption:typeof D=="string"?D:void 0}):void 0,className:X,...te,children:({width:o})=>a(kt,{width:o,height:b,data:f,resolvedSeries:y,x:r,y:be,grid:j,size:m,curve:me,stack:$,baseline:ee,connectNulls:R,referenceLines:w,annotations:de,annotationsLabel:ne.chartAnnotations,patterns:K,patternBaseId:re,overlay:x,maxPoints:M,brush:O,onBrush:l,brushLabel:ge??ne.chartBrush,syncEnabled:fe,margin:pe,tooltip:L,onPointClick:Q,plotLabel:e,formatValue:ye,formatRaw:v,formatX:G})})}export{Ft as AreaChart};
1
+ "use client";import{memo as He,useCallback as x,useId as Ne,useMemo as D,useState as xe}from"react";import{cn as We}from"../../lib/cn.js";import{useUILabels as De,useUILocale as $e}from"../../lib/i18n.js";import{ChartAnnotationLayer as Se,describeAnnotations as Ke}from"../chart/ChartAnnotations.js";import{ChartAxis as Ae}from"../chart/ChartAxis.js";import{ChartBrushLayer as Me,useChartBrush as Oe}from"../chart/ChartBrush.js";import{ChartContainer as Xe}from"../chart/ChartContainer.js";import{ChartGrid as Ge}from"../chart/ChartGrid.js";import{ChartLegend as _e}from"../chart/ChartLegend.js";import{ChartPatternDefs as ze,patternFill as Ue}from"../chart/ChartPatterns.js";import{useChartSync as Ye}from"../chart/ChartSync.js";import{ChartTableView as Fe}from"../chart/ChartTableView.js";import{ChartTooltip as je,ChartTooltipContent as Ze}from"../chart/ChartTooltip.js";import{getSeriesLabel as Be,resolveSeriesColor as qe,toLegendItems as Je}from"../chart/palette.js";import{buildCartesianGeometry as Qe,createCategoryLocator as et,createPlotContext as tt,splitOverlay as nt}from"../chart/utils/cartesian.js";import{collectAllValues as rt,readNumber as ot}from"../chart/utils/data.js";import{decimateIndices as at,warnPointBudget as lt}from"../chart/utils/decimate.js";import{formatAuto as Re,formatPercent as st,formatXValue as it}from"../chart/utils/format.js";import{chartCursorTarget as ut,pressChartMark as ct}from"../chart/utils/keyboard.js";import{buildAreaPath as we,buildLinePath as Te,isolatedPoints as ht}from"../chart/utils/path.js";import{nearestIndex as mt,toKey as Ve}from"../chart/utils/scales.js";import{stackExtent as dt,stackSeries as gt}from"../chart/utils/stack.js";import{extent as ft}from"../chart/utils/ticks.js";import{formatTimeValue as pt}from"../chart/utils/timestamp.js";import{CHART_TOUCH as Ct}from"../chart/utils/touch.js";import{Fragment as Pt,jsx as a,jsxs as $}from"react/jsx-runtime";var bt=.12,yt=.9,vt=10,kt=He(function({bands:f,stacked:r,patterns:d,patternBaseId:b}){return a("g",{children:f.map(s=>$("g",{children:[a("path",{d:s.area,fill:Ue(d,b,s.slot,s.color),fillOpacity:r?yt:bt,stroke:"none"}),s.gap?a("path",{d:s.gap,fill:"none",strokeWidth:2,className:"stroke-white dark:stroke-gray-800"}):null,a("path",{d:s.edge,fill:"none",stroke:s.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}),s.isolated.map(h=>a("circle",{cx:h.x,cy:h.y,r:3,fill:s.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},`${h.x}-${h.y}`))]},s.key))})});function xt({width:g,height:f,data:r,resolvedSeries:d,x:b,y:s,grid:h,size:J,curve:p,stack:P,baseline:L,connectNulls:S,referenceLines:K,annotations:A,annotationsLabel:me,patterns:Q,patternBaseId:ee,overlay:de,maxPoints:y,brush:te,onBrush:ne,brushLabel:ge,syncEnabled:M,margin:re,tooltip:B,onPointClick:R,plotLabel:fe,formatValue:v,formatRaw:O,formatX:E}){let[X,G]=xe(null),l=X!==null&&X<r.length?X:null,[pe,Ce]=xe(null),be=Ye(),i=M?be:null,t=D(()=>{let e=d.filter(T=>!T.hidden),n=e.map(T=>T.key),o=P!=="none",c=gt(r,n,P),se=o?dt(c):ft([...rt(r,n),L]),m=Qe({width:g,height:f,data:r,x:b,y:s,bounds:se,margin:re,placement:"point",formatValue:v,formatX:E,defaultIncludeZero:!0}),ve=m.categoryCenters,ie=m.valueScale,Ee=ie(o?0:L),Ie=e.map((T,ke)=>{let j=r.map((Z,q)=>{let V=c[q].segments[ke];return{x:ve[q],y:V.value===null?Number.NaN:ie(V.end),defined:V.value!==null}}),Pe=r.map((Z,q)=>{let V=c[q].segments[ke];return{x:ve[q],y:V.value===null?Number.NaN:ie(o?V.start:L),defined:V.value!==null}}),ue={connectNulls:S},ce=y&&y>0&&j.length>y?at(j,y):null,he=ce?ce.map(Z=>j[Z]):j,Le=ce?ce.map(Z=>Pe[Z]):Pe;return y||lt("AreaChart",j.length),{key:T.key,color:T.color,slot:T.slot,area:o?we(he,Le,p,ue):we(he,Ee,p,ue),edge:Te(he,p,ue),gap:o&&ke>0?Te(Le,p,ue):"",isolated:ht(he,S)}});return{visible:e,locate:et(m),plot:tt({geometry:m,width:g,height:f,data:r,series:e,formatValue:v,formatX:E}),rows:c,stacked:o,xValues:m.xValues,positions:ve,xTicks:m.categoryTicks,yTicks:m.valueTicks,valueScale:ie,innerWidth:m.innerWidth,innerHeight:m.innerHeight,margin:m.margin,bands:Ie}},[r,d,b,s,g,f,re,p,P,L,S,y,v,E]),_=x(e=>t.visible.map((n,o)=>{let c=ot(r[e],n.key),se=t.rows[e].segments[o],m=c===null?"\u2014":P==="percent"?`${O(c)} (${v(se.end-se.start)})`:v(c);return{seriesKey:n.key,seriesLabel:Be(n),color:n.color,value:c,formattedValue:m,datum:r[e]}}),[r,t.visible,t.rows,P,v,O]),oe=i?i.brush:pe,C=x(e=>{Ce(e),i?.setBrush(e),ne?.(e)},[i,ne]),u=Oe({enabled:te,active:oe!==null,centers:t.positions,xValues:t.xValues,offset:t.margin.left,orientation:"vertical",onCommit:C}),ae=x(e=>{if(u.onPointerMove(e),B===!1||r.length===0)return;let n=e.currentTarget.getBoundingClientRect(),o=e.clientX-n.left-t.margin.left,c=mt(t.positions,o);G(c>=0?c:null),i?.setHovered(c>=0?t.xValues[c]:null)},[u,B,r.length,t.margin.left,t.positions,t.xValues,i]),le=x(()=>{G(null),i?.setHovered(null)},[i]),I=x(()=>{if(!R||l===null)return;let[e]=_(l);e&&R({...e,index:l,x:t.xValues[l]})},[R,l,_,t.xValues]),H=x(e=>{if(r.length===0)return;let n=R&&l!==null&&t.visible.length>0;if(ct(e,n?I:null))return;u.onKeyDown(e,l);let o=ut(e.key,l,r.length,"x");o!==void 0&&(e.preventDefault(),G(o),i?.setHovered(o===null?null:t.xValues[o]))},[r.length,l,u,i,t.xValues,t.visible.length,R,I]),N=x(()=>{u.consumedClick()||I()},[u,I]),ye=l!==null||!i?.hovered?null:(()=>{let e=Ve(i.hovered),n=t.xValues.findIndex(o=>Ve(o)===e);return n<0?null:n})(),k=l??ye,z=l===null?null:_(l),W=k===null?[]:t.visible.map((e,n)=>{let o=t.rows[k].segments[n];return o.value===null?null:{key:e.key,color:e.color,y:t.valueScale(o.end)}}).filter(e=>e!==null),U=u.dragging??oe,Y=(()=>{if(!U)return null;let e=t.locate(U.from),n=t.locate(U.to);return e===null||n===null?null:{from:e,to:n}})(),F=nt(de),w=l===null||z===null?null:{x:t.xValues[l],xLabel:E(t.xValues[l],l),index:l,points:z};return $(Pt,{children:[$("svg",{width:g,height:f,role:"img","aria-label":fe??[t.visible.map(e=>Be(e)).join(", "),Ke(A,me)].filter(Boolean).join(". "),tabIndex:0,className:We(Ct,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500",te&&"select-none"),onPointerDown:u.onPointerDown,onPointerMove:ae,onPointerUp:u.onPointerUp,onPointerCancel:u.onPointerUp,onPointerLeave:le,onKeyDown:H,onBlur:le,onClick:N,children:[Q?a(ze,{id:ee,entries:d.map(e=>({slot:e.slot,color:e.color}))}):null,$("g",{transform:`translate(${t.margin.left}, ${t.margin.top})`,children:[a(Ge,{width:t.innerWidth,height:t.innerHeight,horizontal:h==="y"||h==="both"?t.yTicks.map(e=>e.offset):void 0,vertical:h==="x"||h==="both"?t.xTicks.map(e=>e.offset):void 0}),A?a(Se,{layer:"under",annotations:A,xAt:t.locate,yAt:t.valueScale,width:t.innerWidth,height:t.innerHeight}):null,Y?a(Me,{from:Y.from,to:Y.to,width:t.innerWidth,height:t.innerHeight,live:u.dragging!==null,label:ge}):null,F.under?.(t.plot),a(kt,{bands:t.bands,stacked:t.stacked,patterns:Q&&t.stacked,patternBaseId:ee}),A?a(Se,{annotations:A,xAt:t.locate,yAt:t.valueScale,width:t.innerWidth,height:t.innerHeight}):null,K?.map(e=>{let n=t.valueScale(e.value),o=n<vt?n+12:n-4;return $("g",{children:[a("line",{x1:0,y1:n,x2:t.innerWidth,y2:n,stroke:e.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:e.dashed===!1?void 0:"4 4"}),e.label?a("text",{x:t.innerWidth,y:o,textAnchor:"end",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:e.label}):null]},`${e.value}-${e.label??""}`)}),F.over?.(t.plot),k!==null?$("g",{"aria-hidden":"true",children:[a("line",{x1:t.positions[k],y1:0,x2:t.positions[k],y2:t.innerHeight,className:"stroke-gray-400 dark:stroke-gray-500",strokeWidth:1,strokeDasharray:l===null?"3 3":void 0}),W.map(e=>a("circle",{cx:t.positions[k],cy:e.y,r:4,fill:e.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},e.key))]}):null]}),a("g",{transform:`translate(${t.margin.left}, ${t.margin.top+t.innerHeight})`,children:b.hidden?null:a(Ae,{orientation:"bottom",ticks:t.xTicks,length:t.innerWidth,label:b.label,size:J})}),a("g",{transform:`translate(${t.margin.left}, ${t.margin.top})`,children:s?.hidden?null:a(Ae,{orientation:"left",ticks:t.yTicks,length:t.innerHeight,showLine:!1,label:s?.label,size:J})})]}),w&&B!==!1?a(je,{x:t.margin.left+t.positions[w.index],y:t.margin.top+(W.length>0?Math.min(...W.map(e=>e.y)):t.innerHeight/2),containerWidth:g,children:typeof B=="function"?B(w):a(Ze,{title:w.xLabel,points:w.points})}):null]})}function jt({data:g,series:f,x:r,y:d,height:b=240,width:s,size:h="md",grid:J="y",legend:p,tooltip:P=!0,tableView:L=!1,emphasis:S,title:K,description:A,loading:me=!1,emptyState:Q,error:ee=!1,errorState:de,onRetry:y,actions:te,onPointClick:ne,curve:ge="monotone",stack:M="none",baseline:re=0,connectNulls:B=!1,referenceLines:R,annotations:fe,overlay:v,patterns:O=!1,legendToggle:E=!0,maxPoints:X,brush:G=!1,onBrush:l,brushLabel:pe,sync:Ce=!0,margin:be,locale:i,plotLabel:t,className:_,...oe}){let C=$e(i),u=De(),[ae,le]=xe(()=>new Set),I=Ne(),H=D(()=>f.map((e,n)=>({...e,slot:n,hidden:e.hidden||ae.has(e.key),color:qe(e,n,S)})),[f,ae,S]),N=M==="percent",ye=D(()=>N?{domain:[0,100],...d}:d,[N,d]),k=D(()=>d?.format??(N?e=>st(e,{locale:C,alreadyScaled:!0,maximumFractionDigits:0}):e=>Re(e,C)),[d?.format,N,C]),z=D(()=>e=>Re(e,C),[C]),W=D(()=>r.format??(e=>r.scale==="time"?pt(e,C):it(e,C)),[r.format,r.scale,C]),U=x(e=>{le(n=>{let o=new Set(n);return o.has(e)?o.delete(e):o.add(e),o})},[]),Y=p===void 0?f.length>=2:p!==!1,F=typeof p=="string"?p:"bottom",w=H.filter(e=>!e.hidden).length;return a(Xe,{title:K,description:A,height:b,width:s,size:h,loading:me,empty:g.length===0||w===0,emptyState:Q,error:ee,errorState:de,onRetry:y,actions:te,tableView:L,legendPosition:F,legend:Y?a(_e,{items:Je(H,S,O&&M!=="none"),position:F,marker:"rect",size:h,onToggle:E?U:void 0}):void 0,table:L?a(Fe,{data:g,series:H,xKey:r.key,xLabel:r.label??r.key,formatX:W,formatValue:z,caption:typeof K=="string"?K:void 0}):void 0,className:_,...oe,children:({width:e})=>a(xt,{width:e,height:b,data:g,resolvedSeries:H,x:r,y:ye,grid:J,size:h,curve:ge,stack:M,baseline:re,connectNulls:B,referenceLines:R,annotations:fe,annotationsLabel:u.chartAnnotations,patterns:O,patternBaseId:I,overlay:v,maxPoints:X,brush:G,onBrush:l,brushLabel:pe??u.chartBrush,syncEnabled:Ce,margin:be,tooltip:P,onPointClick:ne,plotLabel:t,formatValue:k,formatRaw:z,formatX:W})})}export{jt as AreaChart};
@@ -1 +1 @@
1
- "use strict";"use client";var nt=Object.defineProperty;var It=Object.getOwnPropertyDescriptor;var Dt=Object.getOwnPropertyNames;var Ht=Object.prototype.hasOwnProperty;var Wt=(f,c)=>{for(var n in c)nt(f,n,{get:c[n],enumerable:!0})},Nt=(f,c,n,m)=>{if(c&&typeof c=="object"||typeof c=="function")for(let h of Dt(c))!Ht.call(f,h)&&h!==n&&nt(f,h,{get:()=>c[h],enumerable:!(m=It(c,h))||m.enumerable});return f};var Ot=f=>Nt(nt({},"__esModule",{value:!0}),f);var Yt={};Wt(Yt,{BarChart:()=>Ft,resetBarChartWarnings:()=>Xt});module.exports=Ot(Yt);var i=require("react"),gt=require("../../lib/cn.cjs"),pt=require("../../lib/i18n.cjs"),Be=require("../chart/ChartAnnotations.cjs"),rt=require("../chart/ChartAxis.cjs"),_e=require("../chart/ChartBrush.cjs"),bt=require("../chart/ChartContainer.cjs"),yt=require("../chart/ChartGrid.cjs"),Ct=require("../chart/ChartLegend.cjs"),$e=require("../chart/ChartPatterns.cjs"),vt=require("../chart/ChartScaleLegend.cjs"),xt=require("../chart/ChartSync.cjs"),kt=require("../chart/ChartTableView.cjs"),Ke=require("../chart/ChartTooltip.cjs"),w=require("../chart/palette.cjs"),G=require("../chart/utils/cartesian.cjs"),M=require("../chart/utils/data.cjs"),he=require("../chart/utils/format.cjs"),Xe=require("../chart/utils/keyboard.cjs"),St=require("../chart/utils/bins.cjs"),Ge=require("../chart/utils/path.cjs"),Pe=require("../chart/utils/scales.cjs"),de=require("../chart/utils/stack.cjs"),Bt=require("../chart/utils/text.cjs"),we=require("../chart/utils/ticks.cjs"),Ue=require("../chart/utils/touch.cjs"),r=require("react/jsx-runtime"),_t=24,ne=2,$t=4,ue=6,Kt=10,ot=!1,at=!1;function Xt(){ot=!1,at=!1}var Gt=(0,i.memo)(function({bars:c,patterns:n,patternBaseId:m}){return(0,r.jsx)("g",{children:c.map((h,T)=>(0,r.jsxs)("g",{children:[(0,r.jsx)("path",{d:h.d,fill:(0,$e.patternFill)(n,m,h.slot,h.color)}),h.label?(0,r.jsx)("text",{x:h.label.x,y:h.label.y,textAnchor:h.label.anchor,dominantBaseline:"middle",className:"fill-gray-600 text-[10px] [font-variant-numeric:tabular-nums] dark:fill-gray-300",children:h.label.text}):null]},`${h.key}-${T}`))})}),Ut=(0,i.memo)(function({lines:c}){return(0,r.jsx)("g",{children:c.map(n=>(0,r.jsxs)("g",{children:[(0,r.jsx)("path",{d:n.d,fill:"none",stroke:n.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:n.dashed?"5 4":void 0}),n.markers.map(m=>(0,r.jsx)("circle",{cx:m.x,cy:m.y,r:3,fill:n.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},`${m.x}-${m.y}`))]},n.key))})});function zt({width:f,height:c,data:n,resolvedSeries:m,x:h,y:T,grid:I,size:Le,orientation:E,stack:N,center:V,centerKey:D,valueColors:U,binned:re,curve:Re,barSize:Ae,showValues:Te,referenceLines:ze,annotations:z,annotationsLabel:Fe,patterns:Ee,patternBaseId:oe,overlay:Ve,brush:L,onBrush:F,brushLabel:Ye,syncEnabled:Ze,margin:ae,tooltip:Y,onPointClick:Z,plotLabel:Me,formatValue:O,formatRaw:j,formatX:le}){let[me,fe]=(0,i.useState)(null),d=me!==null&&me<n.length?me:null,[je,qe]=(0,i.useState)(null),H=(0,xt.useChartSync)(),v=Ze?H:null,e=(0,i.useMemo)(()=>{let t=E==="vertical",o=m.filter(g=>!g.hidden),a=o.filter(g=>g.type!=="line"),b=o.filter(g=>g.type==="line"),R=a.map(g=>g.key),y=D!==null||N!=="none",s=D!==null?(0,de.stackDiverging)(n,R,{centerKey:D,percent:N==="percent"}):(0,de.stackSeries)(n,R,N),l=y?(0,de.stackExtent)(s):(0,we.extent)((0,M.collectAllValues)(n,R)),u=(0,we.extent)((0,M.collectAllValues)(n,b.map(g=>g.key))),p=l===null?u:u===null?l:[Math.min(l[0],u[0]),Math.max(l[1],u[1])],A=(0,G.buildCartesianGeometry)({width:f,height:c,data:n,x:h,y:T,bounds:p===null?null:[Math.min(p[0],V),Math.max(p[1],V)],margin:ae,orientation:E,placement:"band",bandPaddingInner:re?0:void 0,formatValue:O,formatX:le,defaultIncludeZero:V===0}),{valueScale:ve,bandwidth:xe,categoryPositions:lt,innerWidth:it,innerHeight:st}=A,Pt=ve(V),He=Math.max(1,a.length),wt=y?xe:xe/He,X=Math.min(Ae??(re?Number.POSITIVE_INFINITY:_t),Math.max(1,wt-(y&&!re?0:ne))),Lt=y?X:He*X+(He-1)*ne,ct=(xe-Lt)/2,ut=[],ht=g=>y?g.end>=g.start:g.end>=V;s.forEach((g,We)=>{let Q=-1,Ne=-1;g.segments.forEach((P,se)=>{P.value!==null&&P.outer!==!1&&(ht(P)?Q=se:Ne=se)});let ie=0,ke=0;g.segments.forEach((P,se)=>{if(P.value===null)return;let Qe=a[se],x=ht(P),dt=ve(y?P.start:V),mt=ve(P.end),ee=Math.min(dt,mt),ce=Math.abs(mt-dt),At=P.base??(x?ie===0:ke===0),Tt=t?!x:x;y&&!At&&ce>ne&&(ce-=ne,Tt&&(ee+=ne)),x?ie+=1:ke+=1;let Oe=lt[We]+(y?ct:ct+se*(X+ne)),Et=se===(x?Q:Ne)?t?x?"top":"bottom":x?"right":"left":"none",Vt=t?{x:Oe,y:ee,width:X,height:ce}:{x:ee,y:Oe,width:ce,height:X},et=null;if(Te&&!y){let tt=j(P.value),ft=(0,Bt.estimateTextWidth)(tt,10);if(t){let te=x?ee:ee+ce,Se=x?te-ue:te+ue,Mt=He>1?X+ne:xe;ft<=Mt&&(x?Se>8:Se<st-4)&&(et={x:Oe+X/2,y:Se,anchor:"middle",text:tt})}else{let te=x?ee+ce:ee,Se=x?it-te-ue:te-ue;ft<=Se&&(et={x:x?te+ue:te-ue,y:Oe+X/2,anchor:x?"start":"end",text:tt})}}ut.push({key:Qe.key,slot:Qe.slot,color:U&&P.value!==null?U(P.value):Qe.color,d:(0,Ge.buildBarPath)({...Vt,radius:$t,round:Et}),label:et})})});let Rt=b.map(g=>{let We=A.categoryCenters.map((Q,Ne)=>{let ie=(0,M.readNumber)(n[Ne],g.key),ke=ie===null?Number.NaN:ve(ie);return{x:t?Q:ke,y:t?ke:Q,defined:ie!==null}});return{key:g.key,color:g.color,dashed:g.dashed,d:(0,Ge.buildLinePath)(We,Re),markers:We.filter(Q=>Q.defined!==!1)}});return{vertical:t,visible:o,locate:(0,G.createCategoryLocator)(A),barSeries:a,rows:s,stacked:y,plot:(0,G.createPlotContext)({geometry:A,width:f,height:c,data:n,series:o,formatValue:O,formatX:le}),xValues:A.xValues,categoryPositions:lt,categoryCenters:A.categoryCenters,bandwidth:xe,categoryTicks:A.categoryTicks,valueTicks:A.valueTicks,valueScale:ve,baseline:Pt,innerWidth:it,innerHeight:st,margin:A.margin,bars:ut,lines:Rt}},[n,m,h,T,f,c,ae,E,N,V,D,U,re,Re,Ae,Te,O,j,le]),ge=(0,i.useCallback)(t=>e.visible.map(o=>{let a=(0,M.readNumber)(n[t],o.key),b=e.barSeries.indexOf(o),R=b===-1?null:e.rows[t].segments[b],y=a===null?"\u2014":N==="percent"&&R!==null?`${j(a)} (${O(R.end-R.start)})`:O(a);return{seriesKey:o.key,seriesLabel:(0,w.getSeriesLabel)(o),color:o.color,value:a,formattedValue:y,datum:n[t]}}),[n,e.visible,e.barSeries,e.rows,N,O,j]),pe=v?v.brush:je,Ie=(0,i.useCallback)(t=>{qe(t),v?.setBrush(t),F?.(t)},[v,F]),k=(0,_e.useChartBrush)({enabled:L,active:pe!==null,centers:e.categoryCenters,xValues:e.xValues,offset:e.vertical?e.margin.left:e.margin.top,orientation:E,onCommit:Ie}),Je=(0,i.useCallback)(t=>{if(k.onPointerMove(t),Y===!1||n.length===0)return;let o=t.currentTarget.getBoundingClientRect(),a=e.vertical?t.clientX-o.left-e.margin.left:t.clientY-o.top-e.margin.top,b=(0,Pe.nearestIndex)(e.categoryCenters,a);fe(b>=0?b:null),v?.setHovered(b>=0?e.xValues[b]:null)},[k,Y,n.length,e.vertical,e.margin,e.categoryCenters,e.xValues,v]),S=(0,i.useCallback)(()=>{fe(null),v?.setHovered(null)},[v]),C=(0,i.useCallback)(()=>{if(!Z||d===null)return;let[t]=ge(d);t&&Z({...t,index:d,x:e.xValues[d]})},[Z,d,ge,e.xValues]),q=(0,i.useCallback)(t=>{if(n.length===0)return;let o=Z&&d!==null&&e.visible.length>0;if((0,Xe.pressChartMark)(t,o?C:null))return;k.onKeyDown(t,d);let a=(0,Xe.chartCursorTarget)(t.key,d,n.length,e.vertical?"x":"y");a!==void 0&&(t.preventDefault(),fe(a),v?.setHovered(a===null?null:e.xValues[a]))},[n.length,d,e.vertical,k,v,e.xValues,e.visible.length,Z,C]),_=(0,i.useCallback)(()=>{k.consumedClick()||C()},[k,C]),$=d!==null||!v?.hovered?null:(()=>{let t=(0,Pe.toKey)(v.hovered),o=e.xValues.findIndex(a=>(0,Pe.toKey)(a)===t);return o<0?null:o})(),B=d??$,W=k.dragging??pe,K=(()=>{if(!W)return null;let t=e.locate(W.from),o=e.locate(W.to);if(t===null||o===null)return null;let a=e.bandwidth/2;return{from:Math.min(t,o)-a,to:Math.max(t,o)+a}})(),De=(0,G.splitOverlay)(Ve),be=d===null?null:ge(d),J=d===null||be===null?null:{x:e.xValues[d],xLabel:le(e.xValues[d],d),index:d,points:be},ye=t=>{let o=e.rows[t].segments.filter(a=>a.value!==null).map(a=>e.valueScale(a.end));for(let a of e.lines){let b=(0,M.readNumber)(n[t],a.key);b!==null&&o.push(e.valueScale(b))}return o},Ce=d===null?null:e.vertical?{x:e.margin.left+e.categoryCenters[d],y:e.margin.top+Math.min(...ye(d),e.baseline)}:{x:e.margin.left+Math.max(...ye(d),e.baseline),y:e.margin.top+e.categoryCenters[d]};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("svg",{width:f,height:c,role:"img","aria-label":Me??[e.visible.map(t=>(0,w.getSeriesLabel)(t)).join(", "),(0,Be.describeAnnotations)(z,Fe)].filter(Boolean).join(". "),tabIndex:0,className:(0,gt.cn)(L&&!e.vertical?Ue.CHART_TOUCH_VERTICAL_DRAG:Ue.CHART_TOUCH,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500",L&&"select-none"),onPointerDown:k.onPointerDown,onPointerMove:Je,onPointerUp:k.onPointerUp,onPointerCancel:k.onPointerUp,onPointerLeave:S,onKeyDown:q,onBlur:S,onClick:_,children:[Ee?(0,r.jsx)($e.ChartPatternDefs,{id:oe,entries:m.map(t=>({slot:t.slot,color:t.color}))}):null,(0,r.jsxs)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[(0,r.jsx)(yt.ChartGrid,{width:e.innerWidth,height:e.innerHeight,horizontal:e.vertical&&(I==="y"||I==="both")?e.valueTicks.map(t=>t.offset):void 0,vertical:!e.vertical&&(I==="y"||I==="both")?e.valueTicks.map(t=>t.offset):void 0}),z?(0,r.jsx)(Be.ChartAnnotationLayer,{layer:"under",annotations:z,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight,bandwidth:e.bandwidth}):null,K?(0,r.jsx)(_e.ChartBrushLayer,{from:K.from,to:K.to,width:e.innerWidth,height:e.innerHeight,orientation:E,live:k.dragging!==null,label:Ye}):null,B!==null?(0,r.jsx)("rect",{x:e.vertical?e.categoryPositions[B]:0,y:e.vertical?0:e.categoryPositions[B],width:e.vertical?e.bandwidth:e.innerWidth,height:e.vertical?e.innerHeight:e.bandwidth,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,De.under?.(e.plot),(0,r.jsx)(Gt,{bars:e.bars,patterns:Ee,patternBaseId:oe}),e.lines.length>0?(0,r.jsx)(Ut,{lines:e.lines}):null,(0,r.jsx)("line",{x1:e.vertical?0:e.baseline,y1:e.vertical?e.baseline:0,x2:e.vertical?e.innerWidth:e.baseline,y2:e.vertical?e.baseline:e.innerHeight,className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1,shapeRendering:"crispEdges"}),z?(0,r.jsx)(Be.ChartAnnotationLayer,{annotations:z,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight,bandwidth:e.bandwidth}):null,De.over?.(e.plot),ze?.map(t=>{let o=e.valueScale(t.value),a=o<Kt?o+12:o-4;return(0,r.jsxs)("g",{children:[(0,r.jsx)("line",{x1:e.vertical?0:o,y1:e.vertical?o:0,x2:e.vertical?e.innerWidth:o,y2:e.vertical?o:e.innerHeight,stroke:t.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:t.dashed===!1?void 0:"4 4"}),t.label?(0,r.jsx)("text",{x:e.vertical?e.innerWidth:o+4,y:e.vertical?a:8,textAnchor:e.vertical?"end":"start",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)})]}),(0,r.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:(e.vertical?h.hidden:T?.hidden)?null:(0,r.jsx)(rt.ChartAxis,{orientation:"bottom",ticks:e.vertical?e.categoryTicks:e.valueTicks,length:e.innerWidth,label:e.vertical?h.label:T?.label,size:Le})}),(0,r.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:(e.vertical?T?.hidden:h.hidden)?null:(0,r.jsx)(rt.ChartAxis,{orientation:"left",ticks:e.vertical?e.valueTicks:e.categoryTicks,length:e.innerHeight,showLine:!1,label:e.vertical?T?.label:h.label,size:Le})})]}),J&&Ce&&Y!==!1?(0,r.jsx)(Ke.ChartTooltip,{x:Ce.x,y:Ce.y,containerWidth:f,children:typeof Y=="function"?Y(J):(0,r.jsx)(Ke.ChartTooltipContent,{title:J.xLabel,points:J.points})}):null]})}function Ft({data:f,series:c,x:n,y:m,height:h=260,width:T,size:I="md",grid:Le="y",legend:E,tooltip:N=!0,tableView:V=!1,emphasis:D,title:U,description:re,loading:Re=!1,emptyState:Ae,error:Te=!1,errorState:ze,onRetry:z,actions:Fe,onPointClick:Ee,orientation:oe="vertical",stack:Ve="none",diverging:L,bins:F,curve:Ye="linear",barSize:Ze,sort:ae="none",showValues:Y=!1,referenceLines:Z,annotations:Me,overlay:O,patterns:j=!1,legendToggle:le=!0,brush:me=!1,onBrush:fe,brushLabel:d,sync:je=!0,margin:qe,locale:H,plotLabel:v,className:e,...ge}){let pe=(0,pt.useUILabels)(),[Ie,k]=(0,i.useState)(()=>new Set),Je=(0,i.useId)(),S=F!==void 0&&F!==!1,C=S||typeof L!="string"?null:L,q=!S&&typeof L=="number"?L:0,_=(0,i.useMemo)(()=>{let s=C===null?null:(0,w.createDivergingScale)([0,Math.max(1,c.length-1)],{center:Math.max(0,c.findIndex(l=>l.key===C)),symmetric:!1});return c.map((l,u)=>({...l,slot:u,hidden:l.hidden||Ie.has(l.key),color:s&&!l.color&&!D?l.key===C?w.CHART_MUTED_COLOR:s(u):(0,w.resolveSeriesColor)(l,u,D)}))},[c,Ie,D,C]),$=(0,i.useMemo)(()=>s=>(0,he.formatAuto)(s,H),[H]),B=(0,i.useMemo)(()=>{if(!S)return null;c.length>1&&!ot&&(ot=!0,console.warn("[@synertech/ui] BarChart was given `bins` and more than one series. A histogram counts a single field \u2014 the extra series are ignored. Facet the chart, or draw the distributions side by side."));let s=c[0]?.key??"count",l=n.format?p=>n.format(p,0):p=>$(p),u=(0,St.binValues)(f.map(p=>(0,M.readNumber)(p,n.key)),F);return{rows:u.map(p=>({[n.key]:p.from,[s]:p.count})),labels:u.map(p=>`${l(p.from)}\u2013${l(p.to)}`)}},[S,F,f,n.key,n.format,c,$]),W=(0,i.useMemo)(()=>{if(B)return B.rows;if(ae==="none")return f;let s=_.filter(u=>!u.hidden).map(u=>u.key),l=u=>s.reduce((p,A)=>p+((0,M.readNumber)(u,A)??0),0);return[...f].sort((u,p)=>ae==="asc"?l(u)-l(p):l(p)-l(u))},[B,f,ae,_]),K=!S&&Ve==="percent",De=(0,i.useMemo)(()=>K?{domain:C===null?[0,100]:[-100,100],...m}:m,[K,C,m]),be=(0,i.useMemo)(()=>{let s=m?.format??(K?l=>(0,he.formatPercent)(l,{locale:H,alreadyScaled:!0,maximumFractionDigits:0}):$);return C===null?s:l=>s(Math.abs(l))},[m?.format,K,H,$,C]),J=(0,i.useMemo)(()=>B?(s,l)=>B.labels[l]??"":n.format??(s=>(0,he.formatXValue)(s,H)),[B,n.format,H]),ye=(0,i.useMemo)(()=>B?{...n,scale:"category"}:n,[B,n]),Ce=(0,i.useCallback)(s=>{k(l=>{let u=new Set(l);return u.has(s)?u.delete(s):u.add(s),u})},[]),t=oe==="vertical"?Me:void 0;Me&&oe!=="vertical"&&!at&&(at=!0,console.warn("[@synertech/ui] BarChart was given `annotations` and a horizontal orientation. Annotations are read on the category axis, which runs up the side there: they are ignored. Use `referenceLines` for a threshold on the value axis."));let o=E===void 0?c.length>=2:E!==!1,a=typeof E=="string"?E:"bottom",b=_.filter(s=>!s.hidden),R=b.length,y=(0,i.useMemo)(()=>{if(S||L===void 0||L===!1||C!==null||R!==1)return null;let s=(0,M.collectAllValues)(W,b.map(u=>u.key)),l=(0,we.resolveDomain)([...s,q],{domain:m?.domain,includeZero:m?.includeZero??q===0,ticks:m?.ticks??5});return(0,w.createDivergingScale)(l,{center:q})},[S,L,C,R,b,W,q,m]);return(0,r.jsx)(bt.ChartContainer,{title:U,description:re,height:h,width:T,size:I,loading:Re,empty:W.length===0||R===0,emptyState:Ae,error:Te,errorState:ze,onRetry:z,actions:Fe,tableView:V,legendPosition:a,legend:y?(0,r.jsx)(vt.ChartScaleLegend,{scale:y,label:m?.label,format:be,size:I,locale:H}):o?(0,r.jsx)(Ct.ChartLegend,{items:(0,w.toLegendItems)(_,D,j),position:a,marker:"rect",size:I,onToggle:le?Ce:void 0}):void 0,table:V?(0,r.jsx)(kt.ChartTableView,{data:W,series:_,xKey:ye.key,xLabel:n.label??n.key,formatX:J,formatValue:$,caption:typeof U=="string"?U:void 0}):void 0,className:e,...ge,children:({width:s})=>(0,r.jsx)(zt,{width:s,height:h,data:W,resolvedSeries:_,x:ye,y:De,grid:Le,size:I,orientation:oe,stack:S?"none":Ve,center:q,centerKey:C,valueColors:y,binned:S,curve:Ye,barSize:Ze,showValues:Y,referenceLines:Z,annotations:t,annotationsLabel:pe.chartAnnotations,patterns:j&&y===null,patternBaseId:Je,overlay:O,brush:me,onBrush:fe,brushLabel:d??pe.chartBrush,syncEnabled:je,margin:qe,tooltip:N,onPointClick:Ee,plotLabel:v,formatValue:be,formatRaw:$,formatX:J})})}0&&(module.exports={BarChart,resetBarChartWarnings});
1
+ "use strict";"use client";var rt=Object.defineProperty;var It=Object.getOwnPropertyDescriptor;var Dt=Object.getOwnPropertyNames;var Ht=Object.prototype.hasOwnProperty;var Wt=(g,c)=>{for(var n in c)rt(g,n,{get:c[n],enumerable:!0})},Nt=(g,c,n,f)=>{if(c&&typeof c=="object"||typeof c=="function")for(let d of Dt(c))!Ht.call(g,d)&&d!==n&&rt(g,d,{get:()=>c[d],enumerable:!(f=It(c,d))||f.enumerable});return g};var Ot=g=>Nt(rt({},"__esModule",{value:!0}),g);var Yt={};Wt(Yt,{BarChart:()=>Ft,resetBarChartWarnings:()=>Ut});module.exports=Ot(Yt);var s=require("react"),pt=require("../../lib/cn.cjs"),Oe=require("../../lib/i18n.cjs"),ke=require("../chart/ChartAnnotations.cjs"),ot=require("../chart/ChartAxis.cjs"),_e=require("../chart/ChartBrush.cjs"),bt=require("../chart/ChartContainer.cjs"),yt=require("../chart/ChartGrid.cjs"),Ct=require("../chart/ChartLegend.cjs"),$e=require("../chart/ChartPatterns.cjs"),vt=require("../chart/ChartScaleLegend.cjs"),xt=require("../chart/ChartSync.cjs"),kt=require("../chart/ChartTableView.cjs"),Ke=require("../chart/ChartTooltip.cjs"),w=require("../chart/palette.cjs"),U=require("../chart/utils/cartesian.cjs"),I=require("../chart/utils/data.cjs"),me=require("../chart/utils/format.cjs"),Ue=require("../chart/utils/keyboard.cjs"),St=require("../chart/utils/bins.cjs"),Xe=require("../chart/utils/path.cjs"),Se=require("../chart/utils/scales.cjs"),fe=require("../chart/utils/stack.cjs"),Bt=require("../chart/utils/text.cjs"),Be=require("../chart/utils/ticks.cjs"),Ge=require("../chart/utils/touch.cjs"),r=require("react/jsx-runtime"),_t=24,re=2,$t=4,de=6,Kt=10,at=!1,lt=!1;function Ut(){at=!1,lt=!1}var Xt=(0,s.memo)(function({bars:c,patterns:n,patternBaseId:f}){return(0,r.jsx)("g",{children:c.map((d,A)=>(0,r.jsxs)("g",{children:[(0,r.jsx)("path",{d:d.d,fill:(0,$e.patternFill)(n,f,d.slot,d.color)}),d.label?(0,r.jsx)("text",{x:d.label.x,y:d.label.y,textAnchor:d.label.anchor,dominantBaseline:"middle",className:"fill-gray-600 text-[10px] [font-variant-numeric:tabular-nums] dark:fill-gray-300",children:d.label.text}):null]},`${d.key}-${A}`))})}),Gt=(0,s.memo)(function({lines:c}){return(0,r.jsx)("g",{children:c.map(n=>(0,r.jsxs)("g",{children:[(0,r.jsx)("path",{d:n.d,fill:"none",stroke:n.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:n.dashed?"5 4":void 0}),n.markers.map(f=>(0,r.jsx)("circle",{cx:f.x,cy:f.y,r:3,fill:n.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},`${f.x}-${f.y}`))]},n.key))})});function zt({width:g,height:c,data:n,resolvedSeries:f,x:d,y:A,grid:D,size:Pe,orientation:T,stack:N,center:E,centerKey:H,valueColors:X,binned:oe,curve:we,barSize:Le,showValues:Re,referenceLines:ze,annotations:G,annotationsLabel:Fe,patterns:Ae,patternBaseId:ae,overlay:Te,brush:L,onBrush:z,brushLabel:Ye,syncEnabled:Ze,margin:le,tooltip:F,onPointClick:Y,plotLabel:Ee,formatValue:O,formatRaw:Z,formatX:ie}){let[ge,pe]=(0,s.useState)(null),m=ge!==null&&ge<n.length?ge:null,[je,qe]=(0,s.useState)(null),Je=(0,xt.useChartSync)(),C=Ze?Je:null,e=(0,s.useMemo)(()=>{let t=T==="vertical",o=f.filter(p=>!p.hidden),a=o.filter(p=>p.type!=="line"),b=o.filter(p=>p.type==="line"),R=a.map(p=>p.key),y=H!==null||N!=="none",$=H!==null?(0,fe.stackDiverging)(n,R,{centerKey:H,percent:N==="percent"}):(0,fe.stackSeries)(n,R,N),i=y?(0,fe.stackExtent)($):(0,Be.extent)((0,I.collectAllValues)(n,R)),l=(0,Be.extent)((0,I.collectAllValues)(n,b.map(p=>p.key))),u=i===null?l:l===null?i:[Math.min(i[0],l[0]),Math.max(i[1],l[1])],h=(0,U.buildCartesianGeometry)({width:g,height:c,data:n,x:d,y:A,bounds:u===null?null:[Math.min(u[0],E),Math.max(u[1],E)],margin:le,orientation:T,placement:"band",bandPaddingInner:oe?0:void 0,formatValue:O,formatX:ie,defaultIncludeZero:E===0}),{valueScale:Q,bandwidth:Ce,categoryPositions:it,innerWidth:st,innerHeight:ct}=h,Pt=Q(E),De=Math.max(1,a.length),wt=y?Ce:Ce/De,K=Math.min(Le??(oe?Number.POSITIVE_INFINITY:_t),Math.max(1,wt-(y&&!oe?0:re))),Lt=y?K:De*K+(De-1)*re,ut=(Ce-Lt)/2,ht=[],dt=p=>y?p.end>=p.start:p.end>=E;$.forEach((p,He)=>{let ee=-1,We=-1;p.segments.forEach((P,ue)=>{P.value!==null&&P.outer!==!1&&(dt(P)?ee=ue:We=ue)});let ce=0,ve=0;p.segments.forEach((P,ue)=>{if(P.value===null)return;let et=a[ue],k=dt(P),mt=Q(y?P.start:E),ft=Q(P.end),te=Math.min(mt,ft),he=Math.abs(ft-mt),At=P.base??(k?ce===0:ve===0),Tt=t?!k:k;y&&!At&&he>re&&(he-=re,Tt&&(te+=re)),k?ce+=1:ve+=1;let Ne=it[He]+(y?ut:ut+ue*(K+re)),Et=ue===(k?ee:We)?t?k?"top":"bottom":k?"right":"left":"none",Vt=t?{x:Ne,y:te,width:K,height:he}:{x:te,y:Ne,width:he,height:K},tt=null;if(Re&&!y){let nt=Z(P.value),gt=(0,Bt.estimateTextWidth)(nt,10);if(t){let ne=k?te:te+he,xe=k?ne-de:ne+de,Mt=De>1?K+re:Ce;gt<=Mt&&(k?xe>8:xe<ct-4)&&(tt={x:Ne+K/2,y:xe,anchor:"middle",text:nt})}else{let ne=k?te+he:te,xe=k?st-ne-de:ne-de;gt<=xe&&(tt={x:k?ne+de:ne-de,y:Ne+K/2,anchor:k?"start":"end",text:nt})}}ht.push({key:et.key,slot:et.slot,color:X&&P.value!==null?X(P.value):et.color,d:(0,Xe.buildBarPath)({...Vt,radius:$t,round:Et}),label:tt})})});let Rt=b.map(p=>{let He=h.categoryCenters.map((ee,We)=>{let ce=(0,I.readNumber)(n[We],p.key),ve=ce===null?Number.NaN:Q(ce);return{x:t?ee:ve,y:t?ve:ee,defined:ce!==null}});return{key:p.key,color:p.color,dashed:p.dashed,d:(0,Xe.buildLinePath)(He,we),markers:He.filter(ee=>ee.defined!==!1)}});return{vertical:t,visible:o,locate:(0,U.createCategoryLocator)(h),barSeries:a,rows:$,stacked:y,plot:(0,U.createPlotContext)({geometry:h,width:g,height:c,data:n,series:o,formatValue:O,formatX:ie}),xValues:h.xValues,categoryPositions:it,categoryCenters:h.categoryCenters,bandwidth:Ce,categoryTicks:h.categoryTicks,valueTicks:h.valueTicks,valueScale:Q,baseline:Pt,innerWidth:st,innerHeight:ct,margin:h.margin,bars:ht,lines:Rt}},[n,f,d,A,g,c,le,T,N,E,H,X,oe,we,Le,Re,O,Z,ie]),be=(0,s.useCallback)(t=>e.visible.map(o=>{let a=(0,I.readNumber)(n[t],o.key),b=e.barSeries.indexOf(o),R=b===-1?null:e.rows[t].segments[b],y=a===null?"\u2014":N==="percent"&&R!==null?`${Z(a)} (${O(R.end-R.start)})`:O(a);return{seriesKey:o.key,seriesLabel:(0,w.getSeriesLabel)(o),color:o.color,value:a,formattedValue:y,datum:n[t]}}),[n,e.visible,e.barSeries,e.rows,N,O,Z]),V=C?C.brush:je,Ve=(0,s.useCallback)(t=>{qe(t),C?.setBrush(t),z?.(t)},[C,z]),v=(0,_e.useChartBrush)({enabled:L,active:V!==null,centers:e.categoryCenters,xValues:e.xValues,offset:e.vertical?e.margin.left:e.margin.top,orientation:T,onCommit:Ve}),Qe=(0,s.useCallback)(t=>{if(v.onPointerMove(t),F===!1||n.length===0)return;let o=t.currentTarget.getBoundingClientRect(),a=e.vertical?t.clientX-o.left-e.margin.left:t.clientY-o.top-e.margin.top,b=(0,Se.nearestIndex)(e.categoryCenters,a);pe(b>=0?b:null),C?.setHovered(b>=0?e.xValues[b]:null)},[v,F,n.length,e.vertical,e.margin,e.categoryCenters,e.xValues,C]),Me=(0,s.useCallback)(()=>{pe(null),C?.setHovered(null)},[C]),x=(0,s.useCallback)(()=>{if(!Y||m===null)return;let[t]=be(m);t&&Y({...t,index:m,x:e.xValues[m]})},[Y,m,be,e.xValues]),S=(0,s.useCallback)(t=>{if(n.length===0)return;let o=Y&&m!==null&&e.visible.length>0;if((0,Ue.pressChartMark)(t,o?x:null))return;v.onKeyDown(t,m);let a=(0,Ue.chartCursorTarget)(t.key,m,n.length,e.vertical?"x":"y");a!==void 0&&(t.preventDefault(),pe(a),C?.setHovered(a===null?null:e.xValues[a]))},[n.length,m,e.vertical,v,C,e.xValues,e.visible.length,Y,x]),j=(0,s.useCallback)(()=>{v.consumedClick()||x()},[v,x]),_=m!==null||!C?.hovered?null:(()=>{let t=(0,Se.toKey)(C.hovered),o=e.xValues.findIndex(a=>(0,Se.toKey)(a)===t);return o<0?null:o})(),M=m??_,B=v.dragging??V,W=(()=>{if(!B)return null;let t=e.locate(B.from),o=e.locate(B.to);if(t===null||o===null)return null;let a=e.bandwidth/2;return{from:Math.min(t,o)-a,to:Math.max(t,o)+a}})(),q=(0,U.splitOverlay)(Te),Ie=m===null?null:be(m),J=m===null||Ie===null?null:{x:e.xValues[m],xLabel:ie(e.xValues[m],m),index:m,points:Ie},ye=t=>{let o=e.rows[t].segments.filter(a=>a.value!==null).map(a=>e.valueScale(a.end));for(let a of e.lines){let b=(0,I.readNumber)(n[t],a.key);b!==null&&o.push(e.valueScale(b))}return o},se=m===null?null:e.vertical?{x:e.margin.left+e.categoryCenters[m],y:e.margin.top+Math.min(...ye(m),e.baseline)}:{x:e.margin.left+Math.max(...ye(m),e.baseline),y:e.margin.top+e.categoryCenters[m]};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("svg",{width:g,height:c,role:"img","aria-label":Ee??[e.visible.map(t=>(0,w.getSeriesLabel)(t)).join(", "),(0,ke.describeAnnotations)(G,Fe)].filter(Boolean).join(". "),tabIndex:0,className:(0,pt.cn)(L&&!e.vertical?Ge.CHART_TOUCH_VERTICAL_DRAG:Ge.CHART_TOUCH,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500",L&&"select-none"),onPointerDown:v.onPointerDown,onPointerMove:Qe,onPointerUp:v.onPointerUp,onPointerCancel:v.onPointerUp,onPointerLeave:Me,onKeyDown:S,onBlur:Me,onClick:j,children:[Ae?(0,r.jsx)($e.ChartPatternDefs,{id:ae,entries:f.map(t=>({slot:t.slot,color:t.color}))}):null,(0,r.jsxs)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[(0,r.jsx)(yt.ChartGrid,{width:e.innerWidth,height:e.innerHeight,horizontal:e.vertical&&(D==="y"||D==="both")?e.valueTicks.map(t=>t.offset):void 0,vertical:!e.vertical&&(D==="y"||D==="both")?e.valueTicks.map(t=>t.offset):void 0}),G?(0,r.jsx)(ke.ChartAnnotationLayer,{layer:"under",annotations:G,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight,bandwidth:e.bandwidth}):null,W?(0,r.jsx)(_e.ChartBrushLayer,{from:W.from,to:W.to,width:e.innerWidth,height:e.innerHeight,orientation:T,live:v.dragging!==null,label:Ye}):null,M!==null?(0,r.jsx)("rect",{x:e.vertical?e.categoryPositions[M]:0,y:e.vertical?0:e.categoryPositions[M],width:e.vertical?e.bandwidth:e.innerWidth,height:e.vertical?e.innerHeight:e.bandwidth,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,q.under?.(e.plot),(0,r.jsx)(Xt,{bars:e.bars,patterns:Ae,patternBaseId:ae}),e.lines.length>0?(0,r.jsx)(Gt,{lines:e.lines}):null,(0,r.jsx)("line",{x1:e.vertical?0:e.baseline,y1:e.vertical?e.baseline:0,x2:e.vertical?e.innerWidth:e.baseline,y2:e.vertical?e.baseline:e.innerHeight,className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1,shapeRendering:"crispEdges"}),G?(0,r.jsx)(ke.ChartAnnotationLayer,{annotations:G,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight,bandwidth:e.bandwidth}):null,q.over?.(e.plot),ze?.map(t=>{let o=e.valueScale(t.value),a=o<Kt?o+12:o-4;return(0,r.jsxs)("g",{children:[(0,r.jsx)("line",{x1:e.vertical?0:o,y1:e.vertical?o:0,x2:e.vertical?e.innerWidth:o,y2:e.vertical?o:e.innerHeight,stroke:t.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:t.dashed===!1?void 0:"4 4"}),t.label?(0,r.jsx)("text",{x:e.vertical?e.innerWidth:o+4,y:e.vertical?a:8,textAnchor:e.vertical?"end":"start",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)})]}),(0,r.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:(e.vertical?d.hidden:A?.hidden)?null:(0,r.jsx)(ot.ChartAxis,{orientation:"bottom",ticks:e.vertical?e.categoryTicks:e.valueTicks,length:e.innerWidth,label:e.vertical?d.label:A?.label,size:Pe})}),(0,r.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:(e.vertical?A?.hidden:d.hidden)?null:(0,r.jsx)(ot.ChartAxis,{orientation:"left",ticks:e.vertical?e.valueTicks:e.categoryTicks,length:e.innerHeight,showLine:!1,label:e.vertical?A?.label:d.label,size:Pe})})]}),J&&se&&F!==!1?(0,r.jsx)(Ke.ChartTooltip,{x:se.x,y:se.y,containerWidth:g,children:typeof F=="function"?F(J):(0,r.jsx)(Ke.ChartTooltipContent,{title:J.xLabel,points:J.points})}):null]})}function Ft({data:g,series:c,x:n,y:f,height:d=260,width:A,size:D="md",grid:Pe="y",legend:T,tooltip:N=!0,tableView:E=!1,emphasis:H,title:X,description:oe,loading:we=!1,emptyState:Le,error:Re=!1,errorState:ze,onRetry:G,actions:Fe,onPointClick:Ae,orientation:ae="vertical",stack:Te="none",diverging:L,bins:z,curve:Ye="linear",barSize:Ze,sort:le="none",showValues:F=!1,referenceLines:Y,annotations:Ee,overlay:O,patterns:Z=!1,legendToggle:ie=!0,brush:ge=!1,onBrush:pe,brushLabel:m,sync:je=!0,margin:qe,locale:Je,plotLabel:C,className:e,...be}){let V=(0,Oe.useUILocale)(Je),Ve=(0,Oe.useUILabels)(),[v,Qe]=(0,s.useState)(()=>new Set),Me=(0,s.useId)(),x=z!==void 0&&z!==!1,S=x||typeof L!="string"?null:L,j=!x&&typeof L=="number"?L:0,_=(0,s.useMemo)(()=>{let i=S===null?null:(0,w.createDivergingScale)([0,Math.max(1,c.length-1)],{center:Math.max(0,c.findIndex(l=>l.key===S)),symmetric:!1});return c.map((l,u)=>({...l,slot:u,hidden:l.hidden||v.has(l.key),color:i&&!l.color&&!H?l.key===S?w.CHART_MUTED_COLOR:i(u):(0,w.resolveSeriesColor)(l,u,H)}))},[c,v,H,S]),M=(0,s.useMemo)(()=>i=>(0,me.formatAuto)(i,V),[V]),B=(0,s.useMemo)(()=>{if(!x)return null;c.length>1&&!at&&(at=!0,console.warn("[@synertech/ui] BarChart was given `bins` and more than one series. A histogram counts a single field \u2014 the extra series are ignored. Facet the chart, or draw the distributions side by side."));let i=c[0]?.key??"count",l=n.format?h=>n.format(h,0):h=>M(h),u=(0,St.binValues)(g.map(h=>(0,I.readNumber)(h,n.key)),z);return{rows:u.map(h=>({[n.key]:h.from,[i]:h.count})),labels:u.map(h=>`${l(h.from)}\u2013${l(h.to)}`)}},[x,z,g,n.key,n.format,c,M]),W=(0,s.useMemo)(()=>{if(B)return B.rows;if(le==="none")return g;let i=_.filter(u=>!u.hidden).map(u=>u.key),l=u=>i.reduce((h,Q)=>h+((0,I.readNumber)(u,Q)??0),0);return[...g].sort((u,h)=>le==="asc"?l(u)-l(h):l(h)-l(u))},[B,g,le,_]),q=!x&&Te==="percent",Ie=(0,s.useMemo)(()=>q?{domain:S===null?[0,100]:[-100,100],...f}:f,[q,S,f]),J=(0,s.useMemo)(()=>{let i=f?.format??(q?l=>(0,me.formatPercent)(l,{locale:V,alreadyScaled:!0,maximumFractionDigits:0}):M);return S===null?i:l=>i(Math.abs(l))},[f?.format,q,V,M,S]),ye=(0,s.useMemo)(()=>B?(i,l)=>B.labels[l]??"":n.format??(i=>(0,me.formatXValue)(i,V)),[B,n.format,V]),se=(0,s.useMemo)(()=>B?{...n,scale:"category"}:n,[B,n]),t=(0,s.useCallback)(i=>{Qe(l=>{let u=new Set(l);return u.has(i)?u.delete(i):u.add(i),u})},[]),o=ae==="vertical"?Ee:void 0;Ee&&ae!=="vertical"&&!lt&&(lt=!0,console.warn("[@synertech/ui] BarChart was given `annotations` and a horizontal orientation. Annotations are read on the category axis, which runs up the side there: they are ignored. Use `referenceLines` for a threshold on the value axis."));let a=T===void 0?c.length>=2:T!==!1,b=typeof T=="string"?T:"bottom",R=_.filter(i=>!i.hidden),y=R.length,$=(0,s.useMemo)(()=>{if(x||L===void 0||L===!1||S!==null||y!==1)return null;let i=(0,I.collectAllValues)(W,R.map(u=>u.key)),l=(0,Be.resolveDomain)([...i,j],{domain:f?.domain,includeZero:f?.includeZero??j===0,ticks:f?.ticks??5});return(0,w.createDivergingScale)(l,{center:j})},[x,L,S,y,R,W,j,f]);return(0,r.jsx)(bt.ChartContainer,{title:X,description:oe,height:d,width:A,size:D,loading:we,empty:W.length===0||y===0,emptyState:Le,error:Re,errorState:ze,onRetry:G,actions:Fe,tableView:E,legendPosition:b,legend:$?(0,r.jsx)(vt.ChartScaleLegend,{scale:$,label:f?.label,format:J,size:D,locale:V}):a?(0,r.jsx)(Ct.ChartLegend,{items:(0,w.toLegendItems)(_,H,Z),position:b,marker:"rect",size:D,onToggle:ie?t:void 0}):void 0,table:E?(0,r.jsx)(kt.ChartTableView,{data:W,series:_,xKey:se.key,xLabel:n.label??n.key,formatX:ye,formatValue:M,caption:typeof X=="string"?X:void 0}):void 0,className:e,...be,children:({width:i})=>(0,r.jsx)(zt,{width:i,height:d,data:W,resolvedSeries:_,x:se,y:Ie,grid:Pe,size:D,orientation:ae,stack:x?"none":Te,center:j,centerKey:S,valueColors:$,binned:x,curve:Ye,barSize:Ze,showValues:F,referenceLines:Y,annotations:o,annotationsLabel:Ve.chartAnnotations,patterns:Z&&$===null,patternBaseId:Me,overlay:O,brush:ge,onBrush:pe,brushLabel:m??Ve.chartBrush,syncEnabled:je,margin:qe,tooltip:N,onPointClick:Ae,plotLabel:C,formatValue:J,formatRaw:M,formatX:ye})})}0&&(module.exports={BarChart,resetBarChartWarnings});
@@ -1 +1 @@
1
- "use client";import{memo as ut,useCallback as K,useId as vt,useMemo as E,useState as Ue}from"react";import{cn as xt}from"../../lib/cn.js";import{useUILabels as kt}from"../../lib/i18n.js";import{ChartAnnotationLayer as ot,describeAnnotations as St}from"../chart/ChartAnnotations.js";import{ChartAxis as at}from"../chart/ChartAxis.js";import{ChartBrushLayer as Bt,useChartBrush as Pt}from"../chart/ChartBrush.js";import{ChartContainer as wt}from"../chart/ChartContainer.js";import{ChartGrid as Lt}from"../chart/ChartGrid.js";import{ChartLegend as Rt}from"../chart/ChartLegend.js";import{ChartPatternDefs as At,patternFill as Tt}from"../chart/ChartPatterns.js";import{ChartScaleLegend as Et}from"../chart/ChartScaleLegend.js";import{useChartSync as Vt}from"../chart/ChartSync.js";import{ChartTableView as Mt}from"../chart/ChartTableView.js";import{ChartTooltip as It,ChartTooltipContent as Dt}from"../chart/ChartTooltip.js";import{CHART_MUTED_COLOR as Ht,createDivergingScale as lt,getSeriesLabel as it,resolveSeriesColor as Wt,toLegendItems as Nt}from"../chart/palette.js";import{buildCartesianGeometry as Ot,createCategoryLocator as _t,createPlotContext as $t,splitOverlay as Kt}from"../chart/utils/cartesian.js";import{collectAllValues as ze,readNumber as xe}from"../chart/utils/data.js";import{formatAuto as Xt,formatPercent as Gt,formatXValue as Ut}from"../chart/utils/format.js";import{chartCursorTarget as zt,pressChartMark as Ft}from"../chart/utils/keyboard.js";import{binValues as Yt}from"../chart/utils/bins.js";import{buildBarPath as Zt,buildLinePath as jt}from"../chart/utils/path.js";import{nearestIndex as qt,toKey as st}from"../chart/utils/scales.js";import{stackDiverging as Jt,stackExtent as Qt,stackSeries as en}from"../chart/utils/stack.js";import{estimateTextWidth as tn}from"../chart/utils/text.js";import{extent as ct,resolveDomain as nn}from"../chart/utils/ticks.js";import{CHART_TOUCH as rn,CHART_TOUCH_VERTICAL_DRAG as on}from"../chart/utils/touch.js";import{Fragment as dn,jsx as i,jsxs as ce}from"react/jsx-runtime";var an=24,ee=2,ln=4,se=6,sn=10,Fe=!1,Ye=!1;function $n(){Fe=!1,Ye=!1}var cn=ut(function({bars:f,patterns:n,patternBaseId:u}){return i("g",{children:f.map((m,R)=>ce("g",{children:[i("path",{d:m.d,fill:Tt(n,u,m.slot,m.color)}),m.label?i("text",{x:m.label.x,y:m.label.y,textAnchor:m.label.anchor,dominantBaseline:"middle",className:"fill-gray-600 text-[10px] [font-variant-numeric:tabular-nums] dark:fill-gray-300",children:m.label.text}):null]},`${m.key}-${R}`))})}),un=ut(function({lines:f}){return i("g",{children:f.map(n=>ce("g",{children:[i("path",{d:n.d,fill:"none",stroke:n.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:n.dashed?"5 4":void 0}),n.markers.map(u=>i("circle",{cx:u.x,cy:u.y,r:3,fill:n.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},`${u.x}-${u.y}`))]},n.key))})});function hn({width:v,height:f,data:n,resolvedSeries:u,x:m,y:R,grid:V,size:ke,orientation:A,stack:H,center:T,centerKey:M,valueColors:X,binned:te,curve:Se,barSize:Be,showValues:Pe,referenceLines:De,annotations:G,annotationsLabel:He,patterns:we,patternBaseId:ne,overlay:Le,brush:P,onBrush:U,brushLabel:We,syncEnabled:Ne,margin:re,tooltip:z,onPointClick:F,plotLabel:Re,formatValue:W,formatRaw:Y,formatX:oe}){let[ue,he]=Ue(null),c=ue!==null&&ue<n.length?ue:null,[Oe,_e]=Ue(null),I=Vt(),y=Ne?I:null,e=E(()=>{let t=A==="vertical",r=u.filter(h=>!h.hidden),o=r.filter(h=>h.type!=="line"),g=r.filter(h=>h.type==="line"),w=o.map(h=>h.key),p=M!==null||H!=="none",l=M!==null?Jt(n,w,{centerKey:M,percent:H==="percent"}):en(n,w,H),a=p?Qt(l):ct(ze(n,w)),s=ct(ze(n,g.map(h=>h.key))),d=a===null?s:s===null?a:[Math.min(a[0],s[0]),Math.max(a[1],s[1])],L=Ot({width:v,height:f,data:n,x:m,y:R,bounds:d===null?null:[Math.min(d[0],T),Math.max(d[1],T)],margin:re,orientation:A,placement:"band",bandPaddingInner:te?0:void 0,formatValue:W,formatX:oe,defaultIncludeZero:T===0}),{valueScale:be,bandwidth:ye,categoryPositions:Ze,innerWidth:je,innerHeight:qe}=L,ht=be(T),Ee=Math.max(1,o.length),dt=p?ye:ye/Ee,$=Math.min(Be??(te?Number.POSITIVE_INFINITY:an),Math.max(1,dt-(p&&!te?0:ee))),mt=p?$:Ee*$+(Ee-1)*ee,Je=(ye-mt)/2,Qe=[],et=h=>p?h.end>=h.start:h.end>=T;l.forEach((h,Ve)=>{let q=-1,Me=-1;h.segments.forEach((B,le)=>{B.value!==null&&B.outer!==!1&&(et(B)?q=le:Me=le)});let ae=0,Ce=0;h.segments.forEach((B,le)=>{if(B.value===null)return;let Ke=o[le],C=et(B),tt=be(p?B.start:T),nt=be(B.end),J=Math.min(tt,nt),ie=Math.abs(nt-tt),gt=B.base??(C?ae===0:Ce===0),pt=t?!C:C;p&&!gt&&ie>ee&&(ie-=ee,pt&&(J+=ee)),C?ae+=1:Ce+=1;let Ie=Ze[Ve]+(p?Je:Je+le*($+ee)),bt=le===(C?q:Me)?t?C?"top":"bottom":C?"right":"left":"none",yt=t?{x:Ie,y:J,width:$,height:ie}:{x:J,y:Ie,width:ie,height:$},Xe=null;if(Pe&&!p){let Ge=Y(B.value),rt=tn(Ge,10);if(t){let Q=C?J:J+ie,ve=C?Q-se:Q+se,Ct=Ee>1?$+ee:ye;rt<=Ct&&(C?ve>8:ve<qe-4)&&(Xe={x:Ie+$/2,y:ve,anchor:"middle",text:Ge})}else{let Q=C?J+ie:J,ve=C?je-Q-se:Q-se;rt<=ve&&(Xe={x:C?Q+se:Q-se,y:Ie+$/2,anchor:C?"start":"end",text:Ge})}}Qe.push({key:Ke.key,slot:Ke.slot,color:X&&B.value!==null?X(B.value):Ke.color,d:Zt({...yt,radius:ln,round:bt}),label:Xe})})});let ft=g.map(h=>{let Ve=L.categoryCenters.map((q,Me)=>{let ae=xe(n[Me],h.key),Ce=ae===null?Number.NaN:be(ae);return{x:t?q:Ce,y:t?Ce:q,defined:ae!==null}});return{key:h.key,color:h.color,dashed:h.dashed,d:jt(Ve,Se),markers:Ve.filter(q=>q.defined!==!1)}});return{vertical:t,visible:r,locate:_t(L),barSeries:o,rows:l,stacked:p,plot:$t({geometry:L,width:v,height:f,data:n,series:r,formatValue:W,formatX:oe}),xValues:L.xValues,categoryPositions:Ze,categoryCenters:L.categoryCenters,bandwidth:ye,categoryTicks:L.categoryTicks,valueTicks:L.valueTicks,valueScale:be,baseline:ht,innerWidth:je,innerHeight:qe,margin:L.margin,bars:Qe,lines:ft}},[n,u,m,R,v,f,re,A,H,T,M,X,te,Se,Be,Pe,W,Y,oe]),de=K(t=>e.visible.map(r=>{let o=xe(n[t],r.key),g=e.barSeries.indexOf(r),w=g===-1?null:e.rows[t].segments[g],p=o===null?"\u2014":H==="percent"&&w!==null?`${Y(o)} (${W(w.end-w.start)})`:W(o);return{seriesKey:r.key,seriesLabel:it(r),color:r.color,value:o,formattedValue:p,datum:n[t]}}),[n,e.visible,e.barSeries,e.rows,H,W,Y]),me=y?y.brush:Oe,Ae=K(t=>{_e(t),y?.setBrush(t),U?.(t)},[y,U]),x=Pt({enabled:P,active:me!==null,centers:e.categoryCenters,xValues:e.xValues,offset:e.vertical?e.margin.left:e.margin.top,orientation:A,onCommit:Ae}),$e=K(t=>{if(x.onPointerMove(t),z===!1||n.length===0)return;let r=t.currentTarget.getBoundingClientRect(),o=e.vertical?t.clientX-r.left-e.margin.left:t.clientY-r.top-e.margin.top,g=qt(e.categoryCenters,o);he(g>=0?g:null),y?.setHovered(g>=0?e.xValues[g]:null)},[x,z,n.length,e.vertical,e.margin,e.categoryCenters,e.xValues,y]),k=K(()=>{he(null),y?.setHovered(null)},[y]),b=K(()=>{if(!F||c===null)return;let[t]=de(c);t&&F({...t,index:c,x:e.xValues[c]})},[F,c,de,e.xValues]),Z=K(t=>{if(n.length===0)return;let r=F&&c!==null&&e.visible.length>0;if(Ft(t,r?b:null))return;x.onKeyDown(t,c);let o=zt(t.key,c,n.length,e.vertical?"x":"y");o!==void 0&&(t.preventDefault(),he(o),y?.setHovered(o===null?null:e.xValues[o]))},[n.length,c,e.vertical,x,y,e.xValues,e.visible.length,F,b]),N=K(()=>{x.consumedClick()||b()},[x,b]),O=c!==null||!y?.hovered?null:(()=>{let t=st(y.hovered),r=e.xValues.findIndex(o=>st(o)===t);return r<0?null:r})(),S=c??O,D=x.dragging??me,_=(()=>{if(!D)return null;let t=e.locate(D.from),r=e.locate(D.to);if(t===null||r===null)return null;let o=e.bandwidth/2;return{from:Math.min(t,r)-o,to:Math.max(t,r)+o}})(),Te=Kt(Le),fe=c===null?null:de(c),j=c===null||fe===null?null:{x:e.xValues[c],xLabel:oe(e.xValues[c],c),index:c,points:fe},ge=t=>{let r=e.rows[t].segments.filter(o=>o.value!==null).map(o=>e.valueScale(o.end));for(let o of e.lines){let g=xe(n[t],o.key);g!==null&&r.push(e.valueScale(g))}return r},pe=c===null?null:e.vertical?{x:e.margin.left+e.categoryCenters[c],y:e.margin.top+Math.min(...ge(c),e.baseline)}:{x:e.margin.left+Math.max(...ge(c),e.baseline),y:e.margin.top+e.categoryCenters[c]};return ce(dn,{children:[ce("svg",{width:v,height:f,role:"img","aria-label":Re??[e.visible.map(t=>it(t)).join(", "),St(G,He)].filter(Boolean).join(". "),tabIndex:0,className:xt(P&&!e.vertical?on:rn,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500",P&&"select-none"),onPointerDown:x.onPointerDown,onPointerMove:$e,onPointerUp:x.onPointerUp,onPointerCancel:x.onPointerUp,onPointerLeave:k,onKeyDown:Z,onBlur:k,onClick:N,children:[we?i(At,{id:ne,entries:u.map(t=>({slot:t.slot,color:t.color}))}):null,ce("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[i(Lt,{width:e.innerWidth,height:e.innerHeight,horizontal:e.vertical&&(V==="y"||V==="both")?e.valueTicks.map(t=>t.offset):void 0,vertical:!e.vertical&&(V==="y"||V==="both")?e.valueTicks.map(t=>t.offset):void 0}),G?i(ot,{layer:"under",annotations:G,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight,bandwidth:e.bandwidth}):null,_?i(Bt,{from:_.from,to:_.to,width:e.innerWidth,height:e.innerHeight,orientation:A,live:x.dragging!==null,label:We}):null,S!==null?i("rect",{x:e.vertical?e.categoryPositions[S]:0,y:e.vertical?0:e.categoryPositions[S],width:e.vertical?e.bandwidth:e.innerWidth,height:e.vertical?e.innerHeight:e.bandwidth,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,Te.under?.(e.plot),i(cn,{bars:e.bars,patterns:we,patternBaseId:ne}),e.lines.length>0?i(un,{lines:e.lines}):null,i("line",{x1:e.vertical?0:e.baseline,y1:e.vertical?e.baseline:0,x2:e.vertical?e.innerWidth:e.baseline,y2:e.vertical?e.baseline:e.innerHeight,className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1,shapeRendering:"crispEdges"}),G?i(ot,{annotations:G,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight,bandwidth:e.bandwidth}):null,Te.over?.(e.plot),De?.map(t=>{let r=e.valueScale(t.value),o=r<sn?r+12:r-4;return ce("g",{children:[i("line",{x1:e.vertical?0:r,y1:e.vertical?r:0,x2:e.vertical?e.innerWidth:r,y2:e.vertical?r:e.innerHeight,stroke:t.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:t.dashed===!1?void 0:"4 4"}),t.label?i("text",{x:e.vertical?e.innerWidth:r+4,y:e.vertical?o:8,textAnchor:e.vertical?"end":"start",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)})]}),i("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:(e.vertical?m.hidden:R?.hidden)?null:i(at,{orientation:"bottom",ticks:e.vertical?e.categoryTicks:e.valueTicks,length:e.innerWidth,label:e.vertical?m.label:R?.label,size:ke})}),i("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:(e.vertical?R?.hidden:m.hidden)?null:i(at,{orientation:"left",ticks:e.vertical?e.valueTicks:e.categoryTicks,length:e.innerHeight,showLine:!1,label:e.vertical?R?.label:m.label,size:ke})})]}),j&&pe&&z!==!1?i(It,{x:pe.x,y:pe.y,containerWidth:v,children:typeof z=="function"?z(j):i(Dt,{title:j.xLabel,points:j.points})}):null]})}function Kn({data:v,series:f,x:n,y:u,height:m=260,width:R,size:V="md",grid:ke="y",legend:A,tooltip:H=!0,tableView:T=!1,emphasis:M,title:X,description:te,loading:Se=!1,emptyState:Be,error:Pe=!1,errorState:De,onRetry:G,actions:He,onPointClick:we,orientation:ne="vertical",stack:Le="none",diverging:P,bins:U,curve:We="linear",barSize:Ne,sort:re="none",showValues:z=!1,referenceLines:F,annotations:Re,overlay:W,patterns:Y=!1,legendToggle:oe=!0,brush:ue=!1,onBrush:he,brushLabel:c,sync:Oe=!0,margin:_e,locale:I,plotLabel:y,className:e,...de}){let me=kt(),[Ae,x]=Ue(()=>new Set),$e=vt(),k=U!==void 0&&U!==!1,b=k||typeof P!="string"?null:P,Z=!k&&typeof P=="number"?P:0,N=E(()=>{let l=b===null?null:lt([0,Math.max(1,f.length-1)],{center:Math.max(0,f.findIndex(a=>a.key===b)),symmetric:!1});return f.map((a,s)=>({...a,slot:s,hidden:a.hidden||Ae.has(a.key),color:l&&!a.color&&!M?a.key===b?Ht:l(s):Wt(a,s,M)}))},[f,Ae,M,b]),O=E(()=>l=>Xt(l,I),[I]),S=E(()=>{if(!k)return null;f.length>1&&!Fe&&(Fe=!0,console.warn("[@synertech/ui] BarChart was given `bins` and more than one series. A histogram counts a single field \u2014 the extra series are ignored. Facet the chart, or draw the distributions side by side."));let l=f[0]?.key??"count",a=n.format?d=>n.format(d,0):d=>O(d),s=Yt(v.map(d=>xe(d,n.key)),U);return{rows:s.map(d=>({[n.key]:d.from,[l]:d.count})),labels:s.map(d=>`${a(d.from)}\u2013${a(d.to)}`)}},[k,U,v,n.key,n.format,f,O]),D=E(()=>{if(S)return S.rows;if(re==="none")return v;let l=N.filter(s=>!s.hidden).map(s=>s.key),a=s=>l.reduce((d,L)=>d+(xe(s,L)??0),0);return[...v].sort((s,d)=>re==="asc"?a(s)-a(d):a(d)-a(s))},[S,v,re,N]),_=!k&&Le==="percent",Te=E(()=>_?{domain:b===null?[0,100]:[-100,100],...u}:u,[_,b,u]),fe=E(()=>{let l=u?.format??(_?a=>Gt(a,{locale:I,alreadyScaled:!0,maximumFractionDigits:0}):O);return b===null?l:a=>l(Math.abs(a))},[u?.format,_,I,O,b]),j=E(()=>S?(l,a)=>S.labels[a]??"":n.format??(l=>Ut(l,I)),[S,n.format,I]),ge=E(()=>S?{...n,scale:"category"}:n,[S,n]),pe=K(l=>{x(a=>{let s=new Set(a);return s.has(l)?s.delete(l):s.add(l),s})},[]),t=ne==="vertical"?Re:void 0;Re&&ne!=="vertical"&&!Ye&&(Ye=!0,console.warn("[@synertech/ui] BarChart was given `annotations` and a horizontal orientation. Annotations are read on the category axis, which runs up the side there: they are ignored. Use `referenceLines` for a threshold on the value axis."));let r=A===void 0?f.length>=2:A!==!1,o=typeof A=="string"?A:"bottom",g=N.filter(l=>!l.hidden),w=g.length,p=E(()=>{if(k||P===void 0||P===!1||b!==null||w!==1)return null;let l=ze(D,g.map(s=>s.key)),a=nn([...l,Z],{domain:u?.domain,includeZero:u?.includeZero??Z===0,ticks:u?.ticks??5});return lt(a,{center:Z})},[k,P,b,w,g,D,Z,u]);return i(wt,{title:X,description:te,height:m,width:R,size:V,loading:Se,empty:D.length===0||w===0,emptyState:Be,error:Pe,errorState:De,onRetry:G,actions:He,tableView:T,legendPosition:o,legend:p?i(Et,{scale:p,label:u?.label,format:fe,size:V,locale:I}):r?i(Rt,{items:Nt(N,M,Y),position:o,marker:"rect",size:V,onToggle:oe?pe:void 0}):void 0,table:T?i(Mt,{data:D,series:N,xKey:ge.key,xLabel:n.label??n.key,formatX:j,formatValue:O,caption:typeof X=="string"?X:void 0}):void 0,className:e,...de,children:({width:l})=>i(hn,{width:l,height:m,data:D,resolvedSeries:N,x:ge,y:Te,grid:ke,size:V,orientation:ne,stack:k?"none":Le,center:Z,centerKey:b,valueColors:p,binned:k,curve:We,barSize:Ne,showValues:z,referenceLines:F,annotations:t,annotationsLabel:me.chartAnnotations,patterns:Y&&p===null,patternBaseId:$e,overlay:W,brush:ue,onBrush:he,brushLabel:c??me.chartBrush,syncEnabled:Oe,margin:_e,tooltip:H,onPointClick:we,plotLabel:y,formatValue:fe,formatRaw:O,formatX:j})})}export{Kn as BarChart,$n as resetBarChartWarnings};
1
+ "use client";import{memo as ut,useCallback as $,useId as vt,useMemo as V,useState as Ge}from"react";import{cn as xt}from"../../lib/cn.js";import{useUILabels as kt,useUILocale as St}from"../../lib/i18n.js";import{ChartAnnotationLayer as ot,describeAnnotations as Bt}from"../chart/ChartAnnotations.js";import{ChartAxis as at}from"../chart/ChartAxis.js";import{ChartBrushLayer as Pt,useChartBrush as wt}from"../chart/ChartBrush.js";import{ChartContainer as Lt}from"../chart/ChartContainer.js";import{ChartGrid as Rt}from"../chart/ChartGrid.js";import{ChartLegend as At}from"../chart/ChartLegend.js";import{ChartPatternDefs as Tt,patternFill as Et}from"../chart/ChartPatterns.js";import{ChartScaleLegend as Vt}from"../chart/ChartScaleLegend.js";import{useChartSync as Mt}from"../chart/ChartSync.js";import{ChartTableView as It}from"../chart/ChartTableView.js";import{ChartTooltip as Dt,ChartTooltipContent as Ht}from"../chart/ChartTooltip.js";import{CHART_MUTED_COLOR as Wt,createDivergingScale as lt,getSeriesLabel as it,resolveSeriesColor as Nt,toLegendItems as Ot}from"../chart/palette.js";import{buildCartesianGeometry as _t,createCategoryLocator as $t,createPlotContext as Kt,splitOverlay as Ut}from"../chart/utils/cartesian.js";import{collectAllValues as ze,readNumber as Ce}from"../chart/utils/data.js";import{formatAuto as Xt,formatPercent as Gt,formatXValue as zt}from"../chart/utils/format.js";import{chartCursorTarget as Ft,pressChartMark as Yt}from"../chart/utils/keyboard.js";import{binValues as Zt}from"../chart/utils/bins.js";import{buildBarPath as jt,buildLinePath as qt}from"../chart/utils/path.js";import{nearestIndex as Jt,toKey as st}from"../chart/utils/scales.js";import{stackDiverging as Qt,stackExtent as en,stackSeries as tn}from"../chart/utils/stack.js";import{estimateTextWidth as nn}from"../chart/utils/text.js";import{extent as ct,resolveDomain as rn}from"../chart/utils/ticks.js";import{CHART_TOUCH as on,CHART_TOUCH_VERTICAL_DRAG as an}from"../chart/utils/touch.js";import{Fragment as mn,jsx as i,jsxs as he}from"react/jsx-runtime";var ln=24,te=2,sn=4,ue=6,cn=10,Fe=!1,Ye=!1;function Kn(){Fe=!1,Ye=!1}var un=ut(function({bars:f,patterns:n,patternBaseId:h}){return i("g",{children:f.map((m,L)=>he("g",{children:[i("path",{d:m.d,fill:Et(n,h,m.slot,m.color)}),m.label?i("text",{x:m.label.x,y:m.label.y,textAnchor:m.label.anchor,dominantBaseline:"middle",className:"fill-gray-600 text-[10px] [font-variant-numeric:tabular-nums] dark:fill-gray-300",children:m.label.text}):null]},`${m.key}-${L}`))})}),hn=ut(function({lines:f}){return i("g",{children:f.map(n=>he("g",{children:[i("path",{d:n.d,fill:"none",stroke:n.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:n.dashed?"5 4":void 0}),n.markers.map(h=>i("circle",{cx:h.x,cy:h.y,r:3,fill:n.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},`${h.x}-${h.y}`))]},n.key))})});function dn({width:x,height:f,data:n,resolvedSeries:h,x:m,y:L,grid:M,size:ve,orientation:R,stack:H,center:A,centerKey:I,valueColors:K,binned:ne,curve:xe,barSize:ke,showValues:Se,referenceLines:Ie,annotations:U,annotationsLabel:De,patterns:Be,patternBaseId:re,overlay:Pe,brush:P,onBrush:X,brushLabel:He,syncEnabled:We,margin:oe,tooltip:G,onPointClick:z,plotLabel:we,formatValue:W,formatRaw:F,formatX:ae}){let[de,me]=Ge(null),u=de!==null&&de<n.length?de:null,[Ne,Oe]=Ge(null),_e=Mt(),b=We?_e:null,e=V(()=>{let t=R==="vertical",r=h.filter(d=>!d.hidden),o=r.filter(d=>d.type!=="line"),g=r.filter(d=>d.type==="line"),w=o.map(d=>d.key),p=I!==null||H!=="none",O=I!==null?Qt(n,w,{centerKey:I,percent:H==="percent"}):tn(n,w,H),l=p?en(O):ct(ze(n,w)),a=ct(ze(n,g.map(d=>d.key))),s=l===null?a:a===null?l:[Math.min(l[0],a[0]),Math.max(l[1],a[1])],c=_t({width:x,height:f,data:n,x:m,y:L,bounds:s===null?null:[Math.min(s[0],A),Math.max(s[1],A)],margin:oe,orientation:R,placement:"band",bandPaddingInner:ne?0:void 0,formatValue:W,formatX:ae,defaultIncludeZero:A===0}),{valueScale:q,bandwidth:pe,categoryPositions:Ze,innerWidth:je,innerHeight:qe}=c,ht=q(A),Te=Math.max(1,o.length),dt=p?pe:pe/Te,_=Math.min(ke??(ne?Number.POSITIVE_INFINITY:ln),Math.max(1,dt-(p&&!ne?0:te))),mt=p?_:Te*_+(Te-1)*te,Je=(pe-mt)/2,Qe=[],et=d=>p?d.end>=d.start:d.end>=A;O.forEach((d,Ee)=>{let J=-1,Ve=-1;d.segments.forEach((B,se)=>{B.value!==null&&B.outer!==!1&&(et(B)?J=se:Ve=se)});let ie=0,be=0;d.segments.forEach((B,se)=>{if(B.value===null)return;let Ke=o[se],v=et(B),tt=q(p?B.start:A),nt=q(B.end),Q=Math.min(tt,nt),ce=Math.abs(nt-tt),gt=B.base??(v?ie===0:be===0),pt=t?!v:v;p&&!gt&&ce>te&&(ce-=te,pt&&(Q+=te)),v?ie+=1:be+=1;let Me=Ze[Ee]+(p?Je:Je+se*(_+te)),bt=se===(v?J:Ve)?t?v?"top":"bottom":v?"right":"left":"none",yt=t?{x:Me,y:Q,width:_,height:ce}:{x:Q,y:Me,width:ce,height:_},Ue=null;if(Se&&!p){let Xe=F(B.value),rt=nn(Xe,10);if(t){let ee=v?Q:Q+ce,ye=v?ee-ue:ee+ue,Ct=Te>1?_+te:pe;rt<=Ct&&(v?ye>8:ye<qe-4)&&(Ue={x:Me+_/2,y:ye,anchor:"middle",text:Xe})}else{let ee=v?Q+ce:Q,ye=v?je-ee-ue:ee-ue;rt<=ye&&(Ue={x:v?ee+ue:ee-ue,y:Me+_/2,anchor:v?"start":"end",text:Xe})}}Qe.push({key:Ke.key,slot:Ke.slot,color:K&&B.value!==null?K(B.value):Ke.color,d:jt({...yt,radius:sn,round:bt}),label:Ue})})});let ft=g.map(d=>{let Ee=c.categoryCenters.map((J,Ve)=>{let ie=Ce(n[Ve],d.key),be=ie===null?Number.NaN:q(ie);return{x:t?J:be,y:t?be:J,defined:ie!==null}});return{key:d.key,color:d.color,dashed:d.dashed,d:qt(Ee,xe),markers:Ee.filter(J=>J.defined!==!1)}});return{vertical:t,visible:r,locate:$t(c),barSeries:o,rows:O,stacked:p,plot:Kt({geometry:c,width:x,height:f,data:n,series:r,formatValue:W,formatX:ae}),xValues:c.xValues,categoryPositions:Ze,categoryCenters:c.categoryCenters,bandwidth:pe,categoryTicks:c.categoryTicks,valueTicks:c.valueTicks,valueScale:q,baseline:ht,innerWidth:je,innerHeight:qe,margin:c.margin,bars:Qe,lines:ft}},[n,h,m,L,x,f,oe,R,H,A,I,K,ne,xe,ke,Se,W,F,ae]),fe=$(t=>e.visible.map(r=>{let o=Ce(n[t],r.key),g=e.barSeries.indexOf(r),w=g===-1?null:e.rows[t].segments[g],p=o===null?"\u2014":H==="percent"&&w!==null?`${F(o)} (${W(w.end-w.start)})`:W(o);return{seriesKey:r.key,seriesLabel:it(r),color:r.color,value:o,formattedValue:p,datum:n[t]}}),[n,e.visible,e.barSeries,e.rows,H,W,F]),T=b?b.brush:Ne,Le=$(t=>{Oe(t),b?.setBrush(t),X?.(t)},[b,X]),y=wt({enabled:P,active:T!==null,centers:e.categoryCenters,xValues:e.xValues,offset:e.vertical?e.margin.left:e.margin.top,orientation:R,onCommit:Le}),$e=$(t=>{if(y.onPointerMove(t),G===!1||n.length===0)return;let r=t.currentTarget.getBoundingClientRect(),o=e.vertical?t.clientX-r.left-e.margin.left:t.clientY-r.top-e.margin.top,g=Jt(e.categoryCenters,o);me(g>=0?g:null),b?.setHovered(g>=0?e.xValues[g]:null)},[y,G,n.length,e.vertical,e.margin,e.categoryCenters,e.xValues,b]),Re=$(()=>{me(null),b?.setHovered(null)},[b]),C=$(()=>{if(!z||u===null)return;let[t]=fe(u);t&&z({...t,index:u,x:e.xValues[u]})},[z,u,fe,e.xValues]),k=$(t=>{if(n.length===0)return;let r=z&&u!==null&&e.visible.length>0;if(Yt(t,r?C:null))return;y.onKeyDown(t,u);let o=Ft(t.key,u,n.length,e.vertical?"x":"y");o!==void 0&&(t.preventDefault(),me(o),b?.setHovered(o===null?null:e.xValues[o]))},[n.length,u,e.vertical,y,b,e.xValues,e.visible.length,z,C]),Y=$(()=>{y.consumedClick()||C()},[y,C]),N=u!==null||!b?.hovered?null:(()=>{let t=st(b.hovered),r=e.xValues.findIndex(o=>st(o)===t);return r<0?null:r})(),E=u??N,S=y.dragging??T,D=(()=>{if(!S)return null;let t=e.locate(S.from),r=e.locate(S.to);if(t===null||r===null)return null;let o=e.bandwidth/2;return{from:Math.min(t,r)-o,to:Math.max(t,r)+o}})(),Z=Ut(Pe),Ae=u===null?null:fe(u),j=u===null||Ae===null?null:{x:e.xValues[u],xLabel:ae(e.xValues[u],u),index:u,points:Ae},ge=t=>{let r=e.rows[t].segments.filter(o=>o.value!==null).map(o=>e.valueScale(o.end));for(let o of e.lines){let g=Ce(n[t],o.key);g!==null&&r.push(e.valueScale(g))}return r},le=u===null?null:e.vertical?{x:e.margin.left+e.categoryCenters[u],y:e.margin.top+Math.min(...ge(u),e.baseline)}:{x:e.margin.left+Math.max(...ge(u),e.baseline),y:e.margin.top+e.categoryCenters[u]};return he(mn,{children:[he("svg",{width:x,height:f,role:"img","aria-label":we??[e.visible.map(t=>it(t)).join(", "),Bt(U,De)].filter(Boolean).join(". "),tabIndex:0,className:xt(P&&!e.vertical?an:on,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500",P&&"select-none"),onPointerDown:y.onPointerDown,onPointerMove:$e,onPointerUp:y.onPointerUp,onPointerCancel:y.onPointerUp,onPointerLeave:Re,onKeyDown:k,onBlur:Re,onClick:Y,children:[Be?i(Tt,{id:re,entries:h.map(t=>({slot:t.slot,color:t.color}))}):null,he("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[i(Rt,{width:e.innerWidth,height:e.innerHeight,horizontal:e.vertical&&(M==="y"||M==="both")?e.valueTicks.map(t=>t.offset):void 0,vertical:!e.vertical&&(M==="y"||M==="both")?e.valueTicks.map(t=>t.offset):void 0}),U?i(ot,{layer:"under",annotations:U,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight,bandwidth:e.bandwidth}):null,D?i(Pt,{from:D.from,to:D.to,width:e.innerWidth,height:e.innerHeight,orientation:R,live:y.dragging!==null,label:He}):null,E!==null?i("rect",{x:e.vertical?e.categoryPositions[E]:0,y:e.vertical?0:e.categoryPositions[E],width:e.vertical?e.bandwidth:e.innerWidth,height:e.vertical?e.innerHeight:e.bandwidth,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,Z.under?.(e.plot),i(un,{bars:e.bars,patterns:Be,patternBaseId:re}),e.lines.length>0?i(hn,{lines:e.lines}):null,i("line",{x1:e.vertical?0:e.baseline,y1:e.vertical?e.baseline:0,x2:e.vertical?e.innerWidth:e.baseline,y2:e.vertical?e.baseline:e.innerHeight,className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1,shapeRendering:"crispEdges"}),U?i(ot,{annotations:U,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight,bandwidth:e.bandwidth}):null,Z.over?.(e.plot),Ie?.map(t=>{let r=e.valueScale(t.value),o=r<cn?r+12:r-4;return he("g",{children:[i("line",{x1:e.vertical?0:r,y1:e.vertical?r:0,x2:e.vertical?e.innerWidth:r,y2:e.vertical?r:e.innerHeight,stroke:t.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:t.dashed===!1?void 0:"4 4"}),t.label?i("text",{x:e.vertical?e.innerWidth:r+4,y:e.vertical?o:8,textAnchor:e.vertical?"end":"start",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)})]}),i("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:(e.vertical?m.hidden:L?.hidden)?null:i(at,{orientation:"bottom",ticks:e.vertical?e.categoryTicks:e.valueTicks,length:e.innerWidth,label:e.vertical?m.label:L?.label,size:ve})}),i("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:(e.vertical?L?.hidden:m.hidden)?null:i(at,{orientation:"left",ticks:e.vertical?e.valueTicks:e.categoryTicks,length:e.innerHeight,showLine:!1,label:e.vertical?L?.label:m.label,size:ve})})]}),j&&le&&G!==!1?i(Dt,{x:le.x,y:le.y,containerWidth:x,children:typeof G=="function"?G(j):i(Ht,{title:j.xLabel,points:j.points})}):null]})}function Un({data:x,series:f,x:n,y:h,height:m=260,width:L,size:M="md",grid:ve="y",legend:R,tooltip:H=!0,tableView:A=!1,emphasis:I,title:K,description:ne,loading:xe=!1,emptyState:ke,error:Se=!1,errorState:Ie,onRetry:U,actions:De,onPointClick:Be,orientation:re="vertical",stack:Pe="none",diverging:P,bins:X,curve:He="linear",barSize:We,sort:oe="none",showValues:G=!1,referenceLines:z,annotations:we,overlay:W,patterns:F=!1,legendToggle:ae=!0,brush:de=!1,onBrush:me,brushLabel:u,sync:Ne=!0,margin:Oe,locale:_e,plotLabel:b,className:e,...fe}){let T=St(_e),Le=kt(),[y,$e]=Ge(()=>new Set),Re=vt(),C=X!==void 0&&X!==!1,k=C||typeof P!="string"?null:P,Y=!C&&typeof P=="number"?P:0,N=V(()=>{let l=k===null?null:lt([0,Math.max(1,f.length-1)],{center:Math.max(0,f.findIndex(a=>a.key===k)),symmetric:!1});return f.map((a,s)=>({...a,slot:s,hidden:a.hidden||y.has(a.key),color:l&&!a.color&&!I?a.key===k?Wt:l(s):Nt(a,s,I)}))},[f,y,I,k]),E=V(()=>l=>Xt(l,T),[T]),S=V(()=>{if(!C)return null;f.length>1&&!Fe&&(Fe=!0,console.warn("[@synertech/ui] BarChart was given `bins` and more than one series. A histogram counts a single field \u2014 the extra series are ignored. Facet the chart, or draw the distributions side by side."));let l=f[0]?.key??"count",a=n.format?c=>n.format(c,0):c=>E(c),s=Zt(x.map(c=>Ce(c,n.key)),X);return{rows:s.map(c=>({[n.key]:c.from,[l]:c.count})),labels:s.map(c=>`${a(c.from)}\u2013${a(c.to)}`)}},[C,X,x,n.key,n.format,f,E]),D=V(()=>{if(S)return S.rows;if(oe==="none")return x;let l=N.filter(s=>!s.hidden).map(s=>s.key),a=s=>l.reduce((c,q)=>c+(Ce(s,q)??0),0);return[...x].sort((s,c)=>oe==="asc"?a(s)-a(c):a(c)-a(s))},[S,x,oe,N]),Z=!C&&Pe==="percent",Ae=V(()=>Z?{domain:k===null?[0,100]:[-100,100],...h}:h,[Z,k,h]),j=V(()=>{let l=h?.format??(Z?a=>Gt(a,{locale:T,alreadyScaled:!0,maximumFractionDigits:0}):E);return k===null?l:a=>l(Math.abs(a))},[h?.format,Z,T,E,k]),ge=V(()=>S?(l,a)=>S.labels[a]??"":n.format??(l=>zt(l,T)),[S,n.format,T]),le=V(()=>S?{...n,scale:"category"}:n,[S,n]),t=$(l=>{$e(a=>{let s=new Set(a);return s.has(l)?s.delete(l):s.add(l),s})},[]),r=re==="vertical"?we:void 0;we&&re!=="vertical"&&!Ye&&(Ye=!0,console.warn("[@synertech/ui] BarChart was given `annotations` and a horizontal orientation. Annotations are read on the category axis, which runs up the side there: they are ignored. Use `referenceLines` for a threshold on the value axis."));let o=R===void 0?f.length>=2:R!==!1,g=typeof R=="string"?R:"bottom",w=N.filter(l=>!l.hidden),p=w.length,O=V(()=>{if(C||P===void 0||P===!1||k!==null||p!==1)return null;let l=ze(D,w.map(s=>s.key)),a=rn([...l,Y],{domain:h?.domain,includeZero:h?.includeZero??Y===0,ticks:h?.ticks??5});return lt(a,{center:Y})},[C,P,k,p,w,D,Y,h]);return i(Lt,{title:K,description:ne,height:m,width:L,size:M,loading:xe,empty:D.length===0||p===0,emptyState:ke,error:Se,errorState:Ie,onRetry:U,actions:De,tableView:A,legendPosition:g,legend:O?i(Vt,{scale:O,label:h?.label,format:j,size:M,locale:T}):o?i(At,{items:Ot(N,I,F),position:g,marker:"rect",size:M,onToggle:ae?t:void 0}):void 0,table:A?i(It,{data:D,series:N,xKey:le.key,xLabel:n.label??n.key,formatX:ge,formatValue:E,caption:typeof K=="string"?K:void 0}):void 0,className:e,...fe,children:({width:l})=>i(dn,{width:l,height:m,data:D,resolvedSeries:N,x:le,y:Ae,grid:ve,size:M,orientation:re,stack:C?"none":Pe,center:Y,centerKey:k,valueColors:O,binned:C,curve:He,barSize:We,showValues:G,referenceLines:z,annotations:r,annotationsLabel:Le.chartAnnotations,patterns:F&&O===null,patternBaseId:Re,overlay:W,brush:de,onBrush:me,brushLabel:u??Le.chartBrush,syncEnabled:Ne,margin:Oe,tooltip:H,onPointClick:Be,plotLabel:b,formatValue:j,formatRaw:E,formatX:ge})})}export{Un as BarChart,Kn as resetBarChartWarnings};
@@ -1 +1 @@
1
- "use strict";"use client";var se=Object.defineProperty;var ze=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames;var Ge=Object.prototype.hasOwnProperty;var Ke=(s,o)=>{for(var d in o)se(s,d,{get:o[d],enumerable:!0})},qe=(s,o,d,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of De(o))!Ge.call(s,n)&&n!==d&&se(s,n,{get:()=>o[n],enumerable:!(a=ze(o,n))||a.enumerable});return s};var Oe=s=>qe(se({},"__esModule",{value:!0}),s);var Ze={};Ke(Ze,{BoxPlot:()=>je});module.exports=Oe(Ze);var f=require("react"),ue=require("../../lib/i18n.cjs"),me=require("../chart/ChartAxis.cjs"),Ce=require("../chart/ChartContainer.cjs"),ve=require("../chart/ChartGrid.cjs"),ke=require("../chart/ChartTooltip.cjs"),Pe=require("../chart/palette.cjs"),Ne=require("../chart/utils/cartesian.cjs"),B=require("../chart/utils/data.cjs"),ee=require("../chart/utils/format.cjs"),Te=require("../chart/utils/keyboard.cjs"),Be=require("../chart/utils/path.cjs"),we=require("../chart/utils/quantile.cjs"),Se=require("../chart/utils/scales.cjs"),Re=require("../chart/utils/touch.cjs"),Le=require("../table/Table.cjs"),Me=require("../table/TableBody.cjs"),O=require("../table/TableCell.cjs"),$e=require("../table/TableHeader.cjs"),P=require("../table/TableHeaderCell.cjs"),He=require("../table/TableRow.cjs"),t=require("react/jsx-runtime"),_e=40,Qe=3,J=4,ce="text-right [font-variant-numeric:tabular-nums]",Ue=(0,f.memo)(function({boxes:o,color:d}){return(0,t.jsx)("g",{children:o.map(a=>(0,t.jsxs)("g",{children:[(0,t.jsx)("g",{stroke:d,strokeWidth:1.5,strokeLinecap:"round",children:a.whiskers.map(n=>(0,t.jsx)("line",{x1:n.x1,y1:n.y1,x2:n.x2,y2:n.y2},n.key))}),a.body?(0,t.jsx)("path",{d:a.body,fill:d}):null,a.median?(0,t.jsx)("line",{x1:a.median.x1,y1:a.median.y1,x2:a.median.x2,y2:a.median.y2,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"}):null,a.mean?(0,t.jsx)("path",{d:`M${a.mean.cx},${a.mean.cy-J} L${a.mean.cx+J},${a.mean.cy} L${a.mean.cx},${a.mean.cy+J} L${a.mean.cx-J},${a.mean.cy} Z`,strokeWidth:1.5,stroke:d,className:"fill-white dark:fill-gray-800"}):null,a.outliers.map(n=>(0,t.jsx)("circle",{cx:n.cx,cy:n.cy,r:Qe,fill:d,strokeWidth:1.5,className:"stroke-white dark:stroke-gray-800"},n.key))]},a.key))})});function Ye({width:s,height:o,data:d,boxes:a,x:n,y:x,grid:$,size:_,orientation:w,boxSize:Q,showOutliers:U,showMean:I,color:Y,referenceLines:te,margin:z,tooltip:S,plotLabel:ae,formatValue:H,formatX:A,onBoxClick:R}){let[D,E]=(0,f.useState)(null),g=D!==null&&D<a.length?D:null,W=(0,ue.useUILabels)(),e=(0,f.useMemo)(()=>{let l=w==="vertical",c=a.flatMap(m=>m.stats===null?[]:[m.stats.min,m.stats.max,...I&&m.mean!==null?[m.mean]:[]]),b=(0,Ne.buildCartesianGeometry)({width:s,height:o,data:d,x:n,y:x,bounds:c.length===0?null:[Math.min(...c),Math.max(...c)],margin:z,orientation:w,placement:"band",formatValue:H,formatX:A,defaultIncludeZero:!1}),{valueScale:y,bandwidth:C,categoryPositions:N,innerWidth:K,innerHeight:ne}=b,r=Math.min(Q??_e,C),v=r*.5,k=(m,p)=>l?{x:m,y:p}:{x:p,y:m},L=a.map((m,p)=>{let i=N[p]+(C-r)/2,u=i+r/2;if(m.stats===null)return{key:`${p}`,body:"",median:null,whiskers:[],outliers:[],mean:null,top:N[p],height:C};let{q1:T,q3:q,median:j,lower:Ae,upper:Ee,outliers:We}=m.stats,de=y(T),he=y(q),ge=Math.min(de,he),ye=Math.abs(he-de),Xe=(0,Be.buildBarPath)({...l?{x:i,y:ge,width:r,height:Math.max(1,ye)}:{x:ge,y:i,width:Math.max(1,ye),height:r},radius:2,round:"none"}),Z=y(j),Ve=l?{x1:i,y1:Z,x2:i+r,y2:Z}:{x1:Z,y1:i,x2:Z,y2:i+r},le=[];for(let[M,oe,F]of[["lower",Ae,T],["upper",Ee,q]]){let ie=y(oe),Ie=y(F),fe=k(u,ie),pe=k(u,Ie);le.push({key:`${M}-stem`,x1:pe.x,y1:pe.y,x2:fe.x,y2:fe.y});let xe=k(u-v/2,ie),be=k(u+v/2,ie);le.push({key:`${M}-cap`,x1:xe.x,y1:xe.y,x2:be.x,y2:be.y})}return{key:`${p}`,body:Xe,median:Ve,whiskers:le,outliers:U?We.map((M,oe)=>{let F=k(u,y(M));return{key:`${oe}`,cx:F.x,cy:F.y}}):[],mean:I&&m.mean!==null?(()=>{let M=k(u,y(m.mean));return{cx:M.x,cy:M.y}})():null,top:N[p],height:C}});return{vertical:l,rendered:L,categoryPositions:N,categoryCenters:b.categoryCenters,bandwidth:C,categoryTicks:b.categoryTicks,valueTicks:b.valueTicks,valueScale:y,innerWidth:K,innerHeight:ne,margin:b.margin}},[a,d,n,x,s,o,z,w,Q,U,I,H,A]),re=(0,f.useCallback)(l=>{if(S===!1||a.length===0)return;let c=l.currentTarget.getBoundingClientRect(),b=e.vertical?l.clientX-c.left-e.margin.left:l.clientY-c.top-e.margin.top;E((0,Se.nearestIndex)(e.categoryCenters,b))},[S,a.length,e.vertical,e.margin,e.categoryCenters]),G=(0,f.useCallback)(()=>{!R||g===null||R(a[g])},[R,g,a]),X=(0,f.useCallback)(l=>(0,Te.handleChartKeyDown)(l,{count:a.length,current:g,axis:e.vertical?"x":"y",onMove:E,pick:R?G:null}),[a.length,g,e.vertical,R,G]),h=g===null?null:a[g],V=g===null||h===null||h.stats===null?null:e.vertical?{x:e.margin.left+e.categoryCenters[g],y:e.margin.top+e.valueScale(h.stats.q3)}:{x:e.margin.left+e.valueScale(h.stats.q3),y:e.margin.top+e.categoryCenters[g]};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("svg",{width:s,height:o,role:"img","aria-label":ae??a.map(l=>l.label).join(", "),tabIndex:0,className:`${Re.CHART_TOUCH} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500`,onPointerMove:re,onPointerLeave:()=>E(null),onKeyDown:X,onBlur:()=>E(null),onClick:G,children:[(0,t.jsxs)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[(0,t.jsx)(ve.ChartGrid,{width:e.innerWidth,height:e.innerHeight,horizontal:e.vertical&&($==="y"||$==="both")?e.valueTicks.map(l=>l.offset):void 0,vertical:!e.vertical&&($==="y"||$==="both")?e.valueTicks.map(l=>l.offset):void 0}),g!==null?(0,t.jsx)("rect",{x:e.vertical?e.categoryPositions[g]:0,y:e.vertical?0:e.categoryPositions[g],width:e.vertical?e.bandwidth:e.innerWidth,height:e.vertical?e.innerHeight:e.bandwidth,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,te?.map(l=>{let c=e.valueScale(l.value);return(0,t.jsxs)("g",{children:[(0,t.jsx)("line",{x1:e.vertical?0:c,y1:e.vertical?c:0,x2:e.vertical?e.innerWidth:c,y2:e.vertical?c:e.innerHeight,stroke:l.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:l.dashed===!1?void 0:"4 4"}),l.label?(0,t.jsx)("text",{x:e.vertical?e.innerWidth:c+4,y:e.vertical?c-4:8,textAnchor:e.vertical?"end":"start",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:l.label}):null]},`${l.value}-${l.label??""}`)}),(0,t.jsx)(Ue,{boxes:e.rendered,color:Y})]}),(0,t.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:(e.vertical?n.hidden:x?.hidden)?null:(0,t.jsx)(me.ChartAxis,{orientation:"bottom",ticks:e.vertical?e.categoryTicks:e.valueTicks,length:e.innerWidth,label:e.vertical?n.label:x?.label,size:_})}),(0,t.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:(e.vertical?x?.hidden:n.hidden)?null:(0,t.jsx)(me.ChartAxis,{orientation:"left",ticks:e.vertical?e.valueTicks:e.categoryTicks,length:e.innerHeight,showLine:!1,label:e.vertical?x?.label:n.label,size:_})})]}),h&&h.stats&&V&&S!==!1?(0,t.jsx)(ke.ChartTooltip,{x:V.x,y:V.y,containerWidth:s,children:typeof S=="function"?S(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)("dl",{className:"grid grid-cols-[auto_auto] gap-x-3 gap-y-0.5",children:[[[W.chartMax,h.stats.max],["Q3",h.stats.q3],[W.chartMedian,h.stats.median],["Q1",h.stats.q1],[W.chartMin,h.stats.min]].map(([l,c])=>(0,t.jsxs)("div",{className:"contents",children:[(0,t.jsx)("dt",{className:"text-gray-500 dark:text-gray-400",children:l}),(0,t.jsx)("dd",{className:"justify-self-end font-medium text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:H(c)})]},l)),(0,t.jsxs)("div",{className:"contents",children:[(0,t.jsx)("dt",{className:"text-gray-500 dark:text-gray-400",children:W.chartCount}),(0,t.jsx)("dd",{className:"justify-self-end font-medium text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:h.stats.count})]})]})]})}):null]})}function je({data:s,x:o,y:d,values:a,quantiles:n,whisker:x=1.5,orientation:$="vertical",boxSize:_,showOutliers:w=!0,showMean:Q=!1,color:U,referenceLines:I,height:Y=280,width:te,size:z="md",grid:S="y",tooltip:ae=!0,tableView:H=!1,title:A,description:R,loading:D=!1,emptyState:E,error:g=!1,errorState:W,onRetry:e,actions:re,margin:G,locale:X,plotLabel:h,format:V,onBoxClick:l,className:c,...b}){let y=(0,ue.useUILabels)(),C=(0,f.useMemo)(()=>d?.format??V??(r=>(0,ee.formatAuto)(r,X)),[d?.format,V,X]),N=(0,f.useMemo)(()=>o.format??(r=>(0,ee.formatXValue)(r,X)),[o.format,X]),K=(0,f.useMemo)(()=>s.map((r,v)=>{let k=(0,B.readXValue)(r,o.key,v),L=a?(()=>{let i=r[a];return Array.isArray(i)?i.map(u=>typeof u=="number"?u:Number(u)).filter(u=>Number.isFinite(u)):null})():null,m=null,p=null;if(L!==null)m=(0,we.boxStats)(L,x),p=L.length===0?null:L.reduce((i,u)=>i+u,0)/L.length;else if(n){let i=(0,B.readNumber)(r,n.q1),u=(0,B.readNumber)(r,n.median),T=(0,B.readNumber)(r,n.q3);if(i!==null&&u!==null&&T!==null){let q=n.min?(0,B.readNumber)(r,n.min)??i:i,j=n.max?(0,B.readNumber)(r,n.max)??T:T;m={count:0,min:q,max:j,q1:i,median:u,q3:T,iqr:T-i,lower:q,upper:j,outliers:[]}}}return{index:v,x:k,label:N(k,v),stats:m,mean:p,datum:r}}),[s,o.key,a,n,x,N]),ne=K.filter(r=>r.stats!==null);return(0,t.jsx)(Ce.ChartContainer,{title:A,description:R,height:Y,width:te,size:z,loading:D,empty:ne.length===0,emptyState:E,error:g,errorState:W,onRetry:e,actions:re,tableView:H,table:H?(0,t.jsx)("div",{className:"w-full overflow-x-auto",children:(0,t.jsxs)(Le.Table,{children:[typeof A=="string"?(0,t.jsx)("caption",{className:"sr-only",children:A}):null,(0,t.jsxs)($e.TableHeader,{children:[(0,t.jsx)(P.TableHeaderCell,{children:o.label??o.key}),a?(0,t.jsx)(P.TableHeaderCell,{className:"text-right",children:y.chartCount}):null,(0,t.jsx)(P.TableHeaderCell,{className:"text-right",children:y.chartMin}),(0,t.jsx)(P.TableHeaderCell,{className:"text-right",children:"Q1"}),(0,t.jsx)(P.TableHeaderCell,{className:"text-right",children:y.chartMedian}),(0,t.jsx)(P.TableHeaderCell,{className:"text-right",children:"Q3"}),(0,t.jsx)(P.TableHeaderCell,{className:"text-right",children:y.chartMax}),a&&w?(0,t.jsx)(P.TableHeaderCell,{className:"text-right",children:y.chartOutliers}):null]}),(0,t.jsx)(Me.TableBody,{children:K.map(r=>(0,t.jsxs)(He.TableRow,{clickable:!1,children:[(0,t.jsx)(O.TableCell,{className:"font-medium text-gray-900 dark:text-gray-100",children:r.label}),a?(0,t.jsx)(O.TableCell,{className:ce,children:r.stats?.count??"\u2014"}):null,["min","q1","median","q3","max"].map(v=>(0,t.jsx)(O.TableCell,{className:ce,children:r.stats===null?"\u2014":C(r.stats[v])},v)),a&&w?(0,t.jsx)(O.TableCell,{className:ce,children:r.stats===null||r.stats.outliers.length===0?"\u2014":r.stats.outliers.map(C).join(", ")}):null]},r.index))})]})}):void 0,className:c,...b,children:({width:r})=>(0,t.jsx)(Ye,{width:r,height:Y,data:s,boxes:K,x:o,y:d,grid:S,size:z,orientation:$,boxSize:_,showOutliers:w,showMean:Q,color:U??(0,Pe.getSeriesColor)(0),referenceLines:I,margin:G,tooltip:ae,plotLabel:h,formatValue:C,formatX:N,onBoxClick:l})})}0&&(module.exports={BoxPlot});
1
+ "use strict";"use client";var me=Object.defineProperty;var ze=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames;var Ge=Object.prototype.hasOwnProperty;var Ke=(s,o)=>{for(var u in o)me(s,u,{get:o[u],enumerable:!0})},qe=(s,o,u,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of De(o))!Ge.call(s,r)&&r!==u&&me(s,r,{get:()=>o[r],enumerable:!(a=ze(o,r))||a.enumerable});return s};var Oe=s=>qe(me({},"__esModule",{value:!0}),s);var Ze={};Ke(Ze,{BoxPlot:()=>je});module.exports=Oe(Ze);var p=require("react"),O=require("../../lib/i18n.cjs"),de=require("../chart/ChartAxis.cjs"),ve=require("../chart/ChartContainer.cjs"),ke=require("../chart/ChartGrid.cjs"),Pe=require("../chart/ChartTooltip.cjs"),Ne=require("../chart/palette.cjs"),Te=require("../chart/utils/cartesian.cjs"),w=require("../chart/utils/data.cjs"),ae=require("../chart/utils/format.cjs"),Be=require("../chart/utils/keyboard.cjs"),we=require("../chart/utils/path.cjs"),Se=require("../chart/utils/quantile.cjs"),Le=require("../chart/utils/scales.cjs"),Re=require("../chart/utils/touch.cjs"),Me=require("../table/Table.cjs"),$e=require("../table/TableBody.cjs"),q=require("../table/TableCell.cjs"),He=require("../table/TableHeader.cjs"),N=require("../table/TableHeaderCell.cjs"),Ae=require("../table/TableRow.cjs"),t=require("react/jsx-runtime"),Ue=40,_e=3,te=4,ue="text-right [font-variant-numeric:tabular-nums]",Qe=(0,p.memo)(function({boxes:o,color:u}){return(0,t.jsx)("g",{children:o.map(a=>(0,t.jsxs)("g",{children:[(0,t.jsx)("g",{stroke:u,strokeWidth:1.5,strokeLinecap:"round",children:a.whiskers.map(r=>(0,t.jsx)("line",{x1:r.x1,y1:r.y1,x2:r.x2,y2:r.y2},r.key))}),a.body?(0,t.jsx)("path",{d:a.body,fill:u}):null,a.median?(0,t.jsx)("line",{x1:a.median.x1,y1:a.median.y1,x2:a.median.x2,y2:a.median.y2,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"}):null,a.mean?(0,t.jsx)("path",{d:`M${a.mean.cx},${a.mean.cy-te} L${a.mean.cx+te},${a.mean.cy} L${a.mean.cx},${a.mean.cy+te} L${a.mean.cx-te},${a.mean.cy} Z`,strokeWidth:1.5,stroke:u,className:"fill-white dark:fill-gray-800"}):null,a.outliers.map(r=>(0,t.jsx)("circle",{cx:r.cx,cy:r.cy,r:_e,fill:u,strokeWidth:1.5,className:"stroke-white dark:stroke-gray-800"},r.key))]},a.key))})});function Ye({width:s,height:o,data:u,boxes:a,x:r,y:v,grid:$,size:U,orientation:S,boxSize:_,showOutliers:Q,showMean:I,color:Y,referenceLines:re,margin:V,tooltip:L,plotLabel:ne,formatValue:H,formatX:A,onBoxClick:R}){let[z,E]=(0,p.useState)(null),h=z!==null&&z<a.length?z:null,W=(0,O.useUILabels)(),e=(0,p.useMemo)(()=>{let n=S==="vertical",c=a.flatMap(i=>i.stats===null?[]:[i.stats.min,i.stats.max,...I&&i.mean!==null?[i.mean]:[]]),k=(0,Te.buildCartesianGeometry)({width:s,height:o,data:u,x:r,y:v,bounds:c.length===0?null:[Math.min(...c),Math.max(...c)],margin:V,orientation:S,placement:"band",formatValue:H,formatX:A,defaultIncludeZero:!1}),{valueScale:g,bandwidth:b,categoryPositions:T,innerWidth:G,innerHeight:K}=k,P=Math.min(_??Ue,b),l=P*.5,y=(i,x)=>n?{x:i,y:x}:{x,y:i},j=a.map((i,x)=>{let C=T[x]+(b-P)/2,m=C+P/2;if(i.stats===null)return{key:`${x}`,body:"",median:null,whiskers:[],outliers:[],mean:null,top:T[x],height:b};let{q1:f,q3:B,median:Z,lower:F,upper:Ee,outliers:We}=i.stats,he=g(f),ge=g(B),ye=Math.min(he,ge),fe=Math.abs(ge-he),Xe=(0,we.buildBarPath)({...n?{x:C,y:ye,width:P,height:Math.max(1,fe)}:{x:ye,y:C,width:Math.max(1,fe),height:P},radius:2,round:"none"}),J=g(Z),Ie=n?{x1:C,y1:J,x2:C+P,y2:J}:{x1:J,y1:C,x2:J,y2:C+P},ie=[];for(let[M,se,ee]of[["lower",F,f],["upper",Ee,B]]){let ce=g(se),Ve=g(ee),pe=y(m,ce),xe=y(m,Ve);ie.push({key:`${M}-stem`,x1:xe.x,y1:xe.y,x2:pe.x,y2:pe.y});let be=y(m-l/2,ce),Ce=y(m+l/2,ce);ie.push({key:`${M}-cap`,x1:be.x,y1:be.y,x2:Ce.x,y2:Ce.y})}return{key:`${x}`,body:Xe,median:Ie,whiskers:ie,outliers:Q?We.map((M,se)=>{let ee=y(m,g(M));return{key:`${se}`,cx:ee.x,cy:ee.y}}):[],mean:I&&i.mean!==null?(()=>{let M=y(m,g(i.mean));return{cx:M.x,cy:M.y}})():null,top:T[x],height:b}});return{vertical:n,rendered:j,categoryPositions:T,categoryCenters:k.categoryCenters,bandwidth:b,categoryTicks:k.categoryTicks,valueTicks:k.valueTicks,valueScale:g,innerWidth:G,innerHeight:K,margin:k.margin}},[a,u,r,v,s,o,V,S,_,Q,I,H,A]),le=(0,p.useCallback)(n=>{if(L===!1||a.length===0)return;let c=n.currentTarget.getBoundingClientRect(),k=e.vertical?n.clientX-c.left-e.margin.left:n.clientY-c.top-e.margin.top;E((0,Le.nearestIndex)(e.categoryCenters,k))},[L,a.length,e.vertical,e.margin,e.categoryCenters]),D=(0,p.useCallback)(()=>{!R||h===null||R(a[h])},[R,h,a]),oe=(0,p.useCallback)(n=>(0,Be.handleChartKeyDown)(n,{count:a.length,current:h,axis:e.vertical?"x":"y",onMove:E,pick:R?D:null}),[a.length,h,e.vertical,R,D]),d=h===null?null:a[h],X=h===null||d===null||d.stats===null?null:e.vertical?{x:e.margin.left+e.categoryCenters[h],y:e.margin.top+e.valueScale(d.stats.q3)}:{x:e.margin.left+e.valueScale(d.stats.q3),y:e.margin.top+e.categoryCenters[h]};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("svg",{width:s,height:o,role:"img","aria-label":ne??a.map(n=>n.label).join(", "),tabIndex:0,className:`${Re.CHART_TOUCH} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500`,onPointerMove:le,onPointerLeave:()=>E(null),onKeyDown:oe,onBlur:()=>E(null),onClick:D,children:[(0,t.jsxs)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[(0,t.jsx)(ke.ChartGrid,{width:e.innerWidth,height:e.innerHeight,horizontal:e.vertical&&($==="y"||$==="both")?e.valueTicks.map(n=>n.offset):void 0,vertical:!e.vertical&&($==="y"||$==="both")?e.valueTicks.map(n=>n.offset):void 0}),h!==null?(0,t.jsx)("rect",{x:e.vertical?e.categoryPositions[h]:0,y:e.vertical?0:e.categoryPositions[h],width:e.vertical?e.bandwidth:e.innerWidth,height:e.vertical?e.innerHeight:e.bandwidth,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,re?.map(n=>{let c=e.valueScale(n.value);return(0,t.jsxs)("g",{children:[(0,t.jsx)("line",{x1:e.vertical?0:c,y1:e.vertical?c:0,x2:e.vertical?e.innerWidth:c,y2:e.vertical?c:e.innerHeight,stroke:n.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:n.dashed===!1?void 0:"4 4"}),n.label?(0,t.jsx)("text",{x:e.vertical?e.innerWidth:c+4,y:e.vertical?c-4:8,textAnchor:e.vertical?"end":"start",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:n.label}):null]},`${n.value}-${n.label??""}`)}),(0,t.jsx)(Qe,{boxes:e.rendered,color:Y})]}),(0,t.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:(e.vertical?r.hidden:v?.hidden)?null:(0,t.jsx)(de.ChartAxis,{orientation:"bottom",ticks:e.vertical?e.categoryTicks:e.valueTicks,length:e.innerWidth,label:e.vertical?r.label:v?.label,size:U})}),(0,t.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:(e.vertical?v?.hidden:r.hidden)?null:(0,t.jsx)(de.ChartAxis,{orientation:"left",ticks:e.vertical?e.valueTicks:e.categoryTicks,length:e.innerHeight,showLine:!1,label:e.vertical?v?.label:r.label,size:U})})]}),d&&d.stats&&X&&L!==!1?(0,t.jsx)(Pe.ChartTooltip,{x:X.x,y:X.y,containerWidth:s,children:typeof L=="function"?L(d):(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:d.label}),(0,t.jsxs)("dl",{className:"grid grid-cols-[auto_auto] gap-x-3 gap-y-0.5",children:[[[W.chartMax,d.stats.max],["Q3",d.stats.q3],[W.chartMedian,d.stats.median],["Q1",d.stats.q1],[W.chartMin,d.stats.min]].map(([n,c])=>(0,t.jsxs)("div",{className:"contents",children:[(0,t.jsx)("dt",{className:"text-gray-500 dark:text-gray-400",children:n}),(0,t.jsx)("dd",{className:"justify-self-end font-medium text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:H(c)})]},n)),(0,t.jsxs)("div",{className:"contents",children:[(0,t.jsx)("dt",{className:"text-gray-500 dark:text-gray-400",children:W.chartCount}),(0,t.jsx)("dd",{className:"justify-self-end font-medium text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:d.stats.count})]})]})]})}):null]})}function je({data:s,x:o,y:u,values:a,quantiles:r,whisker:v=1.5,orientation:$="vertical",boxSize:U,showOutliers:S=!0,showMean:_=!1,color:Q,referenceLines:I,height:Y=280,width:re,size:V="md",grid:L="y",tooltip:ne=!0,tableView:H=!1,title:A,description:R,loading:z=!1,emptyState:E,error:h=!1,errorState:W,onRetry:e,actions:le,margin:D,locale:oe,plotLabel:d,format:X,onBoxClick:n,className:c,...k}){let g=(0,O.useUILocale)(oe),b=(0,O.useUILabels)(),T=(0,p.useMemo)(()=>u?.format??X??(l=>(0,ae.formatAuto)(l,g)),[u?.format,X,g]),G=(0,p.useMemo)(()=>o.format??(l=>(0,ae.formatXValue)(l,g)),[o.format,g]),K=(0,p.useMemo)(()=>s.map((l,y)=>{let j=(0,w.readXValue)(l,o.key,y),i=a?(()=>{let m=l[a];return Array.isArray(m)?m.map(f=>typeof f=="number"?f:Number(f)).filter(f=>Number.isFinite(f)):null})():null,x=null,C=null;if(i!==null)x=(0,Se.boxStats)(i,v),C=i.length===0?null:i.reduce((m,f)=>m+f,0)/i.length;else if(r){let m=(0,w.readNumber)(l,r.q1),f=(0,w.readNumber)(l,r.median),B=(0,w.readNumber)(l,r.q3);if(m!==null&&f!==null&&B!==null){let Z=r.min?(0,w.readNumber)(l,r.min)??m:m,F=r.max?(0,w.readNumber)(l,r.max)??B:B;x={count:0,min:Z,max:F,q1:m,median:f,q3:B,iqr:B-m,lower:Z,upper:F,outliers:[]}}}return{index:y,x:j,label:G(j,y),stats:x,mean:C,datum:l}}),[s,o.key,a,r,v,G]),P=K.filter(l=>l.stats!==null);return(0,t.jsx)(ve.ChartContainer,{title:A,description:R,height:Y,width:re,size:V,loading:z,empty:P.length===0,emptyState:E,error:h,errorState:W,onRetry:e,actions:le,tableView:H,table:H?(0,t.jsx)("div",{className:"w-full overflow-x-auto",children:(0,t.jsxs)(Me.Table,{children:[typeof A=="string"?(0,t.jsx)("caption",{className:"sr-only",children:A}):null,(0,t.jsxs)(He.TableHeader,{children:[(0,t.jsx)(N.TableHeaderCell,{children:o.label??o.key}),a?(0,t.jsx)(N.TableHeaderCell,{className:"text-right",children:b.chartCount}):null,(0,t.jsx)(N.TableHeaderCell,{className:"text-right",children:b.chartMin}),(0,t.jsx)(N.TableHeaderCell,{className:"text-right",children:"Q1"}),(0,t.jsx)(N.TableHeaderCell,{className:"text-right",children:b.chartMedian}),(0,t.jsx)(N.TableHeaderCell,{className:"text-right",children:"Q3"}),(0,t.jsx)(N.TableHeaderCell,{className:"text-right",children:b.chartMax}),a&&S?(0,t.jsx)(N.TableHeaderCell,{className:"text-right",children:b.chartOutliers}):null]}),(0,t.jsx)($e.TableBody,{children:K.map(l=>(0,t.jsxs)(Ae.TableRow,{clickable:!1,children:[(0,t.jsx)(q.TableCell,{className:"font-medium text-gray-900 dark:text-gray-100",children:l.label}),a?(0,t.jsx)(q.TableCell,{className:ue,children:l.stats?.count??"\u2014"}):null,["min","q1","median","q3","max"].map(y=>(0,t.jsx)(q.TableCell,{className:ue,children:l.stats===null?"\u2014":T(l.stats[y])},y)),a&&S?(0,t.jsx)(q.TableCell,{className:ue,children:l.stats===null||l.stats.outliers.length===0?"\u2014":l.stats.outliers.map(T).join(", ")}):null]},l.index))})]})}):void 0,className:c,...k,children:({width:l})=>(0,t.jsx)(Ye,{width:l,height:Y,data:s,boxes:K,x:o,y:u,grid:L,size:V,orientation:$,boxSize:U,showOutliers:S,showMean:_,color:Q??(0,Ne.getSeriesColor)(0),referenceLines:I,margin:D,tooltip:ne,plotLabel:d,formatValue:T,formatX:G,onBoxClick:n})})}0&&(module.exports={BoxPlot});
@@ -1 +1 @@
1
- "use client";import{memo as Be,useCallback as se,useMemo as ee,useState as we}from"react";import{useUILabels as be}from"../../lib/i18n.js";import{ChartAxis as xe}from"../chart/ChartAxis.js";import{ChartContainer as Se}from"../chart/ChartContainer.js";import{ChartGrid as Re}from"../chart/ChartGrid.js";import{ChartTooltip as Le}from"../chart/ChartTooltip.js";import{getSeriesColor as Me}from"../chart/palette.js";import{buildCartesianGeometry as $e}from"../chart/utils/cartesian.js";import{readNumber as q,readXValue as He}from"../chart/utils/data.js";import{formatAuto as Ae,formatXValue as Ee}from"../chart/utils/format.js";import{handleChartKeyDown as We}from"../chart/utils/keyboard.js";import{buildBarPath as Xe}from"../chart/utils/path.js";import{boxStats as Ve}from"../chart/utils/quantile.js";import{nearestIndex as Ie}from"../chart/utils/scales.js";import{CHART_TOUCH as ze}from"../chart/utils/touch.js";import{Table as De}from"../table/Table.js";import{TableBody as Ge}from"../table/TableBody.js";import{TableCell as F}from"../table/TableCell.js";import{TableHeader as Ke}from"../table/TableHeader.js";import{TableHeaderCell as T}from"../table/TableHeaderCell.js";import{TableRow as qe}from"../table/TableRow.js";import{Fragment as Ye,jsx as a,jsxs as g}from"react/jsx-runtime";var Oe=40,_e=3,J=4,ce="text-right [font-variant-numeric:tabular-nums]",Qe=Be(function({boxes:h,color:y}){return a("g",{children:h.map(t=>g("g",{children:[a("g",{stroke:y,strokeWidth:1.5,strokeLinecap:"round",children:t.whiskers.map(l=>a("line",{x1:l.x1,y1:l.y1,x2:l.x2,y2:l.y2},l.key))}),t.body?a("path",{d:t.body,fill:y}):null,t.median?a("line",{x1:t.median.x1,y1:t.median.y1,x2:t.median.x2,y2:t.median.y2,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"}):null,t.mean?a("path",{d:`M${t.mean.cx},${t.mean.cy-J} L${t.mean.cx+J},${t.mean.cy} L${t.mean.cx},${t.mean.cy+J} L${t.mean.cx-J},${t.mean.cy} Z`,strokeWidth:1.5,stroke:y,className:"fill-white dark:fill-gray-800"}):null,t.outliers.map(l=>a("circle",{cx:l.cx,cy:l.cy,r:_e,fill:y,strokeWidth:1.5,className:"stroke-white dark:stroke-gray-800"},l.key))]},t.key))})});function Ue({width:p,height:h,data:y,boxes:t,x:l,y:x,grid:M,size:O,orientation:B,boxSize:_,showOutliers:Q,showMean:V,color:U,referenceLines:te,margin:I,tooltip:w,plotLabel:ae,formatValue:$,formatX:H,onBoxClick:S}){let[z,A]=we(null),u=z!==null&&z<t.length?z:null,E=be(),e=ee(()=>{let n=B==="vertical",i=t.flatMap(s=>s.stats===null?[]:[s.stats.min,s.stats.max,...V&&s.mean!==null?[s.mean]:[]]),b=$e({width:p,height:h,data:y,x:l,y:x,bounds:i.length===0?null:[Math.min(...i),Math.max(...i)],margin:I,orientation:B,placement:"band",formatValue:$,formatX:H,defaultIncludeZero:!1}),{valueScale:d,bandwidth:C,categoryPositions:P,innerWidth:G,innerHeight:ne}=b,r=Math.min(_??Oe,C),v=r*.5,k=(s,f)=>n?{x:s,y:f}:{x:f,y:s},R=t.map((s,f)=>{let o=P[f]+(C-r)/2,c=o+r/2;if(s.stats===null)return{key:`${f}`,body:"",median:null,whiskers:[],outliers:[],mean:null,top:P[f],height:C};let{q1:N,q3:K,median:Y,lower:Ce,upper:ve,outliers:ke}=s.stats,me=d(N),ue=d(K),de=Math.min(me,ue),he=Math.abs(ue-me),Pe=Xe({...n?{x:o,y:de,width:r,height:Math.max(1,he)}:{x:de,y:o,width:Math.max(1,he),height:r},radius:2,round:"none"}),j=d(Y),Ne=n?{x1:o,y1:j,x2:o+r,y2:j}:{x1:j,y1:o,x2:j,y2:o+r},le=[];for(let[L,oe,Z]of[["lower",Ce,N],["upper",ve,K]]){let ie=d(oe),Te=d(Z),ge=k(c,ie),ye=k(c,Te);le.push({key:`${L}-stem`,x1:ye.x,y1:ye.y,x2:ge.x,y2:ge.y});let fe=k(c-v/2,ie),pe=k(c+v/2,ie);le.push({key:`${L}-cap`,x1:fe.x,y1:fe.y,x2:pe.x,y2:pe.y})}return{key:`${f}`,body:Pe,median:Ne,whiskers:le,outliers:Q?ke.map((L,oe)=>{let Z=k(c,d(L));return{key:`${oe}`,cx:Z.x,cy:Z.y}}):[],mean:V&&s.mean!==null?(()=>{let L=k(c,d(s.mean));return{cx:L.x,cy:L.y}})():null,top:P[f],height:C}});return{vertical:n,rendered:R,categoryPositions:P,categoryCenters:b.categoryCenters,bandwidth:C,categoryTicks:b.categoryTicks,valueTicks:b.valueTicks,valueScale:d,innerWidth:G,innerHeight:ne,margin:b.margin}},[t,y,l,x,p,h,I,B,_,Q,V,$,H]),re=se(n=>{if(w===!1||t.length===0)return;let i=n.currentTarget.getBoundingClientRect(),b=e.vertical?n.clientX-i.left-e.margin.left:n.clientY-i.top-e.margin.top;A(Ie(e.categoryCenters,b))},[w,t.length,e.vertical,e.margin,e.categoryCenters]),D=se(()=>{!S||u===null||S(t[u])},[S,u,t]),W=se(n=>We(n,{count:t.length,current:u,axis:e.vertical?"x":"y",onMove:A,pick:S?D:null}),[t.length,u,e.vertical,S,D]),m=u===null?null:t[u],X=u===null||m===null||m.stats===null?null:e.vertical?{x:e.margin.left+e.categoryCenters[u],y:e.margin.top+e.valueScale(m.stats.q3)}:{x:e.margin.left+e.valueScale(m.stats.q3),y:e.margin.top+e.categoryCenters[u]};return g(Ye,{children:[g("svg",{width:p,height:h,role:"img","aria-label":ae??t.map(n=>n.label).join(", "),tabIndex:0,className:`${ze} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500`,onPointerMove:re,onPointerLeave:()=>A(null),onKeyDown:W,onBlur:()=>A(null),onClick:D,children:[g("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[a(Re,{width:e.innerWidth,height:e.innerHeight,horizontal:e.vertical&&(M==="y"||M==="both")?e.valueTicks.map(n=>n.offset):void 0,vertical:!e.vertical&&(M==="y"||M==="both")?e.valueTicks.map(n=>n.offset):void 0}),u!==null?a("rect",{x:e.vertical?e.categoryPositions[u]:0,y:e.vertical?0:e.categoryPositions[u],width:e.vertical?e.bandwidth:e.innerWidth,height:e.vertical?e.innerHeight:e.bandwidth,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,te?.map(n=>{let i=e.valueScale(n.value);return g("g",{children:[a("line",{x1:e.vertical?0:i,y1:e.vertical?i:0,x2:e.vertical?e.innerWidth:i,y2:e.vertical?i:e.innerHeight,stroke:n.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:n.dashed===!1?void 0:"4 4"}),n.label?a("text",{x:e.vertical?e.innerWidth:i+4,y:e.vertical?i-4:8,textAnchor:e.vertical?"end":"start",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:n.label}):null]},`${n.value}-${n.label??""}`)}),a(Qe,{boxes:e.rendered,color:U})]}),a("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:(e.vertical?l.hidden:x?.hidden)?null:a(xe,{orientation:"bottom",ticks:e.vertical?e.categoryTicks:e.valueTicks,length:e.innerWidth,label:e.vertical?l.label:x?.label,size:O})}),a("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:(e.vertical?x?.hidden:l.hidden)?null:a(xe,{orientation:"left",ticks:e.vertical?e.valueTicks:e.categoryTicks,length:e.innerHeight,showLine:!1,label:e.vertical?x?.label:l.label,size:O})})]}),m&&m.stats&&X&&w!==!1?a(Le,{x:X.x,y:X.y,containerWidth:p,children:typeof w=="function"?w(m):g("div",{className:"flex flex-col gap-1",children:[a("div",{className:"font-medium text-gray-900 dark:text-gray-100",children:m.label}),g("dl",{className:"grid grid-cols-[auto_auto] gap-x-3 gap-y-0.5",children:[[[E.chartMax,m.stats.max],["Q3",m.stats.q3],[E.chartMedian,m.stats.median],["Q1",m.stats.q1],[E.chartMin,m.stats.min]].map(([n,i])=>g("div",{className:"contents",children:[a("dt",{className:"text-gray-500 dark:text-gray-400",children:n}),a("dd",{className:"justify-self-end font-medium text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:$(i)})]},n)),g("div",{className:"contents",children:[a("dt",{className:"text-gray-500 dark:text-gray-400",children:E.chartCount}),a("dd",{className:"justify-self-end font-medium text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:m.stats.count})]})]})]})}):null]})}function pt({data:p,x:h,y,values:t,quantiles:l,whisker:x=1.5,orientation:M="vertical",boxSize:O,showOutliers:B=!0,showMean:_=!1,color:Q,referenceLines:V,height:U=280,width:te,size:I="md",grid:w="y",tooltip:ae=!0,tableView:$=!1,title:H,description:S,loading:z=!1,emptyState:A,error:u=!1,errorState:E,onRetry:e,actions:re,margin:D,locale:W,plotLabel:m,format:X,onBoxClick:n,className:i,...b}){let d=be(),C=ee(()=>y?.format??X??(r=>Ae(r,W)),[y?.format,X,W]),P=ee(()=>h.format??(r=>Ee(r,W)),[h.format,W]),G=ee(()=>p.map((r,v)=>{let k=He(r,h.key,v),R=t?(()=>{let o=r[t];return Array.isArray(o)?o.map(c=>typeof c=="number"?c:Number(c)).filter(c=>Number.isFinite(c)):null})():null,s=null,f=null;if(R!==null)s=Ve(R,x),f=R.length===0?null:R.reduce((o,c)=>o+c,0)/R.length;else if(l){let o=q(r,l.q1),c=q(r,l.median),N=q(r,l.q3);if(o!==null&&c!==null&&N!==null){let K=l.min?q(r,l.min)??o:o,Y=l.max?q(r,l.max)??N:N;s={count:0,min:K,max:Y,q1:o,median:c,q3:N,iqr:N-o,lower:K,upper:Y,outliers:[]}}}return{index:v,x:k,label:P(k,v),stats:s,mean:f,datum:r}}),[p,h.key,t,l,x,P]),ne=G.filter(r=>r.stats!==null);return a(Se,{title:H,description:S,height:U,width:te,size:I,loading:z,empty:ne.length===0,emptyState:A,error:u,errorState:E,onRetry:e,actions:re,tableView:$,table:$?a("div",{className:"w-full overflow-x-auto",children:g(De,{children:[typeof H=="string"?a("caption",{className:"sr-only",children:H}):null,g(Ke,{children:[a(T,{children:h.label??h.key}),t?a(T,{className:"text-right",children:d.chartCount}):null,a(T,{className:"text-right",children:d.chartMin}),a(T,{className:"text-right",children:"Q1"}),a(T,{className:"text-right",children:d.chartMedian}),a(T,{className:"text-right",children:"Q3"}),a(T,{className:"text-right",children:d.chartMax}),t&&B?a(T,{className:"text-right",children:d.chartOutliers}):null]}),a(Ge,{children:G.map(r=>g(qe,{clickable:!1,children:[a(F,{className:"font-medium text-gray-900 dark:text-gray-100",children:r.label}),t?a(F,{className:ce,children:r.stats?.count??"\u2014"}):null,["min","q1","median","q3","max"].map(v=>a(F,{className:ce,children:r.stats===null?"\u2014":C(r.stats[v])},v)),t&&B?a(F,{className:ce,children:r.stats===null||r.stats.outliers.length===0?"\u2014":r.stats.outliers.map(C).join(", ")}):null]},r.index))})]})}):void 0,className:i,...b,children:({width:r})=>a(Ue,{width:r,height:U,data:p,boxes:G,x:h,y,grid:w,size:I,orientation:M,boxSize:O,showOutliers:B,showMean:_,color:Q??Me(0),referenceLines:V,margin:D,tooltip:ae,plotLabel:m,formatValue:C,formatX:P,onBoxClick:n})})}export{pt as BoxPlot};
1
+ "use client";import{memo as Be,useCallback as ce,useMemo as te,useState as we}from"react";import{useUILabels as Ce,useUILocale as Se}from"../../lib/i18n.js";import{ChartAxis as be}from"../chart/ChartAxis.js";import{ChartContainer as Le}from"../chart/ChartContainer.js";import{ChartGrid as Re}from"../chart/ChartGrid.js";import{ChartTooltip as Me}from"../chart/ChartTooltip.js";import{getSeriesColor as $e}from"../chart/palette.js";import{buildCartesianGeometry as He}from"../chart/utils/cartesian.js";import{readNumber as K,readXValue as Ae}from"../chart/utils/data.js";import{formatAuto as Ee,formatXValue as We}from"../chart/utils/format.js";import{handleChartKeyDown as Xe}from"../chart/utils/keyboard.js";import{buildBarPath as Ie}from"../chart/utils/path.js";import{boxStats as Ve}from"../chart/utils/quantile.js";import{nearestIndex as ze}from"../chart/utils/scales.js";import{CHART_TOUCH as De}from"../chart/utils/touch.js";import{Table as Ge}from"../table/Table.js";import{TableBody as Ke}from"../table/TableBody.js";import{TableCell as J}from"../table/TableCell.js";import{TableHeader as qe}from"../table/TableHeader.js";import{TableHeaderCell as B}from"../table/TableHeaderCell.js";import{TableRow as Oe}from"../table/TableRow.js";import{Fragment as je,jsx as a,jsxs as f}from"react/jsx-runtime";var Ue=40,_e=3,ee=4,me="text-right [font-variant-numeric:tabular-nums]",Qe=Be(function({boxes:u,color:p}){return a("g",{children:u.map(t=>f("g",{children:[a("g",{stroke:p,strokeWidth:1.5,strokeLinecap:"round",children:t.whiskers.map(l=>a("line",{x1:l.x1,y1:l.y1,x2:l.x2,y2:l.y2},l.key))}),t.body?a("path",{d:t.body,fill:p}):null,t.median?a("line",{x1:t.median.x1,y1:t.median.y1,x2:t.median.x2,y2:t.median.y2,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"}):null,t.mean?a("path",{d:`M${t.mean.cx},${t.mean.cy-ee} L${t.mean.cx+ee},${t.mean.cy} L${t.mean.cx},${t.mean.cy+ee} L${t.mean.cx-ee},${t.mean.cy} Z`,strokeWidth:1.5,stroke:p,className:"fill-white dark:fill-gray-800"}):null,t.outliers.map(l=>a("circle",{cx:l.cx,cy:l.cy,r:_e,fill:p,strokeWidth:1.5,className:"stroke-white dark:stroke-gray-800"},l.key))]},t.key))})});function Ye({width:C,height:u,data:p,boxes:t,x:l,y:v,grid:M,size:q,orientation:w,boxSize:O,showOutliers:U,showMean:X,color:_,referenceLines:ae,margin:I,tooltip:S,plotLabel:re,formatValue:$,formatX:H,onBoxClick:L}){let[V,A]=we(null),m=V!==null&&V<t.length?V:null,E=Ce(),e=te(()=>{let r=w==="vertical",i=t.flatMap(o=>o.stats===null?[]:[o.stats.min,o.stats.max,...X&&o.mean!==null?[o.mean]:[]]),k=He({width:C,height:u,data:p,x:l,y:v,bounds:i.length===0?null:[Math.min(...i),Math.max(...i)],margin:I,orientation:w,placement:"band",formatValue:$,formatX:H,defaultIncludeZero:!1}),{valueScale:d,bandwidth:x,categoryPositions:N,innerWidth:D,innerHeight:G}=k,P=Math.min(O??Ue,x),n=P*.5,h=(o,y)=>r?{x:o,y}:{x:y,y:o},Q=t.map((o,y)=>{let b=N[y]+(x-P)/2,s=b+P/2;if(o.stats===null)return{key:`${y}`,body:"",median:null,whiskers:[],outliers:[],mean:null,top:N[y],height:x};let{q1:g,q3:T,median:Y,lower:j,upper:ve,outliers:ke}=o.stats,ue=d(g),de=d(T),he=Math.min(ue,de),ge=Math.abs(de-ue),Pe=Ie({...r?{x:b,y:he,width:P,height:Math.max(1,ge)}:{x:he,y:b,width:Math.max(1,ge),height:P},radius:2,round:"none"}),Z=d(Y),Ne=r?{x1:b,y1:Z,x2:b+P,y2:Z}:{x1:Z,y1:b,x2:Z,y2:b+P},oe=[];for(let[R,ie,F]of[["lower",j,g],["upper",ve,T]]){let se=d(ie),Te=d(F),ye=h(s,se),fe=h(s,Te);oe.push({key:`${R}-stem`,x1:fe.x,y1:fe.y,x2:ye.x,y2:ye.y});let pe=h(s-n/2,se),xe=h(s+n/2,se);oe.push({key:`${R}-cap`,x1:pe.x,y1:pe.y,x2:xe.x,y2:xe.y})}return{key:`${y}`,body:Pe,median:Ne,whiskers:oe,outliers:U?ke.map((R,ie)=>{let F=h(s,d(R));return{key:`${ie}`,cx:F.x,cy:F.y}}):[],mean:X&&o.mean!==null?(()=>{let R=h(s,d(o.mean));return{cx:R.x,cy:R.y}})():null,top:N[y],height:x}});return{vertical:r,rendered:Q,categoryPositions:N,categoryCenters:k.categoryCenters,bandwidth:x,categoryTicks:k.categoryTicks,valueTicks:k.valueTicks,valueScale:d,innerWidth:D,innerHeight:G,margin:k.margin}},[t,p,l,v,C,u,I,w,O,U,X,$,H]),ne=ce(r=>{if(S===!1||t.length===0)return;let i=r.currentTarget.getBoundingClientRect(),k=e.vertical?r.clientX-i.left-e.margin.left:r.clientY-i.top-e.margin.top;A(ze(e.categoryCenters,k))},[S,t.length,e.vertical,e.margin,e.categoryCenters]),z=ce(()=>{!L||m===null||L(t[m])},[L,m,t]),le=ce(r=>Xe(r,{count:t.length,current:m,axis:e.vertical?"x":"y",onMove:A,pick:L?z:null}),[t.length,m,e.vertical,L,z]),c=m===null?null:t[m],W=m===null||c===null||c.stats===null?null:e.vertical?{x:e.margin.left+e.categoryCenters[m],y:e.margin.top+e.valueScale(c.stats.q3)}:{x:e.margin.left+e.valueScale(c.stats.q3),y:e.margin.top+e.categoryCenters[m]};return f(je,{children:[f("svg",{width:C,height:u,role:"img","aria-label":re??t.map(r=>r.label).join(", "),tabIndex:0,className:`${De} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500`,onPointerMove:ne,onPointerLeave:()=>A(null),onKeyDown:le,onBlur:()=>A(null),onClick:z,children:[f("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[a(Re,{width:e.innerWidth,height:e.innerHeight,horizontal:e.vertical&&(M==="y"||M==="both")?e.valueTicks.map(r=>r.offset):void 0,vertical:!e.vertical&&(M==="y"||M==="both")?e.valueTicks.map(r=>r.offset):void 0}),m!==null?a("rect",{x:e.vertical?e.categoryPositions[m]:0,y:e.vertical?0:e.categoryPositions[m],width:e.vertical?e.bandwidth:e.innerWidth,height:e.vertical?e.innerHeight:e.bandwidth,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,ae?.map(r=>{let i=e.valueScale(r.value);return f("g",{children:[a("line",{x1:e.vertical?0:i,y1:e.vertical?i:0,x2:e.vertical?e.innerWidth:i,y2:e.vertical?i:e.innerHeight,stroke:r.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:r.dashed===!1?void 0:"4 4"}),r.label?a("text",{x:e.vertical?e.innerWidth:i+4,y:e.vertical?i-4:8,textAnchor:e.vertical?"end":"start",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:r.label}):null]},`${r.value}-${r.label??""}`)}),a(Qe,{boxes:e.rendered,color:_})]}),a("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:(e.vertical?l.hidden:v?.hidden)?null:a(be,{orientation:"bottom",ticks:e.vertical?e.categoryTicks:e.valueTicks,length:e.innerWidth,label:e.vertical?l.label:v?.label,size:q})}),a("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:(e.vertical?v?.hidden:l.hidden)?null:a(be,{orientation:"left",ticks:e.vertical?e.valueTicks:e.categoryTicks,length:e.innerHeight,showLine:!1,label:e.vertical?v?.label:l.label,size:q})})]}),c&&c.stats&&W&&S!==!1?a(Me,{x:W.x,y:W.y,containerWidth:C,children:typeof S=="function"?S(c):f("div",{className:"flex flex-col gap-1",children:[a("div",{className:"font-medium text-gray-900 dark:text-gray-100",children:c.label}),f("dl",{className:"grid grid-cols-[auto_auto] gap-x-3 gap-y-0.5",children:[[[E.chartMax,c.stats.max],["Q3",c.stats.q3],[E.chartMedian,c.stats.median],["Q1",c.stats.q1],[E.chartMin,c.stats.min]].map(([r,i])=>f("div",{className:"contents",children:[a("dt",{className:"text-gray-500 dark:text-gray-400",children:r}),a("dd",{className:"justify-self-end font-medium text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:$(i)})]},r)),f("div",{className:"contents",children:[a("dt",{className:"text-gray-500 dark:text-gray-400",children:E.chartCount}),a("dd",{className:"justify-self-end font-medium text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:c.stats.count})]})]})]})}):null]})}function xt({data:C,x:u,y:p,values:t,quantiles:l,whisker:v=1.5,orientation:M="vertical",boxSize:q,showOutliers:w=!0,showMean:O=!1,color:U,referenceLines:X,height:_=280,width:ae,size:I="md",grid:S="y",tooltip:re=!0,tableView:$=!1,title:H,description:L,loading:V=!1,emptyState:A,error:m=!1,errorState:E,onRetry:e,actions:ne,margin:z,locale:le,plotLabel:c,format:W,onBoxClick:r,className:i,...k}){let d=Se(le),x=Ce(),N=te(()=>p?.format??W??(n=>Ee(n,d)),[p?.format,W,d]),D=te(()=>u.format??(n=>We(n,d)),[u.format,d]),G=te(()=>C.map((n,h)=>{let Q=Ae(n,u.key,h),o=t?(()=>{let s=n[t];return Array.isArray(s)?s.map(g=>typeof g=="number"?g:Number(g)).filter(g=>Number.isFinite(g)):null})():null,y=null,b=null;if(o!==null)y=Ve(o,v),b=o.length===0?null:o.reduce((s,g)=>s+g,0)/o.length;else if(l){let s=K(n,l.q1),g=K(n,l.median),T=K(n,l.q3);if(s!==null&&g!==null&&T!==null){let Y=l.min?K(n,l.min)??s:s,j=l.max?K(n,l.max)??T:T;y={count:0,min:Y,max:j,q1:s,median:g,q3:T,iqr:T-s,lower:Y,upper:j,outliers:[]}}}return{index:h,x:Q,label:D(Q,h),stats:y,mean:b,datum:n}}),[C,u.key,t,l,v,D]),P=G.filter(n=>n.stats!==null);return a(Le,{title:H,description:L,height:_,width:ae,size:I,loading:V,empty:P.length===0,emptyState:A,error:m,errorState:E,onRetry:e,actions:ne,tableView:$,table:$?a("div",{className:"w-full overflow-x-auto",children:f(Ge,{children:[typeof H=="string"?a("caption",{className:"sr-only",children:H}):null,f(qe,{children:[a(B,{children:u.label??u.key}),t?a(B,{className:"text-right",children:x.chartCount}):null,a(B,{className:"text-right",children:x.chartMin}),a(B,{className:"text-right",children:"Q1"}),a(B,{className:"text-right",children:x.chartMedian}),a(B,{className:"text-right",children:"Q3"}),a(B,{className:"text-right",children:x.chartMax}),t&&w?a(B,{className:"text-right",children:x.chartOutliers}):null]}),a(Ke,{children:G.map(n=>f(Oe,{clickable:!1,children:[a(J,{className:"font-medium text-gray-900 dark:text-gray-100",children:n.label}),t?a(J,{className:me,children:n.stats?.count??"\u2014"}):null,["min","q1","median","q3","max"].map(h=>a(J,{className:me,children:n.stats===null?"\u2014":N(n.stats[h])},h)),t&&w?a(J,{className:me,children:n.stats===null||n.stats.outliers.length===0?"\u2014":n.stats.outliers.map(N).join(", ")}):null]},n.index))})]})}):void 0,className:i,...k,children:({width:n})=>a(Ye,{width:n,height:_,data:C,boxes:G,x:u,y:p,grid:S,size:I,orientation:M,boxSize:q,showOutliers:w,showMean:O,color:U??$e(0),referenceLines:X,margin:z,tooltip:re,plotLabel:c,formatValue:N,formatX:D,onBoxClick:r})})}export{xt as BoxPlot};
@@ -1 +1 @@
1
- "use strict";var m=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var k=(n,s)=>{for(var l in s)m(n,l,{get:s[l],enumerable:!0})},C=(n,s,l,i)=>{if(s&&typeof s=="object"||typeof s=="function")for(let r of N(s))!y.call(n,r)&&r!==l&&m(n,r,{get:()=>s[r],enumerable:!(i=h(s,r))||i.enumerable});return n};var v=n=>C(m({},"__esModule",{value:!0}),n);var R={};k(R,{Breadcrumb:()=>I});module.exports=v(R);var t=require("../../lib/cn.cjs"),g=require("../../lib/server-labels.cjs"),e=require("react/jsx-runtime"),B={sm:"text-xs",md:"text-sm",lg:"text-base"};function I({items:n,separator:s="/",size:l="md",maxItems:i,itemColor:r="text-gray-500 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-100",activeColor:f="text-gray-700 font-medium dark:text-gray-200",separatorColor:p="text-gray-500 dark:text-gray-400",className:u,...b}){let d=n,x=!1;if(i&&n.length>i){x=!0;let a=n[0],o=n.slice(-(i-1));d=[a,...o]}return(0,e.jsx)("nav",{"aria-label":g.serverUILabels.breadcrumbLabel,className:(0,t.cn)("inline-flex items-center",B[l],u),...b,children:(0,e.jsx)("ol",{className:"inline-flex items-center space-x-1 md:space-x-2",children:d.map((a,o)=>{let c=o===d.length-1;return(0,e.jsxs)("li",{className:"inline-flex items-center",children:[x&&o===1&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("span",{className:(0,t.cn)("mx-1 select-none",p),children:"..."}),(0,e.jsx)("span",{className:(0,t.cn)("mx-1 select-none",p),"aria-hidden":"true",children:s})]}),a.href||a.onClick?(0,e.jsxs)("a",{href:a.href,onClick:a.onClick,className:(0,t.cn)("inline-flex items-center gap-1.5 transition-colors",c?f:r),"aria-current":c?"page":void 0,children:[a.icon&&(0,e.jsx)("span",{className:"inline-flex","aria-hidden":"true",children:a.icon}),(0,e.jsx)("span",{children:a.label})]}):(0,e.jsxs)("span",{className:(0,t.cn)("inline-flex items-center gap-1.5",c?f:r),"aria-current":c?"page":void 0,children:[a.icon&&(0,e.jsx)("span",{className:"inline-flex","aria-hidden":"true",children:a.icon}),(0,e.jsx)("span",{children:a.label})]}),!c&&(0,e.jsx)("span",{className:(0,t.cn)("mx-2 select-none",p),"aria-hidden":"true",children:s})]},a.href??a.label)})})})}0&&(module.exports={Breadcrumb});
1
+ "use strict";var d=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var B=(n,r)=>{for(var l in r)d(n,l,{get:r[l],enumerable:!0})},I=(n,r,l,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of C(r))!v.call(n,s)&&s!==l&&d(n,s,{get:()=>r[s],enumerable:!(i=k(r,s))||i.enumerable});return n};var R=n=>I(d({},"__esModule",{value:!0}),n);var z={};B(z,{Breadcrumb:()=>L});module.exports=R(z);var t=require("../../lib/cn.cjs"),u=require("../../lib/server-labels.cjs"),b=require("../../lib/safe-href.cjs"),e=require("react/jsx-runtime"),P={sm:"text-xs",md:"text-sm",lg:"text-base"};function L({items:n,separator:r="/",size:l="md",maxItems:i,itemColor:s="text-gray-500 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-100",activeColor:f="text-gray-700 font-medium dark:text-gray-200",separatorColor:p="text-gray-500 dark:text-gray-400",className:h,...N}){let m=n,x=!1;if(i&&n.length>i){x=!0;let a=n[0],o=n.slice(-(i-1));m=[a,...o]}return(0,e.jsx)("nav",{"aria-label":u.serverUILabels.breadcrumbLabel,className:(0,t.cn)("inline-flex items-center",P[l],h),...N,children:(0,e.jsx)("ol",{className:"inline-flex items-center space-x-1 md:space-x-2",children:m.map((a,o)=>{let c=o===m.length-1,y=x&&o===1,g=(0,b.componentHref)("Breadcrumb",a.href);return(0,e.jsxs)("li",{className:"inline-flex items-center",children:[y&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("span",{className:(0,t.cn)("mx-1 select-none",p),children:"..."}),(0,e.jsx)("span",{className:(0,t.cn)("mx-1 select-none",p),"aria-hidden":"true",children:r})]}),g||a.onClick?(0,e.jsxs)("a",{href:g,onClick:a.onClick,className:(0,t.cn)("inline-flex items-center gap-1.5 transition-colors",c?f:s),"aria-current":c?"page":void 0,children:[a.icon&&(0,e.jsx)("span",{className:"inline-flex","aria-hidden":"true",children:a.icon}),(0,e.jsx)("span",{children:a.label})]}):(0,e.jsxs)("span",{className:(0,t.cn)("inline-flex items-center gap-1.5",c?f:s),"aria-current":c?"page":void 0,children:[a.icon&&(0,e.jsx)("span",{className:"inline-flex","aria-hidden":"true",children:a.icon}),(0,e.jsx)("span",{children:a.label})]}),!c&&(0,e.jsx)("span",{className:(0,t.cn)("mx-2 select-none",p),"aria-hidden":"true",children:r})]},a.href??a.label)})})})}0&&(module.exports={Breadcrumb});
@@ -1 +1 @@
1
- import{cn as n}from"../../lib/cn.js";import{serverUILabels as b}from"../../lib/server-labels.js";import{Fragment as N,jsx as a,jsxs as l}from"react/jsx-runtime";var h={sm:"text-xs",md:"text-sm",lg:"text-base"};function v({items:r,separator:p="/",size:x="md",maxItems:i,itemColor:d="text-gray-500 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-100",activeColor:m="text-gray-700 font-medium dark:text-gray-200",separatorColor:c="text-gray-500 dark:text-gray-400",className:g,...u}){let o=r,f=!1;if(i&&r.length>i){f=!0;let e=r[0],t=r.slice(-(i-1));o=[e,...t]}return a("nav",{"aria-label":b.breadcrumbLabel,className:n("inline-flex items-center",h[x],g),...u,children:a("ol",{className:"inline-flex items-center space-x-1 md:space-x-2",children:o.map((e,t)=>{let s=t===o.length-1;return l("li",{className:"inline-flex items-center",children:[f&&t===1&&l(N,{children:[a("span",{className:n("mx-1 select-none",c),children:"..."}),a("span",{className:n("mx-1 select-none",c),"aria-hidden":"true",children:p})]}),e.href||e.onClick?l("a",{href:e.href,onClick:e.onClick,className:n("inline-flex items-center gap-1.5 transition-colors",s?m:d),"aria-current":s?"page":void 0,children:[e.icon&&a("span",{className:"inline-flex","aria-hidden":"true",children:e.icon}),a("span",{children:e.label})]}):l("span",{className:n("inline-flex items-center gap-1.5",s?m:d),"aria-current":s?"page":void 0,children:[e.icon&&a("span",{className:"inline-flex","aria-hidden":"true",children:e.icon}),a("span",{children:e.label})]}),!s&&a("span",{className:n("mx-2 select-none",c),"aria-hidden":"true",children:p})]},e.href??e.label)})})})}export{v as Breadcrumb};
1
+ import{cn as n}from"../../lib/cn.js";import{serverUILabels as N}from"../../lib/server-labels.js";import{componentHref as y}from"../../lib/safe-href.js";import{Fragment as C,jsx as a,jsxs as l}from"react/jsx-runtime";var k={sm:"text-xs",md:"text-sm",lg:"text-base"};function R({items:s,separator:p="/",size:g="md",maxItems:i,itemColor:m="text-gray-500 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-100",activeColor:d="text-gray-700 font-medium dark:text-gray-200",separatorColor:c="text-gray-500 dark:text-gray-400",className:u,...b}){let o=s,f=!1;if(i&&s.length>i){f=!0;let e=s[0],t=s.slice(-(i-1));o=[e,...t]}return a("nav",{"aria-label":N.breadcrumbLabel,className:n("inline-flex items-center",k[g],u),...b,children:a("ol",{className:"inline-flex items-center space-x-1 md:space-x-2",children:o.map((e,t)=>{let r=t===o.length-1,h=f&&t===1,x=y("Breadcrumb",e.href);return l("li",{className:"inline-flex items-center",children:[h&&l(C,{children:[a("span",{className:n("mx-1 select-none",c),children:"..."}),a("span",{className:n("mx-1 select-none",c),"aria-hidden":"true",children:p})]}),x||e.onClick?l("a",{href:x,onClick:e.onClick,className:n("inline-flex items-center gap-1.5 transition-colors",r?d:m),"aria-current":r?"page":void 0,children:[e.icon&&a("span",{className:"inline-flex","aria-hidden":"true",children:e.icon}),a("span",{children:e.label})]}):l("span",{className:n("inline-flex items-center gap-1.5",r?d:m),"aria-current":r?"page":void 0,children:[e.icon&&a("span",{className:"inline-flex","aria-hidden":"true",children:e.icon}),a("span",{children:e.label})]}),!r&&a("span",{className:n("mx-2 select-none",c),"aria-hidden":"true",children:p})]},e.href??e.label)})})})}export{R as Breadcrumb};