@synertech/ui 0.45.0 → 0.45.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/skills/use-synertech-ui/SKILL.md +1 -1
- package/dist/components/area-chart/AreaChart.cjs +1 -1
- package/dist/components/area-chart/AreaChart.js +1 -1
- package/dist/components/bar-chart/BarChart.cjs +1 -1
- package/dist/components/bar-chart/BarChart.js +1 -1
- package/dist/components/box-plot/BoxPlot.cjs +1 -1
- package/dist/components/box-plot/BoxPlot.js +1 -1
- package/dist/components/bullet-chart/BulletChart.cjs +1 -1
- package/dist/components/bullet-chart/BulletChart.js +1 -1
- package/dist/components/candlestick-chart/CandlestickChart.cjs +1 -1
- package/dist/components/candlestick-chart/CandlestickChart.js +1 -1
- package/dist/components/chart/ChartSync.cjs +1 -1
- package/dist/components/chart/ChartSync.js +1 -1
- package/dist/components/chart/utils/cartesian.cjs +1 -1
- package/dist/components/chart/utils/cartesian.js +1 -1
- package/dist/components/chart/utils/path.cjs +1 -1
- package/dist/components/chart/utils/path.js +1 -1
- package/dist/components/chart/utils/time.cjs +1 -1
- package/dist/components/chart/utils/time.js +1 -1
- package/dist/components/chart/utils/timestamp.cjs +1 -0
- package/dist/components/chart/utils/timestamp.js +1 -0
- package/dist/components/chart/utils/touch.cjs +1 -0
- package/dist/components/chart/utils/touch.js +1 -0
- package/dist/components/dumbbell-chart/DumbbellChart.cjs +1 -1
- package/dist/components/dumbbell-chart/DumbbellChart.js +1 -1
- package/dist/components/funnel-chart/FunnelChart.cjs +1 -1
- package/dist/components/funnel-chart/FunnelChart.js +1 -1
- package/dist/components/gantt-chart/GanttChart.cjs +1 -1
- package/dist/components/gantt-chart/GanttChart.js +1 -1
- package/dist/components/heat-map/Heatmap.cjs +1 -1
- package/dist/components/heat-map/Heatmap.js +1 -1
- package/dist/components/line-chart/LineChart.cjs +1 -1
- package/dist/components/line-chart/LineChart.js +1 -1
- package/dist/components/pie-chart/PieChart.cjs +1 -1
- package/dist/components/pie-chart/PieChart.js +1 -1
- package/dist/components/scatter-chart/ScatterChart.cjs +1 -1
- package/dist/components/scatter-chart/ScatterChart.js +1 -1
- package/dist/components/waterfall-chart/WaterfallChart.cjs +1 -1
- package/dist/components/waterfall-chart/WaterfallChart.js +1 -1
- package/dist/index.d.cts +16 -3
- package/dist/index.d.ts +16 -3
- package/dist/styles.css +27 -0
- package/package.json +13 -13
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: use-synertech-ui
|
|
3
3
|
description: Guide for optimal usage of @synertech/ui components in consuming projects. Provides component API reference, composition patterns, setup instructions, and anti-patterns to avoid.
|
|
4
|
-
allowed-tools: Read, Glob, Grep
|
|
4
|
+
allowed-tools: Read, Glob, Grep
|
|
5
5
|
argument-hint: "[component-name or question]"
|
|
6
6
|
---
|
|
7
7
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";"use client";var Ee=Object.defineProperty;var Ye=Object.getOwnPropertyDescriptor;var _e=Object.getOwnPropertyNames;var Ue=Object.prototype.hasOwnProperty;var Fe=(h,i)=>{for(var r in i)Ee(h,r,{get:i[r],enumerable:!0})},je=(h,i,r,g)=>{if(i&&typeof i=="object"||typeof i=="function")for(let m of _e(i))!Ue.call(h,m)&&m!==r&&Ee(h,m,{get:()=>i[m],enumerable:!(g=Ye(i,m))||g.enumerable});return h};var Ze=h=>je(Ee({},"__esModule",{value:!0}),h);var rt={};Fe(rt,{AreaChart:()=>nt});module.exports=Ze(rt);var s=require("react"),He=require("../../lib/cn.cjs"),We=require("../../lib/i18n.cjs"),Q=require("../chart/ChartAnnotations.cjs"),Te=require("../chart/ChartAxis.cjs"),de=require("../chart/ChartBrush.cjs"),De=require("../chart/ChartContainer.cjs"),Me=require("../chart/ChartGrid.cjs"),Ke=require("../chart/ChartLegend.cjs"),ge=require("../chart/ChartPatterns.cjs"),$e=require("../chart/ChartSync.cjs"),Xe=require("../chart/ChartTableView.cjs"),fe=require("../chart/ChartTooltip.cjs"),E=require("../chart/palette.cjs"),P=require("../chart/utils/cartesian.cjs"),pe=require("../chart/utils/data.cjs"),be=require("../chart/utils/decimate.cjs"),x=require("../chart/utils/format.cjs"),M=require("../chart/utils/path.cjs"),T=require("../chart/utils/scales.cjs"),Ce=require("../chart/utils/stack.cjs"),Ge=require("../chart/utils/ticks.cjs"),n=require("react/jsx-runtime"),qe=.12,Je=.9,Qe=10,et=(0,s.memo)(function({bands:i,stacked:r,patterns:g,patternBaseId:m}){return(0,n.jsx)("g",{children:i.map(d=>(0,n.jsxs)("g",{children:[(0,n.jsx)("path",{d:d.area,fill:(0,ge.patternFill)(g,m,d.slot,d.color),fillOpacity:r?Je:qe,stroke:"none"}),d.gap?(0,n.jsx)("path",{d:d.gap,fill:"none",strokeWidth:2,className:"stroke-white dark:stroke-gray-800"}):null,(0,n.jsx)("path",{d:d.edge,fill:"none",stroke:d.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"})]},d.key))})});function tt({width:h,height:i,data:r,resolvedSeries:g,x:m,y:d,grid:C,size:ee,curve:b,stack:L,baseline:A,connectNulls:N,referenceLines:K,annotations:S,annotationsLabel:ye,patterns:te,patternBaseId:ne,overlay:ke,maxPoints:y,brush:re,onBrush:oe,brushLabel:ve,syncEnabled:$,margin:ae,tooltip:B,onPointClick:X,plotLabel:xe,formatValue:k,formatRaw:G,formatX:I}){let[O,z]=(0,s.useState)(null),u=O!==null&&O<r.length?O:null,[Pe,Le]=(0,s.useState)(null),Ae=(0,$e.useChartSync)(),l=$?Ae:null,t=(0,s.useMemo)(()=>{let e=g.filter(w=>!w.hidden),o=e.map(w=>w.key),a=L!=="none",c=(0,Ce.stackSeries)(r,o,L),ue=a?(0,Ce.stackExtent)(c):(0,Ge.extent)([...(0,pe.collectAllValues)(r,o),A]),p=(0,P.buildCartesianGeometry)({width:h,height:i,data:r,x:m,y:d,bounds:ue,margin:ae,placement:"point",formatValue:k,formatX:I,defaultIncludeZero:!0}),Re=p.categoryCenters,ce=p.valueScale,Oe=ce(a?0:A),ze=e.map((w,we)=>{let Z=r.map((q,J)=>{let V=c[J].segments[we];return{x:Re[J],y:V.value===null?Number.NaN:ce(V.end),defined:V.value!==null}}),Ne=r.map((q,J)=>{let V=c[J].segments[we];return{x:Re[J],y:V.value===null?Number.NaN:ce(a?V.start:A),defined:V.value!==null}}),he={connectNulls:N},me=y&&y>0&&Z.length>y?(0,be.decimateIndices)(Z,y):null,Ve=me?me.map(q=>Z[q]):Z,Ie=me?me.map(q=>Ne[q]):Ne;return y||(0,be.warnPointBudget)("AreaChart",Z.length),{key:w.key,color:w.color,slot:w.slot,area:a?(0,M.buildAreaPath)(Ve,Ie,b,he):(0,M.buildAreaPath)(Ve,Oe,b,he),edge:(0,M.buildLinePath)(Ve,b,he),gap:a&&we>0?(0,M.buildLinePath)(Ie,b,he):""}});return{visible:e,locate:(0,P.createCategoryLocator)(p),plot:(0,P.createPlotContext)({geometry:p,width:h,height:i,data:r,series:e,formatValue:k,formatX:I}),rows:c,stacked:a,xValues:p.xValues,positions:Re,xTicks:p.categoryTicks,yTicks:p.valueTicks,valueScale:ce,innerWidth:p.innerWidth,innerHeight:p.innerHeight,margin:p.margin,bands:ze}},[r,g,m,d,h,i,ae,b,L,A,N,y,k,I]),Y=(0,s.useCallback)(e=>t.visible.map((o,a)=>{let c=(0,pe.readNumber)(r[e],o.key),ue=t.rows[e].segments[a],p=c===null?"\u2014":L==="percent"?`${G(c)} (${k(ue.end-ue.start)})`:k(c);return{seriesKey:o.key,seriesLabel:(0,E.getSeriesLabel)(o),color:o.color,value:c,formattedValue:p,datum:r[e]}}),[r,t.visible,t.rows,L,k,G]),se=l?l.brush:Pe,le=(0,s.useCallback)(e=>{Le(e),l?.setBrush(e),oe?.(e)},[l,oe]),f=(0,de.useChartBrush)({enabled:re,active:se!==null,centers:t.positions,xValues:t.xValues,offset:t.margin.left,orientation:"vertical",onCommit:le}),Se=(0,s.useCallback)(e=>{if(f.onPointerMove(e),B===!1||r.length===0)return;let o=e.currentTarget.getBoundingClientRect(),a=e.clientX-o.left-t.margin.left,c=(0,T.nearestIndex)(t.positions,a);z(c>=0?c:null),l?.setHovered(c>=0?t.xValues[c]:null)},[f,B,r.length,t.margin.left,t.positions,t.xValues,l]),ie=(0,s.useCallback)(()=>{z(null),l?.setHovered(null)},[l]),H=(0,s.useCallback)(e=>{if(r.length===0)return;f.onKeyDown(e,u);let o=r.length-1,a=u??0,c=e.key==="ArrowRight"?Math.min(o,a+1):e.key==="ArrowLeft"?Math.max(0,a-1):e.key==="Home"?0:e.key==="End"?o:e.key==="Escape"?null:void 0;c!==void 0&&(e.preventDefault(),z(c),l?.setHovered(c===null?null:t.xValues[c]))},[r.length,u,f,l,t.xValues]),W=(0,s.useCallback)(()=>{if(f.consumedClick()||!X||u===null)return;let[e]=Y(u);e&&X({...e,index:u,x:t.xValues[u]})},[f,X,u,Y,t.xValues]),Be=u!==null||!l?.hovered?null:(()=>{let e=(0,T.toKey)(l.hovered),o=t.xValues.findIndex(a=>(0,T.toKey)(a)===e);return o<0?null:o})(),v=u??Be,_=u===null?null:Y(u),D=v===null?[]:t.visible.map((e,o)=>{let a=t.rows[v].segments[o];return a.value===null?null:{key:e.key,color:e.color,y:t.valueScale(a.end)}}).filter(e=>e!==null),U=f.dragging??se,F=(()=>{if(!U)return null;let e=t.locate(U.from),o=t.locate(U.to);return e===null||o===null?null:{from:e,to:o}})(),j=(0,P.splitOverlay)(ke),R=u===null||_===null?null:{x:t.xValues[u],xLabel:I(t.xValues[u],u),index:u,points:_};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("svg",{width:h,height:i,role:"img","aria-label":xe??[t.visible.map(e=>(0,E.getSeriesLabel)(e)).join(", "),(0,Q.describeAnnotations)(S,ye)].filter(Boolean).join(". "),tabIndex:0,className:(0,He.cn)("touch-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500",re&&"select-none"),onPointerDown:f.onPointerDown,onPointerMove:Se,onPointerUp:f.onPointerUp,onPointerCancel:f.onPointerUp,onPointerLeave:ie,onKeyDown:H,onBlur:ie,onClick:W,children:[te?(0,n.jsx)(ge.ChartPatternDefs,{id:ne,entries:g.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:C==="y"||C==="both"?t.yTicks.map(e=>e.offset):void 0,vertical:C==="x"||C==="both"?t.xTicks.map(e=>e.offset):void 0}),S?(0,n.jsx)(Q.ChartAnnotationLayer,{layer:"under",annotations:S,xAt:t.locate,yAt:t.valueScale,width:t.innerWidth,height:t.innerHeight}):null,F?(0,n.jsx)(de.ChartBrushLayer,{from:F.from,to:F.to,width:t.innerWidth,height:t.innerHeight,live:f.dragging!==null,label:ve}):null,j.under?.(t.plot),(0,n.jsx)(et,{bands:t.bands,stacked:t.stacked,patterns:te&&t.stacked,patternBaseId:ne}),S?(0,n.jsx)(Q.ChartAnnotationLayer,{annotations:S,xAt:t.locate,yAt:t.valueScale,width:t.innerWidth,height:t.innerHeight}):null,K?.map(e=>{let o=t.valueScale(e.value),a=o<Qe?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??""}`)}),j.over?.(t.plot),v!==null?(0,n.jsxs)("g",{"aria-hidden":"true",children:[(0,n.jsx)("line",{x1:t.positions[v],y1:0,x2:t.positions[v],y2:t.innerHeight,className:"stroke-gray-400 dark:stroke-gray-500",strokeWidth:1,strokeDasharray:u===null?"3 3":void 0}),D.map(e=>(0,n.jsx)("circle",{cx:t.positions[v],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:m.hidden?null:(0,n.jsx)(Te.ChartAxis,{orientation:"bottom",ticks:t.xTicks,length:t.innerWidth,label:m.label,size:ee})}),(0,n.jsx)("g",{transform:`translate(${t.margin.left}, ${t.margin.top})`,children:d?.hidden?null:(0,n.jsx)(Te.ChartAxis,{orientation:"left",ticks:t.yTicks,length:t.innerHeight,showLine:!1,label:d?.label,size:ee})})]}),R&&B!==!1?(0,n.jsx)(fe.ChartTooltip,{x:t.margin.left+t.positions[R.index],y:t.margin.top+(D.length>0?Math.min(...D.map(e=>e.y)):t.innerHeight/2),containerWidth:h,children:typeof B=="function"?B(R):(0,n.jsx)(fe.ChartTooltipContent,{title:R.xLabel,points:R.points})}):null]})}function nt({data:h,series:i,x:r,y:g,height:m=240,width:d,size:C="md",grid:ee="y",legend:b,tooltip:L=!0,tableView:A=!1,emphasis:N,title:K,description:S,loading:ye=!1,emptyState:te,error:ne=!1,errorState:ke,onRetry:y,actions:re,onPointClick:oe,curve:ve="monotone",stack:$="none",baseline:ae=0,connectNulls:B=!1,referenceLines:X,annotations:xe,overlay:k,patterns:G=!1,legendToggle:I=!0,maxPoints:O,brush:z=!1,onBrush:u,brushLabel:Pe,sync:Le=!0,margin:Ae,locale:l,plotLabel:t,className:Y,...se}){let le=(0,We.useUILabels)(),[f,Se]=(0,s.useState)(()=>new Set),ie=(0,s.useId)(),H=(0,s.useMemo)(()=>i.map((e,o)=>({...e,slot:o,hidden:e.hidden||f.has(e.key),color:(0,E.resolveSeriesColor)(e,o,N)})),[i,f,N]),W=$==="percent",Be=(0,s.useMemo)(()=>W?{domain:[0,100],...g}:g,[W,g]),v=(0,s.useMemo)(()=>g?.format??(W?e=>(0,x.formatPercent)(e,{locale:l,alreadyScaled:!0,maximumFractionDigits:0}):e=>(0,x.formatAuto)(e,l)),[g?.format,W,l]),_=(0,s.useMemo)(()=>e=>(0,x.formatAuto)(e,l),[l]),D=(0,s.useMemo)(()=>r.format??(e=>r.scale==="time"?(0,x.formatXValue)(e instanceof Date?e:new Date((0,T.toNumber)(e)),l):(0,x.formatXValue)(e,l)),[r.format,r.scale,l]),U=(0,s.useCallback)(e=>{Se(o=>{let a=new Set(o);return a.has(e)?a.delete(e):a.add(e),a})},[]),F=b===void 0?i.length>=2:b!==!1,j=typeof b=="string"?b:"bottom",R=H.filter(e=>!e.hidden).length;return(0,n.jsx)(De.ChartContainer,{title:K,description:S,height:m,width:d,size:C,loading:ye,empty:h.length===0||R===0,emptyState:te,error:ne,errorState:ke,onRetry:y,actions:re,tableView:A,legendPosition:j,legend:F?(0,n.jsx)(Ke.ChartLegend,{items:(0,E.toLegendItems)(H,N,G&&$!=="none"),position:j,marker:"rect",size:C,onToggle:I?U:void 0}):void 0,table:A?(0,n.jsx)(Xe.ChartTableView,{data:h,series:H,xKey:r.key,xLabel:r.label??r.key,formatX:D,formatValue:_,caption:typeof K=="string"?K:void 0}):void 0,className:Y,...se,children:({width:e})=>(0,n.jsx)(tt,{width:e,height:m,data:h,resolvedSeries:H,x:r,y:Be,grid:ee,size:C,curve:ve,stack:$,baseline:ae,connectNulls:B,referenceLines:X,annotations:xe,annotationsLabel:le.chartAnnotations,patterns:G,patternBaseId:ie,overlay:k,maxPoints:O,brush:z,onBrush:u,brushLabel:Pe??le.chartBrush,syncEnabled:Le,margin:Ae,tooltip:L,onPointClick:oe,plotLabel:t,formatValue:v,formatRaw:_,formatX:D})})}0&&(module.exports={AreaChart});
|
|
1
|
+
"use strict";"use client";var Ve=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var Fe=Object.getOwnPropertyNames;var je=Object.prototype.hasOwnProperty;var Ze=(h,i)=>{for(var r in i)Ve(h,r,{get:i[r],enumerable:!0})},qe=(h,i,r,g)=>{if(i&&typeof i=="object"||typeof i=="function")for(let d of Fe(i))!je.call(h,d)&&d!==r&&Ve(h,d,{get:()=>i[d],enumerable:!(g=Ue(i,d))||g.enumerable});return h};var Je=h=>qe(Ve({},"__esModule",{value:!0}),h);var at={};Ze(at,{AreaChart:()=>ot});module.exports=Je(at);var s=require("react"),Ne=require("../../lib/cn.cjs"),We=require("../../lib/i18n.cjs"),J=require("../chart/ChartAnnotations.cjs"),Ee=require("../chart/ChartAxis.cjs"),ge=require("../chart/ChartBrush.cjs"),De=require("../chart/ChartContainer.cjs"),Me=require("../chart/ChartGrid.cjs"),$e=require("../chart/ChartLegend.cjs"),fe=require("../chart/ChartPatterns.cjs"),Ke=require("../chart/ChartSync.cjs"),Oe=require("../chart/ChartTableView.cjs"),pe=require("../chart/ChartTooltip.cjs"),E=require("../chart/palette.cjs"),P=require("../chart/utils/cartesian.cjs"),ye=require("../chart/utils/data.cjs"),Ce=require("../chart/utils/decimate.cjs"),H=require("../chart/utils/format.cjs"),x=require("../chart/utils/path.cjs"),Q=require("../chart/utils/scales.cjs"),be=require("../chart/utils/stack.cjs"),Xe=require("../chart/utils/ticks.cjs"),Ge=require("../chart/utils/timestamp.cjs"),_e=require("../chart/utils/touch.cjs"),n=require("react/jsx-runtime"),Qe=.12,et=.9,tt=10,nt=(0,s.memo)(function({bands:i,stacked:r,patterns:g,patternBaseId:d}){return(0,n.jsx)("g",{children:i.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?et:Qe,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(p=>(0,n.jsx)("circle",{cx:p.x,cy:p.y,r:3,fill:m.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},`${p.x}-${p.y}`))]},m.key))})});function rt({width:h,height:i,data:r,resolvedSeries:g,x:d,y:m,grid:p,size:ee,curve:C,stack:A,baseline:L,connectNulls:S,referenceLines:M,annotations:B,annotationsLabel:ke,patterns:te,patternBaseId:ne,overlay:ve,maxPoints:b,brush:re,onBrush:oe,brushLabel:xe,syncEnabled:$,margin:ae,tooltip:R,onPointClick:K,plotLabel:Pe,formatValue:k,formatRaw:O,formatX:I}){let[X,G]=(0,s.useState)(null),u=X!==null&&X<r.length?X:null,[Ae,Le]=(0,s.useState)(null),Se=(0,Ke.useChartSync)(),l=$?Se:null,t=(0,s.useMemo)(()=>{let e=g.filter(T=>!T.hidden),o=e.map(T=>T.key),a=A!=="none",c=(0,be.stackSeries)(r,o,A),ue=a?(0,be.stackExtent)(c):(0,Xe.extent)([...(0,ye.collectAllValues)(r,o),L]),y=(0,P.buildCartesianGeometry)({width:h,height:i,data:r,x:d,y:m,bounds:ue,margin:ae,placement:"point",formatValue:k,formatX:I,defaultIncludeZero:!0}),we=y.categoryCenters,ce=y.valueScale,ze=ce(a?0:L),Ye=e.map((T,Te)=>{let j=r.map((Z,q)=>{let V=c[q].segments[Te];return{x:we[q],y:V.value===null?Number.NaN:ce(V.end),defined:V.value!==null}}),He=r.map((Z,q)=>{let V=c[q].segments[Te];return{x:we[q],y:V.value===null?Number.NaN:ce(a?V.start:L),defined:V.value!==null}}),he={connectNulls:S},me=b&&b>0&&j.length>b?(0,Ce.decimateIndices)(j,b):null,de=me?me.map(Z=>j[Z]):j,Ie=me?me.map(Z=>He[Z]):He;return b||(0,Ce.warnPointBudget)("AreaChart",j.length),{key:T.key,color:T.color,slot:T.slot,area:a?(0,x.buildAreaPath)(de,Ie,C,he):(0,x.buildAreaPath)(de,ze,C,he),edge:(0,x.buildLinePath)(de,C,he),gap:a&&Te>0?(0,x.buildLinePath)(Ie,C,he):"",isolated:(0,x.isolatedPoints)(de,S)}});return{visible:e,locate:(0,P.createCategoryLocator)(y),plot:(0,P.createPlotContext)({geometry:y,width:h,height:i,data:r,series:e,formatValue:k,formatX:I}),rows:c,stacked:a,xValues:y.xValues,positions:we,xTicks:y.categoryTicks,yTicks:y.valueTicks,valueScale:ce,innerWidth:y.innerWidth,innerHeight:y.innerHeight,margin:y.margin,bands:Ye}},[r,g,d,m,h,i,ae,C,A,L,S,b,k,I]),_=(0,s.useCallback)(e=>t.visible.map((o,a)=>{let c=(0,ye.readNumber)(r[e],o.key),ue=t.rows[e].segments[a],y=c===null?"\u2014":A==="percent"?`${O(c)} (${k(ue.end-ue.start)})`:k(c);return{seriesKey:o.key,seriesLabel:(0,E.getSeriesLabel)(o),color:o.color,value:c,formattedValue:y,datum:r[e]}}),[r,t.visible,t.rows,A,k,O]),se=l?l.brush:Ae,le=(0,s.useCallback)(e=>{Le(e),l?.setBrush(e),oe?.(e)},[l,oe]),f=(0,ge.useChartBrush)({enabled:re,active:se!==null,centers:t.positions,xValues:t.xValues,offset:t.margin.left,orientation:"vertical",onCommit:le}),Be=(0,s.useCallback)(e=>{if(f.onPointerMove(e),R===!1||r.length===0)return;let o=e.currentTarget.getBoundingClientRect(),a=e.clientX-o.left-t.margin.left,c=(0,Q.nearestIndex)(t.positions,a);G(c>=0?c:null),l?.setHovered(c>=0?t.xValues[c]:null)},[f,R,r.length,t.margin.left,t.positions,t.xValues,l]),ie=(0,s.useCallback)(()=>{G(null),l?.setHovered(null)},[l]),N=(0,s.useCallback)(e=>{if(r.length===0)return;f.onKeyDown(e,u);let o=r.length-1,a=u??0,c=e.key==="ArrowRight"?Math.min(o,a+1):e.key==="ArrowLeft"?Math.max(0,a-1):e.key==="Home"?0:e.key==="End"?o:e.key==="Escape"?null:void 0;c!==void 0&&(e.preventDefault(),G(c),l?.setHovered(c===null?null:t.xValues[c]))},[r.length,u,f,l,t.xValues]),W=(0,s.useCallback)(()=>{if(f.consumedClick()||!K||u===null)return;let[e]=_(u);e&&K({...e,index:u,x:t.xValues[u]})},[f,K,u,_,t.xValues]),Re=u!==null||!l?.hovered?null:(()=>{let e=(0,Q.toKey)(l.hovered),o=t.xValues.findIndex(a=>(0,Q.toKey)(a)===e);return o<0?null:o})(),v=u??Re,z=u===null?null:_(u),D=v===null?[]:t.visible.map((e,o)=>{let a=t.rows[v].segments[o];return a.value===null?null:{key:e.key,color:e.color,y:t.valueScale(a.end)}}).filter(e=>e!==null),Y=f.dragging??se,U=(()=>{if(!Y)return null;let e=t.locate(Y.from),o=t.locate(Y.to);return e===null||o===null?null:{from:e,to:o}})(),F=(0,P.splitOverlay)(ve),w=u===null||z===null?null:{x:t.xValues[u],xLabel:I(t.xValues[u],u),index:u,points:z};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("svg",{width:h,height:i,role:"img","aria-label":Pe??[t.visible.map(e=>(0,E.getSeriesLabel)(e)).join(", "),(0,J.describeAnnotations)(B,ke)].filter(Boolean).join(". "),tabIndex:0,className:(0,Ne.cn)(_e.CHART_TOUCH,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500",re&&"select-none"),onPointerDown:f.onPointerDown,onPointerMove:Be,onPointerUp:f.onPointerUp,onPointerCancel:f.onPointerUp,onPointerLeave:ie,onKeyDown:N,onBlur:ie,onClick:W,children:[te?(0,n.jsx)(fe.ChartPatternDefs,{id:ne,entries:g.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}),B?(0,n.jsx)(J.ChartAnnotationLayer,{layer:"under",annotations:B,xAt:t.locate,yAt:t.valueScale,width:t.innerWidth,height:t.innerHeight}):null,U?(0,n.jsx)(ge.ChartBrushLayer,{from:U.from,to:U.to,width:t.innerWidth,height:t.innerHeight,live:f.dragging!==null,label:xe}):null,F.under?.(t.plot),(0,n.jsx)(nt,{bands:t.bands,stacked:t.stacked,patterns:te&&t.stacked,patternBaseId:ne}),B?(0,n.jsx)(J.ChartAnnotationLayer,{annotations:B,xAt:t.locate,yAt:t.valueScale,width:t.innerWidth,height:t.innerHeight}):null,M?.map(e=>{let o=t.valueScale(e.value),a=o<tt?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??""}`)}),F.over?.(t.plot),v!==null?(0,n.jsxs)("g",{"aria-hidden":"true",children:[(0,n.jsx)("line",{x1:t.positions[v],y1:0,x2:t.positions[v],y2:t.innerHeight,className:"stroke-gray-400 dark:stroke-gray-500",strokeWidth:1,strokeDasharray:u===null?"3 3":void 0}),D.map(e=>(0,n.jsx)("circle",{cx:t.positions[v],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:d.hidden?null:(0,n.jsx)(Ee.ChartAxis,{orientation:"bottom",ticks:t.xTicks,length:t.innerWidth,label:d.label,size:ee})}),(0,n.jsx)("g",{transform:`translate(${t.margin.left}, ${t.margin.top})`,children:m?.hidden?null:(0,n.jsx)(Ee.ChartAxis,{orientation:"left",ticks:t.yTicks,length:t.innerHeight,showLine:!1,label:m?.label,size:ee})})]}),w&&R!==!1?(0,n.jsx)(pe.ChartTooltip,{x:t.margin.left+t.positions[w.index],y:t.margin.top+(D.length>0?Math.min(...D.map(e=>e.y)):t.innerHeight/2),containerWidth:h,children:typeof R=="function"?R(w):(0,n.jsx)(pe.ChartTooltipContent,{title:w.xLabel,points:w.points})}):null]})}function ot({data:h,series:i,x:r,y:g,height:d=240,width:m,size:p="md",grid:ee="y",legend:C,tooltip:A=!0,tableView:L=!1,emphasis:S,title:M,description:B,loading:ke=!1,emptyState:te,error:ne=!1,errorState:ve,onRetry:b,actions:re,onPointClick:oe,curve:xe="monotone",stack:$="none",baseline:ae=0,connectNulls:R=!1,referenceLines:K,annotations:Pe,overlay:k,patterns:O=!1,legendToggle:I=!0,maxPoints:X,brush:G=!1,onBrush:u,brushLabel:Ae,sync:Le=!0,margin:Se,locale:l,plotLabel:t,className:_,...se}){let le=(0,We.useUILabels)(),[f,Be]=(0,s.useState)(()=>new Set),ie=(0,s.useId)(),N=(0,s.useMemo)(()=>i.map((e,o)=>({...e,slot:o,hidden:e.hidden||f.has(e.key),color:(0,E.resolveSeriesColor)(e,o,S)})),[i,f,S]),W=$==="percent",Re=(0,s.useMemo)(()=>W?{domain:[0,100],...g}:g,[W,g]),v=(0,s.useMemo)(()=>g?.format??(W?e=>(0,H.formatPercent)(e,{locale:l,alreadyScaled:!0,maximumFractionDigits:0}):e=>(0,H.formatAuto)(e,l)),[g?.format,W,l]),z=(0,s.useMemo)(()=>e=>(0,H.formatAuto)(e,l),[l]),D=(0,s.useMemo)(()=>r.format??(e=>r.scale==="time"?(0,Ge.formatTimeValue)(e,l):(0,H.formatXValue)(e,l)),[r.format,r.scale,l]),Y=(0,s.useCallback)(e=>{Be(o=>{let a=new Set(o);return a.has(e)?a.delete(e):a.add(e),a})},[]),U=C===void 0?i.length>=2:C!==!1,F=typeof C=="string"?C:"bottom",w=N.filter(e=>!e.hidden).length;return(0,n.jsx)(De.ChartContainer,{title:M,description:B,height:d,width:m,size:p,loading:ke,empty:h.length===0||w===0,emptyState:te,error:ne,errorState:ve,onRetry:b,actions:re,tableView:L,legendPosition:F,legend:U?(0,n.jsx)($e.ChartLegend,{items:(0,E.toLegendItems)(N,S,O&&$!=="none"),position:F,marker:"rect",size:p,onToggle:I?Y:void 0}):void 0,table:L?(0,n.jsx)(Oe.ChartTableView,{data:h,series:N,xKey:r.key,xLabel:r.label??r.key,formatX:D,formatValue:z,caption:typeof M=="string"?M:void 0}):void 0,className:_,...se,children:({width:e})=>(0,n.jsx)(rt,{width:e,height:d,data:h,resolvedSeries:N,x:r,y:Re,grid:ee,size:p,curve:xe,stack:$,baseline:ae,connectNulls:R,referenceLines:K,annotations:Pe,annotationsLabel:le.chartAnnotations,patterns:O,patternBaseId:ie,overlay:k,maxPoints:X,brush:G,onBrush:u,brushLabel:Ae??le.chartBrush,syncEnabled:Le,margin:Se,tooltip:A,onPointClick:oe,plotLabel:t,formatValue:v,formatRaw:z,formatX:D})})}0&&(module.exports={AreaChart});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{memo as Ie,useCallback as R,useId as He,useMemo as I,useState as ve}from"react";import{cn as We}from"../../lib/cn.js";import{useUILabels as De}from"../../lib/i18n.js";import{ChartAnnotationLayer as Le,describeAnnotations as Me}from"../chart/ChartAnnotations.js";import{ChartAxis as Ae}from"../chart/ChartAxis.js";import{ChartBrushLayer as Ke,useChartBrush as $e}from"../chart/ChartBrush.js";import{ChartContainer as Xe}from"../chart/ChartContainer.js";import{ChartGrid as Ge}from"../chart/ChartGrid.js";import{ChartLegend as Oe}from"../chart/ChartLegend.js";import{ChartPatternDefs as ze,patternFill as Ye}from"../chart/ChartPatterns.js";import{useChartSync as _e}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 Se,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 Be,formatPercent as st,formatXValue as Re}from"../chart/utils/format.js";import{buildAreaPath as we,buildLinePath as Ve}from"../chart/utils/path.js";import{nearestIndex as lt,toKey as Ee,toNumber as it}from"../chart/utils/scales.js";import{stackExtent as ut,stackSeries as ct}from"../chart/utils/stack.js";import{extent as ht}from"../chart/utils/ticks.js";import{Fragment as bt,jsx as a,jsxs as H}from"react/jsx-runtime";var mt=.12,dt=.9,gt=10,ft=Ie(function({bands:g,stacked:r,patterns:m,patternBaseId:p}){return a("g",{children:g.map(u=>H("g",{children:[a("path",{d:u.area,fill:Ye(m,p,u.slot,u.color),fillOpacity:r?dt:mt,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.key))})});function pt({width:d,height:g,data:r,resolvedSeries:m,x:p,y:u,grid:b,size:Z,curve:f,stack:v,baseline:x,connectNulls:w,referenceLines:W,annotations:P,annotationsLabel:ue,patterns:q,patternBaseId:J,overlay:ce,maxPoints:C,brush:Q,onBrush:ee,brushLabel:he,syncEnabled:D,margin:te,tooltip:L,onPointClick:M,plotLabel:me,formatValue:y,formatRaw:K,formatX:V}){let[$,X]=ve(null),l=$!==null&&$<r.length?$:null,[de,ge]=ve(null),fe=_e(),s=D?fe:null,t=I(()=>{let e=m.filter(S=>!S.hidden),n=e.map(S=>S.key),o=v!=="none",i=ct(r,n,v),ae=o?ut(i):ht([...nt(r,n),x]),h=Je({width:d,height:g,data:r,x:p,y:u,bounds:ae,margin:te,placement:"point",formatValue:y,formatX:V,defaultIncludeZero:!0}),Ce=h.categoryCenters,se=h.valueScale,Te=se(o?0:x),Ne=e.map((S,ye)=>{let U=r.map((F,j)=>{let B=i[j].segments[ye];return{x:Ce[j],y:B.value===null?Number.NaN:se(B.end),defined:B.value!==null}}),xe=r.map((F,j)=>{let B=i[j].segments[ye];return{x:Ce[j],y:B.value===null?Number.NaN:se(o?B.start:x),defined:B.value!==null}}),le={connectNulls:w},ie=C&&C>0&&U.length>C?ot(U,C):null,ke=ie?ie.map(F=>U[F]):U,Pe=ie?ie.map(F=>xe[F]):xe;return C||at("AreaChart",U.length),{key:S.key,color:S.color,slot:S.slot,area:o?we(ke,Pe,f,le):we(ke,Te,f,le),edge:Ve(ke,f,le),gap:o&&ye>0?Ve(Pe,f,le):""}});return{visible:e,locate:Qe(h),plot:et({geometry:h,width:d,height:g,data:r,series:e,formatValue:y,formatX:V}),rows:i,stacked:o,xValues:h.xValues,positions:Ce,xTicks:h.categoryTicks,yTicks:h.valueTicks,valueScale:se,innerWidth:h.innerWidth,innerHeight:h.innerHeight,margin:h.margin,bands:Ne}},[r,m,p,u,d,g,te,f,v,x,w,C,y,V]),G=R(e=>t.visible.map((n,o)=>{let i=rt(r[e],n.key),ae=t.rows[e].segments[o],h=i===null?"\u2014":v==="percent"?`${K(i)} (${y(ae.end-ae.start)})`:y(i);return{seriesKey:n.key,seriesLabel:Se(n),color:n.color,value:i,formattedValue:h,datum:r[e]}}),[r,t.visible,t.rows,v,y,K]),ne=s?s.brush:de,re=R(e=>{ge(e),s?.setBrush(e),ee?.(e)},[s,ee]),c=$e({enabled:Q,active:ne!==null,centers:t.positions,xValues:t.xValues,offset:t.margin.left,orientation:"vertical",onCommit:re}),pe=R(e=>{if(c.onPointerMove(e),L===!1||r.length===0)return;let n=e.currentTarget.getBoundingClientRect(),o=e.clientX-n.left-t.margin.left,i=lt(t.positions,o);X(i>=0?i:null),s?.setHovered(i>=0?t.xValues[i]:null)},[c,L,r.length,t.margin.left,t.positions,t.xValues,s]),oe=R(()=>{X(null),s?.setHovered(null)},[s]),E=R(e=>{if(r.length===0)return;c.onKeyDown(e,l);let n=r.length-1,o=l??0,i=e.key==="ArrowRight"?Math.min(n,o+1):e.key==="ArrowLeft"?Math.max(0,o-1):e.key==="Home"?0:e.key==="End"?n:e.key==="Escape"?null:void 0;i!==void 0&&(e.preventDefault(),X(i),s?.setHovered(i===null?null:t.xValues[i]))},[r.length,l,c,s,t.xValues]),T=R(()=>{if(c.consumedClick()||!M||l===null)return;let[e]=G(l);e&&M({...e,index:l,x:t.xValues[l]})},[c,M,l,G,t.xValues]),be=l!==null||!s?.hovered?null:(()=>{let e=Ee(s.hovered),n=t.xValues.findIndex(o=>Ee(o)===e);return n<0?null:n})(),k=l??be,O=l===null?null:G(l),N=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),z=c.dragging??ne,Y=(()=>{if(!z)return null;let e=t.locate(z.from),n=t.locate(z.to);return e===null||n===null?null:{from:e,to:n}})(),_=tt(ce),A=l===null||O===null?null:{x:t.xValues[l],xLabel:V(t.xValues[l],l),index:l,points:O};return H(bt,{children:[H("svg",{width:d,height:g,role:"img","aria-label":me??[t.visible.map(e=>Se(e)).join(", "),Me(P,ue)].filter(Boolean).join(". "),tabIndex:0,className:We("touch-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500",Q&&"select-none"),onPointerDown:c.onPointerDown,onPointerMove:pe,onPointerUp:c.onPointerUp,onPointerCancel:c.onPointerUp,onPointerLeave:oe,onKeyDown:E,onBlur:oe,onClick:T,children:[q?a(ze,{id:J,entries:m.map(e=>({slot:e.slot,color:e.color}))}):null,H("g",{transform:`translate(${t.margin.left}, ${t.margin.top})`,children:[a(Ge,{width:t.innerWidth,height:t.innerHeight,horizontal:b==="y"||b==="both"?t.yTicks.map(e=>e.offset):void 0,vertical:b==="x"||b==="both"?t.xTicks.map(e=>e.offset):void 0}),P?a(Le,{layer:"under",annotations:P,xAt:t.locate,yAt:t.valueScale,width:t.innerWidth,height:t.innerHeight}):null,Y?a(Ke,{from:Y.from,to:Y.to,width:t.innerWidth,height:t.innerHeight,live:c.dragging!==null,label:he}):null,_.under?.(t.plot),a(ft,{bands:t.bands,stacked:t.stacked,patterns:q&&t.stacked,patternBaseId:J}),P?a(Le,{annotations:P,xAt:t.locate,yAt:t.valueScale,width:t.innerWidth,height:t.innerHeight}):null,W?.map(e=>{let n=t.valueScale(e.value),o=n<gt?n+12:n-4;return H("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??""}`)}),_.over?.(t.plot),k!==null?H("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}),N.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:p.hidden?null:a(Ae,{orientation:"bottom",ticks:t.xTicks,length:t.innerWidth,label:p.label,size:Z})}),a("g",{transform:`translate(${t.margin.left}, ${t.margin.top})`,children:u?.hidden?null:a(Ae,{orientation:"left",ticks:t.yTicks,length:t.innerHeight,showLine:!1,label:u?.label,size:Z})})]}),A&&L!==!1?a(Fe,{x:t.margin.left+t.positions[A.index],y:t.margin.top+(N.length>0?Math.min(...N.map(e=>e.y)):t.innerHeight/2),containerWidth:d,children:typeof L=="function"?L(A):a(je,{title:A.xLabel,points:A.points})}):null]})}function $t({data:d,series:g,x:r,y:m,height:p=240,width:u,size:b="md",grid:Z="y",legend:f,tooltip:v=!0,tableView:x=!1,emphasis:w,title:W,description:P,loading:ue=!1,emptyState:q,error:J=!1,errorState:ce,onRetry:C,actions:Q,onPointClick:ee,curve:he="monotone",stack:D="none",baseline:te=0,connectNulls:L=!1,referenceLines:M,annotations:me,overlay:y,patterns:K=!1,legendToggle:V=!0,maxPoints:$,brush:X=!1,onBrush:l,brushLabel:de,sync:ge=!0,margin:fe,locale:s,plotLabel:t,className:G,...ne}){let re=De(),[c,pe]=ve(()=>new Set),oe=He(),E=I(()=>g.map((e,n)=>({...e,slot:n,hidden:e.hidden||c.has(e.key),color:Ze(e,n,w)})),[g,c,w]),T=D==="percent",be=I(()=>T?{domain:[0,100],...m}:m,[T,m]),k=I(()=>m?.format??(T?e=>st(e,{locale:s,alreadyScaled:!0,maximumFractionDigits:0}):e=>Be(e,s)),[m?.format,T,s]),O=I(()=>e=>Be(e,s),[s]),N=I(()=>r.format??(e=>r.scale==="time"?Re(e instanceof Date?e:new Date(it(e)),s):Re(e,s)),[r.format,r.scale,s]),z=R(e=>{pe(n=>{let o=new Set(n);return o.has(e)?o.delete(e):o.add(e),o})},[]),Y=f===void 0?g.length>=2:f!==!1,_=typeof f=="string"?f:"bottom",A=E.filter(e=>!e.hidden).length;return a(Xe,{title:W,description:P,height:p,width:u,size:b,loading:ue,empty:d.length===0||A===0,emptyState:q,error:J,errorState:ce,onRetry:C,actions:Q,tableView:x,legendPosition:_,legend:Y?a(Oe,{items:qe(E,w,K&&D!=="none"),position:_,marker:"rect",size:b,onToggle:V?z:void 0}):void 0,table:x?a(Ue,{data:d,series:E,xKey:r.key,xLabel:r.label??r.key,formatX:N,formatValue:O,caption:typeof W=="string"?W:void 0}):void 0,className:G,...ne,children:({width:e})=>a(pt,{width:e,height:p,data:d,resolvedSeries:E,x:r,y:be,grid:Z,size:b,curve:he,stack:D,baseline:te,connectNulls:L,referenceLines:M,annotations:me,annotationsLabel:re.chartAnnotations,patterns:K,patternBaseId:oe,overlay:y,maxPoints:$,brush:X,onBrush:l,brushLabel:de??re.chartBrush,syncEnabled:ge,margin:fe,tooltip:v,onPointClick:ee,plotLabel:t,formatValue:k,formatRaw:O,formatX:N})})}export{$t as AreaChart};
|
|
1
|
+
"use client";import{memo as He,useCallback as w,useId as Ie,useMemo as I,useState as ve}from"react";import{cn as Ne}from"../../lib/cn.js";import{useUILabels as We}from"../../lib/i18n.js";import{ChartAnnotationLayer as Ae,describeAnnotations as De}from"../chart/ChartAnnotations.js";import{ChartAxis as Le}from"../chart/ChartAxis.js";import{ChartBrushLayer as Me,useChartBrush as $e}from"../chart/ChartBrush.js";import{ChartContainer as Ke}from"../chart/ChartContainer.js";import{ChartGrid as Oe}from"../chart/ChartGrid.js";import{ChartLegend as Xe}from"../chart/ChartLegend.js";import{ChartPatternDefs as Ge,patternFill as _e}from"../chart/ChartPatterns.js";import{useChartSync as ze}from"../chart/ChartSync.js";import{ChartTableView as Ye}from"../chart/ChartTableView.js";import{ChartTooltip as Ue,ChartTooltipContent as Fe}from"../chart/ChartTooltip.js";import{getSeriesLabel as Se,resolveSeriesColor as je,toLegendItems as Ze}from"../chart/palette.js";import{buildCartesianGeometry as qe,createCategoryLocator as Je,createPlotContext as Qe,splitOverlay as et}from"../chart/utils/cartesian.js";import{collectAllValues as tt,readNumber as nt}from"../chart/utils/data.js";import{decimateIndices as rt,warnPointBudget as ot}from"../chart/utils/decimate.js";import{formatAuto as Be,formatPercent as at,formatXValue as st}from"../chart/utils/format.js";import{buildAreaPath as Re,buildLinePath as we,isolatedPoints as lt}from"../chart/utils/path.js";import{nearestIndex as it,toKey as Te}from"../chart/utils/scales.js";import{stackExtent as ut,stackSeries as ct}from"../chart/utils/stack.js";import{extent as ht}from"../chart/utils/ticks.js";import{formatTimeValue as mt}from"../chart/utils/timestamp.js";import{CHART_TOUCH as dt}from"../chart/utils/touch.js";import{Fragment as bt,jsx as a,jsxs as N}from"react/jsx-runtime";var gt=.12,ft=.9,pt=10,yt=He(function({bands:f,stacked:r,patterns:d,patternBaseId:y}){return a("g",{children:f.map(u=>N("g",{children:[a("path",{d:u.area,fill:_e(d,y,u.slot,u.color),fillOpacity:r?ft:gt,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(h=>a("circle",{cx:h.x,cy:h.y,r:3,fill:u.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},`${h.x}-${h.y}`))]},u.key))})});function Ct({width:g,height:f,data:r,resolvedSeries:d,x:y,y:u,grid:h,size:Z,curve:p,stack:v,baseline:x,connectNulls:P,referenceLines:W,annotations:A,annotationsLabel:ce,patterns:q,patternBaseId:J,overlay:he,maxPoints:C,brush:Q,onBrush:ee,brushLabel:me,syncEnabled:D,margin:te,tooltip:L,onPointClick:M,plotLabel:de,formatValue:b,formatRaw:$,formatX:T}){let[K,O]=ve(null),l=K!==null&&K<r.length?K:null,[ge,fe]=ve(null),pe=ze(),s=D?pe:null,t=I(()=>{let e=d.filter(B=>!B.hidden),n=e.map(B=>B.key),o=v!=="none",i=ct(r,n,v),ae=o?ut(i):ht([...tt(r,n),x]),m=qe({width:g,height:f,data:r,x:y,y:u,bounds:ae,margin:te,placement:"point",formatValue:b,formatX:T,defaultIncludeZero:!0}),be=m.categoryCenters,se=m.valueScale,Ve=se(o?0:x),Ee=e.map((B,ke)=>{let U=r.map((F,j)=>{let R=i[j].segments[ke];return{x:be[j],y:R.value===null?Number.NaN:se(R.end),defined:R.value!==null}}),xe=r.map((F,j)=>{let R=i[j].segments[ke];return{x:be[j],y:R.value===null?Number.NaN:se(o?R.start:x),defined:R.value!==null}}),le={connectNulls:P},ie=C&&C>0&&U.length>C?rt(U,C):null,ue=ie?ie.map(F=>U[F]):U,Pe=ie?ie.map(F=>xe[F]):xe;return C||ot("AreaChart",U.length),{key:B.key,color:B.color,slot:B.slot,area:o?Re(ue,Pe,p,le):Re(ue,Ve,p,le),edge:we(ue,p,le),gap:o&&ke>0?we(Pe,p,le):"",isolated:lt(ue,P)}});return{visible:e,locate:Je(m),plot:Qe({geometry:m,width:g,height:f,data:r,series:e,formatValue:b,formatX:T}),rows:i,stacked:o,xValues:m.xValues,positions:be,xTicks:m.categoryTicks,yTicks:m.valueTicks,valueScale:se,innerWidth:m.innerWidth,innerHeight:m.innerHeight,margin:m.margin,bands:Ee}},[r,d,y,u,g,f,te,p,v,x,P,C,b,T]),X=w(e=>t.visible.map((n,o)=>{let i=nt(r[e],n.key),ae=t.rows[e].segments[o],m=i===null?"\u2014":v==="percent"?`${$(i)} (${b(ae.end-ae.start)})`:b(i);return{seriesKey:n.key,seriesLabel:Se(n),color:n.color,value:i,formattedValue:m,datum:r[e]}}),[r,t.visible,t.rows,v,b,$]),ne=s?s.brush:ge,re=w(e=>{fe(e),s?.setBrush(e),ee?.(e)},[s,ee]),c=$e({enabled:Q,active:ne!==null,centers:t.positions,xValues:t.xValues,offset:t.margin.left,orientation:"vertical",onCommit:re}),ye=w(e=>{if(c.onPointerMove(e),L===!1||r.length===0)return;let n=e.currentTarget.getBoundingClientRect(),o=e.clientX-n.left-t.margin.left,i=it(t.positions,o);O(i>=0?i:null),s?.setHovered(i>=0?t.xValues[i]:null)},[c,L,r.length,t.margin.left,t.positions,t.xValues,s]),oe=w(()=>{O(null),s?.setHovered(null)},[s]),V=w(e=>{if(r.length===0)return;c.onKeyDown(e,l);let n=r.length-1,o=l??0,i=e.key==="ArrowRight"?Math.min(n,o+1):e.key==="ArrowLeft"?Math.max(0,o-1):e.key==="Home"?0:e.key==="End"?n:e.key==="Escape"?null:void 0;i!==void 0&&(e.preventDefault(),O(i),s?.setHovered(i===null?null:t.xValues[i]))},[r.length,l,c,s,t.xValues]),E=w(()=>{if(c.consumedClick()||!M||l===null)return;let[e]=X(l);e&&M({...e,index:l,x:t.xValues[l]})},[c,M,l,X,t.xValues]),Ce=l!==null||!s?.hovered?null:(()=>{let e=Te(s.hovered),n=t.xValues.findIndex(o=>Te(o)===e);return n<0?null:n})(),k=l??Ce,G=l===null?null:X(l),H=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),_=c.dragging??ne,z=(()=>{if(!_)return null;let e=t.locate(_.from),n=t.locate(_.to);return e===null||n===null?null:{from:e,to:n}})(),Y=et(he),S=l===null||G===null?null:{x:t.xValues[l],xLabel:T(t.xValues[l],l),index:l,points:G};return N(bt,{children:[N("svg",{width:g,height:f,role:"img","aria-label":de??[t.visible.map(e=>Se(e)).join(", "),De(A,ce)].filter(Boolean).join(". "),tabIndex:0,className:Ne(dt,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500",Q&&"select-none"),onPointerDown:c.onPointerDown,onPointerMove:ye,onPointerUp:c.onPointerUp,onPointerCancel:c.onPointerUp,onPointerLeave:oe,onKeyDown:V,onBlur:oe,onClick:E,children:[q?a(Ge,{id:J,entries:d.map(e=>({slot:e.slot,color:e.color}))}):null,N("g",{transform:`translate(${t.margin.left}, ${t.margin.top})`,children:[a(Oe,{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(Ae,{layer:"under",annotations:A,xAt:t.locate,yAt:t.valueScale,width:t.innerWidth,height:t.innerHeight}):null,z?a(Me,{from:z.from,to:z.to,width:t.innerWidth,height:t.innerHeight,live:c.dragging!==null,label:me}):null,Y.under?.(t.plot),a(yt,{bands:t.bands,stacked:t.stacked,patterns:q&&t.stacked,patternBaseId:J}),A?a(Ae,{annotations:A,xAt:t.locate,yAt:t.valueScale,width:t.innerWidth,height:t.innerHeight}):null,W?.map(e=>{let n=t.valueScale(e.value),o=n<pt?n+12:n-4;return N("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??""}`)}),Y.over?.(t.plot),k!==null?N("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}),H.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:y.hidden?null:a(Le,{orientation:"bottom",ticks:t.xTicks,length:t.innerWidth,label:y.label,size:Z})}),a("g",{transform:`translate(${t.margin.left}, ${t.margin.top})`,children:u?.hidden?null:a(Le,{orientation:"left",ticks:t.yTicks,length:t.innerHeight,showLine:!1,label:u?.label,size:Z})})]}),S&&L!==!1?a(Ue,{x:t.margin.left+t.positions[S.index],y:t.margin.top+(H.length>0?Math.min(...H.map(e=>e.y)):t.innerHeight/2),containerWidth:g,children:typeof L=="function"?L(S):a(Fe,{title:S.xLabel,points:S.points})}):null]})}function _t({data:g,series:f,x:r,y:d,height:y=240,width:u,size:h="md",grid:Z="y",legend:p,tooltip:v=!0,tableView:x=!1,emphasis:P,title:W,description:A,loading:ce=!1,emptyState:q,error:J=!1,errorState:he,onRetry:C,actions:Q,onPointClick:ee,curve:me="monotone",stack:D="none",baseline:te=0,connectNulls:L=!1,referenceLines:M,annotations:de,overlay:b,patterns:$=!1,legendToggle:T=!0,maxPoints:K,brush:O=!1,onBrush:l,brushLabel:ge,sync:fe=!0,margin:pe,locale:s,plotLabel:t,className:X,...ne}){let re=We(),[c,ye]=ve(()=>new Set),oe=Ie(),V=I(()=>f.map((e,n)=>({...e,slot:n,hidden:e.hidden||c.has(e.key),color:je(e,n,P)})),[f,c,P]),E=D==="percent",Ce=I(()=>E?{domain:[0,100],...d}:d,[E,d]),k=I(()=>d?.format??(E?e=>at(e,{locale:s,alreadyScaled:!0,maximumFractionDigits:0}):e=>Be(e,s)),[d?.format,E,s]),G=I(()=>e=>Be(e,s),[s]),H=I(()=>r.format??(e=>r.scale==="time"?mt(e,s):st(e,s)),[r.format,r.scale,s]),_=w(e=>{ye(n=>{let o=new Set(n);return o.has(e)?o.delete(e):o.add(e),o})},[]),z=p===void 0?f.length>=2:p!==!1,Y=typeof p=="string"?p:"bottom",S=V.filter(e=>!e.hidden).length;return a(Ke,{title:W,description:A,height:y,width:u,size:h,loading:ce,empty:g.length===0||S===0,emptyState:q,error:J,errorState:he,onRetry:C,actions:Q,tableView:x,legendPosition:Y,legend:z?a(Xe,{items:Ze(V,P,$&&D!=="none"),position:Y,marker:"rect",size:h,onToggle:T?_:void 0}):void 0,table:x?a(Ye,{data:g,series:V,xKey:r.key,xLabel:r.label??r.key,formatX:H,formatValue:G,caption:typeof W=="string"?W:void 0}):void 0,className:X,...ne,children:({width:e})=>a(Ct,{width:e,height:y,data:g,resolvedSeries:V,x:r,y:Ce,grid:Z,size:h,curve:me,stack:D,baseline:te,connectNulls:L,referenceLines:M,annotations:de,annotationsLabel:re.chartAnnotations,patterns:$,patternBaseId:oe,overlay:b,maxPoints:K,brush:O,onBrush:l,brushLabel:ge??re.chartBrush,syncEnabled:fe,margin:pe,tooltip:v,onPointClick:ee,plotLabel:t,formatValue:k,formatRaw:G,formatX:H})})}export{_t as AreaChart};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";"use client";var Qe=Object.defineProperty;var Mt=Object.getOwnPropertyDescriptor;var Vt=Object.getOwnPropertyNames;var Tt=Object.prototype.hasOwnProperty;var It=(g,c)=>{for(var n in c)Qe(g,n,{get:c[n],enumerable:!0})},Dt=(g,c,n,m)=>{if(c&&typeof c=="object"||typeof c=="function")for(let d of Vt(c))!Tt.call(g,d)&&d!==n&&Qe(g,d,{get:()=>c[d],enumerable:!(m=Mt(c,d))||m.enumerable});return g};var Wt=g=>Dt(Qe({},"__esModule",{value:!0}),g);var Gt={};It(Gt,{BarChart:()=>zt,resetBarChartWarnings:()=>Ot});module.exports=Wt(Gt);var s=require("react"),dt=require("../../lib/cn.cjs"),mt=require("../../lib/i18n.cjs"),we=require("../chart/ChartAnnotations.cjs"),et=require("../chart/ChartAxis.cjs"),$e=require("../chart/ChartBrush.cjs"),ft=require("../chart/ChartContainer.cjs"),gt=require("../chart/ChartGrid.cjs"),bt=require("../chart/ChartLegend.cjs"),Oe=require("../chart/ChartPatterns.cjs"),pt=require("../chart/ChartScaleLegend.cjs"),yt=require("../chart/ChartSync.cjs"),Ct=require("../chart/ChartTableView.cjs"),Ke=require("../chart/ChartTooltip.cjs"),L=require("../chart/palette.cjs"),X=require("../chart/utils/cartesian.cjs"),T=require("../chart/utils/data.cjs"),de=require("../chart/utils/format.cjs"),vt=require("../chart/utils/bins.cjs"),_e=require("../chart/utils/path.cjs"),Se=require("../chart/utils/scales.cjs"),me=require("../chart/utils/stack.cjs"),xt=require("../chart/utils/text.cjs"),Be=require("../chart/utils/ticks.cjs"),r=require("react/jsx-runtime"),Ht=24,ne=2,Nt=4,he=6,$t=10,tt=!1,nt=!1;function Ot(){tt=!1,nt=!1}var Kt=(0,s.memo)(function({bars:c,patterns:n,patternBaseId:m}){return(0,r.jsx)("g",{children:c.map((d,A)=>(0,r.jsxs)("g",{children:[(0,r.jsx)("path",{d:d.d,fill:(0,Oe.patternFill)(n,m,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}`))})}),_t=(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(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 Xt({width:g,height:c,data:n,resolvedSeries:m,x:d,y:A,grid:I,size:Pe,orientation:R,stack:N,center:E,centerKey:D,valueColors:z,binned:re,curve:Le,barSize:Ae,showValues:Re,referenceLines:Xe,annotations:G,annotationsLabel:ze,patterns:Ee,patternBaseId:oe,overlay:Me,brush:M,onBrush:U,brushLabel:Ge,syncEnabled:Ue,margin:ae,tooltip:F,onPointClick:fe,plotLabel:Ve,formatValue:$,formatRaw:Y,formatX:le}){let[ge,be]=(0,s.useState)(null),f=ge!==null&&ge<n.length?ge:null,[Fe,Ye]=(0,s.useState)(null),W=(0,yt.useChartSync)(),C=Ue?W:null,e=(0,s.useMemo)(()=>{let t=R==="vertical",o=m.filter(p=>!p.hidden),l=o.filter(p=>p.type!=="line"),y=o.filter(p=>p.type==="line"),w=l.map(p=>p.key),b=D!==null||N!=="none",K=D!==null?(0,me.stackDiverging)(n,w,{centerKey:D,percent:N==="percent"}):(0,me.stackSeries)(n,w,N),i=b?(0,me.stackExtent)(K):(0,Be.extent)((0,T.collectAllValues)(n,w)),a=(0,Be.extent)((0,T.collectAllValues)(n,y.map(p=>p.key))),u=i===null?a:a===null?i:[Math.min(i[0],a[0]),Math.max(i[1],a[1])],h=(0,X.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:ae,orientation:R,placement:"band",bandPaddingInner:re?0:void 0,formatValue:$,formatX:le,defaultIncludeZero:E===0}),{valueScale:J,bandwidth:ve,categoryPositions:rt,innerWidth:ot,innerHeight:at}=h,kt=J(E),De=Math.max(1,l.length),wt=b?ve:ve/De,_=Math.min(Ae??(re?Number.POSITIVE_INFINITY:Ht),Math.max(1,wt-(b&&!re?0:ne))),St=b?_:De*_+(De-1)*ne,lt=(ve-St)/2,it=[],st=p=>b?p.end>=p.start:p.end>=E;K.forEach((p,We)=>{let Q=-1,He=-1;p.segments.forEach((P,ce)=>{P.value!==null&&P.outer!==!1&&(st(P)?Q=ce:He=ce)});let se=0,xe=0;p.segments.forEach((P,ce)=>{if(P.value===null)return;let je=l[ce],v=st(P),ct=J(b?P.start:E),ut=J(P.end),ee=Math.min(ct,ut),ue=Math.abs(ut-ct),Pt=P.base??(v?se===0:xe===0),Lt=t?!v:v;b&&!Pt&&ue>ne&&(ue-=ne,Lt&&(ee+=ne)),v?se+=1:xe+=1;let Ne=rt[We]+(b?lt:lt+ce*(_+ne)),At=ce===(v?Q:He)?t?v?"top":"bottom":v?"right":"left":"none",Rt=t?{x:Ne,y:ee,width:_,height:ue}:{x:ee,y:Ne,width:ue,height:_},qe=null;if(Re&&!b){let Je=Y(P.value),ht=(0,xt.estimateTextWidth)(Je,10);if(t){let te=v?ee:ee+ue,ke=v?te-he:te+he,Et=De>1?_+ne:ve;ht<=Et&&(v?ke>8:ke<at-4)&&(qe={x:Ne+_/2,y:ke,anchor:"middle",text:Je})}else{let te=v?ee+ue:ee,ke=v?ot-te-he:te-he;ht<=ke&&(qe={x:v?te+he:te-he,y:Ne+_/2,anchor:v?"start":"end",text:Je})}}it.push({key:je.key,slot:je.slot,color:z&&P.value!==null?z(P.value):je.color,d:(0,_e.buildBarPath)({...Rt,radius:Nt,round:At}),label:qe})})});let Bt=y.map(p=>{let We=h.categoryCenters.map((Q,He)=>{let se=(0,T.readNumber)(n[He],p.key),xe=se===null?Number.NaN:J(se);return{x:t?Q:xe,y:t?xe:Q,defined:se!==null}});return{key:p.key,color:p.color,dashed:p.dashed,d:(0,_e.buildLinePath)(We,Le),markers:We.filter(Q=>Q.defined!==!1)}});return{vertical:t,visible:o,locate:(0,X.createCategoryLocator)(h),barSeries:l,rows:K,stacked:b,plot:(0,X.createPlotContext)({geometry:h,width:g,height:c,data:n,series:o,formatValue:$,formatX:le}),xValues:h.xValues,categoryPositions:rt,categoryCenters:h.categoryCenters,bandwidth:ve,categoryTicks:h.categoryTicks,valueTicks:h.valueTicks,valueScale:J,baseline:kt,innerWidth:ot,innerHeight:at,margin:h.margin,bars:it,lines:Bt}},[n,m,d,A,g,c,ae,R,N,E,D,z,re,Le,Ae,Re,$,Y,le]),pe=(0,s.useCallback)(t=>e.visible.map(o=>{let l=(0,T.readNumber)(n[t],o.key),y=e.barSeries.indexOf(o),w=y===-1?null:e.rows[t].segments[y],b=l===null?"\u2014":N==="percent"&&w!==null?`${Y(l)} (${$(w.end-w.start)})`:$(l);return{seriesKey:o.key,seriesLabel:(0,L.getSeriesLabel)(o),color:o.color,value:l,formattedValue:b,datum:n[t]}}),[n,e.visible,e.barSeries,e.rows,N,$,Y]),ye=C?C.brush:Fe,Te=(0,s.useCallback)(t=>{Ye(t),C?.setBrush(t),U?.(t)},[C,U]),x=(0,$e.useChartBrush)({enabled:M,active:ye!==null,centers:e.categoryCenters,xValues:e.xValues,offset:e.vertical?e.margin.left:e.margin.top,orientation:R,onCommit:Te}),Ze=(0,s.useCallback)(t=>{if(x.onPointerMove(t),F===!1||n.length===0)return;let o=t.currentTarget.getBoundingClientRect(),l=e.vertical?t.clientX-o.left-e.margin.left:t.clientY-o.top-e.margin.top,y=(0,Se.nearestIndex)(e.categoryCenters,l);be(y>=0?y:null),C?.setHovered(y>=0?e.xValues[y]:null)},[x,F,n.length,e.vertical,e.margin,e.categoryCenters,e.xValues,C]),S=(0,s.useCallback)(()=>{be(null),C?.setHovered(null)},[C]),k=(0,s.useCallback)(t=>{if(n.length===0)return;x.onKeyDown(t,f);let o=n.length-1,l=f??0,y=e.vertical?"ArrowRight":"ArrowDown",w=e.vertical?"ArrowLeft":"ArrowUp",b=t.key===y?Math.min(o,l+1):t.key===w?Math.max(0,l-1):t.key==="Home"?0:t.key==="End"?o:t.key==="Escape"?null:void 0;b!==void 0&&(t.preventDefault(),be(b),C?.setHovered(b===null?null:e.xValues[b]))},[n.length,f,e.vertical,x,C,e.xValues]),Z=(0,s.useCallback)(()=>{if(x.consumedClick()||!fe||f===null)return;let[t]=pe(f);t&&fe({...t,index:f,x:e.xValues[f]})},[x,fe,f,pe,e.xValues]),O=f!==null||!C?.hovered?null:(()=>{let t=(0,Se.toKey)(C.hovered),o=e.xValues.findIndex(l=>(0,Se.toKey)(l)===t);return o<0?null:o})(),V=f??O,B=x.dragging??ye,H=(()=>{if(!B)return null;let t=e.locate(B.from),o=e.locate(B.to);if(t===null||o===null)return null;let l=e.bandwidth/2;return{from:Math.min(t,o)-l,to:Math.max(t,o)+l}})(),j=(0,X.splitOverlay)(Me),Ie=f===null?null:pe(f),q=f===null||Ie===null?null:{x:e.xValues[f],xLabel:le(e.xValues[f],f),index:f,points:Ie},Ce=t=>{let o=e.rows[t].segments.filter(l=>l.value!==null).map(l=>e.valueScale(l.end));for(let l of e.lines){let y=(0,T.readNumber)(n[t],l.key);y!==null&&o.push(e.valueScale(y))}return o},ie=f===null?null:e.vertical?{x:e.margin.left+e.categoryCenters[f],y:e.margin.top+Math.min(...Ce(f),e.baseline)}:{x:e.margin.left+Math.max(...Ce(f),e.baseline),y:e.margin.top+e.categoryCenters[f]};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("svg",{width:g,height:c,role:"img","aria-label":Ve??[e.visible.map(t=>(0,L.getSeriesLabel)(t)).join(", "),(0,we.describeAnnotations)(G,ze)].filter(Boolean).join(". "),tabIndex:0,className:(0,dt.cn)("touch-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500",M&&"select-none"),onPointerDown:x.onPointerDown,onPointerMove:Ze,onPointerUp:x.onPointerUp,onPointerCancel:x.onPointerUp,onPointerLeave:S,onKeyDown:k,onBlur:S,onClick:Z,children:[Ee?(0,r.jsx)(Oe.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)(gt.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}),G?(0,r.jsx)(we.ChartAnnotationLayer,{layer:"under",annotations:G,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight,bandwidth:e.bandwidth}):null,H?(0,r.jsx)($e.ChartBrushLayer,{from:H.from,to:H.to,width:e.innerWidth,height:e.innerHeight,orientation:R,live:x.dragging!==null,label:Ge}):null,V!==null?(0,r.jsx)("rect",{x:e.vertical?e.categoryPositions[V]:0,y:e.vertical?0:e.categoryPositions[V],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,j.under?.(e.plot),(0,r.jsx)(Kt,{bars:e.bars,patterns:Ee,patternBaseId:oe}),e.lines.length>0?(0,r.jsx)(_t,{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)(we.ChartAnnotationLayer,{annotations:G,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight,bandwidth:e.bandwidth}):null,j.over?.(e.plot),Xe?.map(t=>{let o=e.valueScale(t.value),l=o<$t?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?l: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)(et.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)(et.ChartAxis,{orientation:"left",ticks:e.vertical?e.valueTicks:e.categoryTicks,length:e.innerHeight,showLine:!1,label:e.vertical?A?.label:d.label,size:Pe})})]}),q&&ie&&F!==!1?(0,r.jsx)(Ke.ChartTooltip,{x:ie.x,y:ie.y,containerWidth:g,children:typeof F=="function"?F(q):(0,r.jsx)(Ke.ChartTooltipContent,{title:q.xLabel,points:q.points})}):null]})}function zt({data:g,series:c,x:n,y:m,height:d=260,width:A,size:I="md",grid:Pe="y",legend:R,tooltip:N=!0,tableView:E=!1,emphasis:D,title:z,description:re,loading:Le=!1,emptyState:Ae,error:Re=!1,errorState:Xe,onRetry:G,actions:ze,onPointClick:Ee,orientation:oe="vertical",stack:Me="none",diverging:M,bins:U,curve:Ge="linear",barSize:Ue,sort:ae="none",showValues:F=!1,referenceLines:fe,annotations:Ve,overlay:$,patterns:Y=!1,legendToggle:le=!0,brush:ge=!1,onBrush:be,brushLabel:f,sync:Fe=!0,margin:Ye,locale:W,plotLabel:C,className:e,...pe}){let ye=(0,mt.useUILabels)(),[Te,x]=(0,s.useState)(()=>new Set),Ze=(0,s.useId)(),S=U!==void 0&&U!==!1,k=S||typeof M!="string"?null:M,Z=!S&&typeof M=="number"?M:0,O=(0,s.useMemo)(()=>{let i=k===null?null:(0,L.createDivergingScale)([0,Math.max(1,c.length-1)],{center:Math.max(0,c.findIndex(a=>a.key===k)),symmetric:!1});return c.map((a,u)=>({...a,slot:u,hidden:a.hidden||Te.has(a.key),color:i&&!a.color&&!D?a.key===k?L.CHART_MUTED_COLOR:i(u):(0,L.resolveSeriesColor)(a,u,D)}))},[c,Te,D,k]),V=(0,s.useMemo)(()=>i=>(0,de.formatAuto)(i,W),[W]),B=(0,s.useMemo)(()=>{if(!S)return null;c.length>1&&!tt&&(tt=!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",a=n.format?h=>n.format(h,0):h=>V(h),u=(0,vt.binValues)(g.map(h=>(0,T.readNumber)(h,n.key)),U);return{rows:u.map(h=>({[n.key]:h.from,[i]:h.count})),labels:u.map(h=>`${a(h.from)}\u2013${a(h.to)}`)}},[S,U,g,n.key,n.format,c,V]),H=(0,s.useMemo)(()=>{if(B)return B.rows;if(ae==="none")return g;let i=O.filter(u=>!u.hidden).map(u=>u.key),a=u=>i.reduce((h,J)=>h+((0,T.readNumber)(u,J)??0),0);return[...g].sort((u,h)=>ae==="asc"?a(u)-a(h):a(h)-a(u))},[B,g,ae,O]),j=!S&&Me==="percent",Ie=(0,s.useMemo)(()=>j?{domain:k===null?[0,100]:[-100,100],...m}:m,[j,k,m]),q=(0,s.useMemo)(()=>{let i=m?.format??(j?a=>(0,de.formatPercent)(a,{locale:W,alreadyScaled:!0,maximumFractionDigits:0}):V);return k===null?i:a=>i(Math.abs(a))},[m?.format,j,W,V,k]),Ce=(0,s.useMemo)(()=>B?(i,a)=>B.labels[a]??"":n.format??(i=>(0,de.formatXValue)(i,W)),[B,n.format,W]),ie=(0,s.useMemo)(()=>B?{...n,scale:"category"}:n,[B,n]),t=(0,s.useCallback)(i=>{x(a=>{let u=new Set(a);return u.has(i)?u.delete(i):u.add(i),u})},[]),o=oe==="vertical"?Ve:void 0;Ve&&oe!=="vertical"&&!nt&&(nt=!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 l=R===void 0?c.length>=2:R!==!1,y=typeof R=="string"?R:"bottom",w=O.filter(i=>!i.hidden),b=w.length,K=(0,s.useMemo)(()=>{if(S||M===void 0||M===!1||k!==null||b!==1)return null;let i=(0,T.collectAllValues)(H,w.map(u=>u.key)),a=(0,Be.resolveDomain)([...i,Z],{domain:m?.domain,includeZero:m?.includeZero??Z===0,ticks:m?.ticks??5});return(0,L.createDivergingScale)(a,{center:Z})},[S,M,k,b,w,H,Z,m]);return(0,r.jsx)(ft.ChartContainer,{title:z,description:re,height:d,width:A,size:I,loading:Le,empty:H.length===0||b===0,emptyState:Ae,error:Re,errorState:Xe,onRetry:G,actions:ze,tableView:E,legendPosition:y,legend:K?(0,r.jsx)(pt.ChartScaleLegend,{scale:K,label:m?.label,format:q,size:I,locale:W}):l?(0,r.jsx)(bt.ChartLegend,{items:(0,L.toLegendItems)(O,D,Y),position:y,marker:"rect",size:I,onToggle:le?t:void 0}):void 0,table:E?(0,r.jsx)(Ct.ChartTableView,{data:H,series:O,xKey:ie.key,xLabel:n.label??n.key,formatX:Ce,formatValue:V,caption:typeof z=="string"?z:void 0}):void 0,className:e,...pe,children:({width:i})=>(0,r.jsx)(Xt,{width:i,height:d,data:H,resolvedSeries:O,x:ie,y:Ie,grid:Pe,size:I,orientation:oe,stack:S?"none":Me,center:Z,centerKey:k,valueColors:K,binned:S,curve:Ge,barSize:Ue,showValues:F,referenceLines:fe,annotations:o,annotationsLabel:ye.chartAnnotations,patterns:Y&&K===null,patternBaseId:Ze,overlay:$,brush:ge,onBrush:be,brushLabel:f??ye.chartBrush,syncEnabled:Fe,margin:Ye,tooltip:N,onPointClick:Ee,plotLabel:C,formatValue:q,formatRaw:V,formatX:Ce})})}0&&(module.exports={BarChart,resetBarChartWarnings});
|
|
1
|
+
"use strict";"use client";var et=Object.defineProperty;var Vt=Object.getOwnPropertyDescriptor;var Mt=Object.getOwnPropertyNames;var It=Object.prototype.hasOwnProperty;var Dt=(g,c)=>{for(var n in c)et(g,n,{get:c[n],enumerable:!0})},Ht=(g,c,n,m)=>{if(c&&typeof c=="object"||typeof c=="function")for(let d of Mt(c))!It.call(g,d)&&d!==n&&et(g,d,{get:()=>c[d],enumerable:!(m=Vt(c,d))||m.enumerable});return g};var Wt=g=>Ht(et({},"__esModule",{value:!0}),g);var zt={};Dt(zt,{BarChart:()=>Gt,resetBarChartWarnings:()=>$t});module.exports=Wt(zt);var s=require("react"),mt=require("../../lib/cn.cjs"),ft=require("../../lib/i18n.cjs"),we=require("../chart/ChartAnnotations.cjs"),tt=require("../chart/ChartAxis.cjs"),Oe=require("../chart/ChartBrush.cjs"),gt=require("../chart/ChartContainer.cjs"),pt=require("../chart/ChartGrid.cjs"),bt=require("../chart/ChartLegend.cjs"),_e=require("../chart/ChartPatterns.cjs"),yt=require("../chart/ChartScaleLegend.cjs"),Ct=require("../chart/ChartSync.cjs"),vt=require("../chart/ChartTableView.cjs"),$e=require("../chart/ChartTooltip.cjs"),L=require("../chart/palette.cjs"),U=require("../chart/utils/cartesian.cjs"),M=require("../chart/utils/data.cjs"),de=require("../chart/utils/format.cjs"),xt=require("../chart/utils/bins.cjs"),Ke=require("../chart/utils/path.cjs"),Se=require("../chart/utils/scales.cjs"),me=require("../chart/utils/stack.cjs"),kt=require("../chart/utils/text.cjs"),Be=require("../chart/utils/ticks.cjs"),Ue=require("../chart/utils/touch.cjs"),r=require("react/jsx-runtime"),Nt=24,ne=2,Ot=4,he=6,_t=10,nt=!1,rt=!1;function $t(){nt=!1,rt=!1}var Kt=(0,s.memo)(function({bars:c,patterns:n,patternBaseId:m}){return(0,r.jsx)("g",{children:c.map((d,R)=>(0,r.jsxs)("g",{children:[(0,r.jsx)("path",{d:d.d,fill:(0,_e.patternFill)(n,m,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}-${R}`))})}),Ut=(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(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 Xt({width:g,height:c,data:n,resolvedSeries:m,x:d,y:R,grid:I,size:Pe,orientation:E,stack:N,center:T,centerKey:D,valueColors:X,binned:re,curve:Le,barSize:Ae,showValues:Re,referenceLines:Xe,annotations:G,annotationsLabel:Ge,patterns:Ee,patternBaseId:oe,overlay:Te,brush:A,onBrush:z,brushLabel:ze,syncEnabled:Fe,margin:ae,tooltip:F,onPointClick:fe,plotLabel:Ve,formatValue:O,formatRaw:Y,formatX:le}){let[ge,pe]=(0,s.useState)(null),f=ge!==null&&ge<n.length?ge:null,[Ye,Ze]=(0,s.useState)(null),H=(0,Ct.useChartSync)(),C=Fe?H:null,e=(0,s.useMemo)(()=>{let t=E==="vertical",o=m.filter(b=>!b.hidden),l=o.filter(b=>b.type!=="line"),y=o.filter(b=>b.type==="line"),w=l.map(b=>b.key),p=D!==null||N!=="none",$=D!==null?(0,me.stackDiverging)(n,w,{centerKey:D,percent:N==="percent"}):(0,me.stackSeries)(n,w,N),i=p?(0,me.stackExtent)($):(0,Be.extent)((0,M.collectAllValues)(n,w)),a=(0,Be.extent)((0,M.collectAllValues)(n,y.map(b=>b.key))),u=i===null?a:a===null?i:[Math.min(i[0],a[0]),Math.max(i[1],a[1])],h=(0,U.buildCartesianGeometry)({width:g,height:c,data:n,x:d,y:R,bounds:u===null?null:[Math.min(u[0],T),Math.max(u[1],T)],margin:ae,orientation:E,placement:"band",bandPaddingInner:re?0:void 0,formatValue:O,formatX:le,defaultIncludeZero:T===0}),{valueScale:J,bandwidth:ve,categoryPositions:ot,innerWidth:at,innerHeight:lt}=h,wt=J(T),De=Math.max(1,l.length),St=p?ve:ve/De,K=Math.min(Ae??(re?Number.POSITIVE_INFINITY:Nt),Math.max(1,St-(p&&!re?0:ne))),Bt=p?K:De*K+(De-1)*ne,it=(ve-Bt)/2,st=[],ct=b=>p?b.end>=b.start:b.end>=T;$.forEach((b,He)=>{let Q=-1,We=-1;b.segments.forEach((P,ce)=>{P.value!==null&&P.outer!==!1&&(ct(P)?Q=ce:We=ce)});let se=0,xe=0;b.segments.forEach((P,ce)=>{if(P.value===null)return;let qe=l[ce],v=ct(P),ut=J(p?P.start:T),ht=J(P.end),ee=Math.min(ut,ht),ue=Math.abs(ht-ut),Lt=P.base??(v?se===0:xe===0),At=t?!v:v;p&&!Lt&&ue>ne&&(ue-=ne,At&&(ee+=ne)),v?se+=1:xe+=1;let Ne=ot[He]+(p?it:it+ce*(K+ne)),Rt=ce===(v?Q:We)?t?v?"top":"bottom":v?"right":"left":"none",Et=t?{x:Ne,y:ee,width:K,height:ue}:{x:ee,y:Ne,width:ue,height:K},Je=null;if(Re&&!p){let Qe=Y(P.value),dt=(0,kt.estimateTextWidth)(Qe,10);if(t){let te=v?ee:ee+ue,ke=v?te-he:te+he,Tt=De>1?K+ne:ve;dt<=Tt&&(v?ke>8:ke<lt-4)&&(Je={x:Ne+K/2,y:ke,anchor:"middle",text:Qe})}else{let te=v?ee+ue:ee,ke=v?at-te-he:te-he;dt<=ke&&(Je={x:v?te+he:te-he,y:Ne+K/2,anchor:v?"start":"end",text:Qe})}}st.push({key:qe.key,slot:qe.slot,color:X&&P.value!==null?X(P.value):qe.color,d:(0,Ke.buildBarPath)({...Et,radius:Ot,round:Rt}),label:Je})})});let Pt=y.map(b=>{let He=h.categoryCenters.map((Q,We)=>{let se=(0,M.readNumber)(n[We],b.key),xe=se===null?Number.NaN:J(se);return{x:t?Q:xe,y:t?xe:Q,defined:se!==null}});return{key:b.key,color:b.color,dashed:b.dashed,d:(0,Ke.buildLinePath)(He,Le),markers:He.filter(Q=>Q.defined!==!1)}});return{vertical:t,visible:o,locate:(0,U.createCategoryLocator)(h),barSeries:l,rows:$,stacked:p,plot:(0,U.createPlotContext)({geometry:h,width:g,height:c,data:n,series:o,formatValue:O,formatX:le}),xValues:h.xValues,categoryPositions:ot,categoryCenters:h.categoryCenters,bandwidth:ve,categoryTicks:h.categoryTicks,valueTicks:h.valueTicks,valueScale:J,baseline:wt,innerWidth:at,innerHeight:lt,margin:h.margin,bars:st,lines:Pt}},[n,m,d,R,g,c,ae,E,N,T,D,X,re,Le,Ae,Re,O,Y,le]),be=(0,s.useCallback)(t=>e.visible.map(o=>{let l=(0,M.readNumber)(n[t],o.key),y=e.barSeries.indexOf(o),w=y===-1?null:e.rows[t].segments[y],p=l===null?"\u2014":N==="percent"&&w!==null?`${Y(l)} (${O(w.end-w.start)})`:O(l);return{seriesKey:o.key,seriesLabel:(0,L.getSeriesLabel)(o),color:o.color,value:l,formattedValue:p,datum:n[t]}}),[n,e.visible,e.barSeries,e.rows,N,O,Y]),ye=C?C.brush:Ye,Me=(0,s.useCallback)(t=>{Ze(t),C?.setBrush(t),z?.(t)},[C,z]),x=(0,Oe.useChartBrush)({enabled:A,active:ye!==null,centers:e.categoryCenters,xValues:e.xValues,offset:e.vertical?e.margin.left:e.margin.top,orientation:E,onCommit:Me}),je=(0,s.useCallback)(t=>{if(x.onPointerMove(t),F===!1||n.length===0)return;let o=t.currentTarget.getBoundingClientRect(),l=e.vertical?t.clientX-o.left-e.margin.left:t.clientY-o.top-e.margin.top,y=(0,Se.nearestIndex)(e.categoryCenters,l);pe(y>=0?y:null),C?.setHovered(y>=0?e.xValues[y]:null)},[x,F,n.length,e.vertical,e.margin,e.categoryCenters,e.xValues,C]),S=(0,s.useCallback)(()=>{pe(null),C?.setHovered(null)},[C]),k=(0,s.useCallback)(t=>{if(n.length===0)return;x.onKeyDown(t,f);let o=n.length-1,l=f??0,y=e.vertical?"ArrowRight":"ArrowDown",w=e.vertical?"ArrowLeft":"ArrowUp",p=t.key===y?Math.min(o,l+1):t.key===w?Math.max(0,l-1):t.key==="Home"?0:t.key==="End"?o:t.key==="Escape"?null:void 0;p!==void 0&&(t.preventDefault(),pe(p),C?.setHovered(p===null?null:e.xValues[p]))},[n.length,f,e.vertical,x,C,e.xValues]),Z=(0,s.useCallback)(()=>{if(x.consumedClick()||!fe||f===null)return;let[t]=be(f);t&&fe({...t,index:f,x:e.xValues[f]})},[x,fe,f,be,e.xValues]),_=f!==null||!C?.hovered?null:(()=>{let t=(0,Se.toKey)(C.hovered),o=e.xValues.findIndex(l=>(0,Se.toKey)(l)===t);return o<0?null:o})(),V=f??_,B=x.dragging??ye,W=(()=>{if(!B)return null;let t=e.locate(B.from),o=e.locate(B.to);if(t===null||o===null)return null;let l=e.bandwidth/2;return{from:Math.min(t,o)-l,to:Math.max(t,o)+l}})(),j=(0,U.splitOverlay)(Te),Ie=f===null?null:be(f),q=f===null||Ie===null?null:{x:e.xValues[f],xLabel:le(e.xValues[f],f),index:f,points:Ie},Ce=t=>{let o=e.rows[t].segments.filter(l=>l.value!==null).map(l=>e.valueScale(l.end));for(let l of e.lines){let y=(0,M.readNumber)(n[t],l.key);y!==null&&o.push(e.valueScale(y))}return o},ie=f===null?null:e.vertical?{x:e.margin.left+e.categoryCenters[f],y:e.margin.top+Math.min(...Ce(f),e.baseline)}:{x:e.margin.left+Math.max(...Ce(f),e.baseline),y:e.margin.top+e.categoryCenters[f]};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("svg",{width:g,height:c,role:"img","aria-label":Ve??[e.visible.map(t=>(0,L.getSeriesLabel)(t)).join(", "),(0,we.describeAnnotations)(G,Ge)].filter(Boolean).join(". "),tabIndex:0,className:(0,mt.cn)(A&&!e.vertical?Ue.CHART_TOUCH_VERTICAL_DRAG:Ue.CHART_TOUCH,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500",A&&"select-none"),onPointerDown:x.onPointerDown,onPointerMove:je,onPointerUp:x.onPointerUp,onPointerCancel:x.onPointerUp,onPointerLeave:S,onKeyDown:k,onBlur:S,onClick:Z,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)(pt.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}),G?(0,r.jsx)(we.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)(Oe.ChartBrushLayer,{from:W.from,to:W.to,width:e.innerWidth,height:e.innerHeight,orientation:E,live:x.dragging!==null,label:ze}):null,V!==null?(0,r.jsx)("rect",{x:e.vertical?e.categoryPositions[V]:0,y:e.vertical?0:e.categoryPositions[V],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,j.under?.(e.plot),(0,r.jsx)(Kt,{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"}),G?(0,r.jsx)(we.ChartAnnotationLayer,{annotations:G,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight,bandwidth:e.bandwidth}):null,j.over?.(e.plot),Xe?.map(t=>{let o=e.valueScale(t.value),l=o<_t?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?l: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:R?.hidden)?null:(0,r.jsx)(tt.ChartAxis,{orientation:"bottom",ticks:e.vertical?e.categoryTicks:e.valueTicks,length:e.innerWidth,label:e.vertical?d.label:R?.label,size:Pe})}),(0,r.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:(e.vertical?R?.hidden:d.hidden)?null:(0,r.jsx)(tt.ChartAxis,{orientation:"left",ticks:e.vertical?e.valueTicks:e.categoryTicks,length:e.innerHeight,showLine:!1,label:e.vertical?R?.label:d.label,size:Pe})})]}),q&&ie&&F!==!1?(0,r.jsx)($e.ChartTooltip,{x:ie.x,y:ie.y,containerWidth:g,children:typeof F=="function"?F(q):(0,r.jsx)($e.ChartTooltipContent,{title:q.xLabel,points:q.points})}):null]})}function Gt({data:g,series:c,x:n,y:m,height:d=260,width:R,size:I="md",grid:Pe="y",legend:E,tooltip:N=!0,tableView:T=!1,emphasis:D,title:X,description:re,loading:Le=!1,emptyState:Ae,error:Re=!1,errorState:Xe,onRetry:G,actions:Ge,onPointClick:Ee,orientation:oe="vertical",stack:Te="none",diverging:A,bins:z,curve:ze="linear",barSize:Fe,sort:ae="none",showValues:F=!1,referenceLines:fe,annotations:Ve,overlay:O,patterns:Y=!1,legendToggle:le=!0,brush:ge=!1,onBrush:pe,brushLabel:f,sync:Ye=!0,margin:Ze,locale:H,plotLabel:C,className:e,...be}){let ye=(0,ft.useUILabels)(),[Me,x]=(0,s.useState)(()=>new Set),je=(0,s.useId)(),S=z!==void 0&&z!==!1,k=S||typeof A!="string"?null:A,Z=!S&&typeof A=="number"?A:0,_=(0,s.useMemo)(()=>{let i=k===null?null:(0,L.createDivergingScale)([0,Math.max(1,c.length-1)],{center:Math.max(0,c.findIndex(a=>a.key===k)),symmetric:!1});return c.map((a,u)=>({...a,slot:u,hidden:a.hidden||Me.has(a.key),color:i&&!a.color&&!D?a.key===k?L.CHART_MUTED_COLOR:i(u):(0,L.resolveSeriesColor)(a,u,D)}))},[c,Me,D,k]),V=(0,s.useMemo)(()=>i=>(0,de.formatAuto)(i,H),[H]),B=(0,s.useMemo)(()=>{if(!S)return null;c.length>1&&!nt&&(nt=!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",a=n.format?h=>n.format(h,0):h=>V(h),u=(0,xt.binValues)(g.map(h=>(0,M.readNumber)(h,n.key)),z);return{rows:u.map(h=>({[n.key]:h.from,[i]:h.count})),labels:u.map(h=>`${a(h.from)}\u2013${a(h.to)}`)}},[S,z,g,n.key,n.format,c,V]),W=(0,s.useMemo)(()=>{if(B)return B.rows;if(ae==="none")return g;let i=_.filter(u=>!u.hidden).map(u=>u.key),a=u=>i.reduce((h,J)=>h+((0,M.readNumber)(u,J)??0),0);return[...g].sort((u,h)=>ae==="asc"?a(u)-a(h):a(h)-a(u))},[B,g,ae,_]),j=!S&&Te==="percent",Ie=(0,s.useMemo)(()=>j?{domain:k===null?[0,100]:[-100,100],...m}:m,[j,k,m]),q=(0,s.useMemo)(()=>{let i=m?.format??(j?a=>(0,de.formatPercent)(a,{locale:H,alreadyScaled:!0,maximumFractionDigits:0}):V);return k===null?i:a=>i(Math.abs(a))},[m?.format,j,H,V,k]),Ce=(0,s.useMemo)(()=>B?(i,a)=>B.labels[a]??"":n.format??(i=>(0,de.formatXValue)(i,H)),[B,n.format,H]),ie=(0,s.useMemo)(()=>B?{...n,scale:"category"}:n,[B,n]),t=(0,s.useCallback)(i=>{x(a=>{let u=new Set(a);return u.has(i)?u.delete(i):u.add(i),u})},[]),o=oe==="vertical"?Ve:void 0;Ve&&oe!=="vertical"&&!rt&&(rt=!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 l=E===void 0?c.length>=2:E!==!1,y=typeof E=="string"?E:"bottom",w=_.filter(i=>!i.hidden),p=w.length,$=(0,s.useMemo)(()=>{if(S||A===void 0||A===!1||k!==null||p!==1)return null;let i=(0,M.collectAllValues)(W,w.map(u=>u.key)),a=(0,Be.resolveDomain)([...i,Z],{domain:m?.domain,includeZero:m?.includeZero??Z===0,ticks:m?.ticks??5});return(0,L.createDivergingScale)(a,{center:Z})},[S,A,k,p,w,W,Z,m]);return(0,r.jsx)(gt.ChartContainer,{title:X,description:re,height:d,width:R,size:I,loading:Le,empty:W.length===0||p===0,emptyState:Ae,error:Re,errorState:Xe,onRetry:G,actions:Ge,tableView:T,legendPosition:y,legend:$?(0,r.jsx)(yt.ChartScaleLegend,{scale:$,label:m?.label,format:q,size:I,locale:H}):l?(0,r.jsx)(bt.ChartLegend,{items:(0,L.toLegendItems)(_,D,Y),position:y,marker:"rect",size:I,onToggle:le?t:void 0}):void 0,table:T?(0,r.jsx)(vt.ChartTableView,{data:W,series:_,xKey:ie.key,xLabel:n.label??n.key,formatX:Ce,formatValue:V,caption:typeof X=="string"?X:void 0}):void 0,className:e,...be,children:({width:i})=>(0,r.jsx)(Xt,{width:i,height:d,data:W,resolvedSeries:_,x:ie,y:Ie,grid:Pe,size:I,orientation:oe,stack:S?"none":Te,center:Z,centerKey:k,valueColors:$,binned:S,curve:ze,barSize:Fe,showValues:F,referenceLines:fe,annotations:o,annotationsLabel:ye.chartAnnotations,patterns:Y&&$===null,patternBaseId:je,overlay:O,brush:ge,onBrush:pe,brushLabel:f??ye.chartBrush,syncEnabled:Ye,margin:Ze,tooltip:N,onPointClick:Ee,plotLabel:C,formatValue:q,formatRaw:V,formatX:Ce})})}0&&(module.exports={BarChart,resetBarChartWarnings});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{memo as ct,useCallback as ee,useId as Ct,useMemo as M,useState as ze}from"react";import{cn as vt}from"../../lib/cn.js";import{useUILabels as xt}from"../../lib/i18n.js";import{ChartAnnotationLayer as rt,describeAnnotations as kt}from"../chart/ChartAnnotations.js";import{ChartAxis as ot}from"../chart/ChartAxis.js";import{ChartBrushLayer as wt,useChartBrush as St}from"../chart/ChartBrush.js";import{ChartContainer as Bt}from"../chart/ChartContainer.js";import{ChartGrid as Pt}from"../chart/ChartGrid.js";import{ChartLegend as Lt}from"../chart/ChartLegend.js";import{ChartPatternDefs as At,patternFill as Rt}from"../chart/ChartPatterns.js";import{ChartScaleLegend as Et}from"../chart/ChartScaleLegend.js";import{useChartSync as Mt}from"../chart/ChartSync.js";import{ChartTableView as Vt}from"../chart/ChartTableView.js";import{ChartTooltip as Tt,ChartTooltipContent as It}from"../chart/ChartTooltip.js";import{CHART_MUTED_COLOR as Dt,createDivergingScale as at,getSeriesLabel as lt,resolveSeriesColor as Wt,toLegendItems as Ht}from"../chart/palette.js";import{buildCartesianGeometry as Nt,createCategoryLocator as $t,createPlotContext as Ot,splitOverlay as Kt}from"../chart/utils/cartesian.js";import{collectAllValues as Ge,readNumber as ve}from"../chart/utils/data.js";import{formatAuto as _t,formatPercent as Xt,formatXValue as zt}from"../chart/utils/format.js";import{binValues as Gt}from"../chart/utils/bins.js";import{buildBarPath as Ut,buildLinePath as Ft}from"../chart/utils/path.js";import{nearestIndex as Yt,toKey as it}from"../chart/utils/scales.js";import{stackDiverging as Zt,stackExtent as jt,stackSeries as qt}from"../chart/utils/stack.js";import{estimateTextWidth as Jt}from"../chart/utils/text.js";import{extent as st,resolveDomain as Qt}from"../chart/utils/ticks.js";import{Fragment as ln,jsx as i,jsxs as ue}from"react/jsx-runtime";var en=24,Q=2,tn=4,ce=6,nn=10,Ue=!1,Fe=!1;function In(){Ue=!1,Fe=!1}var rn=ct(function({bars:b,patterns:n,patternBaseId:h}){return i("g",{children:b.map((f,P)=>ue("g",{children:[i("path",{d:f.d,fill:Rt(n,h,f.slot,f.color)}),f.label?i("text",{x:f.label.x,y:f.label.y,textAnchor:f.label.anchor,dominantBaseline:"middle",className:"fill-gray-600 text-[10px] [font-variant-numeric:tabular-nums] dark:fill-gray-300",children:f.label.text}):null]},`${f.key}-${P}`))})}),on=ct(function({lines:b}){return i("g",{children:b.map(n=>ue("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 an({width:C,height:b,data:n,resolvedSeries:h,x:f,y:P,grid:V,size:xe,orientation:L,stack:W,center:A,centerKey:T,valueColors:K,binned:te,curve:ke,barSize:we,showValues:Se,referenceLines:Ie,annotations:_,annotationsLabel:De,patterns:Be,patternBaseId:ne,overlay:Pe,brush:R,onBrush:X,brushLabel:We,syncEnabled:He,margin:re,tooltip:z,onPointClick:he,plotLabel:Le,formatValue:H,formatRaw:G,formatX:oe}){let[de,me]=ze(null),u=de!==null&&de<n.length?de:null,[Ne,$e]=ze(null),I=Mt(),p=He?I:null,e=M(()=>{let t=L==="vertical",r=h.filter(m=>!m.hidden),a=r.filter(m=>m.type!=="line"),g=r.filter(m=>m.type==="line"),k=a.map(m=>m.key),d=T!==null||W!=="none",$=T!==null?Zt(n,k,{centerKey:T,percent:W==="percent"}):qt(n,k,W),l=d?jt($):st(Ge(n,k)),o=st(Ge(n,g.map(m=>m.key))),s=l===null?o:o===null?l:[Math.min(l[0],o[0]),Math.max(l[1],o[1])],c=Nt({width:C,height:b,data:n,x:f,y:P,bounds:s===null?null:[Math.min(s[0],A),Math.max(s[1],A)],margin:re,orientation:L,placement:"band",bandPaddingInner:te?0:void 0,formatValue:H,formatX:oe,defaultIncludeZero:A===0}),{valueScale:Z,bandwidth:pe,categoryPositions:Ye,innerWidth:Ze,innerHeight:je}=c,ut=Z(A),Ee=Math.max(1,a.length),ht=d?pe:pe/Ee,O=Math.min(we??(te?Number.POSITIVE_INFINITY:en),Math.max(1,ht-(d&&!te?0:Q))),dt=d?O:Ee*O+(Ee-1)*Q,qe=(pe-dt)/2,Je=[],Qe=m=>d?m.end>=m.start:m.end>=A;$.forEach((m,Me)=>{let j=-1,Ve=-1;m.segments.forEach((B,ie)=>{B.value!==null&&B.outer!==!1&&(Qe(B)?j=ie:Ve=ie)});let le=0,ye=0;m.segments.forEach((B,ie)=>{if(B.value===null)return;let Ke=a[ie],y=Qe(B),et=Z(d?B.start:A),tt=Z(B.end),q=Math.min(et,tt),se=Math.abs(tt-et),ft=B.base??(y?le===0:ye===0),gt=t?!y:y;d&&!ft&&se>Q&&(se-=Q,gt&&(q+=Q)),y?le+=1:ye+=1;let Te=Ye[Me]+(d?qe:qe+ie*(O+Q)),bt=ie===(y?j:Ve)?t?y?"top":"bottom":y?"right":"left":"none",pt=t?{x:Te,y:q,width:O,height:se}:{x:q,y:Te,width:se,height:O},_e=null;if(Se&&!d){let Xe=G(B.value),nt=Jt(Xe,10);if(t){let J=y?q:q+se,Ce=y?J-ce:J+ce,yt=Ee>1?O+Q:pe;nt<=yt&&(y?Ce>8:Ce<je-4)&&(_e={x:Te+O/2,y:Ce,anchor:"middle",text:Xe})}else{let J=y?q+se:q,Ce=y?Ze-J-ce:J-ce;nt<=Ce&&(_e={x:y?J+ce:J-ce,y:Te+O/2,anchor:y?"start":"end",text:Xe})}}Je.push({key:Ke.key,slot:Ke.slot,color:K&&B.value!==null?K(B.value):Ke.color,d:Ut({...pt,radius:tn,round:bt}),label:_e})})});let mt=g.map(m=>{let Me=c.categoryCenters.map((j,Ve)=>{let le=ve(n[Ve],m.key),ye=le===null?Number.NaN:Z(le);return{x:t?j:ye,y:t?ye:j,defined:le!==null}});return{key:m.key,color:m.color,dashed:m.dashed,d:Ft(Me,ke),markers:Me.filter(j=>j.defined!==!1)}});return{vertical:t,visible:r,locate:$t(c),barSeries:a,rows:$,stacked:d,plot:Ot({geometry:c,width:C,height:b,data:n,series:r,formatValue:H,formatX:oe}),xValues:c.xValues,categoryPositions:Ye,categoryCenters:c.categoryCenters,bandwidth:pe,categoryTicks:c.categoryTicks,valueTicks:c.valueTicks,valueScale:Z,baseline:ut,innerWidth:Ze,innerHeight:je,margin:c.margin,bars:Je,lines:mt}},[n,h,f,P,C,b,re,L,W,A,T,K,te,ke,we,Se,H,G,oe]),fe=ee(t=>e.visible.map(r=>{let a=ve(n[t],r.key),g=e.barSeries.indexOf(r),k=g===-1?null:e.rows[t].segments[g],d=a===null?"\u2014":W==="percent"&&k!==null?`${G(a)} (${H(k.end-k.start)})`:H(a);return{seriesKey:r.key,seriesLabel:lt(r),color:r.color,value:a,formattedValue:d,datum:n[t]}}),[n,e.visible,e.barSeries,e.rows,W,H,G]),ge=p?p.brush:Ne,Ae=ee(t=>{$e(t),p?.setBrush(t),X?.(t)},[p,X]),v=St({enabled:R,active:ge!==null,centers:e.categoryCenters,xValues:e.xValues,offset:e.vertical?e.margin.left:e.margin.top,orientation:L,onCommit:Ae}),Oe=ee(t=>{if(v.onPointerMove(t),z===!1||n.length===0)return;let r=t.currentTarget.getBoundingClientRect(),a=e.vertical?t.clientX-r.left-e.margin.left:t.clientY-r.top-e.margin.top,g=Yt(e.categoryCenters,a);me(g>=0?g:null),p?.setHovered(g>=0?e.xValues[g]:null)},[v,z,n.length,e.vertical,e.margin,e.categoryCenters,e.xValues,p]),w=ee(()=>{me(null),p?.setHovered(null)},[p]),x=ee(t=>{if(n.length===0)return;v.onKeyDown(t,u);let r=n.length-1,a=u??0,g=e.vertical?"ArrowRight":"ArrowDown",k=e.vertical?"ArrowLeft":"ArrowUp",d=t.key===g?Math.min(r,a+1):t.key===k?Math.max(0,a-1):t.key==="Home"?0:t.key==="End"?r:t.key==="Escape"?null:void 0;d!==void 0&&(t.preventDefault(),me(d),p?.setHovered(d===null?null:e.xValues[d]))},[n.length,u,e.vertical,v,p,e.xValues]),U=ee(()=>{if(v.consumedClick()||!he||u===null)return;let[t]=fe(u);t&&he({...t,index:u,x:e.xValues[u]})},[v,he,u,fe,e.xValues]),N=u!==null||!p?.hovered?null:(()=>{let t=it(p.hovered),r=e.xValues.findIndex(a=>it(a)===t);return r<0?null:r})(),E=u??N,S=v.dragging??ge,D=(()=>{if(!S)return null;let t=e.locate(S.from),r=e.locate(S.to);if(t===null||r===null)return null;let a=e.bandwidth/2;return{from:Math.min(t,r)-a,to:Math.max(t,r)+a}})(),F=Kt(Pe),Re=u===null?null:fe(u),Y=u===null||Re===null?null:{x:e.xValues[u],xLabel:oe(e.xValues[u],u),index:u,points:Re},be=t=>{let r=e.rows[t].segments.filter(a=>a.value!==null).map(a=>e.valueScale(a.end));for(let a of e.lines){let g=ve(n[t],a.key);g!==null&&r.push(e.valueScale(g))}return r},ae=u===null?null:e.vertical?{x:e.margin.left+e.categoryCenters[u],y:e.margin.top+Math.min(...be(u),e.baseline)}:{x:e.margin.left+Math.max(...be(u),e.baseline),y:e.margin.top+e.categoryCenters[u]};return ue(ln,{children:[ue("svg",{width:C,height:b,role:"img","aria-label":Le??[e.visible.map(t=>lt(t)).join(", "),kt(_,De)].filter(Boolean).join(". "),tabIndex:0,className:vt("touch-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500",R&&"select-none"),onPointerDown:v.onPointerDown,onPointerMove:Oe,onPointerUp:v.onPointerUp,onPointerCancel:v.onPointerUp,onPointerLeave:w,onKeyDown:x,onBlur:w,onClick:U,children:[Be?i(At,{id:ne,entries:h.map(t=>({slot:t.slot,color:t.color}))}):null,ue("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[i(Pt,{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}),_?i(rt,{layer:"under",annotations:_,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight,bandwidth:e.bandwidth}):null,D?i(wt,{from:D.from,to:D.to,width:e.innerWidth,height:e.innerHeight,orientation:L,live:v.dragging!==null,label:We}):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,F.under?.(e.plot),i(rn,{bars:e.bars,patterns:Be,patternBaseId:ne}),e.lines.length>0?i(on,{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"}),_?i(rt,{annotations:_,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight,bandwidth:e.bandwidth}):null,F.over?.(e.plot),Ie?.map(t=>{let r=e.valueScale(t.value),a=r<nn?r+12:r-4;return ue("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?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??""}`)})]}),i("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:(e.vertical?f.hidden:P?.hidden)?null:i(ot,{orientation:"bottom",ticks:e.vertical?e.categoryTicks:e.valueTicks,length:e.innerWidth,label:e.vertical?f.label:P?.label,size:xe})}),i("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:(e.vertical?P?.hidden:f.hidden)?null:i(ot,{orientation:"left",ticks:e.vertical?e.valueTicks:e.categoryTicks,length:e.innerHeight,showLine:!1,label:e.vertical?P?.label:f.label,size:xe})})]}),Y&&ae&&z!==!1?i(Tt,{x:ae.x,y:ae.y,containerWidth:C,children:typeof z=="function"?z(Y):i(It,{title:Y.xLabel,points:Y.points})}):null]})}function Dn({data:C,series:b,x:n,y:h,height:f=260,width:P,size:V="md",grid:xe="y",legend:L,tooltip:W=!0,tableView:A=!1,emphasis:T,title:K,description:te,loading:ke=!1,emptyState:we,error:Se=!1,errorState:Ie,onRetry:_,actions:De,onPointClick:Be,orientation:ne="vertical",stack:Pe="none",diverging:R,bins:X,curve:We="linear",barSize:He,sort:re="none",showValues:z=!1,referenceLines:he,annotations:Le,overlay:H,patterns:G=!1,legendToggle:oe=!0,brush:de=!1,onBrush:me,brushLabel:u,sync:Ne=!0,margin:$e,locale:I,plotLabel:p,className:e,...fe}){let ge=xt(),[Ae,v]=ze(()=>new Set),Oe=Ct(),w=X!==void 0&&X!==!1,x=w||typeof R!="string"?null:R,U=!w&&typeof R=="number"?R:0,N=M(()=>{let l=x===null?null:at([0,Math.max(1,b.length-1)],{center:Math.max(0,b.findIndex(o=>o.key===x)),symmetric:!1});return b.map((o,s)=>({...o,slot:s,hidden:o.hidden||Ae.has(o.key),color:l&&!o.color&&!T?o.key===x?Dt:l(s):Wt(o,s,T)}))},[b,Ae,T,x]),E=M(()=>l=>_t(l,I),[I]),S=M(()=>{if(!w)return null;b.length>1&&!Ue&&(Ue=!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=b[0]?.key??"count",o=n.format?c=>n.format(c,0):c=>E(c),s=Gt(C.map(c=>ve(c,n.key)),X);return{rows:s.map(c=>({[n.key]:c.from,[l]:c.count})),labels:s.map(c=>`${o(c.from)}\u2013${o(c.to)}`)}},[w,X,C,n.key,n.format,b,E]),D=M(()=>{if(S)return S.rows;if(re==="none")return C;let l=N.filter(s=>!s.hidden).map(s=>s.key),o=s=>l.reduce((c,Z)=>c+(ve(s,Z)??0),0);return[...C].sort((s,c)=>re==="asc"?o(s)-o(c):o(c)-o(s))},[S,C,re,N]),F=!w&&Pe==="percent",Re=M(()=>F?{domain:x===null?[0,100]:[-100,100],...h}:h,[F,x,h]),Y=M(()=>{let l=h?.format??(F?o=>Xt(o,{locale:I,alreadyScaled:!0,maximumFractionDigits:0}):E);return x===null?l:o=>l(Math.abs(o))},[h?.format,F,I,E,x]),be=M(()=>S?(l,o)=>S.labels[o]??"":n.format??(l=>zt(l,I)),[S,n.format,I]),ae=M(()=>S?{...n,scale:"category"}:n,[S,n]),t=ee(l=>{v(o=>{let s=new Set(o);return s.has(l)?s.delete(l):s.add(l),s})},[]),r=ne==="vertical"?Le:void 0;Le&&ne!=="vertical"&&!Fe&&(Fe=!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=L===void 0?b.length>=2:L!==!1,g=typeof L=="string"?L:"bottom",k=N.filter(l=>!l.hidden),d=k.length,$=M(()=>{if(w||R===void 0||R===!1||x!==null||d!==1)return null;let l=Ge(D,k.map(s=>s.key)),o=Qt([...l,U],{domain:h?.domain,includeZero:h?.includeZero??U===0,ticks:h?.ticks??5});return at(o,{center:U})},[w,R,x,d,k,D,U,h]);return i(Bt,{title:K,description:te,height:f,width:P,size:V,loading:ke,empty:D.length===0||d===0,emptyState:we,error:Se,errorState:Ie,onRetry:_,actions:De,tableView:A,legendPosition:g,legend:$?i(Et,{scale:$,label:h?.label,format:Y,size:V,locale:I}):a?i(Lt,{items:Ht(N,T,G),position:g,marker:"rect",size:V,onToggle:oe?t:void 0}):void 0,table:A?i(Vt,{data:D,series:N,xKey:ae.key,xLabel:n.label??n.key,formatX:be,formatValue:E,caption:typeof K=="string"?K:void 0}):void 0,className:e,...fe,children:({width:l})=>i(an,{width:l,height:f,data:D,resolvedSeries:N,x:ae,y:Re,grid:xe,size:V,orientation:ne,stack:w?"none":Pe,center:U,centerKey:x,valueColors:$,binned:w,curve:We,barSize:He,showValues:z,referenceLines:he,annotations:r,annotationsLabel:ge.chartAnnotations,patterns:G&&$===null,patternBaseId:Oe,overlay:H,brush:de,onBrush:me,brushLabel:u??ge.chartBrush,syncEnabled:Ne,margin:$e,tooltip:W,onPointClick:Be,plotLabel:p,formatValue:Y,formatRaw:E,formatX:be})})}export{Dn as BarChart,In as resetBarChartWarnings};
|
|
1
|
+
"use client";import{memo as ct,useCallback as ee,useId as Ct,useMemo as T,useState as Xe}from"react";import{cn as vt}from"../../lib/cn.js";import{useUILabels as xt}from"../../lib/i18n.js";import{ChartAnnotationLayer as rt,describeAnnotations as kt}from"../chart/ChartAnnotations.js";import{ChartAxis as ot}from"../chart/ChartAxis.js";import{ChartBrushLayer as wt,useChartBrush as St}from"../chart/ChartBrush.js";import{ChartContainer as Bt}from"../chart/ChartContainer.js";import{ChartGrid as Pt}from"../chart/ChartGrid.js";import{ChartLegend as Lt}from"../chart/ChartLegend.js";import{ChartPatternDefs as At,patternFill as Rt}from"../chart/ChartPatterns.js";import{ChartScaleLegend as Et}from"../chart/ChartScaleLegend.js";import{useChartSync as Tt}from"../chart/ChartSync.js";import{ChartTableView as Vt}from"../chart/ChartTableView.js";import{ChartTooltip as Mt,ChartTooltipContent as It}from"../chart/ChartTooltip.js";import{CHART_MUTED_COLOR as Dt,createDivergingScale as at,getSeriesLabel as lt,resolveSeriesColor as Ht,toLegendItems as Wt}from"../chart/palette.js";import{buildCartesianGeometry as Nt,createCategoryLocator as Ot,createPlotContext as _t,splitOverlay as $t}from"../chart/utils/cartesian.js";import{collectAllValues as Ge,readNumber as ve}from"../chart/utils/data.js";import{formatAuto as Kt,formatPercent as Ut,formatXValue as Xt}from"../chart/utils/format.js";import{binValues as Gt}from"../chart/utils/bins.js";import{buildBarPath as zt,buildLinePath as Ft}from"../chart/utils/path.js";import{nearestIndex as Yt,toKey as it}from"../chart/utils/scales.js";import{stackDiverging as Zt,stackExtent as jt,stackSeries as qt}from"../chart/utils/stack.js";import{estimateTextWidth as Jt}from"../chart/utils/text.js";import{extent as st,resolveDomain as Qt}from"../chart/utils/ticks.js";import{CHART_TOUCH as en,CHART_TOUCH_VERTICAL_DRAG as tn}from"../chart/utils/touch.js";import{Fragment as cn,jsx as i,jsxs as ue}from"react/jsx-runtime";var nn=24,Q=2,rn=4,ce=6,on=10,ze=!1,Fe=!1;function Wn(){ze=!1,Fe=!1}var an=ct(function({bars:p,patterns:n,patternBaseId:h}){return i("g",{children:p.map((f,L)=>ue("g",{children:[i("path",{d:f.d,fill:Rt(n,h,f.slot,f.color)}),f.label?i("text",{x:f.label.x,y:f.label.y,textAnchor:f.label.anchor,dominantBaseline:"middle",className:"fill-gray-600 text-[10px] [font-variant-numeric:tabular-nums] dark:fill-gray-300",children:f.label.text}):null]},`${f.key}-${L}`))})}),ln=ct(function({lines:p}){return i("g",{children:p.map(n=>ue("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 sn({width:C,height:p,data:n,resolvedSeries:h,x:f,y:L,grid:V,size:xe,orientation:A,stack:H,center:R,centerKey:M,valueColors:$,binned:te,curve:ke,barSize:we,showValues:Se,referenceLines:Ie,annotations:K,annotationsLabel:De,patterns:Be,patternBaseId:ne,overlay:Pe,brush:P,onBrush:U,brushLabel:He,syncEnabled:We,margin:re,tooltip:X,onPointClick:he,plotLabel:Le,formatValue:W,formatRaw:G,formatX:oe}){let[de,me]=Xe(null),u=de!==null&&de<n.length?de:null,[Ne,Oe]=Xe(null),I=Tt(),b=We?I:null,e=T(()=>{let t=A==="vertical",r=h.filter(m=>!m.hidden),a=r.filter(m=>m.type!=="line"),g=r.filter(m=>m.type==="line"),k=a.map(m=>m.key),d=M!==null||H!=="none",O=M!==null?Zt(n,k,{centerKey:M,percent:H==="percent"}):qt(n,k,H),l=d?jt(O):st(Ge(n,k)),o=st(Ge(n,g.map(m=>m.key))),s=l===null?o:o===null?l:[Math.min(l[0],o[0]),Math.max(l[1],o[1])],c=Nt({width:C,height:p,data:n,x:f,y:L,bounds:s===null?null:[Math.min(s[0],R),Math.max(s[1],R)],margin:re,orientation:A,placement:"band",bandPaddingInner:te?0:void 0,formatValue:W,formatX:oe,defaultIncludeZero:R===0}),{valueScale:Z,bandwidth:be,categoryPositions:Ye,innerWidth:Ze,innerHeight:je}=c,ut=Z(R),Ee=Math.max(1,a.length),ht=d?be:be/Ee,_=Math.min(we??(te?Number.POSITIVE_INFINITY:nn),Math.max(1,ht-(d&&!te?0:Q))),dt=d?_:Ee*_+(Ee-1)*Q,qe=(be-dt)/2,Je=[],Qe=m=>d?m.end>=m.start:m.end>=R;O.forEach((m,Te)=>{let j=-1,Ve=-1;m.segments.forEach((B,ie)=>{B.value!==null&&B.outer!==!1&&(Qe(B)?j=ie:Ve=ie)});let le=0,ye=0;m.segments.forEach((B,ie)=>{if(B.value===null)return;let $e=a[ie],y=Qe(B),et=Z(d?B.start:R),tt=Z(B.end),q=Math.min(et,tt),se=Math.abs(tt-et),ft=B.base??(y?le===0:ye===0),gt=t?!y:y;d&&!ft&&se>Q&&(se-=Q,gt&&(q+=Q)),y?le+=1:ye+=1;let Me=Ye[Te]+(d?qe:qe+ie*(_+Q)),pt=ie===(y?j:Ve)?t?y?"top":"bottom":y?"right":"left":"none",bt=t?{x:Me,y:q,width:_,height:se}:{x:q,y:Me,width:se,height:_},Ke=null;if(Se&&!d){let Ue=G(B.value),nt=Jt(Ue,10);if(t){let J=y?q:q+se,Ce=y?J-ce:J+ce,yt=Ee>1?_+Q:be;nt<=yt&&(y?Ce>8:Ce<je-4)&&(Ke={x:Me+_/2,y:Ce,anchor:"middle",text:Ue})}else{let J=y?q+se:q,Ce=y?Ze-J-ce:J-ce;nt<=Ce&&(Ke={x:y?J+ce:J-ce,y:Me+_/2,anchor:y?"start":"end",text:Ue})}}Je.push({key:$e.key,slot:$e.slot,color:$&&B.value!==null?$(B.value):$e.color,d:zt({...bt,radius:rn,round:pt}),label:Ke})})});let mt=g.map(m=>{let Te=c.categoryCenters.map((j,Ve)=>{let le=ve(n[Ve],m.key),ye=le===null?Number.NaN:Z(le);return{x:t?j:ye,y:t?ye:j,defined:le!==null}});return{key:m.key,color:m.color,dashed:m.dashed,d:Ft(Te,ke),markers:Te.filter(j=>j.defined!==!1)}});return{vertical:t,visible:r,locate:Ot(c),barSeries:a,rows:O,stacked:d,plot:_t({geometry:c,width:C,height:p,data:n,series:r,formatValue:W,formatX:oe}),xValues:c.xValues,categoryPositions:Ye,categoryCenters:c.categoryCenters,bandwidth:be,categoryTicks:c.categoryTicks,valueTicks:c.valueTicks,valueScale:Z,baseline:ut,innerWidth:Ze,innerHeight:je,margin:c.margin,bars:Je,lines:mt}},[n,h,f,L,C,p,re,A,H,R,M,$,te,ke,we,Se,W,G,oe]),fe=ee(t=>e.visible.map(r=>{let a=ve(n[t],r.key),g=e.barSeries.indexOf(r),k=g===-1?null:e.rows[t].segments[g],d=a===null?"\u2014":H==="percent"&&k!==null?`${G(a)} (${W(k.end-k.start)})`:W(a);return{seriesKey:r.key,seriesLabel:lt(r),color:r.color,value:a,formattedValue:d,datum:n[t]}}),[n,e.visible,e.barSeries,e.rows,H,W,G]),ge=b?b.brush:Ne,Ae=ee(t=>{Oe(t),b?.setBrush(t),U?.(t)},[b,U]),v=St({enabled:P,active:ge!==null,centers:e.categoryCenters,xValues:e.xValues,offset:e.vertical?e.margin.left:e.margin.top,orientation:A,onCommit:Ae}),_e=ee(t=>{if(v.onPointerMove(t),X===!1||n.length===0)return;let r=t.currentTarget.getBoundingClientRect(),a=e.vertical?t.clientX-r.left-e.margin.left:t.clientY-r.top-e.margin.top,g=Yt(e.categoryCenters,a);me(g>=0?g:null),b?.setHovered(g>=0?e.xValues[g]:null)},[v,X,n.length,e.vertical,e.margin,e.categoryCenters,e.xValues,b]),w=ee(()=>{me(null),b?.setHovered(null)},[b]),x=ee(t=>{if(n.length===0)return;v.onKeyDown(t,u);let r=n.length-1,a=u??0,g=e.vertical?"ArrowRight":"ArrowDown",k=e.vertical?"ArrowLeft":"ArrowUp",d=t.key===g?Math.min(r,a+1):t.key===k?Math.max(0,a-1):t.key==="Home"?0:t.key==="End"?r:t.key==="Escape"?null:void 0;d!==void 0&&(t.preventDefault(),me(d),b?.setHovered(d===null?null:e.xValues[d]))},[n.length,u,e.vertical,v,b,e.xValues]),z=ee(()=>{if(v.consumedClick()||!he||u===null)return;let[t]=fe(u);t&&he({...t,index:u,x:e.xValues[u]})},[v,he,u,fe,e.xValues]),N=u!==null||!b?.hovered?null:(()=>{let t=it(b.hovered),r=e.xValues.findIndex(a=>it(a)===t);return r<0?null:r})(),E=u??N,S=v.dragging??ge,D=(()=>{if(!S)return null;let t=e.locate(S.from),r=e.locate(S.to);if(t===null||r===null)return null;let a=e.bandwidth/2;return{from:Math.min(t,r)-a,to:Math.max(t,r)+a}})(),F=$t(Pe),Re=u===null?null:fe(u),Y=u===null||Re===null?null:{x:e.xValues[u],xLabel:oe(e.xValues[u],u),index:u,points:Re},pe=t=>{let r=e.rows[t].segments.filter(a=>a.value!==null).map(a=>e.valueScale(a.end));for(let a of e.lines){let g=ve(n[t],a.key);g!==null&&r.push(e.valueScale(g))}return r},ae=u===null?null:e.vertical?{x:e.margin.left+e.categoryCenters[u],y:e.margin.top+Math.min(...pe(u),e.baseline)}:{x:e.margin.left+Math.max(...pe(u),e.baseline),y:e.margin.top+e.categoryCenters[u]};return ue(cn,{children:[ue("svg",{width:C,height:p,role:"img","aria-label":Le??[e.visible.map(t=>lt(t)).join(", "),kt(K,De)].filter(Boolean).join(". "),tabIndex:0,className:vt(P&&!e.vertical?tn:en,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500",P&&"select-none"),onPointerDown:v.onPointerDown,onPointerMove:_e,onPointerUp:v.onPointerUp,onPointerCancel:v.onPointerUp,onPointerLeave:w,onKeyDown:x,onBlur:w,onClick:z,children:[Be?i(At,{id:ne,entries:h.map(t=>({slot:t.slot,color:t.color}))}):null,ue("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[i(Pt,{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}),K?i(rt,{layer:"under",annotations:K,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight,bandwidth:e.bandwidth}):null,D?i(wt,{from:D.from,to:D.to,width:e.innerWidth,height:e.innerHeight,orientation:A,live:v.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,F.under?.(e.plot),i(an,{bars:e.bars,patterns:Be,patternBaseId:ne}),e.lines.length>0?i(ln,{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"}),K?i(rt,{annotations:K,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight,bandwidth:e.bandwidth}):null,F.over?.(e.plot),Ie?.map(t=>{let r=e.valueScale(t.value),a=r<on?r+12:r-4;return ue("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?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??""}`)})]}),i("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:(e.vertical?f.hidden:L?.hidden)?null:i(ot,{orientation:"bottom",ticks:e.vertical?e.categoryTicks:e.valueTicks,length:e.innerWidth,label:e.vertical?f.label:L?.label,size:xe})}),i("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:(e.vertical?L?.hidden:f.hidden)?null:i(ot,{orientation:"left",ticks:e.vertical?e.valueTicks:e.categoryTicks,length:e.innerHeight,showLine:!1,label:e.vertical?L?.label:f.label,size:xe})})]}),Y&&ae&&X!==!1?i(Mt,{x:ae.x,y:ae.y,containerWidth:C,children:typeof X=="function"?X(Y):i(It,{title:Y.xLabel,points:Y.points})}):null]})}function Nn({data:C,series:p,x:n,y:h,height:f=260,width:L,size:V="md",grid:xe="y",legend:A,tooltip:H=!0,tableView:R=!1,emphasis:M,title:$,description:te,loading:ke=!1,emptyState:we,error:Se=!1,errorState:Ie,onRetry:K,actions:De,onPointClick:Be,orientation:ne="vertical",stack:Pe="none",diverging:P,bins:U,curve:He="linear",barSize:We,sort:re="none",showValues:X=!1,referenceLines:he,annotations:Le,overlay:W,patterns:G=!1,legendToggle:oe=!0,brush:de=!1,onBrush:me,brushLabel:u,sync:Ne=!0,margin:Oe,locale:I,plotLabel:b,className:e,...fe}){let ge=xt(),[Ae,v]=Xe(()=>new Set),_e=Ct(),w=U!==void 0&&U!==!1,x=w||typeof P!="string"?null:P,z=!w&&typeof P=="number"?P:0,N=T(()=>{let l=x===null?null:at([0,Math.max(1,p.length-1)],{center:Math.max(0,p.findIndex(o=>o.key===x)),symmetric:!1});return p.map((o,s)=>({...o,slot:s,hidden:o.hidden||Ae.has(o.key),color:l&&!o.color&&!M?o.key===x?Dt:l(s):Ht(o,s,M)}))},[p,Ae,M,x]),E=T(()=>l=>Kt(l,I),[I]),S=T(()=>{if(!w)return null;p.length>1&&!ze&&(ze=!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=p[0]?.key??"count",o=n.format?c=>n.format(c,0):c=>E(c),s=Gt(C.map(c=>ve(c,n.key)),U);return{rows:s.map(c=>({[n.key]:c.from,[l]:c.count})),labels:s.map(c=>`${o(c.from)}\u2013${o(c.to)}`)}},[w,U,C,n.key,n.format,p,E]),D=T(()=>{if(S)return S.rows;if(re==="none")return C;let l=N.filter(s=>!s.hidden).map(s=>s.key),o=s=>l.reduce((c,Z)=>c+(ve(s,Z)??0),0);return[...C].sort((s,c)=>re==="asc"?o(s)-o(c):o(c)-o(s))},[S,C,re,N]),F=!w&&Pe==="percent",Re=T(()=>F?{domain:x===null?[0,100]:[-100,100],...h}:h,[F,x,h]),Y=T(()=>{let l=h?.format??(F?o=>Ut(o,{locale:I,alreadyScaled:!0,maximumFractionDigits:0}):E);return x===null?l:o=>l(Math.abs(o))},[h?.format,F,I,E,x]),pe=T(()=>S?(l,o)=>S.labels[o]??"":n.format??(l=>Xt(l,I)),[S,n.format,I]),ae=T(()=>S?{...n,scale:"category"}:n,[S,n]),t=ee(l=>{v(o=>{let s=new Set(o);return s.has(l)?s.delete(l):s.add(l),s})},[]),r=ne==="vertical"?Le:void 0;Le&&ne!=="vertical"&&!Fe&&(Fe=!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=A===void 0?p.length>=2:A!==!1,g=typeof A=="string"?A:"bottom",k=N.filter(l=>!l.hidden),d=k.length,O=T(()=>{if(w||P===void 0||P===!1||x!==null||d!==1)return null;let l=Ge(D,k.map(s=>s.key)),o=Qt([...l,z],{domain:h?.domain,includeZero:h?.includeZero??z===0,ticks:h?.ticks??5});return at(o,{center:z})},[w,P,x,d,k,D,z,h]);return i(Bt,{title:$,description:te,height:f,width:L,size:V,loading:ke,empty:D.length===0||d===0,emptyState:we,error:Se,errorState:Ie,onRetry:K,actions:De,tableView:R,legendPosition:g,legend:O?i(Et,{scale:O,label:h?.label,format:Y,size:V,locale:I}):a?i(Lt,{items:Wt(N,M,G),position:g,marker:"rect",size:V,onToggle:oe?t:void 0}):void 0,table:R?i(Vt,{data:D,series:N,xKey:ae.key,xLabel:n.label??n.key,formatX:pe,formatValue:E,caption:typeof $=="string"?$:void 0}):void 0,className:e,...fe,children:({width:l})=>i(sn,{width:l,height:f,data:D,resolvedSeries:N,x:ae,y:Re,grid:xe,size:V,orientation:ne,stack:w?"none":Pe,center:z,centerKey:x,valueColors:O,binned:w,curve:He,barSize:We,showValues:X,referenceLines:he,annotations:r,annotationsLabel:ge.chartAnnotations,patterns:G&&O===null,patternBaseId:_e,overlay:W,brush:de,onBrush:me,brushLabel:u??ge.chartBrush,syncEnabled:Ne,margin:Oe,tooltip:H,onPointClick:Be,plotLabel:b,formatValue:Y,formatRaw:E,formatX:pe})})}export{Nn as BarChart,Wn as resetBarChartWarnings};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";"use client";var se=Object.defineProperty;var Xe=Object.getOwnPropertyDescriptor;var Ve=Object.getOwnPropertyNames;var De=Object.prototype.hasOwnProperty;var Ie=(m,o)=>{for(var d in o)se(m,d,{get:o[d],enumerable:!0})},ze=(m,o,d,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of Ve(o))!De.call(m,n)&&n!==d&&se(m,n,{get:()=>o[n],enumerable:!(a=Xe(o,n))||a.enumerable});return m};var Ge=m=>ze(se({},"__esModule",{value:!0}),m);var _e={};Ie(_e,{BoxPlot:()=>Ue});module.exports=Ge(_e);var f=require("react"),ue=require("../../lib/i18n.cjs"),me=require("../chart/ChartAxis.cjs"),Ce=require("../chart/ChartContainer.cjs"),ke=require("../chart/ChartGrid.cjs"),ve=require("../chart/ChartTooltip.cjs"),Ne=require("../chart/palette.cjs"),Pe=require("../chart/utils/cartesian.cjs"),w=require("../chart/utils/data.cjs"),J=require("../chart/utils/format.cjs"),Be=require("../chart/utils/path.cjs"),Te=require("../chart/utils/quantile.cjs"),we=require("../chart/utils/scales.cjs"),Se=require("../table/Table.cjs"),Le=require("../table/TableBody.cjs"),z=require("../table/TableCell.cjs"),Re=require("../table/TableHeader.cjs"),B=require("../table/TableHeaderCell.cjs"),Me=require("../table/TableRow.cjs"),t=require("react/jsx-runtime"),qe=40,Ke=3,F=4,ce="text-right [font-variant-numeric:tabular-nums]",Oe=(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-F} L${a.mean.cx+F},${a.mean.cy} L${a.mean.cx},${a.mean.cy+F} L${a.mean.cx-F},${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:Ke,fill:d,strokeWidth:1.5,className:"stroke-white dark:stroke-gray-800"},n.key))]},a.key))})});function Qe({width:m,height:o,data:d,boxes:a,x:n,y:N,grid:M,size:G,orientation:S,boxSize:q,showOutliers:K,showMean:E,color:O,referenceLines:ee,margin:W,tooltip:L,plotLabel:te,formatValue:A,formatX:H,onBoxClick:X}){let[h,$]=(0,f.useState)(null),Q=(0,ue.useUILabels)(),e=(0,f.useMemo)(()=>{let r=S==="vertical",i=a.flatMap(c=>c.stats===null?[]:[c.stats.min,c.stats.max,...E&&c.mean!==null?[c.mean]:[]]),p=(0,Pe.buildCartesianGeometry)({width:m,height:o,data:d,x:n,y:N,bounds:i.length===0?null:[Math.min(...i),Math.max(...i)],margin:W,orientation:S,placement:"band",formatValue:A,formatX:H,defaultIncludeZero:!1}),{valueScale:x,bandwidth:C,categoryPositions:k,innerWidth:D,innerHeight:I}=p,P=Math.min(q??qe,C),l=P*.5,g=(c,b)=>r?{x:c,y:b}:{x:b,y:c},U=a.map((c,b)=>{let v=k[b]+(C-P)/2,u=v+P/2;if(c.stats===null)return{key:`${b}`,body:"",median:null,whiskers:[],outliers:[],mean:null,top:k[b],height:C};let{q1:y,q3:T,median:_,lower:Y,upper:Ae,outliers:He}=c.stats,de=x(y),he=x(T),ge=Math.min(de,he),ye=Math.abs(he-de),$e=(0,Be.buildBarPath)({...r?{x:v,y:ge,width:P,height:Math.max(1,ye)}:{x:ge,y:v,width:Math.max(1,ye),height:P},radius:2,round:"none"}),j=x(_),Ee=r?{x1:v,y1:j,x2:v+P,y2:j}:{x1:j,y1:v,x2:j,y2:v+P},le=[];for(let[R,oe,Z]of[["lower",Y,y],["upper",Ae,T]]){let ie=x(oe),We=x(Z),fe=g(u,ie),pe=g(u,We);le.push({key:`${R}-stem`,x1:pe.x,y1:pe.y,x2:fe.x,y2:fe.y});let xe=g(u-l/2,ie),be=g(u+l/2,ie);le.push({key:`${R}-cap`,x1:xe.x,y1:xe.y,x2:be.x,y2:be.y})}return{key:`${b}`,body:$e,median:Ee,whiskers:le,outliers:K?He.map((R,oe)=>{let Z=g(u,x(R));return{key:`${oe}`,cx:Z.x,cy:Z.y}}):[],mean:E&&c.mean!==null?(()=>{let R=g(u,x(c.mean));return{cx:R.x,cy:R.y}})():null,top:k[b],height:C}});return{vertical:r,rendered:U,categoryPositions:k,categoryCenters:p.categoryCenters,bandwidth:C,categoryTicks:p.categoryTicks,valueTicks:p.valueTicks,valueScale:x,innerWidth:D,innerHeight:I,margin:p.margin}},[a,d,n,N,m,o,W,S,q,K,E,A,H]),ae=(0,f.useCallback)(r=>{if(L===!1||a.length===0)return;let i=r.currentTarget.getBoundingClientRect(),p=e.vertical?r.clientX-i.left-e.margin.left:r.clientY-i.top-e.margin.top;$((0,we.nearestIndex)(e.categoryCenters,p))},[L,a.length,e.vertical,e.margin,e.categoryCenters]),re=(0,f.useCallback)(r=>{if(a.length===0)return;let i=a.length-1,p=h??0,x=e.vertical?"ArrowRight":"ArrowDown",C=e.vertical?"ArrowLeft":"ArrowUp",k=r.key===x?Math.min(i,p+1):r.key===C?Math.max(0,p-1):r.key==="Home"?0:r.key==="End"?i:r.key==="Escape"?null:void 0;k!==void 0&&(r.preventDefault(),$(k))},[a.length,h,e.vertical]),ne=(0,f.useCallback)(()=>{!X||h===null||X(a[h])},[X,h,a]),s=h===null?null:a[h],V=h===null||s===null||s.stats===null?null:e.vertical?{x:e.margin.left+e.categoryCenters[h],y:e.margin.top+e.valueScale(s.stats.q3)}:{x:e.margin.left+e.valueScale(s.stats.q3),y:e.margin.top+e.categoryCenters[h]};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("svg",{width:m,height:o,role:"img","aria-label":te??a.map(r=>r.label).join(", "),tabIndex:0,className:"touch-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500",onPointerMove:ae,onPointerLeave:()=>$(null),onKeyDown:re,onBlur:()=>$(null),onClick:ne,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&&(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}),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,ee?.map(r=>{let i=e.valueScale(r.value);return(0,t.jsxs)("g",{children:[(0,t.jsx)("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?(0,t.jsx)("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??""}`)}),(0,t.jsx)(Oe,{boxes:e.rendered,color:O})]}),(0,t.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:(e.vertical?n.hidden:N?.hidden)?null:(0,t.jsx)(me.ChartAxis,{orientation:"bottom",ticks:e.vertical?e.categoryTicks:e.valueTicks,length:e.innerWidth,label:e.vertical?n.label:N?.label,size:G})}),(0,t.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:(e.vertical?N?.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?N?.label:n.label,size:G})})]}),s&&s.stats&&V&&L!==!1?(0,t.jsx)(ve.ChartTooltip,{x:V.x,y:V.y,containerWidth:m,children:typeof L=="function"?L(s):(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:s.label}),(0,t.jsxs)("dl",{className:"grid grid-cols-[auto_auto] gap-x-3 gap-y-0.5",children:[[["Max",s.stats.max],["Q3",s.stats.q3],[Q.chartMedian,s.stats.median],["Q1",s.stats.q1],["Min",s.stats.min]].map(([r,i])=>(0,t.jsxs)("div",{className:"contents",children:[(0,t.jsx)("dt",{className:"text-gray-500 dark:text-gray-400",children:r}),(0,t.jsx)("dd",{className:"justify-self-end font-medium text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:A(i)})]},r)),(0,t.jsxs)("div",{className:"contents",children:[(0,t.jsx)("dt",{className:"text-gray-500 dark:text-gray-400",children:Q.chartCount}),(0,t.jsx)("dd",{className:"justify-self-end font-medium text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:s.stats.count})]})]})]})}):null]})}function Ue({data:m,x:o,y:d,values:a,quantiles:n,whisker:N=1.5,orientation:M="vertical",boxSize:G,showOutliers:S=!0,showMean:q=!1,color:K,referenceLines:E,height:O=280,width:ee,size:W="md",grid:L="y",tooltip:te=!0,tableView:A=!1,title:H,description:X,loading:h=!1,emptyState:$,error:Q=!1,errorState:e,onRetry:ae,actions:re,margin:ne,locale:s,plotLabel:V,format:r,onBoxClick:i,className:p,...x}){let C=(0,ue.useUILabels)(),k=(0,f.useMemo)(()=>d?.format??r??(l=>(0,J.formatAuto)(l,s)),[d?.format,r,s]),D=(0,f.useMemo)(()=>o.format??(l=>(0,J.formatXValue)(l,s)),[o.format,s]),I=(0,f.useMemo)(()=>m.map((l,g)=>{let U=(0,w.readXValue)(l,o.key,g),c=a?(()=>{let u=l[a];return Array.isArray(u)?u.map(y=>typeof y=="number"?y:Number(y)).filter(y=>Number.isFinite(y)):null})():null,b=null,v=null;if(c!==null)b=(0,Te.boxStats)(c,N),v=c.length===0?null:c.reduce((u,y)=>u+y,0)/c.length;else if(n){let u=(0,w.readNumber)(l,n.q1),y=(0,w.readNumber)(l,n.median),T=(0,w.readNumber)(l,n.q3);if(u!==null&&y!==null&&T!==null){let _=n.min?(0,w.readNumber)(l,n.min)??u:u,Y=n.max?(0,w.readNumber)(l,n.max)??T:T;b={count:0,min:_,max:Y,q1:u,median:y,q3:T,iqr:T-u,lower:_,upper:Y,outliers:[]}}}return{index:g,x:U,label:D(U,g),stats:b,mean:v,datum:l}}),[m,o.key,a,n,N,D]),P=I.filter(l=>l.stats!==null);return(0,t.jsx)(Ce.ChartContainer,{title:H,description:X,height:O,width:ee,size:W,loading:h,empty:P.length===0,emptyState:$,error:Q,errorState:e,onRetry:ae,actions:re,tableView:A,table:A?(0,t.jsx)("div",{className:"w-full overflow-x-auto",children:(0,t.jsxs)(Se.Table,{children:[typeof H=="string"?(0,t.jsx)("caption",{className:"sr-only",children:H}):null,(0,t.jsxs)(Re.TableHeader,{children:[(0,t.jsx)(B.TableHeaderCell,{children:o.label??o.key}),a?(0,t.jsx)(B.TableHeaderCell,{className:"text-right",children:C.chartCount}):null,(0,t.jsx)(B.TableHeaderCell,{className:"text-right",children:"Min"}),(0,t.jsx)(B.TableHeaderCell,{className:"text-right",children:"Q1"}),(0,t.jsx)(B.TableHeaderCell,{className:"text-right",children:C.chartMedian}),(0,t.jsx)(B.TableHeaderCell,{className:"text-right",children:"Q3"}),(0,t.jsx)(B.TableHeaderCell,{className:"text-right",children:"Max"}),a&&S?(0,t.jsx)(B.TableHeaderCell,{className:"text-right",children:C.chartOutliers}):null]}),(0,t.jsx)(Le.TableBody,{children:I.map(l=>(0,t.jsxs)(Me.TableRow,{clickable:!1,children:[(0,t.jsx)(z.TableCell,{className:"font-medium text-gray-900 dark:text-gray-100",children:l.label}),a?(0,t.jsx)(z.TableCell,{className:ce,children:l.stats?.count??"\u2014"}):null,["min","q1","median","q3","max"].map(g=>(0,t.jsx)(z.TableCell,{className:ce,children:l.stats===null?"\u2014":k(l.stats[g])},g)),a&&S?(0,t.jsx)(z.TableCell,{className:ce,children:l.stats===null||l.stats.outliers.length===0?"\u2014":l.stats.outliers.map(k).join(", ")}):null]},l.index))})]})}):void 0,className:p,...x,children:({width:l})=>(0,t.jsx)(Qe,{width:l,height:O,data:m,boxes:I,x:o,y:d,grid:L,size:W,orientation:M,boxSize:G,showOutliers:S,showMean:q,color:K??(0,Ne.getSeriesColor)(0),referenceLines:E,margin:ne,tooltip:te,plotLabel:V,formatValue:k,formatX:D,onBoxClick:i})})}0&&(module.exports={BoxPlot});
|
|
1
|
+
"use strict";"use client";var se=Object.defineProperty;var Ie=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames;var ze=Object.prototype.hasOwnProperty;var Ge=(c,o)=>{for(var d in o)se(c,d,{get:o[d],enumerable:!0})},qe=(c,o,d,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let l of De(o))!ze.call(c,l)&&l!==d&&se(c,l,{get:()=>o[l],enumerable:!(a=Ie(o,l))||a.enumerable});return c};var Ke=c=>qe(se({},"__esModule",{value:!0}),c);var je={};Ge(je,{BoxPlot:()=>Ye});module.exports=Ke(je);var f=require("react"),ue=require("../../lib/i18n.cjs"),me=require("../chart/ChartAxis.cjs"),Ce=require("../chart/ChartContainer.cjs"),ke=require("../chart/ChartGrid.cjs"),ve=require("../chart/ChartTooltip.cjs"),Pe=require("../chart/palette.cjs"),Ne=require("../chart/utils/cartesian.cjs"),T=require("../chart/utils/data.cjs"),J=require("../chart/utils/format.cjs"),Be=require("../chart/utils/path.cjs"),Te=require("../chart/utils/quantile.cjs"),we=require("../chart/utils/scales.cjs"),Re=require("../chart/utils/touch.cjs"),Se=require("../table/Table.cjs"),Le=require("../table/TableBody.cjs"),q=require("../table/TableCell.cjs"),Me=require("../table/TableHeader.cjs"),N=require("../table/TableHeaderCell.cjs"),Ae=require("../table/TableRow.cjs"),t=require("react/jsx-runtime"),Oe=40,Ue=3,F=4,ce="text-right [font-variant-numeric:tabular-nums]",_e=(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(l=>(0,t.jsx)("line",{x1:l.x1,y1:l.y1,x2:l.x2,y2:l.y2},l.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-F} L${a.mean.cx+F},${a.mean.cy} L${a.mean.cx},${a.mean.cy+F} L${a.mean.cx-F},${a.mean.cy} Z`,strokeWidth:1.5,stroke:d,className:"fill-white dark:fill-gray-800"}):null,a.outliers.map(l=>(0,t.jsx)("circle",{cx:l.cx,cy:l.cy,r:Ue,fill:d,strokeWidth:1.5,className:"stroke-white dark:stroke-gray-800"},l.key))]},a.key))})});function Qe({width:c,height:o,data:d,boxes:a,x:l,y:k,grid:M,size:K,orientation:w,boxSize:O,showOutliers:U,showMean:X,color:_,referenceLines:ee,margin:V,tooltip:R,plotLabel:te,formatValue:A,formatX:H,onBoxClick:I}){let[D,$]=(0,f.useState)(null),g=D!==null&&D<a.length?D:null,Q=(0,ue.useUILabels)(),e=(0,f.useMemo)(()=>{let r=w==="vertical",i=a.flatMap(m=>m.stats===null?[]:[m.stats.min,m.stats.max,...X&&m.mean!==null?[m.mean]:[]]),p=(0,Ne.buildCartesianGeometry)({width:c,height:o,data:d,x:l,y:k,bounds:i.length===0?null:[Math.min(...i),Math.max(...i)],margin:V,orientation:w,placement:"band",formatValue:A,formatX:H,defaultIncludeZero:!1}),{valueScale:y,bandwidth:x,categoryPositions:b,innerWidth:z,innerHeight:ne}=p,n=Math.min(O??Oe,x),v=n*.5,P=(m,C)=>r?{x:m,y:C}:{x:C,y:m},S=a.map((m,C)=>{let s=b[C]+(x-n)/2,u=s+n/2;if(m.stats===null)return{key:`${C}`,body:"",median:null,whiskers:[],outliers:[],mean:null,top:b[C],height:x};let{q1:B,q3:G,median:Y,lower:He,upper:$e,outliers:Ee}=m.stats,de=y(B),he=y(G),ge=Math.min(de,he),ye=Math.abs(he-de),We=(0,Be.buildBarPath)({...r?{x:s,y:ge,width:n,height:Math.max(1,ye)}:{x:ge,y:s,width:Math.max(1,ye),height:n},radius:2,round:"none"}),j=y(Y),Xe=r?{x1:s,y1:j,x2:s+n,y2:j}:{x1:j,y1:s,x2:j,y2:s+n},le=[];for(let[L,oe,Z]of[["lower",He,B],["upper",$e,G]]){let ie=y(oe),Ve=y(Z),fe=P(u,ie),pe=P(u,Ve);le.push({key:`${L}-stem`,x1:pe.x,y1:pe.y,x2:fe.x,y2:fe.y});let xe=P(u-v/2,ie),be=P(u+v/2,ie);le.push({key:`${L}-cap`,x1:xe.x,y1:xe.y,x2:be.x,y2:be.y})}return{key:`${C}`,body:We,median:Xe,whiskers:le,outliers:U?Ee.map((L,oe)=>{let Z=P(u,y(L));return{key:`${oe}`,cx:Z.x,cy:Z.y}}):[],mean:X&&m.mean!==null?(()=>{let L=P(u,y(m.mean));return{cx:L.x,cy:L.y}})():null,top:b[C],height:x}});return{vertical:r,rendered:S,categoryPositions:b,categoryCenters:p.categoryCenters,bandwidth:x,categoryTicks:p.categoryTicks,valueTicks:p.valueTicks,valueScale:y,innerWidth:z,innerHeight:ne,margin:p.margin}},[a,d,l,k,c,o,V,w,O,U,X,A,H]),ae=(0,f.useCallback)(r=>{if(R===!1||a.length===0)return;let i=r.currentTarget.getBoundingClientRect(),p=e.vertical?r.clientX-i.left-e.margin.left:r.clientY-i.top-e.margin.top;$((0,we.nearestIndex)(e.categoryCenters,p))},[R,a.length,e.vertical,e.margin,e.categoryCenters]),re=(0,f.useCallback)(r=>{if(a.length===0)return;let i=a.length-1,p=g??0,y=e.vertical?"ArrowRight":"ArrowDown",x=e.vertical?"ArrowLeft":"ArrowUp",b=r.key===y?Math.min(i,p+1):r.key===x?Math.max(0,p-1):r.key==="Home"?0:r.key==="End"?i:r.key==="Escape"?null:void 0;b!==void 0&&(r.preventDefault(),$(b))},[a.length,g,e.vertical]),E=(0,f.useCallback)(()=>{!I||g===null||I(a[g])},[I,g,a]),h=g===null?null:a[g],W=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:c,height:o,role:"img","aria-label":te??a.map(r=>r.label).join(", "),tabIndex:0,className:`${Re.CHART_TOUCH} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500`,onPointerMove:ae,onPointerLeave:()=>$(null),onKeyDown:re,onBlur:()=>$(null),onClick:E,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&&(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}),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,ee?.map(r=>{let i=e.valueScale(r.value);return(0,t.jsxs)("g",{children:[(0,t.jsx)("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?(0,t.jsx)("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??""}`)}),(0,t.jsx)(_e,{boxes:e.rendered,color:_})]}),(0,t.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:(e.vertical?l.hidden:k?.hidden)?null:(0,t.jsx)(me.ChartAxis,{orientation:"bottom",ticks:e.vertical?e.categoryTicks:e.valueTicks,length:e.innerWidth,label:e.vertical?l.label:k?.label,size:K})}),(0,t.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:(e.vertical?k?.hidden:l.hidden)?null:(0,t.jsx)(me.ChartAxis,{orientation:"left",ticks:e.vertical?e.valueTicks:e.categoryTicks,length:e.innerHeight,showLine:!1,label:e.vertical?k?.label:l.label,size:K})})]}),h&&h.stats&&W&&R!==!1?(0,t.jsx)(ve.ChartTooltip,{x:W.x,y:W.y,containerWidth:c,children:typeof R=="function"?R(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:[[["Max",h.stats.max],["Q3",h.stats.q3],[Q.chartMedian,h.stats.median],["Q1",h.stats.q1],["Min",h.stats.min]].map(([r,i])=>(0,t.jsxs)("div",{className:"contents",children:[(0,t.jsx)("dt",{className:"text-gray-500 dark:text-gray-400",children:r}),(0,t.jsx)("dd",{className:"justify-self-end font-medium text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:A(i)})]},r)),(0,t.jsxs)("div",{className:"contents",children:[(0,t.jsx)("dt",{className:"text-gray-500 dark:text-gray-400",children:Q.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 Ye({data:c,x:o,y:d,values:a,quantiles:l,whisker:k=1.5,orientation:M="vertical",boxSize:K,showOutliers:w=!0,showMean:O=!1,color:U,referenceLines:X,height:_=280,width:ee,size:V="md",grid:R="y",tooltip:te=!0,tableView:A=!1,title:H,description:I,loading:D=!1,emptyState:$,error:g=!1,errorState:Q,onRetry:e,actions:ae,margin:re,locale:E,plotLabel:h,format:W,onBoxClick:r,className:i,...p}){let y=(0,ue.useUILabels)(),x=(0,f.useMemo)(()=>d?.format??W??(n=>(0,J.formatAuto)(n,E)),[d?.format,W,E]),b=(0,f.useMemo)(()=>o.format??(n=>(0,J.formatXValue)(n,E)),[o.format,E]),z=(0,f.useMemo)(()=>c.map((n,v)=>{let P=(0,T.readXValue)(n,o.key,v),S=a?(()=>{let s=n[a];return Array.isArray(s)?s.map(u=>typeof u=="number"?u:Number(u)).filter(u=>Number.isFinite(u)):null})():null,m=null,C=null;if(S!==null)m=(0,Te.boxStats)(S,k),C=S.length===0?null:S.reduce((s,u)=>s+u,0)/S.length;else if(l){let s=(0,T.readNumber)(n,l.q1),u=(0,T.readNumber)(n,l.median),B=(0,T.readNumber)(n,l.q3);if(s!==null&&u!==null&&B!==null){let G=l.min?(0,T.readNumber)(n,l.min)??s:s,Y=l.max?(0,T.readNumber)(n,l.max)??B:B;m={count:0,min:G,max:Y,q1:s,median:u,q3:B,iqr:B-s,lower:G,upper:Y,outliers:[]}}}return{index:v,x:P,label:b(P,v),stats:m,mean:C,datum:n}}),[c,o.key,a,l,k,b]),ne=z.filter(n=>n.stats!==null);return(0,t.jsx)(Ce.ChartContainer,{title:H,description:I,height:_,width:ee,size:V,loading:D,empty:ne.length===0,emptyState:$,error:g,errorState:Q,onRetry:e,actions:ae,tableView:A,table:A?(0,t.jsx)("div",{className:"w-full overflow-x-auto",children:(0,t.jsxs)(Se.Table,{children:[typeof H=="string"?(0,t.jsx)("caption",{className:"sr-only",children:H}):null,(0,t.jsxs)(Me.TableHeader,{children:[(0,t.jsx)(N.TableHeaderCell,{children:o.label??o.key}),a?(0,t.jsx)(N.TableHeaderCell,{className:"text-right",children:y.chartCount}):null,(0,t.jsx)(N.TableHeaderCell,{className:"text-right",children:"Min"}),(0,t.jsx)(N.TableHeaderCell,{className:"text-right",children:"Q1"}),(0,t.jsx)(N.TableHeaderCell,{className:"text-right",children:y.chartMedian}),(0,t.jsx)(N.TableHeaderCell,{className:"text-right",children:"Q3"}),(0,t.jsx)(N.TableHeaderCell,{className:"text-right",children:"Max"}),a&&w?(0,t.jsx)(N.TableHeaderCell,{className:"text-right",children:y.chartOutliers}):null]}),(0,t.jsx)(Le.TableBody,{children:z.map(n=>(0,t.jsxs)(Ae.TableRow,{clickable:!1,children:[(0,t.jsx)(q.TableCell,{className:"font-medium text-gray-900 dark:text-gray-100",children:n.label}),a?(0,t.jsx)(q.TableCell,{className:ce,children:n.stats?.count??"\u2014"}):null,["min","q1","median","q3","max"].map(v=>(0,t.jsx)(q.TableCell,{className:ce,children:n.stats===null?"\u2014":x(n.stats[v])},v)),a&&w?(0,t.jsx)(q.TableCell,{className:ce,children:n.stats===null||n.stats.outliers.length===0?"\u2014":n.stats.outliers.map(x).join(", ")}):null]},n.index))})]})}):void 0,className:i,...p,children:({width:n})=>(0,t.jsx)(Qe,{width:n,height:_,data:c,boxes:z,x:o,y:d,grid:R,size:V,orientation:M,boxSize:K,showOutliers:w,showMean:O,color:U??(0,Pe.getSeriesColor)(0),referenceLines:X,margin:re,tooltip:te,plotLabel:h,formatValue:x,formatX:b,onBoxClick:r})})}0&&(module.exports={BoxPlot});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{memo as Be,useCallback as se,useMemo as J,useState as Te}from"react";import{useUILabels as be}from"../../lib/i18n.js";import{ChartAxis as xe}from"../chart/ChartAxis.js";import{ChartContainer as we}from"../chart/ChartContainer.js";import{ChartGrid as Se}from"../chart/ChartGrid.js";import{ChartTooltip as Le}from"../chart/ChartTooltip.js";import{getSeriesColor as Re}from"../chart/palette.js";import{buildCartesianGeometry as Me}from"../chart/utils/cartesian.js";import{readNumber as I,readXValue as Ae}from"../chart/utils/data.js";import{formatAuto as He,formatXValue as $e}from"../chart/utils/format.js";import{buildBarPath as Ee}from"../chart/utils/path.js";import{boxStats as We}from"../chart/utils/quantile.js";import{nearestIndex as Xe}from"../chart/utils/scales.js";import{Table as Ve}from"../table/Table.js";import{TableBody as De}from"../table/TableBody.js";import{TableCell as Z}from"../table/TableCell.js";import{TableHeader as Ie}from"../table/TableHeader.js";import{TableHeaderCell as T}from"../table/TableHeaderCell.js";import{TableRow as ze}from"../table/TableRow.js";import{Fragment as Qe,jsx as a,jsxs as p}from"react/jsx-runtime";var Ge=40,qe=3,F=4,ce="text-right [font-variant-numeric:tabular-nums]",Ke=Be(function({boxes:u,color:x}){return a("g",{children:u.map(t=>p("g",{children:[a("g",{stroke:x,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:x}):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-F} L${t.mean.cx+F},${t.mean.cy} L${t.mean.cx},${t.mean.cy+F} L${t.mean.cx-F},${t.mean.cy} Z`,strokeWidth:1.5,stroke:x,className:"fill-white dark:fill-gray-800"}):null,t.outliers.map(l=>a("circle",{cx:l.cx,cy:l.cy,r:qe,fill:x,strokeWidth:1.5,className:"stroke-white dark:stroke-gray-800"},l.key))]},t.key))})});function Oe({width:v,height:u,data:x,boxes:t,x:l,y:N,grid:R,size:z,orientation:w,boxSize:G,showOutliers:q,showMean:$,color:K,referenceLines:ee,margin:E,tooltip:S,plotLabel:te,formatValue:M,formatX:A,onBoxClick:W}){let[m,H]=Te(null),O=be(),e=J(()=>{let r=w==="vertical",o=t.flatMap(s=>s.stats===null?[]:[s.stats.min,s.stats.max,...$&&s.mean!==null?[s.mean]:[]]),g=Me({width:v,height:u,data:x,x:l,y:N,bounds:o.length===0?null:[Math.min(...o),Math.max(...o)],margin:E,orientation:w,placement:"band",formatValue:M,formatX:A,defaultIncludeZero:!1}),{valueScale:y,bandwidth:b,categoryPositions:C,innerWidth:V,innerHeight:D}=g,P=Math.min(G??Ge,b),n=P*.5,d=(s,f)=>r?{x:s,y:f}:{x:f,y:s},Q=t.map((s,f)=>{let k=C[f]+(b-P)/2,c=k+P/2;if(s.stats===null)return{key:`${f}`,body:"",median:null,whiskers:[],outliers:[],mean:null,top:C[f],height:b};let{q1:h,q3:B,median:U,lower:_,upper:Ce,outliers:ke}=s.stats,me=y(h),ue=y(B),de=Math.min(me,ue),he=Math.abs(ue-me),ve=Ee({...r?{x:k,y:de,width:P,height:Math.max(1,he)}:{x:de,y:k,width:Math.max(1,he),height:P},radius:2,round:"none"}),Y=y(U),Ne=r?{x1:k,y1:Y,x2:k+P,y2:Y}:{x1:Y,y1:k,x2:Y,y2:k+P},le=[];for(let[L,oe,j]of[["lower",_,h],["upper",Ce,B]]){let ie=y(oe),Pe=y(j),ge=d(c,ie),ye=d(c,Pe);le.push({key:`${L}-stem`,x1:ye.x,y1:ye.y,x2:ge.x,y2:ge.y});let fe=d(c-n/2,ie),pe=d(c+n/2,ie);le.push({key:`${L}-cap`,x1:fe.x,y1:fe.y,x2:pe.x,y2:pe.y})}return{key:`${f}`,body:ve,median:Ne,whiskers:le,outliers:q?ke.map((L,oe)=>{let j=d(c,y(L));return{key:`${oe}`,cx:j.x,cy:j.y}}):[],mean:$&&s.mean!==null?(()=>{let L=d(c,y(s.mean));return{cx:L.x,cy:L.y}})():null,top:C[f],height:b}});return{vertical:r,rendered:Q,categoryPositions:C,categoryCenters:g.categoryCenters,bandwidth:b,categoryTicks:g.categoryTicks,valueTicks:g.valueTicks,valueScale:y,innerWidth:V,innerHeight:D,margin:g.margin}},[t,x,l,N,v,u,E,w,G,q,$,M,A]),ae=se(r=>{if(S===!1||t.length===0)return;let o=r.currentTarget.getBoundingClientRect(),g=e.vertical?r.clientX-o.left-e.margin.left:r.clientY-o.top-e.margin.top;H(Xe(e.categoryCenters,g))},[S,t.length,e.vertical,e.margin,e.categoryCenters]),re=se(r=>{if(t.length===0)return;let o=t.length-1,g=m??0,y=e.vertical?"ArrowRight":"ArrowDown",b=e.vertical?"ArrowLeft":"ArrowUp",C=r.key===y?Math.min(o,g+1):r.key===b?Math.max(0,g-1):r.key==="Home"?0:r.key==="End"?o:r.key==="Escape"?null:void 0;C!==void 0&&(r.preventDefault(),H(C))},[t.length,m,e.vertical]),ne=se(()=>{!W||m===null||W(t[m])},[W,m,t]),i=m===null?null:t[m],X=m===null||i===null||i.stats===null?null:e.vertical?{x:e.margin.left+e.categoryCenters[m],y:e.margin.top+e.valueScale(i.stats.q3)}:{x:e.margin.left+e.valueScale(i.stats.q3),y:e.margin.top+e.categoryCenters[m]};return p(Qe,{children:[p("svg",{width:v,height:u,role:"img","aria-label":te??t.map(r=>r.label).join(", "),tabIndex:0,className:"touch-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500",onPointerMove:ae,onPointerLeave:()=>H(null),onKeyDown:re,onBlur:()=>H(null),onClick:ne,children:[p("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[a(Se,{width:e.innerWidth,height:e.innerHeight,horizontal:e.vertical&&(R==="y"||R==="both")?e.valueTicks.map(r=>r.offset):void 0,vertical:!e.vertical&&(R==="y"||R==="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,ee?.map(r=>{let o=e.valueScale(r.value);return p("g",{children:[a("line",{x1:e.vertical?0:o,y1:e.vertical?o:0,x2:e.vertical?e.innerWidth:o,y2:e.vertical?o: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:o+4,y:e.vertical?o-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(Ke,{boxes:e.rendered,color:K})]}),a("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:(e.vertical?l.hidden:N?.hidden)?null:a(xe,{orientation:"bottom",ticks:e.vertical?e.categoryTicks:e.valueTicks,length:e.innerWidth,label:e.vertical?l.label:N?.label,size:z})}),a("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:(e.vertical?N?.hidden:l.hidden)?null:a(xe,{orientation:"left",ticks:e.vertical?e.valueTicks:e.categoryTicks,length:e.innerHeight,showLine:!1,label:e.vertical?N?.label:l.label,size:z})})]}),i&&i.stats&&X&&S!==!1?a(Le,{x:X.x,y:X.y,containerWidth:v,children:typeof S=="function"?S(i):p("div",{className:"flex flex-col gap-1",children:[a("div",{className:"font-medium text-gray-900 dark:text-gray-100",children:i.label}),p("dl",{className:"grid grid-cols-[auto_auto] gap-x-3 gap-y-0.5",children:[[["Max",i.stats.max],["Q3",i.stats.q3],[O.chartMedian,i.stats.median],["Q1",i.stats.q1],["Min",i.stats.min]].map(([r,o])=>p("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:M(o)})]},r)),p("div",{className:"contents",children:[a("dt",{className:"text-gray-500 dark:text-gray-400",children:O.chartCount}),a("dd",{className:"justify-self-end font-medium text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:i.stats.count})]})]})]})}):null]})}function dt({data:v,x:u,y:x,values:t,quantiles:l,whisker:N=1.5,orientation:R="vertical",boxSize:z,showOutliers:w=!0,showMean:G=!1,color:q,referenceLines:$,height:K=280,width:ee,size:E="md",grid:S="y",tooltip:te=!0,tableView:M=!1,title:A,description:W,loading:m=!1,emptyState:H,error:O=!1,errorState:e,onRetry:ae,actions:re,margin:ne,locale:i,plotLabel:X,format:r,onBoxClick:o,className:g,...y}){let b=be(),C=J(()=>x?.format??r??(n=>He(n,i)),[x?.format,r,i]),V=J(()=>u.format??(n=>$e(n,i)),[u.format,i]),D=J(()=>v.map((n,d)=>{let Q=Ae(n,u.key,d),s=t?(()=>{let c=n[t];return Array.isArray(c)?c.map(h=>typeof h=="number"?h:Number(h)).filter(h=>Number.isFinite(h)):null})():null,f=null,k=null;if(s!==null)f=We(s,N),k=s.length===0?null:s.reduce((c,h)=>c+h,0)/s.length;else if(l){let c=I(n,l.q1),h=I(n,l.median),B=I(n,l.q3);if(c!==null&&h!==null&&B!==null){let U=l.min?I(n,l.min)??c:c,_=l.max?I(n,l.max)??B:B;f={count:0,min:U,max:_,q1:c,median:h,q3:B,iqr:B-c,lower:U,upper:_,outliers:[]}}}return{index:d,x:Q,label:V(Q,d),stats:f,mean:k,datum:n}}),[v,u.key,t,l,N,V]),P=D.filter(n=>n.stats!==null);return a(we,{title:A,description:W,height:K,width:ee,size:E,loading:m,empty:P.length===0,emptyState:H,error:O,errorState:e,onRetry:ae,actions:re,tableView:M,table:M?a("div",{className:"w-full overflow-x-auto",children:p(Ve,{children:[typeof A=="string"?a("caption",{className:"sr-only",children:A}):null,p(Ie,{children:[a(T,{children:u.label??u.key}),t?a(T,{className:"text-right",children:b.chartCount}):null,a(T,{className:"text-right",children:"Min"}),a(T,{className:"text-right",children:"Q1"}),a(T,{className:"text-right",children:b.chartMedian}),a(T,{className:"text-right",children:"Q3"}),a(T,{className:"text-right",children:"Max"}),t&&w?a(T,{className:"text-right",children:b.chartOutliers}):null]}),a(De,{children:D.map(n=>p(ze,{clickable:!1,children:[a(Z,{className:"font-medium text-gray-900 dark:text-gray-100",children:n.label}),t?a(Z,{className:ce,children:n.stats?.count??"\u2014"}):null,["min","q1","median","q3","max"].map(d=>a(Z,{className:ce,children:n.stats===null?"\u2014":C(n.stats[d])},d)),t&&w?a(Z,{className:ce,children:n.stats===null||n.stats.outliers.length===0?"\u2014":n.stats.outliers.map(C).join(", ")}):null]},n.index))})]})}):void 0,className:g,...y,children:({width:n})=>a(Oe,{width:n,height:K,data:v,boxes:D,x:u,y:x,grid:S,size:E,orientation:R,boxSize:z,showOutliers:w,showMean:G,color:q??Re(0),referenceLines:$,margin:ne,tooltip:te,plotLabel:X,formatValue:C,formatX:V,onBoxClick:o})})}export{dt as BoxPlot};
|
|
1
|
+
"use client";import{memo as Te,useCallback as se,useMemo as J,useState as we}from"react";import{useUILabels as be}from"../../lib/i18n.js";import{ChartAxis as xe}from"../chart/ChartAxis.js";import{ChartContainer as Re}from"../chart/ChartContainer.js";import{ChartGrid as Se}from"../chart/ChartGrid.js";import{ChartTooltip as Le}from"../chart/ChartTooltip.js";import{getSeriesColor as Me}from"../chart/palette.js";import{buildCartesianGeometry as Ae}from"../chart/utils/cartesian.js";import{readNumber as G,readXValue as He}from"../chart/utils/data.js";import{formatAuto as $e,formatXValue as Ee}from"../chart/utils/format.js";import{buildBarPath as We}from"../chart/utils/path.js";import{boxStats as Xe}from"../chart/utils/quantile.js";import{nearestIndex as Ve}from"../chart/utils/scales.js";import{CHART_TOUCH as Ie}from"../chart/utils/touch.js";import{Table as De}from"../table/Table.js";import{TableBody as ze}from"../table/TableBody.js";import{TableCell as Z}from"../table/TableCell.js";import{TableHeader as Ge}from"../table/TableHeader.js";import{TableHeaderCell as B}from"../table/TableHeaderCell.js";import{TableRow as qe}from"../table/TableRow.js";import{Fragment as Qe,jsx as a,jsxs as y}from"react/jsx-runtime";var Ke=40,Oe=3,F=4,ce="text-right [font-variant-numeric:tabular-nums]",Ue=Te(function({boxes:h,color:f}){return a("g",{children:h.map(t=>y("g",{children:[a("g",{stroke:f,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:f}):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-F} L${t.mean.cx+F},${t.mean.cy} L${t.mean.cx},${t.mean.cy+F} L${t.mean.cx-F},${t.mean.cy} Z`,strokeWidth:1.5,stroke:f,className:"fill-white dark:fill-gray-800"}):null,t.outliers.map(l=>a("circle",{cx:l.cx,cy:l.cy,r:Oe,fill:f,strokeWidth:1.5,className:"stroke-white dark:stroke-gray-800"},l.key))]},t.key))})});function _e({width:C,height:h,data:f,boxes:t,x:l,y:k,grid:L,size:q,orientation:T,boxSize:K,showOutliers:O,showMean:W,color:U,referenceLines:ee,margin:X,tooltip:w,plotLabel:te,formatValue:M,formatX:A,onBoxClick:V}){let[I,H]=we(null),u=I!==null&&I<t.length?I:null,_=be(),e=J(()=>{let r=T==="vertical",o=t.flatMap(s=>s.stats===null?[]:[s.stats.min,s.stats.max,...W&&s.mean!==null?[s.mean]:[]]),g=Ae({width:C,height:h,data:f,x:l,y:k,bounds:o.length===0?null:[Math.min(...o),Math.max(...o)],margin:X,orientation:T,placement:"band",formatValue:M,formatX:A,defaultIncludeZero:!1}),{valueScale:d,bandwidth:p,categoryPositions:x,innerWidth:D,innerHeight:ne}=g,n=Math.min(K??Ke,p),v=n*.5,P=(s,b)=>r?{x:s,y:b}:{x:b,y:s},R=t.map((s,b)=>{let i=x[b]+(p-n)/2,c=i+n/2;if(s.stats===null)return{key:`${b}`,body:"",median:null,whiskers:[],outliers:[],mean:null,top:x[b],height:p};let{q1:N,q3:z,median:Q,lower:Ce,upper:ke,outliers:ve}=s.stats,me=d(N),ue=d(z),de=Math.min(me,ue),he=Math.abs(ue-me),Pe=We({...r?{x:i,y:de,width:n,height:Math.max(1,he)}:{x:de,y:i,width:Math.max(1,he),height:n},radius:2,round:"none"}),Y=d(Q),Ne=r?{x1:i,y1:Y,x2:i+n,y2:Y}:{x1:Y,y1:i,x2:Y,y2:i+n},le=[];for(let[S,oe,j]of[["lower",Ce,N],["upper",ke,z]]){let ie=d(oe),Be=d(j),ge=P(c,ie),ye=P(c,Be);le.push({key:`${S}-stem`,x1:ye.x,y1:ye.y,x2:ge.x,y2:ge.y});let fe=P(c-v/2,ie),pe=P(c+v/2,ie);le.push({key:`${S}-cap`,x1:fe.x,y1:fe.y,x2:pe.x,y2:pe.y})}return{key:`${b}`,body:Pe,median:Ne,whiskers:le,outliers:O?ve.map((S,oe)=>{let j=P(c,d(S));return{key:`${oe}`,cx:j.x,cy:j.y}}):[],mean:W&&s.mean!==null?(()=>{let S=P(c,d(s.mean));return{cx:S.x,cy:S.y}})():null,top:x[b],height:p}});return{vertical:r,rendered:R,categoryPositions:x,categoryCenters:g.categoryCenters,bandwidth:p,categoryTicks:g.categoryTicks,valueTicks:g.valueTicks,valueScale:d,innerWidth:D,innerHeight:ne,margin:g.margin}},[t,f,l,k,C,h,X,T,K,O,W,M,A]),ae=se(r=>{if(w===!1||t.length===0)return;let o=r.currentTarget.getBoundingClientRect(),g=e.vertical?r.clientX-o.left-e.margin.left:r.clientY-o.top-e.margin.top;H(Ve(e.categoryCenters,g))},[w,t.length,e.vertical,e.margin,e.categoryCenters]),re=se(r=>{if(t.length===0)return;let o=t.length-1,g=u??0,d=e.vertical?"ArrowRight":"ArrowDown",p=e.vertical?"ArrowLeft":"ArrowUp",x=r.key===d?Math.min(o,g+1):r.key===p?Math.max(0,g-1):r.key==="Home"?0:r.key==="End"?o:r.key==="Escape"?null:void 0;x!==void 0&&(r.preventDefault(),H(x))},[t.length,u,e.vertical]),$=se(()=>{!V||u===null||V(t[u])},[V,u,t]),m=u===null?null:t[u],E=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 y(Qe,{children:[y("svg",{width:C,height:h,role:"img","aria-label":te??t.map(r=>r.label).join(", "),tabIndex:0,className:`${Ie} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500`,onPointerMove:ae,onPointerLeave:()=>H(null),onKeyDown:re,onBlur:()=>H(null),onClick:$,children:[y("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[a(Se,{width:e.innerWidth,height:e.innerHeight,horizontal:e.vertical&&(L==="y"||L==="both")?e.valueTicks.map(r=>r.offset):void 0,vertical:!e.vertical&&(L==="y"||L==="both")?e.valueTicks.map(r=>r.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,ee?.map(r=>{let o=e.valueScale(r.value);return y("g",{children:[a("line",{x1:e.vertical?0:o,y1:e.vertical?o:0,x2:e.vertical?e.innerWidth:o,y2:e.vertical?o: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:o+4,y:e.vertical?o-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(Ue,{boxes:e.rendered,color:U})]}),a("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:(e.vertical?l.hidden:k?.hidden)?null:a(xe,{orientation:"bottom",ticks:e.vertical?e.categoryTicks:e.valueTicks,length:e.innerWidth,label:e.vertical?l.label:k?.label,size:q})}),a("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:(e.vertical?k?.hidden:l.hidden)?null:a(xe,{orientation:"left",ticks:e.vertical?e.valueTicks:e.categoryTicks,length:e.innerHeight,showLine:!1,label:e.vertical?k?.label:l.label,size:q})})]}),m&&m.stats&&E&&w!==!1?a(Le,{x:E.x,y:E.y,containerWidth:C,children:typeof w=="function"?w(m):y("div",{className:"flex flex-col gap-1",children:[a("div",{className:"font-medium text-gray-900 dark:text-gray-100",children:m.label}),y("dl",{className:"grid grid-cols-[auto_auto] gap-x-3 gap-y-0.5",children:[[["Max",m.stats.max],["Q3",m.stats.q3],[_.chartMedian,m.stats.median],["Q1",m.stats.q1],["Min",m.stats.min]].map(([r,o])=>y("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:M(o)})]},r)),y("div",{className:"contents",children:[a("dt",{className:"text-gray-500 dark:text-gray-400",children:_.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 yt({data:C,x:h,y:f,values:t,quantiles:l,whisker:k=1.5,orientation:L="vertical",boxSize:q,showOutliers:T=!0,showMean:K=!1,color:O,referenceLines:W,height:U=280,width:ee,size:X="md",grid:w="y",tooltip:te=!0,tableView:M=!1,title:A,description:V,loading:I=!1,emptyState:H,error:u=!1,errorState:_,onRetry:e,actions:ae,margin:re,locale:$,plotLabel:m,format:E,onBoxClick:r,className:o,...g}){let d=be(),p=J(()=>f?.format??E??(n=>$e(n,$)),[f?.format,E,$]),x=J(()=>h.format??(n=>Ee(n,$)),[h.format,$]),D=J(()=>C.map((n,v)=>{let P=He(n,h.key,v),R=t?(()=>{let i=n[t];return Array.isArray(i)?i.map(c=>typeof c=="number"?c:Number(c)).filter(c=>Number.isFinite(c)):null})():null,s=null,b=null;if(R!==null)s=Xe(R,k),b=R.length===0?null:R.reduce((i,c)=>i+c,0)/R.length;else if(l){let i=G(n,l.q1),c=G(n,l.median),N=G(n,l.q3);if(i!==null&&c!==null&&N!==null){let z=l.min?G(n,l.min)??i:i,Q=l.max?G(n,l.max)??N:N;s={count:0,min:z,max:Q,q1:i,median:c,q3:N,iqr:N-i,lower:z,upper:Q,outliers:[]}}}return{index:v,x:P,label:x(P,v),stats:s,mean:b,datum:n}}),[C,h.key,t,l,k,x]),ne=D.filter(n=>n.stats!==null);return a(Re,{title:A,description:V,height:U,width:ee,size:X,loading:I,empty:ne.length===0,emptyState:H,error:u,errorState:_,onRetry:e,actions:ae,tableView:M,table:M?a("div",{className:"w-full overflow-x-auto",children:y(De,{children:[typeof A=="string"?a("caption",{className:"sr-only",children:A}):null,y(Ge,{children:[a(B,{children:h.label??h.key}),t?a(B,{className:"text-right",children:d.chartCount}):null,a(B,{className:"text-right",children:"Min"}),a(B,{className:"text-right",children:"Q1"}),a(B,{className:"text-right",children:d.chartMedian}),a(B,{className:"text-right",children:"Q3"}),a(B,{className:"text-right",children:"Max"}),t&&T?a(B,{className:"text-right",children:d.chartOutliers}):null]}),a(ze,{children:D.map(n=>y(qe,{clickable:!1,children:[a(Z,{className:"font-medium text-gray-900 dark:text-gray-100",children:n.label}),t?a(Z,{className:ce,children:n.stats?.count??"\u2014"}):null,["min","q1","median","q3","max"].map(v=>a(Z,{className:ce,children:n.stats===null?"\u2014":p(n.stats[v])},v)),t&&T?a(Z,{className:ce,children:n.stats===null||n.stats.outliers.length===0?"\u2014":n.stats.outliers.map(p).join(", ")}):null]},n.index))})]})}):void 0,className:o,...g,children:({width:n})=>a(_e,{width:n,height:U,data:C,boxes:D,x:h,y:f,grid:w,size:X,orientation:L,boxSize:q,showOutliers:T,showMean:K,color:O??Me(0),referenceLines:W,margin:re,tooltip:te,plotLabel:m,formatValue:p,formatX:x,onBoxClick:r})})}export{yt as BoxPlot};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";"use client";var
|
|
1
|
+
"use strict";"use client";var te=Object.defineProperty;var be=Object.getOwnPropertyDescriptor;var pe=Object.getOwnPropertyNames;var ye=Object.prototype.hasOwnProperty;var ke=(i,l)=>{for(var t in l)te(i,t,{get:l[t],enumerable:!0})},Ce=(i,l,t,e)=>{if(l&&typeof l=="object"||typeof l=="function")for(let s of pe(l))!ye.call(i,s)&&s!==t&&te(i,s,{get:()=>l[s],enumerable:!(e=be(l,s))||e.enumerable});return i};var xe=i=>Ce(te({},"__esModule",{value:!0}),i);var Ee={};ke(Ee,{BulletChart:()=>Be});module.exports=xe(Ee);var c=require("react"),ue=require("../../lib/i18n.cjs"),ne=require("../chart/ChartAxis.cjs"),me=require("../chart/ChartContainer.cjs"),ce=require("../chart/ChartTableView.cjs"),ge=require("../chart/ChartTooltip.cjs"),de=require("../chart/palette.cjs"),G=require("../chart/utils/data.cjs"),X=require("../chart/utils/format.cjs"),ae=require("../chart/utils/path.cjs"),L=require("../chart/utils/scales.cjs"),re=require("../chart/utils/text.cjs"),I=require("../chart/utils/ticks.cjs"),he=require("../chart/utils/touch.cjs"),n=require("react/jsx-runtime"),Re=22,ve=.42,ie=3,se=8,Te=12,Ne=["fill-gray-300 dark:fill-gray-500","fill-gray-200 dark:fill-gray-600","fill-gray-100 dark:fill-gray-700","fill-gray-50 dark:fill-gray-800"],Se=(0,c.memo)(function({rows:l,color:t}){return(0,n.jsx)("g",{children:l.map(e=>(0,n.jsxs)("g",{children:[e.bands.map(s=>(0,n.jsx)("path",{d:s.d,className:s.className,fill:s.fill},s.key)),e.measure?(0,n.jsx)("path",{d:e.measure,fill:t}):null,e.target?(0,n.jsx)("line",{x1:e.target.x,y1:e.target.y1,x2:e.target.x,y2:e.target.y2,strokeWidth:2,strokeLinecap:"round",className:"stroke-gray-900 dark:stroke-white"}):null,e.label?(0,n.jsx)("text",{x:e.label.x,y:e.label.y,dominantBaseline:"middle",className:"fill-gray-700 text-[11px] font-medium [font-variant-numeric:tabular-nums] dark:fill-gray-200",children:e.label.text}):null]},e.key))})});function Ve({width:i,height:l,rows:t,x:e,size:s,sharedDomain:d,showValues:T,trackSize:K,rangeColors:z,color:W,tooltip:N,plotLabel:q,formatValue:U,locale:w,onRowClick:H}){let[M,R]=(0,c.useState)(null),u=M!==null&&M<t.length?M:null,r=(0,c.useMemo)(()=>{let m=t.map(a=>a.label),h=T?t.map(a=>a.formattedValue):[],f={top:6,right:T?(0,re.widestLabel)(h)+se*2:8,bottom:d?26+(e.label?16:0):6,left:e.hidden?8:e.height??(0,re.widestLabel)(m)+Te},p=Math.max(0,i-f.left-f.right),_=Math.max(0,l-f.top-f.bottom),b=(0,L.createBandScale)(t.map((a,g)=>g),[0,_],{paddingInner:.34}),S=Math.min(K??Re,b.bandwidth),D=Math.max(3,S*ve),O=z??Ne,V=z!==void 0,B=t.map((a,g)=>{let F=Math.max(0,a.value??0,a.target??0,...a.ranges.length>0?a.ranges:[0]),A=d??(a.ranges.length>0?[0,F]:(0,I.niceDomain)(0,F,4)),o=(0,L.createLinearScale)(A,[0,p]),y=b(g)+(b.bandwidth-S)/2,x=y+S/2,P=a.ranges.length>0?[...a.ranges].sort((C,j)=>C-j):[A[1]],k=A[0],Y=P.map((C,j)=>{let le=o(k),fe=o(Math.max(k,C));k=C;let oe=O[Math.min(j,O.length-1)];return{key:`${g}-${j}`,d:(0,ae.buildBarPath)({x:le,y,width:Math.max(0,fe-le),height:S,radius:0}),className:V?void 0:oe,fill:V?oe:void 0}}),ee=a.value===null?null:(0,ae.buildBarPath)({x:o(A[0]),y:x-D/2,width:Math.max(0,o(a.value)-o(A[0])),height:D,radius:2,round:"right"});return{key:`${g}`,bands:Y,measure:ee,target:a.target===null?null:{x:o(a.target),y1:y-ie,y2:y+S+ie},label:T?{x:p+se,y:x,text:a.formattedValue}:null,top:b(g),height:b.bandwidth}}),$=e.hidden?[]:t.map((a,g)=>({value:a.x,offset:b.center(g),label:a.label})),E=d?(0,I.niceTicks)(d[0],d[1],5).map(a=>({value:a,offset:(0,L.createLinearScale)(d,[0,p])(a),label:U(a)})):[];return{margin:f,innerWidth:p,innerHeight:_,band:b,rendered:B,categoryTicks:$,valueTicks:E,centers:t.map((a,g)=>b.center(g))}},[t,e,i,l,d,T,K,z,U]),J=(0,c.useCallback)(m=>{if(N===!1||t.length===0)return;let h=m.currentTarget.getBoundingClientRect(),f=m.clientY-h.top-r.margin.top;R((0,L.nearestIndex)(r.centers,f))},[N,t.length,r.margin.top,r.centers]),Q=(0,c.useCallback)(m=>{if(t.length===0)return;let h=t.length-1,f=u??0,p=m.key==="ArrowDown"?Math.min(h,f+1):m.key==="ArrowUp"?Math.max(0,f-1):m.key==="Home"?0:m.key==="End"?h:m.key==="Escape"?null:void 0;p!==void 0&&(m.preventDefault(),R(p))},[t.length,u]),Z=(0,c.useCallback)(()=>{!H||u===null||H(t[u])},[H,u,t]),v=u===null?null:t[u];return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("svg",{width:i,height:l,role:"img","aria-label":q??t.map(m=>m.label).join(", "),tabIndex:0,className:`${he.CHART_TOUCH} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500`,onPointerMove:J,onPointerLeave:()=>R(null),onKeyDown:Q,onBlur:()=>R(null),onClick:Z,children:[(0,n.jsxs)("g",{transform:`translate(${r.margin.left}, ${r.margin.top})`,children:[u!==null&&r.rendered[u]?(0,n.jsx)("rect",{x:-4,y:r.rendered[u].top,width:r.innerWidth+8,height:r.rendered[u].height,rx:4,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,(0,n.jsx)(Se,{rows:r.rendered,color:W})]}),(0,n.jsx)("g",{transform:`translate(${r.margin.left}, ${r.margin.top})`,children:e.hidden?null:(0,n.jsx)(ne.ChartAxis,{orientation:"left",ticks:r.categoryTicks,length:r.innerHeight,showLine:!1,tickSize:0,size:s})}),d?(0,n.jsx)("g",{transform:`translate(${r.margin.left}, ${r.margin.top+r.innerHeight})`,children:(0,n.jsx)(ne.ChartAxis,{orientation:"bottom",ticks:r.valueTicks,length:r.innerWidth,label:e.label,size:s})}):null]}),v&&u!==null&&N!==!1?(0,n.jsx)(ge.ChartTooltip,{x:r.margin.left+r.innerWidth/2,y:r.margin.top+r.centers[u],containerWidth:i,children:typeof N=="function"?N(v):(0,n.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,n.jsx)("div",{className:"font-medium text-gray-900 dark:text-gray-100",children:v.label}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"h-0.5 w-3 shrink-0 rounded-full",style:{backgroundColor:W},"aria-hidden":"true"}),(0,n.jsx)("span",{className:"font-semibold text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:v.formattedValue}),v.attainment!==null?(0,n.jsx)("span",{className:"text-gray-500 [font-variant-numeric:tabular-nums] dark:text-gray-400",children:(0,X.formatPercent)(v.attainment,{locale:w})}):null]})]})}):null]})}function Be({data:i,x:l,value:t,target:e,ranges:s,domain:d,normalize:T="row",showValues:K=!0,trackSize:z,rangeColors:W,color:N,height:q,width:U,size:w="md",tooltip:H=!0,tableView:M=!1,title:R,description:u,loading:r=!1,emptyState:J,error:Q=!1,errorState:Z,onRetry:v,actions:m,locale:h,plotLabel:f,valueLabel:p,targetLabel:_,format:b,onRowClick:S,className:D,...O}){let V=(0,ue.useUILabels)(),B=(0,c.useMemo)(()=>b??(o=>(0,X.formatAuto)(o,h)),[b,h]),$=(0,c.useMemo)(()=>l.format??(o=>(0,X.formatXValue)(o,h)),[l.format,h]),E=(0,c.useMemo)(()=>i.map((o,y)=>{let x=(0,G.readXValue)(o,l.key,y),P=(0,G.readNumber)(o,t),k=e?(0,G.readNumber)(o,e):null,Y=s?o[s]:void 0,ee=Array.isArray(Y)?Y.map(C=>typeof C=="number"?C:Number(C)).filter(C=>Number.isFinite(C)):[];return{index:y,x,label:$(x,y),value:P,target:k,ranges:ee,formattedValue:P===null?"\u2014":B(P),formattedTarget:k===null?"\u2014":B(k),attainment:P===null||k===null||k===0?null:P/k,datum:o}}),[i,l.key,t,e,s,B,$]),a=(0,c.useMemo)(()=>{if(d)return d;if(T!=="shared")return null;let o=E.reduce((y,x)=>Math.max(y,x.value??0,x.target??0,...x.ranges),0);return(0,I.niceDomain)(0,o,5)},[d,T,E]),g=q??Math.max(72,E.length*34+(a?30:12)),F=(0,c.useMemo)(()=>[{key:t,label:p??V.chartValue},...e?[{key:e,label:_??V.chartTarget}]:[]],[t,e,p,_,V.chartValue,V.chartTarget]),A=N??(0,de.getSeriesColor)(0);return(0,n.jsx)(me.ChartContainer,{title:R,description:u,height:g,width:U,size:w,loading:r,empty:E.length===0,emptyState:J,error:Q,errorState:Z,onRetry:v,actions:m,tableView:M,table:M?(0,n.jsx)(ce.ChartTableView,{data:i,series:F,xKey:l.key,xLabel:l.label??l.key,formatX:$,formatValue:B,caption:typeof R=="string"?R:void 0}):void 0,className:D,...O,children:({width:o})=>(0,n.jsx)(Ve,{width:o,height:g,rows:E,x:l,size:w,sharedDomain:a,showValues:K,trackSize:z,rangeColors:W,color:A,tooltip:H,plotLabel:f,formatValue:B,locale:h,onRowClick:S})})}0&&(module.exports={BulletChart});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{memo as
|
|
1
|
+
"use client";import{memo as me,useCallback as Q,useMemo as L,useState as ce}from"react";import{useUILabels as ge}from"../../lib/i18n.js";import{ChartAxis as te}from"../chart/ChartAxis.js";import{ChartContainer as de}from"../chart/ChartContainer.js";import{ChartTableView as he}from"../chart/ChartTableView.js";import{ChartTooltip as fe}from"../chart/ChartTooltip.js";import{getSeriesColor as be}from"../chart/palette.js";import{readNumber as ne,readXValue as pe}from"../chart/utils/data.js";import{formatAuto as ye,formatPercent as ke,formatXValue as Ce}from"../chart/utils/format.js";import{buildBarPath as ae}from"../chart/utils/path.js";import{createBandScale as xe,createLinearScale as re,nearestIndex as Re}from"../chart/utils/scales.js";import{widestLabel as le}from"../chart/utils/text.js";import{niceDomain as se,niceTicks as ve}from"../chart/utils/ticks.js";import{CHART_TOUCH as Te}from"../chart/utils/touch.js";import{Fragment as Pe,jsx as l,jsxs as M}from"react/jsx-runtime";var Ne=22,Se=.42,oe=3,ie=8,Ve=12,Be=["fill-gray-300 dark:fill-gray-500","fill-gray-200 dark:fill-gray-600","fill-gray-100 dark:fill-gray-700","fill-gray-50 dark:fill-gray-800"],Ee=me(function({rows:s,color:a}){return l("g",{children:s.map(e=>M("g",{children:[e.bands.map(d=>l("path",{d:d.d,className:d.className,fill:d.fill},d.key)),e.measure?l("path",{d:e.measure,fill:a}):null,e.target?l("line",{x1:e.target.x,y1:e.target.y1,x2:e.target.x,y2:e.target.y2,strokeWidth:2,strokeLinecap:"round",className:"stroke-gray-900 dark:stroke-white"}):null,e.label?l("text",{x:e.label.x,y:e.label.y,dominantBaseline:"middle",className:"fill-gray-700 text-[11px] font-medium [font-variant-numeric:tabular-nums] dark:fill-gray-200",children:e.label.text}):null]},e.key))})});function Ae({width:k,height:s,rows:a,x:e,size:d,sharedDomain:m,showValues:v,trackSize:$,rangeColors:X,color:G,tooltip:T,plotLabel:F,formatValue:I,locale:K,onRowClick:z}){let[P,x]=ce(null),o=P!==null&&P<a.length?P:null,n=L(()=>{let i=a.map(t=>t.label),c=v?a.map(t=>t.formattedValue):[],g={top:6,right:v?le(c)+ie*2:8,bottom:m?26+(e.label?16:0):6,left:e.hidden?8:e.height??le(i)+Ve},f=Math.max(0,k-g.left-g.right),H=Math.max(0,s-g.top-g.bottom),h=xe(a.map((t,u)=>u),[0,H],{paddingInner:.34}),N=Math.min($??Ne,h.bandwidth),W=Math.max(3,N*Se),U=X??Be,S=X!==void 0,V=a.map((t,u)=>{let w=Math.max(0,t.value??0,t.target??0,...t.ranges.length>0?t.ranges:[0]),E=m??(t.ranges.length>0?[0,w]:se(0,w,4)),r=re(E,[0,f]),b=h(u)+(h.bandwidth-N)/2,C=b+N/2,A=t.ranges.length>0?[...t.ranges].sort((y,O)=>y-O):[E[1]],p=E[0],D=A.map((y,O)=>{let Z=r(p),ue=r(Math.max(p,y));p=y;let ee=U[Math.min(O,U.length-1)];return{key:`${u}-${O}`,d:ae({x:Z,y:b,width:Math.max(0,ue-Z),height:N,radius:0}),className:S?void 0:ee,fill:S?ee:void 0}}),J=t.value===null?null:ae({x:r(E[0]),y:C-W/2,width:Math.max(0,r(t.value)-r(E[0])),height:W,radius:2,round:"right"});return{key:`${u}`,bands:D,measure:J,target:t.target===null?null:{x:r(t.target),y1:b-oe,y2:b+N+oe},label:v?{x:f+ie,y:C,text:t.formattedValue}:null,top:h(u),height:h.bandwidth}}),_=e.hidden?[]:a.map((t,u)=>({value:t.x,offset:h.center(u),label:t.label})),B=m?ve(m[0],m[1],5).map(t=>({value:t,offset:re(m,[0,f])(t),label:I(t)})):[];return{margin:g,innerWidth:f,innerHeight:H,band:h,rendered:V,categoryTicks:_,valueTicks:B,centers:a.map((t,u)=>h.center(u))}},[a,e,k,s,m,v,$,X,I]),Y=Q(i=>{if(T===!1||a.length===0)return;let c=i.currentTarget.getBoundingClientRect(),g=i.clientY-c.top-n.margin.top;x(Re(n.centers,g))},[T,a.length,n.margin.top,n.centers]),j=Q(i=>{if(a.length===0)return;let c=a.length-1,g=o??0,f=i.key==="ArrowDown"?Math.min(c,g+1):i.key==="ArrowUp"?Math.max(0,g-1):i.key==="Home"?0:i.key==="End"?c:i.key==="Escape"?null:void 0;f!==void 0&&(i.preventDefault(),x(f))},[a.length,o]),q=Q(()=>{!z||o===null||z(a[o])},[z,o,a]),R=o===null?null:a[o];return M(Pe,{children:[M("svg",{width:k,height:s,role:"img","aria-label":F??a.map(i=>i.label).join(", "),tabIndex:0,className:`${Te} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500`,onPointerMove:Y,onPointerLeave:()=>x(null),onKeyDown:j,onBlur:()=>x(null),onClick:q,children:[M("g",{transform:`translate(${n.margin.left}, ${n.margin.top})`,children:[o!==null&&n.rendered[o]?l("rect",{x:-4,y:n.rendered[o].top,width:n.innerWidth+8,height:n.rendered[o].height,rx:4,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,l(Ee,{rows:n.rendered,color:G})]}),l("g",{transform:`translate(${n.margin.left}, ${n.margin.top})`,children:e.hidden?null:l(te,{orientation:"left",ticks:n.categoryTicks,length:n.innerHeight,showLine:!1,tickSize:0,size:d})}),m?l("g",{transform:`translate(${n.margin.left}, ${n.margin.top+n.innerHeight})`,children:l(te,{orientation:"bottom",ticks:n.valueTicks,length:n.innerWidth,label:e.label,size:d})}):null]}),R&&o!==null&&T!==!1?l(fe,{x:n.margin.left+n.innerWidth/2,y:n.margin.top+n.centers[o],containerWidth:k,children:typeof T=="function"?T(R):M("div",{className:"flex flex-col gap-1",children:[l("div",{className:"font-medium text-gray-900 dark:text-gray-100",children:R.label}),M("div",{className:"flex items-center gap-2",children:[l("span",{className:"h-0.5 w-3 shrink-0 rounded-full",style:{backgroundColor:G},"aria-hidden":"true"}),l("span",{className:"font-semibold text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:R.formattedValue}),R.attainment!==null?l("span",{className:"text-gray-500 [font-variant-numeric:tabular-nums] dark:text-gray-400",children:ke(R.attainment,{locale:K})}):null]})]})}):null]})}function Oe({data:k,x:s,value:a,target:e,ranges:d,domain:m,normalize:v="row",showValues:$=!0,trackSize:X,rangeColors:G,color:T,height:F,width:I,size:K="md",tooltip:z=!0,tableView:P=!1,title:x,description:o,loading:n=!1,emptyState:Y,error:j=!1,errorState:q,onRetry:R,actions:i,locale:c,plotLabel:g,valueLabel:f,targetLabel:H,format:h,onRowClick:N,className:W,...U}){let S=ge(),V=L(()=>h??(r=>ye(r,c)),[h,c]),_=L(()=>s.format??(r=>Ce(r,c)),[s.format,c]),B=L(()=>k.map((r,b)=>{let C=pe(r,s.key,b),A=ne(r,a),p=e?ne(r,e):null,D=d?r[d]:void 0,J=Array.isArray(D)?D.map(y=>typeof y=="number"?y:Number(y)).filter(y=>Number.isFinite(y)):[];return{index:b,x:C,label:_(C,b),value:A,target:p,ranges:J,formattedValue:A===null?"\u2014":V(A),formattedTarget:p===null?"\u2014":V(p),attainment:A===null||p===null||p===0?null:A/p,datum:r}}),[k,s.key,a,e,d,V,_]),t=L(()=>{if(m)return m;if(v!=="shared")return null;let r=B.reduce((b,C)=>Math.max(b,C.value??0,C.target??0,...C.ranges),0);return se(0,r,5)},[m,v,B]),u=F??Math.max(72,B.length*34+(t?30:12)),w=L(()=>[{key:a,label:f??S.chartValue},...e?[{key:e,label:H??S.chartTarget}]:[]],[a,e,f,H,S.chartValue,S.chartTarget]),E=T??be(0);return l(de,{title:x,description:o,height:u,width:I,size:K,loading:n,empty:B.length===0,emptyState:Y,error:j,errorState:q,onRetry:R,actions:i,tableView:P,table:P?l(he,{data:k,series:w,xKey:s.key,xLabel:s.label??s.key,formatX:_,formatValue:V,caption:typeof x=="string"?x:void 0}):void 0,className:W,...U,children:({width:r})=>l(Ae,{width:r,height:u,rows:B,x:s,size:K,sharedDomain:t,showValues:$,trackSize:X,rangeColors:G,color:E,tooltip:z,plotLabel:g,formatValue:V,locale:c,onRowClick:N})})}export{Oe as BulletChart};
|