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