@synertech/ui 0.51.0 → 0.52.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 +183 -147
- package/README.md +27 -19
- package/dist/components/advance-detachable/AdvanceDetachable.cjs +1 -1
- package/dist/components/advance-detachable/AdvanceDetachable.js +1 -1
- package/dist/components/area-chart/AreaChart.cjs +1 -1
- package/dist/components/area-chart/AreaChart.js +1 -1
- package/dist/components/avatar/Avatar.cjs +1 -1
- package/dist/components/avatar/Avatar.js +1 -1
- package/dist/components/avatar/AvatarImage.cjs +1 -0
- package/dist/components/avatar/AvatarImage.js +1 -0
- package/dist/components/banner/Banner.cjs +1 -1
- package/dist/components/banner/Banner.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/breadcrumb/Breadcrumb.cjs +1 -1
- package/dist/components/breadcrumb/Breadcrumb.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/card/Card.cjs +1 -1
- package/dist/components/card/Card.js +1 -1
- package/dist/components/chart/ChartAnnotations.cjs +1 -1
- package/dist/components/chart/ChartAnnotations.js +1 -1
- package/dist/components/chart/ChartBrush.cjs +1 -1
- package/dist/components/chart/ChartBrush.js +1 -1
- package/dist/components/chart/ChartContainer.cjs +1 -1
- package/dist/components/chart/ChartContainer.js +1 -1
- package/dist/components/chart/ChartExportButton.cjs +1 -1
- package/dist/components/chart/ChartExportButton.js +1 -1
- package/dist/components/chart/ChartPatterns.cjs +1 -1
- package/dist/components/chart/ChartPatterns.js +1 -1
- package/dist/components/chart/ChartPlotClip.cjs +1 -0
- package/dist/components/chart/ChartPlotClip.js +1 -0
- package/dist/components/chart/ChartSync.cjs +1 -1
- package/dist/components/chart/ChartSync.js +1 -1
- package/dist/components/chart/ChartTableView.cjs +1 -1
- package/dist/components/chart/ChartTableView.js +1 -1
- package/dist/components/chart/exportSource.cjs +1 -0
- package/dist/components/chart/exportSource.js +1 -0
- package/dist/components/chart/palette.cjs +1 -1
- package/dist/components/chart/palette.js +1 -1
- package/dist/components/chart/useChartSize.cjs +1 -1
- package/dist/components/chart/useChartSize.js +1 -1
- package/dist/components/chart/utils/bins.cjs +1 -1
- package/dist/components/chart/utils/bins.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/export.cjs +7 -1
- package/dist/components/chart/utils/export.js +7 -1
- package/dist/components/chart/utils/format.cjs +1 -1
- package/dist/components/chart/utils/format.js +1 -1
- package/dist/components/chart/utils/keyboard.cjs +1 -1
- package/dist/components/chart/utils/keyboard.js +1 -1
- package/dist/components/chart/utils/period.cjs +1 -1
- package/dist/components/chart/utils/period.js +1 -1
- package/dist/components/chart/utils/regression.cjs +1 -0
- package/dist/components/chart/utils/regression.js +1 -0
- package/dist/components/chart/utils/stack.cjs +1 -1
- package/dist/components/chart/utils/stack.js +1 -1
- package/dist/components/chart/utils/ticks.cjs +1 -1
- package/dist/components/chart/utils/ticks.js +1 -1
- package/dist/components/checkbox/Checkbox.cjs +1 -1
- package/dist/components/checkbox/Checkbox.js +1 -1
- package/dist/components/circular-progress/CircularProgress.cjs +1 -1
- package/dist/components/circular-progress/CircularProgress.js +1 -1
- package/dist/components/datagrid/DataGrid.cjs +1 -1
- package/dist/components/datagrid/DataGrid.js +1 -1
- package/dist/components/detachable/Detachable.cjs +1 -1
- package/dist/components/detachable/Detachable.js +1 -1
- package/dist/components/detachable/popup-window.cjs +1 -0
- package/dist/components/detachable/popup-window.js +1 -0
- package/dist/components/device-mockup/DeviceMockup.cjs +1 -1
- package/dist/components/device-mockup/DeviceMockup.js +1 -1
- package/dist/components/divider/Divider.cjs +1 -1
- package/dist/components/divider/Divider.js +1 -1
- package/dist/components/dumbbell-chart/DumbbellChart.cjs +1 -1
- package/dist/components/dumbbell-chart/DumbbellChart.js +1 -1
- package/dist/components/file-selector/FileSelector.cjs +1 -1
- package/dist/components/file-selector/FileSelector.js +1 -1
- package/dist/components/footer/FooterBottom.cjs +1 -1
- package/dist/components/footer/FooterBottom.js +1 -1
- package/dist/components/form/input/Input.cjs +1 -1
- package/dist/components/form/input/Input.js +1 -1
- package/dist/components/form/mention-input/MentionInput.cjs +5 -4
- package/dist/components/form/mention-input/MentionInput.js +5 -4
- package/dist/components/form/number-input/NumberInput.cjs +1 -1
- package/dist/components/form/number-input/NumberInput.js +1 -1
- package/dist/components/form/shared/InputWrapper.cjs +1 -1
- package/dist/components/form/shared/InputWrapper.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/image-uploader/ImageUploader.cjs +1 -1
- package/dist/components/image-uploader/ImageUploader.js +1 -1
- package/dist/components/line-chart/LineChart.cjs +1 -1
- package/dist/components/line-chart/LineChart.js +1 -1
- package/dist/components/pagination/Pagination.cjs +1 -1
- package/dist/components/pagination/Pagination.js +1 -1
- package/dist/components/pie-chart/PieChart.cjs +1 -1
- package/dist/components/pie-chart/PieChart.js +1 -1
- package/dist/components/progress-bar/ProgressBar.cjs +1 -1
- package/dist/components/progress-bar/ProgressBar.js +1 -1
- package/dist/components/radio-button/RadioButton.cjs +1 -1
- package/dist/components/radio-button/RadioButton.js +1 -1
- package/dist/components/scatter-chart/ScatterChart.cjs +1 -1
- package/dist/components/scatter-chart/ScatterChart.js +1 -1
- package/dist/components/scatter-chart/index.cjs +1 -1
- package/dist/components/scatter-chart/index.js +1 -1
- package/dist/components/schema-editor/SchemaEditor.cjs +1 -1
- package/dist/components/schema-editor/SchemaEditor.js +1 -1
- package/dist/components/schema-editor/canvas/GridLayer.cjs +1 -1
- package/dist/components/schema-editor/canvas/GridLayer.js +1 -1
- package/dist/components/schema-editor/relations/SchemaRelationRenderer.cjs +1 -1
- package/dist/components/schema-editor/relations/SchemaRelationRenderer.js +1 -1
- package/dist/components/schema-editor/utils/sql-export.cjs +4 -4
- package/dist/components/schema-editor/utils/sql-export.js +7 -7
- package/dist/components/slider/Slider.cjs +1 -1
- package/dist/components/slider/Slider.js +1 -1
- package/dist/components/sparkline/Sparkline.cjs +1 -1
- package/dist/components/sparkline/Sparkline.js +1 -1
- package/dist/components/table/TableRow.cjs +1 -1
- package/dist/components/table/TableRow.js +1 -1
- package/dist/components/waterfall-chart/WaterfallChart.cjs +1 -1
- package/dist/components/waterfall-chart/WaterfallChart.js +1 -1
- package/dist/components/workflow-editor/WorkflowEditor.cjs +1 -1
- package/dist/components/workflow-editor/WorkflowEditor.js +1 -1
- package/dist/components/workflow-editor/canvas/GridLayer.cjs +1 -1
- package/dist/components/workflow-editor/canvas/GridLayer.js +1 -1
- package/dist/index.d.cts +433 -170
- package/dist/index.d.ts +433 -170
- package/dist/lib/accept.cjs +1 -0
- package/dist/lib/accept.js +1 -0
- package/dist/lib/css-value.cjs +1 -0
- package/dist/lib/css-value.js +1 -0
- package/dist/lib/ui-labels.cjs +1 -1
- package/dist/lib/ui-labels.js +1 -1
- package/dist/styles-no-preflight.css +10270 -0
- package/dist/styles.css +301 -28
- package/package.json +9 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";"use client";var
|
|
1
|
+
"use strict";"use client";var ee=Object.defineProperty;var de=Object.getOwnPropertyDescriptor;var he=Object.getOwnPropertyNames;var fe=Object.prototype.hasOwnProperty;var pe=(o,n)=>{for(var t in n)ee(o,t,{get:n[t],enumerable:!0})},be=(o,n,t,f)=>{if(n&&typeof n=="object"||typeof n=="function")for(let p of he(n))!fe.call(o,p)&&p!==t&&ee(o,p,{get:()=>n[p],enumerable:!(f=de(n,p))||f.enumerable});return o};var ge=o=>be(ee({},"__esModule",{value:!0}),o);var Te={};pe(Te,{FunnelChart:()=>Se});module.exports=ge(Te);var u=require("react"),G=require("../../lib/i18n.cjs"),ne=require("../chart/ChartAxis.cjs"),ae=require("../chart/ChartContainer.cjs"),re=require("../chart/ChartTooltip.cjs"),L=require("../chart/palette.cjs"),F=require("../chart/utils/data.cjs"),x=require("../chart/utils/format.cjs"),le=require("../chart/utils/keyboard.cjs"),oe=require("../chart/utils/path.cjs"),A=require("../chart/utils/scales.cjs"),Y=require("../chart/utils/text.cjs"),ie=require("../chart/utils/touch.cjs"),se=require("../table/Table.cjs"),ue=require("../table/TableBody.cjs"),K=require("../table/TableCell.cjs"),me=require("../table/TableHeader.cjs"),W=require("../table/TableHeaderCell.cjs"),ce=require("../table/TableRow.cjs"),e=require("react/jsx-runtime"),ve=8,ye=12,xe=44,te="text-right [font-variant-numeric:tabular-nums]",Ce=(0,u.memo)(function({stages:n}){return(0,e.jsx)("g",{children:n.map(t=>(0,e.jsxs)("g",{children:[(0,e.jsx)("path",{d:t.d,fill:t.color}),t.value?(0,e.jsx)("text",{x:t.value.x,y:t.value.y,textAnchor:t.value.anchor,dominantBaseline:"middle",className:t.value.inside?t.value.onDark?"fill-gray-50 text-[11px] font-semibold [font-variant-numeric:tabular-nums] dark:fill-gray-900":"fill-gray-900 text-[11px] font-semibold [font-variant-numeric:tabular-nums] dark:fill-gray-50":"fill-gray-700 text-[11px] font-semibold [font-variant-numeric:tabular-nums] dark:fill-gray-200",children:t.value.text}):null,t.conversion?(0,e.jsx)("text",{x:t.conversion.x,y:t.conversion.y,textAnchor:"middle",dominantBaseline:"middle",className:"fill-gray-500 text-[10px] [font-variant-numeric:tabular-nums] dark:fill-gray-400",children:t.conversion.text}):null]},t.key))})});function ke({width:o,height:n,stages:t,x:f,size:p,align:E,showConversion:H,showValues:_,stageSize:U,ramp:O,tooltip:C,plotLabel:j,locale:T,onStageClick:v}){let[I,w]=(0,u.useState)(null),s=I!==null&&I<t.length?I:null,J=(0,G.useUILabels)(),r=(0,u.useMemo)(()=>{let c=t.map(i=>i.label),d={top:6,right:12,bottom:6,left:f.hidden?8:f.height??(0,Y.widestLabel)(c)+ye},g=Math.max(0,o-d.left-d.right),X=Math.max(0,n-d.top-d.bottom),h=(0,A.createBandScale)(t.map((i,l)=>l),[0,X],{paddingInner:H?.45:.28}),N=Math.min(U??xe,h.bandwidth),$=Math.max(0,...t.map(i=>i.value??0)),k=(0,A.createLinearScale)([0,$>0?$:1],[0,g]),y=t.map((i,l)=>{let R=i.value===null?0:Math.max(0,k(i.value)),V=E==="center"?(g-R)/2:0,B=h(l)+(h.bandwidth-N)/2,a=B+N/2,D=null;if(_&&i.value!==null){let m=i.formattedValue;D=(0,Y.estimateTextWidth)(m,11)+16<=R?{x:V+R/2,y:a,anchor:"middle",text:m,inside:!0,onDark:O.onDark(l)}:{x:V+R+ve,y:a,anchor:"start",text:m,inside:!1,onDark:!1}}let S=h(l-1)+(h.bandwidth-N)/2+N,q=H&&i.conversion!==null&&l>0?{x:g/2,y:(S+B)/2,text:(0,x.formatPercent)(i.conversion,{locale:T,maximumFractionDigits:0})}:null;return{key:`${l}`,d:(0,oe.buildBarPath)({x:V,y:B,width:R,height:N,radius:4,round:E==="center"?"none":"right"}),color:O(l),value:D,conversion:q,top:h(l),height:h.bandwidth}}),z=f.hidden?[]:t.map((i,l)=>({value:i.x,offset:h.center(l),label:i.label}));return{margin:d,innerWidth:g,innerHeight:X,rendered:y,stageTicks:z,centers:t.map((i,l)=>h.center(l))}},[t,f,o,n,E,H,_,U,O,T]),Q=(0,u.useCallback)(c=>{if(C===!1||t.length===0)return;let d=c.currentTarget.getBoundingClientRect(),g=c.clientY-d.top-r.margin.top;w((0,A.nearestIndex)(r.centers,g))},[C,t.length,r.margin.top,r.centers]),M=(0,u.useCallback)(()=>{!v||s===null||v(t[s])},[v,s,t]),Z=(0,u.useCallback)(c=>(0,le.handleChartKeyDown)(c,{count:t.length,current:s,axis:"y",onMove:w,pick:v?M:null}),[t.length,s,v,M]),b=s===null?null:t[s];return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("svg",{width:o,height:n,role:"img","aria-label":j??t.map(c=>c.label).join(", "),tabIndex:0,className:`${ie.CHART_TOUCH} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500`,onPointerMove:Q,onPointerLeave:()=>w(null),onKeyDown:Z,onBlur:()=>w(null),onClick:M,children:[(0,e.jsxs)("g",{transform:`translate(${r.margin.left}, ${r.margin.top})`,children:[s!==null&&r.rendered[s]?(0,e.jsx)("rect",{x:-4,y:r.rendered[s].top,width:r.innerWidth+8,height:r.rendered[s].height,rx:4,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,(0,e.jsx)(Ce,{stages:r.rendered})]}),(0,e.jsx)("g",{transform:`translate(${r.margin.left}, ${r.margin.top})`,children:f.hidden?null:(0,e.jsx)(ne.ChartAxis,{orientation:"left",ticks:r.stageTicks,length:r.innerHeight,showLine:!1,tickSize:0,size:p})})]}),b&&s!==null&&C!==!1?(0,e.jsx)(re.ChartTooltip,{x:r.margin.left+r.innerWidth/2,y:r.margin.top+r.centers[s],containerWidth:o,children:typeof C=="function"?C(b):(0,e.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,e.jsx)("div",{className:"font-medium text-gray-900 dark:text-gray-100",children:b.label}),(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)("span",{className:"h-2.5 w-2.5 shrink-0 rounded-sm",style:{backgroundColor:r.rendered[s]?.color},"aria-hidden":"true"}),(0,e.jsx)("span",{className:"font-semibold text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:b.formattedValue})]}),b.conversion!==null?(0,e.jsxs)("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[(0,e.jsx)("span",{children:J.chartConversion}),(0,e.jsx)("span",{className:"[font-variant-numeric:tabular-nums]",children:(0,x.formatPercent)(b.conversion,{locale:T,maximumFractionDigits:1})})]}):null,b.overall!==null?(0,e.jsxs)("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[(0,e.jsx)("span",{children:t[0]?.label}),(0,e.jsx)("span",{className:"[font-variant-numeric:tabular-nums]",children:(0,x.formatPercent)(b.overall,{locale:T,maximumFractionDigits:1})})]}):null]})}):null]})}function Se({data:o,x:n,value:t,align:f="center",showConversion:p=!0,showValues:E=!0,stageSize:H,colors:_,height:U,width:O,size:C="md",tooltip:j=!0,tableView:T=!1,title:v,description:I,loading:w=!1,emptyState:s,error:J=!1,errorState:r,onRetry:Q,actions:M,locale:Z,plotLabel:b,valueLabel:c,conversionLabel:d,dropOffLabel:g,format:X,onStageClick:h,className:N,...$}){let k=(0,G.useUILocale)(Z),y=(0,G.useUILabels)(),z=(0,u.useMemo)(()=>X??(a=>(0,x.formatAuto)(a,k)),[X,k]),i=(0,u.useMemo)(()=>n.format??(a=>(0,x.formatXValue)(a,k)),[n.format,k]),l=(0,u.useMemo)(()=>{let a=(0,F.readNumber)(o[0]??{},t);return o.map((D,S)=>{let q=(0,F.readXValue)(D,n.key,S),m=(0,F.readNumber)(D,t),P=S===0?null:(0,F.readNumber)(o[S-1],t);return{index:S,x:q,label:i(q,S),value:m,overall:S===0||a===null||a===0||m===null?null:m/a,conversion:P===null||P===0||m===null?null:m/P,dropOff:P===null||m===null?null:P-m,formattedValue:m===null?"\u2014":z(m),datum:D}})},[o,n.key,t,z,i]),R=(0,u.useMemo)(()=>(0,L.createSequentialScale)([0,Math.max(1,l.length-1)],{colors:_??L.CHART_ORDINAL_COLORS,..._?{}:{darkStops:L.CHART_ORDINAL_DARK_STOPS}}),[l.length,_]),V=U??Math.max(96,l.length*(p?56:44)+12),B=(0,u.useMemo)(()=>({data:l.map(a=>({[n.key]:a.x,__value:a.value,__conversion:a.conversion,__dropOff:a.dropOff})),series:[{key:"__value",label:c??y.chartValue},{key:"__conversion",label:d??y.chartConversion},{key:"__dropOff",label:g??y.chartDropOff}],xKey:n.key,xLabel:n.label??n.key,formatX:n.format}),[l,n.key,n.label,n.format,c,d,g,y]);return(0,e.jsx)(ae.ChartContainer,{title:v,description:I,height:V,width:O,size:C,loading:w,empty:!l.some(a=>a.value!==null&&a.value>0),emptyState:s,error:J,errorState:r,onRetry:Q,actions:M,exportSource:B,tableView:T,table:T?(0,e.jsx)("div",{className:"w-full overflow-x-auto",children:(0,e.jsxs)(se.Table,{children:[typeof v=="string"?(0,e.jsx)("caption",{className:"sr-only",children:v}):null,(0,e.jsxs)(me.TableHeader,{children:[(0,e.jsx)(W.TableHeaderCell,{children:n.label??n.key}),(0,e.jsx)(W.TableHeaderCell,{className:"text-right",children:c??y.chartValue}),(0,e.jsx)(W.TableHeaderCell,{className:"text-right",children:d??y.chartConversion}),(0,e.jsx)(W.TableHeaderCell,{className:"text-right",children:g??y.chartDropOff})]}),(0,e.jsx)(ue.TableBody,{children:l.map(a=>(0,e.jsxs)(ce.TableRow,{clickable:!1,children:[(0,e.jsx)(K.TableCell,{className:"font-medium text-gray-900 dark:text-gray-100",children:a.label}),(0,e.jsx)(K.TableCell,{className:te,children:a.formattedValue}),(0,e.jsx)(K.TableCell,{className:te,children:a.conversion===null?"\u2014":(0,x.formatPercent)(a.conversion,{locale:k,maximumFractionDigits:1})}),(0,e.jsx)(K.TableCell,{className:te,children:a.dropOff===null?"\u2014":z(a.dropOff)})]},a.index))})]})}):void 0,className:N,...$,children:({width:a})=>(0,e.jsx)(ke,{width:a,height:V,stages:l,x:n,size:C,align:f,showConversion:p,showValues:E,stageSize:H,ramp:R,tooltip:j,plotLabel:b,locale:k,onStageClick:h})})}0&&(module.exports={FunnelChart});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{memo as
|
|
1
|
+
"use client";import{memo as ee,useCallback as j,useMemo as D,useState as te}from"react";import{useUILabels as Z,useUILocale as ne}from"../../lib/i18n.js";import{ChartAxis as ae}from"../chart/ChartAxis.js";import{ChartContainer as re}from"../chart/ChartContainer.js";import{ChartTooltip as le}from"../chart/ChartTooltip.js";import{CHART_ORDINAL_COLORS as oe,CHART_ORDINAL_DARK_STOPS as ie,createSequentialScale as se}from"../chart/palette.js";import{readNumber as J,readXValue as ue}from"../chart/utils/data.js";import{formatAuto as me,formatPercent as G,formatXValue as ce}from"../chart/utils/format.js";import{handleChartKeyDown as de}from"../chart/utils/keyboard.js";import{buildBarPath as he}from"../chart/utils/path.js";import{createBandScale as fe,createLinearScale as pe,nearestIndex as be}from"../chart/utils/scales.js";import{estimateTextWidth as ge,widestLabel as ve}from"../chart/utils/text.js";import{CHART_TOUCH as ye}from"../chart/utils/touch.js";import{Table as xe}from"../table/Table.js";import{TableBody as Ce}from"../table/TableBody.js";import{TableCell as K}from"../table/TableCell.js";import{TableHeader as ke}from"../table/TableHeader.js";import{TableHeaderCell as W}from"../table/TableHeaderCell.js";import{TableRow as Se}from"../table/TableRow.js";import{Fragment as Ve,jsx as t,jsxs as d}from"react/jsx-runtime";var Te=8,Ne=12,Re=44,Q="text-right [font-variant-numeric:tabular-nums]",_e=ee(function({stages:l}){return t("g",{children:l.map(e=>d("g",{children:[t("path",{d:e.d,fill:e.color}),e.value?t("text",{x:e.value.x,y:e.value.y,textAnchor:e.value.anchor,dominantBaseline:"middle",className:e.value.inside?e.value.onDark?"fill-gray-50 text-[11px] font-semibold [font-variant-numeric:tabular-nums] dark:fill-gray-900":"fill-gray-900 text-[11px] font-semibold [font-variant-numeric:tabular-nums] dark:fill-gray-50":"fill-gray-700 text-[11px] font-semibold [font-variant-numeric:tabular-nums] dark:fill-gray-200",children:e.value.text}):null,e.conversion?t("text",{x:e.conversion.x,y:e.conversion.y,textAnchor:"middle",dominantBaseline:"middle",className:"fill-gray-500 text-[10px] [font-variant-numeric:tabular-nums] dark:fill-gray-400",children:e.conversion.text}):null]},e.key))})});function we({width:h,height:l,stages:e,x:C,size:M,align:P,showConversion:F,showValues:N,stageSize:X,ramp:L,tooltip:v,plotLabel:U,locale:k,onStageClick:b}){let[A,R]=te(null),i=A!==null&&A<e.length?A:null,$=Z(),a=D(()=>{let u=e.map(o=>o.label),m={top:6,right:12,bottom:6,left:C.hidden?8:C.height??ve(u)+Ne},p=Math.max(0,h-m.left-m.right),H=Math.max(0,l-m.top-m.bottom),c=fe(e.map((o,r)=>r),[0,H],{paddingInner:F?.45:.28}),S=Math.min(X??Re,c.bandwidth),z=Math.max(0,...e.map(o=>o.value??0)),y=pe([0,z>0?z:1],[0,p]),g=e.map((o,r)=>{let T=o.value===null?0:Math.max(0,y(o.value)),_=P==="center"?(p-T)/2:0,I=c(r)+(c.bandwidth-S)/2,n=I+S/2,w=null;if(N&&o.value!==null){let s=o.formattedValue;w=ge(s,11)+16<=T?{x:_+T/2,y:n,anchor:"middle",text:s,inside:!0,onDark:L.onDark(r)}:{x:_+T+Te,y:n,anchor:"start",text:s,inside:!1,onDark:!1}}let x=c(r-1)+(c.bandwidth-S)/2+S,B=F&&o.conversion!==null&&r>0?{x:p/2,y:(x+I)/2,text:G(o.conversion,{locale:k,maximumFractionDigits:0})}:null;return{key:`${r}`,d:he({x:_,y:I,width:T,height:S,radius:4,round:P==="center"?"none":"right"}),color:L(r),value:w,conversion:B,top:c(r),height:c.bandwidth}}),O=C.hidden?[]:e.map((o,r)=>({value:o.x,offset:c.center(r),label:o.label}));return{margin:m,innerWidth:p,innerHeight:H,rendered:g,stageTicks:O,centers:e.map((o,r)=>c.center(r))}},[e,C,h,l,P,F,N,X,L,k]),q=j(u=>{if(v===!1||e.length===0)return;let m=u.currentTarget.getBoundingClientRect(),p=u.clientY-m.top-a.margin.top;R(be(a.centers,p))},[v,e.length,a.margin.top,a.centers]),E=j(()=>{!b||i===null||b(e[i])},[b,i,e]),Y=j(u=>de(u,{count:e.length,current:i,axis:"y",onMove:R,pick:b?E:null}),[e.length,i,b,E]),f=i===null?null:e[i];return d(Ve,{children:[d("svg",{width:h,height:l,role:"img","aria-label":U??e.map(u=>u.label).join(", "),tabIndex:0,className:`${ye} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500`,onPointerMove:q,onPointerLeave:()=>R(null),onKeyDown:Y,onBlur:()=>R(null),onClick:E,children:[d("g",{transform:`translate(${a.margin.left}, ${a.margin.top})`,children:[i!==null&&a.rendered[i]?t("rect",{x:-4,y:a.rendered[i].top,width:a.innerWidth+8,height:a.rendered[i].height,rx:4,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,t(_e,{stages:a.rendered})]}),t("g",{transform:`translate(${a.margin.left}, ${a.margin.top})`,children:C.hidden?null:t(ae,{orientation:"left",ticks:a.stageTicks,length:a.innerHeight,showLine:!1,tickSize:0,size:M})})]}),f&&i!==null&&v!==!1?t(le,{x:a.margin.left+a.innerWidth/2,y:a.margin.top+a.centers[i],containerWidth:h,children:typeof v=="function"?v(f):d("div",{className:"flex flex-col gap-1",children:[t("div",{className:"font-medium text-gray-900 dark:text-gray-100",children:f.label}),d("div",{className:"flex items-center gap-2",children:[t("span",{className:"h-2.5 w-2.5 shrink-0 rounded-sm",style:{backgroundColor:a.rendered[i]?.color},"aria-hidden":"true"}),t("span",{className:"font-semibold text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:f.formattedValue})]}),f.conversion!==null?d("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[t("span",{children:$.chartConversion}),t("span",{className:"[font-variant-numeric:tabular-nums]",children:G(f.conversion,{locale:k,maximumFractionDigits:1})})]}):null,f.overall!==null?d("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[t("span",{children:e[0]?.label}),t("span",{className:"[font-variant-numeric:tabular-nums]",children:G(f.overall,{locale:k,maximumFractionDigits:1})})]}):null]})}):null]})}function je({data:h,x:l,value:e,align:C="center",showConversion:M=!0,showValues:P=!0,stageSize:F,colors:N,height:X,width:L,size:v="md",tooltip:U=!0,tableView:k=!1,title:b,description:A,loading:R=!1,emptyState:i,error:$=!1,errorState:a,onRetry:q,actions:E,locale:Y,plotLabel:f,valueLabel:u,conversionLabel:m,dropOffLabel:p,format:H,onStageClick:c,className:S,...z}){let y=ne(Y),g=Z(),O=D(()=>H??(n=>me(n,y)),[H,y]),o=D(()=>l.format??(n=>ce(n,y)),[l.format,y]),r=D(()=>{let n=J(h[0]??{},e);return h.map((w,x)=>{let B=ue(w,l.key,x),s=J(w,e),V=x===0?null:J(h[x-1],e);return{index:x,x:B,label:o(B,x),value:s,overall:x===0||n===null||n===0||s===null?null:s/n,conversion:V===null||V===0||s===null?null:s/V,dropOff:V===null||s===null?null:V-s,formattedValue:s===null?"\u2014":O(s),datum:w}})},[h,l.key,e,O,o]),T=D(()=>se([0,Math.max(1,r.length-1)],{colors:N??oe,...N?{}:{darkStops:ie}}),[r.length,N]),_=X??Math.max(96,r.length*(M?56:44)+12),I=D(()=>({data:r.map(n=>({[l.key]:n.x,__value:n.value,__conversion:n.conversion,__dropOff:n.dropOff})),series:[{key:"__value",label:u??g.chartValue},{key:"__conversion",label:m??g.chartConversion},{key:"__dropOff",label:p??g.chartDropOff}],xKey:l.key,xLabel:l.label??l.key,formatX:l.format}),[r,l.key,l.label,l.format,u,m,p,g]);return t(re,{title:b,description:A,height:_,width:L,size:v,loading:R,empty:!r.some(n=>n.value!==null&&n.value>0),emptyState:i,error:$,errorState:a,onRetry:q,actions:E,exportSource:I,tableView:k,table:k?t("div",{className:"w-full overflow-x-auto",children:d(xe,{children:[typeof b=="string"?t("caption",{className:"sr-only",children:b}):null,d(ke,{children:[t(W,{children:l.label??l.key}),t(W,{className:"text-right",children:u??g.chartValue}),t(W,{className:"text-right",children:m??g.chartConversion}),t(W,{className:"text-right",children:p??g.chartDropOff})]}),t(Ce,{children:r.map(n=>d(Se,{clickable:!1,children:[t(K,{className:"font-medium text-gray-900 dark:text-gray-100",children:n.label}),t(K,{className:Q,children:n.formattedValue}),t(K,{className:Q,children:n.conversion===null?"\u2014":G(n.conversion,{locale:y,maximumFractionDigits:1})}),t(K,{className:Q,children:n.dropOff===null?"\u2014":O(n.dropOff)})]},n.index))})]})}):void 0,className:S,...z,children:({width:n})=>t(we,{width:n,height:_,stages:r,x:l,size:v,align:C,showConversion:M,showValues:P,stageSize:F,ramp:T,tooltip:U,plotLabel:f,locale:y,onStageClick:c})})}export{je as FunnelChart};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";"use client";var dt=Object.defineProperty;var Ht=Object.getOwnPropertyDescriptor;var Wt=Object.getOwnPropertyNames;var Xt=Object.prototype.hasOwnProperty;var Vt=(s,o)=>{for(var f in o)dt(s,f,{get:o[f],enumerable:!0})},zt=(s,o,f,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let u of Wt(o))!Xt.call(s,u)&&u!==f&&dt(s,u,{get:()=>o[u],enumerable:!(r=Ht(o,u))||r.enumerable});return s};var _t=s=>zt(dt({},"__esModule",{value:!0}),s);var Zt={};Vt(Zt,{GanttChart:()=>Ft});module.exports=_t(Zt);var i=require("react"),F=require("../../lib/i18n.cjs"),pt=require("../chart/ChartAxis.cjs"),Nt=require("../chart/ChartContainer.cjs"),wt=require("../chart/ChartGrid.cjs"),St=require("../chart/ChartLegend.cjs"),$t=require("../chart/ChartTooltip.cjs"),nt=require("../chart/palette.cjs"),Lt=require("../chart/utils/cartesian.cjs"),at=require("../chart/utils/data.cjs"),Z=require("../chart/utils/format.cjs"),Pt=require("../chart/utils/keyboard.cjs"),ft=require("../chart/utils/path.cjs"),Rt=require("../chart/utils/scales.cjs"),T=require("../chart/utils/time.cjs"),Gt=require("../chart/utils/touch.cjs"),Mt=require("../table/Table.cjs"),Dt=require("../table/TableBody.cjs"),U=require("../table/TableCell.cjs"),Ot=require("../table/TableHeader.cjs"),Y=require("../table/TableHeaderCell.cjs"),It=require("../table/TableRow.cjs"),t=require("react/jsx-runtime"),Bt=18,kt=.5,Kt=.3,rt=7,vt=10,xt=.02,ht="text-right [font-variant-numeric:tabular-nums]",Ut=(0,i.memo)(function({tasks:o,arrows:f}){return(0,t.jsxs)("g",{children:[(0,t.jsx)("g",{className:"fill-gray-400 stroke-gray-400 dark:fill-gray-500 dark:stroke-gray-500",children:f.map(r=>(0,t.jsxs)("g",{children:[(0,t.jsx)("path",{d:r.d,fill:"none",strokeWidth:1}),(0,t.jsx)("path",{d:r.head,strokeWidth:0})]},r.key))}),o.map(r=>(0,t.jsxs)("g",{children:[r.track?(0,t.jsx)("path",{d:r.track,fill:r.color,fillOpacity:r.trackOpacity}):null,r.progress?(0,t.jsx)("path",{d:r.progress,fill:r.color}):null,r.milestone?(0,t.jsx)("path",{d:r.milestone,fill:r.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"}):null]},r.key))]})});function Yt({width:s,height:o,data:f,tasks:r,x:u,domain:x,unit:M,timeTicks:A,today:L,grid:E,size:H,barSize:V,colorOf:j,margin:q,tooltip:P,plotLabel:ot,todayLabel:lt,locale:R,formatDate:J,formatX:D,onTaskClick:O}){let[W,G]=(0,i.useState)(null),h=W!==null&&W<r.length?W:null,z=(0,F.useUILabels)(),n=(0,i.useMemo)(()=>{let m=(0,Lt.buildCartesianGeometry)({width:s,height:o,data:f,x:u,y:{domain:x},bounds:x,margin:q,orientation:"horizontal",placement:"band",formatValue:a=>(0,T.formatTimeTick)(a,M,R),formatX:D}),{valueScale:k,bandwidth:b,categoryPositions:N,innerWidth:ct,innerHeight:mt}=m,I=Math.min(V??Bt,b),Q=new Map(r.map((a,c)=>[a.id,c])),ut=r.map((a,c)=>{let w=N[c]+(b-I)/2,l=w+I/2,p=j(a);if(a.start===null)return{key:`${c}`,color:p,track:null,trackOpacity:1,progress:null,milestone:null,top:N[c],height:b};let y=k(a.start);if(a.milestone)return{key:`${c}`,color:p,track:null,trackOpacity:1,progress:null,milestone:`M${y},${l-rt} L${y+rt},${l} L${y},${l+rt} L${y-rt},${l} Z`,top:N[c],height:b};let S=k(a.end??a.start),C=Math.max(2,S-y);return{key:`${c}`,color:p,track:(0,ft.buildBarPath)({x:y,y:w,width:C,height:I,radius:3}),trackOpacity:a.progress===null?1:Kt,progress:a.progress===null?null:(0,ft.buildBarPath)({x:y,y:l-I*kt/2,width:Math.max(0,C*Math.min(1,Math.max(0,a.progress))),height:I*kt,radius:2,round:"right"}),milestone:null,top:N[c],height:b}}),tt=[];r.forEach((a,c)=>{if(a.start!==null)for(let w of a.dependsOn){let l=Q.get(w);if(l===void 0||l===c)continue;let p=r[l];if(p.start===null)continue;let y=k(p.end??p.start),S=N[l]+b/2,C=k(a.start),$=N[c]+b/2,et=Math.max(y+vt,C-vt);tt.push({key:`${w}-${a.id}`,d:`M${y},${S} L${et},${S} L${et},${$} L${C-5},${$}`,head:`M${C},${$} L${C-5},${$-3.5} L${C-5},${$+3.5} Z`})}});let gt=A.map(a=>({value:a,offset:k(a),label:(0,T.formatTimeTick)(a,M,R)}));return{rendered:ut,arrows:tt,categoryPositions:N,categoryCenters:m.categoryCenters,bandwidth:b,categoryTicks:m.categoryTicks,valueTicks:gt,valueScale:k,innerWidth:ct,innerHeight:mt,margin:m.margin}},[r,f,u,x,M,A,s,o,q,V,j,R,D]),it=(0,i.useCallback)(m=>{if(P===!1||r.length===0)return;let k=m.currentTarget.getBoundingClientRect(),b=m.clientY-k.top-n.margin.top;G((0,Rt.nearestIndex)(n.categoryCenters,b))},[P,r.length,n.margin.top,n.categoryCenters]),_=(0,i.useCallback)(()=>{!O||h===null||O(r[h])},[O,h,r]),st=(0,i.useCallback)(m=>(0,Pt.handleChartKeyDown)(m,{count:r.length,current:h,axis:"y",onMove:G,pick:O?_:null}),[r.length,h,O,_]),g=h===null?null:r[h];return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("svg",{width:s,height:o,role:"img","aria-label":ot??r.map(m=>m.label).join(", "),tabIndex:0,className:`${Gt.CHART_TOUCH} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500`,onPointerMove:it,onPointerLeave:()=>G(null),onKeyDown:st,onBlur:()=>G(null),onClick:_,children:[(0,t.jsxs)("g",{transform:`translate(${n.margin.left}, ${n.margin.top})`,children:[(0,t.jsx)(wt.ChartGrid,{width:n.innerWidth,height:n.innerHeight,vertical:E?n.valueTicks.map(m=>m.offset):void 0}),h!==null?(0,t.jsx)("rect",{x:0,y:n.categoryPositions[h],width:n.innerWidth,height:n.bandwidth,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,(0,t.jsx)(Ut,{tasks:n.rendered,arrows:n.arrows}),L!==null?(0,t.jsxs)("g",{children:[(0,t.jsx)("line",{x1:n.valueScale(L),y1:0,x2:n.valueScale(L),y2:n.innerHeight,className:"stroke-gray-900 dark:stroke-white",strokeWidth:1,strokeDasharray:"4 4"}),(0,t.jsx)("text",{x:n.valueScale(L)+4,y:8,className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:lt})]}):null]}),(0,t.jsx)("g",{transform:`translate(${n.margin.left}, ${n.margin.top+n.innerHeight})`,children:(0,t.jsx)(pt.ChartAxis,{orientation:"bottom",ticks:n.valueTicks,length:n.innerWidth,size:H})}),(0,t.jsx)("g",{transform:`translate(${n.margin.left}, ${n.margin.top})`,children:u.hidden?null:(0,t.jsx)(pt.ChartAxis,{orientation:"left",ticks:n.categoryTicks,length:n.innerHeight,showLine:!1,tickSize:0,label:u.label,size:H})})]}),g&&h!==null&&P!==!1?(0,t.jsx)($t.ChartTooltip,{x:n.margin.left+(g.start===null?n.innerWidth/2:n.valueScale(g.start)),y:n.margin.top+n.categoryCenters[h],containerWidth:s,children:typeof P=="function"?P(g):(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:g.label}),(0,t.jsxs)("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[(0,t.jsx)("span",{children:z.chartStart}),(0,t.jsx)("span",{className:"[font-variant-numeric:tabular-nums] text-gray-900 dark:text-gray-100",children:g.start===null?"\u2014":J(g.start)})]}),g.milestone?null:(0,t.jsxs)("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[(0,t.jsx)("span",{children:z.chartEnd}),(0,t.jsx)("span",{className:"[font-variant-numeric:tabular-nums] text-gray-900 dark:text-gray-100",children:g.end===null?"\u2014":J(g.end)})]}),g.progress===null?null:(0,t.jsxs)("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[(0,t.jsx)("span",{children:z.chartProgress}),(0,t.jsx)("span",{className:"[font-variant-numeric:tabular-nums] text-gray-900 dark:text-gray-100",children:(0,Z.formatPercent)(g.progress,{locale:R,maximumFractionDigits:0})})]})]})}):null]})}function Ft({data:s,x:o,start:f,end:r,id:u,progress:x,milestone:M,dependencies:A,group:L,domain:E,today:H,ticks:V=6,barSize:j,rowSize:q=30,color:P,height:ot,width:lt,size:R="md",grid:J=!0,legend:D,tooltip:O=!0,tableView:W=!1,title:G,description:h,loading:z=!1,emptyState:n,error:it=!1,errorState:_,onRetry:st,actions:g,margin:m,locale:k,plotLabel:b,startLabel:N,endLabel:ct,progressLabel:mt,todayLabel:I,formatDate:Q,onTaskClick:ut,className:tt,...gt}){let a=(0,F.useUILocale)(k),c=(0,F.useUILabels)(),w=(0,i.useMemo)(()=>o.format??(e=>(0,Z.formatXValue)(e,a)),[o.format,a]),l=(0,i.useMemo)(()=>s.map((e,d)=>{let B=(0,at.readXValue)(e,o.key,d),X=(0,T.toTimestamp)(e[f]),v=r?(0,T.toTimestamp)(e[r]):null,K=M?!!e[M]:v===null,Tt=A?e[A]:void 0;return{index:d,id:String(u?e[u]??d:d),x:B,label:w(B,d),start:X,end:K?X:v??X,progress:x?(0,at.readNumber)(e,x):null,milestone:K,dependsOn:Array.isArray(Tt)?Tt.map(Et=>String(Et)):[],group:L?e[L]??null:null,datum:e}}),[s,o.key,f,r,u,x,M,A,L,w]),p=(0,i.useMemo)(()=>{let e=[];for(let d of l)d.group!==null&&!e.includes(d.group)&&e.push(d.group);return e},[l]),y=(0,i.useCallback)(e=>e.group===null?P??(0,nt.getSeriesColor)(0):(0,nt.getSeriesColor)(p.indexOf(e.group)),[p,P]),S=(0,i.useMemo)(()=>{if(E){let v=(0,T.toTimestamp)(E[0]),K=(0,T.toTimestamp)(E[1]);if(v!==null&&K!==null)return[v,K]}let e=l.flatMap(v=>v.start===null?[]:[v.start,v.end??v.start]);if(e.length===0)return[0,1];let d=Math.min(...e),B=Math.max(...e),X=B-d||864e5;return[d-X*xt,B+X*xt]},[E,l]),C=(0,i.useMemo)(()=>(0,T.niceTimeTicks)(S[0],S[1],V),[S,V]),$=(0,i.useMemo)(()=>Q??(e=>new Intl.DateTimeFormat(a,{day:"numeric",month:"short",year:"numeric"}).format(new Date(e))),[Q,a]),et=(0,i.useMemo)(()=>H===!1?null:(0,T.toTimestamp)(H??Date.now()),[H]),bt=(0,i.useMemo)(()=>p.map((e,d)=>({key:e,label:e,color:(0,nt.getSeriesColor)(d),marker:"rect"})),[p]),yt=ot??Math.max(120,l.length*q+48),At=D===void 0?p.length>=2:D!==!1,Ct=typeof D=="string"?D:"bottom";return(0,t.jsx)(Nt.ChartContainer,{title:G,description:h,height:yt,width:lt,size:R,loading:z,empty:l.length===0,emptyState:n,error:it,errorState:_,onRetry:st,actions:g,tableView:W,legendPosition:Ct,legend:At&&bt.length>0?(0,t.jsx)(St.ChartLegend,{items:bt,position:Ct,marker:"rect",size:R}):void 0,table:W?(0,t.jsx)("div",{className:"w-full overflow-x-auto",children:(0,t.jsxs)(Mt.Table,{children:[typeof G=="string"?(0,t.jsx)("caption",{className:"sr-only",children:G}):null,(0,t.jsxs)(Ot.TableHeader,{children:[(0,t.jsx)(Y.TableHeaderCell,{children:o.label??o.key}),(0,t.jsx)(Y.TableHeaderCell,{className:"text-right",children:N??c.chartStart}),(0,t.jsx)(Y.TableHeaderCell,{className:"text-right",children:ct??c.chartEnd}),x?(0,t.jsx)(Y.TableHeaderCell,{className:"text-right",children:mt??c.chartProgress}):null]}),(0,t.jsx)(Dt.TableBody,{children:l.map(e=>(0,t.jsxs)(It.TableRow,{clickable:!1,children:[(0,t.jsx)(U.TableCell,{className:"font-medium text-gray-900 dark:text-gray-100",children:e.label}),(0,t.jsx)(U.TableCell,{className:ht,children:e.start===null?"\u2014":$(e.start)}),(0,t.jsx)(U.TableCell,{className:ht,children:e.milestone||e.end===null?"\u2014":$(e.end)}),x?(0,t.jsx)(U.TableCell,{className:ht,children:e.progress===null?"\u2014":(0,Z.formatPercent)(e.progress,{locale:a,maximumFractionDigits:0})}):null]},e.index))})]})}):void 0,className:tt,...gt,children:({width:e})=>(0,t.jsx)(Yt,{width:e,height:yt,data:s,tasks:l,x:o,domain:S,unit:C.unit,timeTicks:C.values,today:et,grid:J,size:R,barSize:j,colorOf:y,margin:m,tooltip:O,plotLabel:b,todayLabel:I??c.chartToday,locale:a,formatDate:$,formatX:w,onTaskClick:ut})})}0&&(module.exports={GanttChart});
|
|
1
|
+
"use strict";"use client";var ft=Object.defineProperty;var Xt=Object.getOwnPropertyDescriptor;var Vt=Object.getOwnPropertyNames;var _t=Object.prototype.hasOwnProperty;var zt=(c,o)=>{for(var p in o)ft(c,p,{get:o[p],enumerable:!0})},Bt=(c,o,p,l)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of Vt(o))!_t.call(c,n)&&n!==p&&ft(c,n,{get:()=>o[n],enumerable:!(l=Xt(o,n))||l.enumerable});return c};var Kt=c=>Bt(ft({},"__esModule",{value:!0}),c);var qt={};zt(qt,{GanttChart:()=>jt});module.exports=Kt(qt);var s=require("react"),tt=require("../../lib/i18n.cjs"),bt=require("../chart/ChartAxis.cjs"),$t=require("../chart/ChartContainer.cjs"),wt=require("../chart/ChartGrid.cjs"),Lt=require("../chart/ChartLegend.cjs"),H=require("../chart/ChartPlotClip.cjs"),Nt=require("../chart/ChartTooltip.cjs"),B=require("../chart/palette.cjs"),St=require("../chart/utils/cartesian.cjs"),st=require("../chart/utils/data.cjs"),et=require("../chart/utils/format.cjs"),Rt=require("../chart/utils/keyboard.cjs"),Ct=require("../chart/utils/path.cjs"),At=require("../chart/utils/scales.cjs"),Gt=require("../chart/utils/ticks.cjs"),k=require("../chart/utils/time.cjs"),It=require("../chart/utils/touch.cjs"),Mt=require("../table/Table.cjs"),Ot=require("../table/TableBody.cjs"),J=require("../table/TableCell.cjs"),Dt=require("../table/TableHeader.cjs"),Q=require("../table/TableHeaderCell.cjs"),Et=require("../table/TableRow.cjs"),t=require("react/jsx-runtime"),Ut=18,xt=.5,Ft=.3,it=7,vt=10,Pt=.02,yt="text-right [font-variant-numeric:tabular-nums]",Yt=(0,s.memo)(function({tasks:o,arrows:p,clipId:l}){return(0,t.jsxs)("g",{children:[(0,t.jsxs)("g",{clipPath:`url(#${l})`,children:[(0,t.jsx)("g",{className:"fill-gray-400 stroke-gray-400 dark:fill-gray-500 dark:stroke-gray-500",children:p.map(n=>(0,t.jsxs)("g",{children:[(0,t.jsx)("path",{d:n.d,fill:"none",strokeWidth:1}),(0,t.jsx)("path",{d:n.head,strokeWidth:0})]},n.key))}),o.map(n=>n.track?(0,t.jsxs)("g",{children:[(0,t.jsx)("path",{d:n.track,fill:n.color,fillOpacity:n.trackOpacity}),n.progress?(0,t.jsx)("path",{d:n.progress,fill:n.color}):null]},n.key):null)]}),o.map(n=>n.milestone?(0,t.jsx)("path",{d:n.milestone,fill:n.color,strokeWidth:2,stroke:B.CHART_SURFACE_COLOR},n.key):null)]})});function Zt({width:c,height:o,data:p,tasks:l,x:n,domain:P,unit:M,timeTicks:W,today:O,grid:X,size:V,barSize:K,colorOf:rt,margin:nt,tooltip:w,plotLabel:ct,todayLabel:mt,locale:L,formatDate:at,formatX:D,onTaskClick:E}){let[_,N]=(0,s.useState)(null),h=_!==null&&_<l.length?_:null,U=(0,tt.useUILabels)(),ot=(0,H.plotClipId)((0,s.useId)()),e=(0,s.useMemo)(()=>{let m=(0,St.buildCartesianGeometry)({width:c,height:o,data:p,x:n,y:{domain:P},bounds:P,margin:nt,orientation:"horizontal",placement:"band",formatValue:a=>(0,k.formatTimeTick)(a,M,L),formatX:D}),{valueScale:C,bandwidth:f,categoryPositions:$,innerWidth:Y,innerHeight:dt}=m,S=Math.min(K??Ut,f),ht=new Map(l.map((a,i)=>[a.id,i])),pt=l.map((a,i)=>{let T=$[i]+(f-S)/2,y=T+S/2,b=rt(a);if(a.start===null)return{key:`${i}`,color:b,track:null,trackOpacity:1,progress:null,milestone:null,top:$[i],height:f};let g=C(a.start);if(a.milestone)return{key:`${i}`,color:b,track:null,trackOpacity:1,progress:null,milestone:(0,H.isOnPlot)(g,Y)?`M${g},${y-it} L${g+it},${y} L${g},${y+it} L${g-it},${y} Z`:null,top:$[i],height:f};let G=C(a.end??a.start),x=Math.max(2,G-g);return{key:`${i}`,color:b,track:(0,Ct.buildBarPath)({x:g,y:T,width:x,height:S,radius:3}),trackOpacity:a.progress===null?1:Ft,progress:a.progress===null?null:(0,Ct.buildBarPath)({x:g,y:y-S*xt/2,width:Math.max(0,x*Math.min(1,Math.max(0,a.progress))),height:S*xt,radius:2,round:"right"}),milestone:null,top:$[i],height:f}}),lt=[];l.forEach((a,i)=>{if(a.start!==null)for(let T of a.dependsOn){let y=ht.get(T);if(y===void 0||y===i)continue;let b=l[y];if(b.start===null)continue;let g=C(b.end??b.start),G=$[y]+f/2,x=C(a.start),I=$[i]+f/2,Z=Math.max(g+vt,x-vt);lt.push({key:`${T}-${a.id}`,d:`M${g},${G} L${Z},${G} L${Z},${I} L${x-5},${I}`,head:`M${x},${I} L${x-5},${I-3.5} L${x-5},${I+3.5} Z`})}});let R=W.map(a=>({value:a,offset:C(a),label:(0,k.formatTimeTick)(a,M,L)})),A=O===null?null:C(O);return{rendered:pt,arrows:lt,categoryPositions:$,categoryCenters:m.categoryCenters,bandwidth:f,categoryTicks:m.categoryTicks,valueTicks:R,valueScale:C,todayAt:A!==null&&(0,H.isOnPlot)(A,Y)?A:null,innerWidth:Y,innerHeight:dt,margin:m.margin}},[l,p,n,P,M,W,O,c,o,nt,K,rt,L,D]),ut=(0,s.useCallback)(m=>{if(w===!1||l.length===0)return;let C=m.currentTarget.getBoundingClientRect(),f=m.clientY-C.top-e.margin.top;N((0,At.nearestIndex)(e.categoryCenters,f))},[w,l.length,e.margin.top,e.categoryCenters]),F=(0,s.useCallback)(()=>{!E||h===null||E(l[h])},[E,h,l]),gt=(0,s.useCallback)(m=>(0,Rt.handleChartKeyDown)(m,{count:l.length,current:h,axis:"y",onMove:N,pick:E?F:null}),[l.length,h,E,F]),u=h===null?null:l[h];return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("svg",{width:c,height:o,role:"img","aria-label":ct??l.map(m=>m.label).join(", "),tabIndex:0,className:`${It.CHART_TOUCH} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500`,onPointerMove:ut,onPointerLeave:()=>N(null),onKeyDown:gt,onBlur:()=>N(null),onClick:F,children:[(0,t.jsxs)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[(0,t.jsx)(H.ChartPlotClip,{id:ot,width:e.innerWidth,height:e.innerHeight}),(0,t.jsx)(wt.ChartGrid,{width:e.innerWidth,height:e.innerHeight,vertical:X?e.valueTicks.map(m=>m.offset):void 0}),h!==null?(0,t.jsx)("rect",{x:0,y:e.categoryPositions[h],width:e.innerWidth,height:e.bandwidth,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,(0,t.jsx)(Yt,{tasks:e.rendered,arrows:e.arrows,clipId:ot}),e.todayAt!==null?(0,t.jsxs)("g",{children:[(0,t.jsx)("line",{x1:e.todayAt,y1:0,x2:e.todayAt,y2:e.innerHeight,className:"stroke-gray-900 dark:stroke-white",strokeWidth:1,strokeDasharray:"4 4"}),(0,t.jsx)("text",{x:e.todayAt+4,y:8,className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:mt})]}):null]}),(0,t.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:(0,t.jsx)(bt.ChartAxis,{orientation:"bottom",ticks:e.valueTicks,length:e.innerWidth,size:V})}),(0,t.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:n.hidden?null:(0,t.jsx)(bt.ChartAxis,{orientation:"left",ticks:e.categoryTicks,length:e.innerHeight,showLine:!1,tickSize:0,label:n.label,size:V})})]}),u&&h!==null&&w!==!1?(0,t.jsx)(Nt.ChartTooltip,{x:e.margin.left+(u.start===null?e.innerWidth/2:Math.min(e.innerWidth,Math.max(0,e.valueScale(u.start)))),y:e.margin.top+e.categoryCenters[h],containerWidth:c,children:typeof w=="function"?w(u):(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:u.label}),(0,t.jsxs)("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[(0,t.jsx)("span",{children:U.chartStart}),(0,t.jsx)("span",{className:"[font-variant-numeric:tabular-nums] text-gray-900 dark:text-gray-100",children:u.start===null?"\u2014":at(u.start)})]}),u.milestone?null:(0,t.jsxs)("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[(0,t.jsx)("span",{children:U.chartEnd}),(0,t.jsx)("span",{className:"[font-variant-numeric:tabular-nums] text-gray-900 dark:text-gray-100",children:u.end===null?"\u2014":at(u.end)})]}),u.progress===null?null:(0,t.jsxs)("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[(0,t.jsx)("span",{children:U.chartProgress}),(0,t.jsx)("span",{className:"[font-variant-numeric:tabular-nums] text-gray-900 dark:text-gray-100",children:(0,et.formatPercent)(u.progress,{locale:L,maximumFractionDigits:0})})]})]})}):null]})}function jt({data:c,x:o,start:p,end:l,id:n,progress:P,milestone:M,dependencies:W,group:O,domain:X,today:V,ticks:K=6,barSize:rt,rowSize:nt=30,color:w,height:ct,width:mt,size:L="md",grid:at=!0,legend:D,tooltip:E=!0,tableView:_=!1,title:N,description:h,loading:U=!1,emptyState:ot,error:e=!1,errorState:ut,onRetry:F,actions:gt,margin:u,locale:m,plotLabel:C,startLabel:f,endLabel:$,progressLabel:Y,todayLabel:dt,formatDate:S,onTaskClick:ht,className:pt,...lt}){let R=(0,tt.useUILocale)(m),A=(0,tt.useUILabels)(),a=(0,s.useMemo)(()=>o.format??(r=>(0,et.formatXValue)(r,R)),[o.format,R]),i=(0,s.useMemo)(()=>c.map((r,d)=>{let j=(0,st.readXValue)(r,o.key,d),z=(0,k.toTimestamp)(r[p]),v=l?(0,k.toTimestamp)(r[l]):null,q=v===null||(M?!!r[M]:!1),kt=W?r[W]:void 0;return{index:d,id:String(n?r[n]??d:d),x:j,label:a(j,d),start:z,end:q?z:v??z,progress:P?(0,st.readNumber)(r,P):null,milestone:q,dependsOn:Array.isArray(kt)?kt.map(Wt=>String(Wt)):[],group:O?r[O]??null:null,datum:r}}),[c,o.key,p,l,n,P,M,W,O,a]),T=(0,s.useMemo)(()=>{let r=[];for(let d of i)d.group!==null&&!r.includes(d.group)&&r.push(d.group);return r},[i]),y=(0,s.useCallback)(r=>r.group===null?(0,B.getSeriesColor)(0,w):(0,B.getSeriesColor)(T.indexOf(r.group)),[T,w]),b=(0,s.useMemo)(()=>{if(X){let v=(0,k.toTimestamp)(X[0]),q=(0,k.toTimestamp)(X[1]);if(v!==null&&q!==null)return[v,q]}let r=(0,Gt.extent)(i.flatMap(v=>v.start===null?[]:[v.start,v.end??v.start]));if(r===null)return[0,1];let[d,j]=r,z=j-d||864e5;return[d-z*Pt,j+z*Pt]},[X,i]),g=(0,s.useMemo)(()=>(0,k.niceTimeTicks)(b[0],b[1],K),[b,K]),G=(0,s.useMemo)(()=>S??(r=>new Intl.DateTimeFormat(R,{day:"numeric",month:"short",year:"numeric"}).format(new Date(r))),[S,R]),x=(0,s.useMemo)(()=>V===!1?null:(0,k.toTimestamp)(V??Date.now()),[V]),I=(0,s.useMemo)(()=>T.map((r,d)=>({key:r,label:r,color:(0,B.getSeriesColor)(d),marker:"rect"})),[T]),Z=ct??Math.max(120,i.length*nt+48),Ht=D===void 0?T.length>=2:D!==!1,Tt=typeof D=="string"?D:"bottom";return(0,t.jsx)($t.ChartContainer,{title:N,description:h,height:Z,width:mt,size:L,loading:U,empty:i.length===0,emptyState:ot,error:e,errorState:ut,onRetry:F,actions:gt,tableView:_,legendPosition:Tt,legend:Ht&&I.length>0?(0,t.jsx)(Lt.ChartLegend,{items:I,position:Tt,marker:"rect",size:L}):void 0,table:_?(0,t.jsx)("div",{className:"w-full overflow-x-auto",children:(0,t.jsxs)(Mt.Table,{children:[typeof N=="string"?(0,t.jsx)("caption",{className:"sr-only",children:N}):null,(0,t.jsxs)(Dt.TableHeader,{children:[(0,t.jsx)(Q.TableHeaderCell,{children:o.label??o.key}),(0,t.jsx)(Q.TableHeaderCell,{className:"text-right",children:f??A.chartStart}),(0,t.jsx)(Q.TableHeaderCell,{className:"text-right",children:$??A.chartEnd}),P?(0,t.jsx)(Q.TableHeaderCell,{className:"text-right",children:Y??A.chartProgress}):null]}),(0,t.jsx)(Ot.TableBody,{children:i.map(r=>(0,t.jsxs)(Et.TableRow,{clickable:!1,children:[(0,t.jsx)(J.TableCell,{className:"font-medium text-gray-900 dark:text-gray-100",children:r.label}),(0,t.jsx)(J.TableCell,{className:yt,children:r.start===null?"\u2014":G(r.start)}),(0,t.jsx)(J.TableCell,{className:yt,children:r.milestone||r.end===null?"\u2014":G(r.end)}),P?(0,t.jsx)(J.TableCell,{className:yt,children:r.progress===null?"\u2014":(0,et.formatPercent)(r.progress,{locale:R,maximumFractionDigits:0})}):null]},r.index))})]})}):void 0,className:pt,...lt,children:({width:r})=>(0,t.jsx)(Zt,{width:r,height:Z,data:c,tasks:i,x:o,domain:b,unit:g.unit,timeTicks:g.values,today:x,grid:at,size:L,barSize:rt,colorOf:y,margin:u,tooltip:E,plotLabel:C,todayLabel:dt??A.chartToday,locale:R,formatDate:G,formatX:a,onTaskClick:ht})})}0&&(module.exports={GanttChart});
|
|
@@ -1 +1 @@
|
|
|
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
|
+
"use client";import{memo as Nt,useCallback as ot,useId as St,useMemo as P,useState as Rt}from"react";import{useUILabels as Pt,useUILocale as At}from"../../lib/i18n.js";import{ChartAxis as yt}from"../chart/ChartAxis.js";import{ChartContainer as Gt}from"../chart/ChartContainer.js";import{ChartGrid as It}from"../chart/ChartGrid.js";import{ChartLegend as Mt}from"../chart/ChartLegend.js";import{ChartPlotClip as Ot,isOnPlot as bt,plotClipId as Dt}from"../chart/ChartPlotClip.js";import{ChartTooltip as Et}from"../chart/ChartTooltip.js";import{CHART_SURFACE_COLOR as Ht,getSeriesColor as dt}from"../chart/palette.js";import{buildCartesianGeometry as Wt}from"../chart/utils/cartesian.js";import{readNumber as Xt,readXValue as Vt}from"../chart/utils/data.js";import{formatPercent as $t,formatXValue as _t}from"../chart/utils/format.js";import{handleChartKeyDown as zt}from"../chart/utils/keyboard.js";import{buildBarPath as Ct}from"../chart/utils/path.js";import{nearestIndex as Bt}from"../chart/utils/scales.js";import{extent as Kt}from"../chart/utils/ticks.js";import{formatTimeTick as Tt,niceTimeTicks as Ut,toTimestamp as j}from"../chart/utils/time.js";import{CHART_TOUCH as Ft}from"../chart/utils/touch.js";import{Table as Yt}from"../table/Table.js";import{TableBody as Zt}from"../table/TableBody.js";import{TableCell as rt}from"../table/TableCell.js";import{TableHeader as jt}from"../table/TableHeader.js";import{TableHeaderCell as nt}from"../table/TableHeaderCell.js";import{TableRow as qt}from"../table/TableRow.js";import{Fragment as re,jsx as r,jsxs as s}from"react/jsx-runtime";var Jt=18,kt=.5,Qt=.3,at=7,xt=10,vt=.02,ht="text-right [font-variant-numeric:tabular-nums]",te=Nt(function({tasks:c,arrows:I,clipId:l}){return s("g",{children:[s("g",{clipPath:`url(#${l})`,children:[r("g",{className:"fill-gray-400 stroke-gray-400 dark:fill-gray-500 dark:stroke-gray-500",children:I.map(n=>s("g",{children:[r("path",{d:n.d,fill:"none",strokeWidth:1}),r("path",{d:n.head,strokeWidth:0})]},n.key))}),c.map(n=>n.track?s("g",{children:[r("path",{d:n.track,fill:n.color,fillOpacity:n.trackOpacity}),n.progress?r("path",{d:n.progress,fill:n.color}):null]},n.key):null)]}),c.map(n=>n.milestone?r("path",{d:n.milestone,fill:n.color,strokeWidth:2,stroke:Ht},n.key):null)]})});function ee({width:k,height:c,data:I,tasks:l,x:n,domain:x,unit:M,timeTicks:H,today:O,grid:W,size:X,barSize:z,colorOf:q,margin:J,tooltip:$,plotLabel:lt,todayLabel:it,locale:w,formatDate:Q,formatX:D,onTaskClick:E}){let[V,L]=Rt(null),d=V!==null&&V<l.length?V:null,B=Pt(),tt=Dt(St()),t=P(()=>{let i=Wt({width:k,height:c,data:I,x:n,y:{domain:x},bounds:x,margin:J,orientation:"horizontal",placement:"band",formatValue:a=>Tt(a,M,w),formatX:D}),{valueScale:y,bandwidth:h,categoryPositions:v,innerWidth:U,innerHeight:mt}=i,N=Math.min(z??Jt,h),ut=new Map(l.map((a,o)=>[a.id,o])),gt=l.map((a,o)=>{let b=v[o]+(h-N)/2,p=b+N/2,f=q(a);if(a.start===null)return{key:`${o}`,color:f,track:null,trackOpacity:1,progress:null,milestone:null,top:v[o],height:h};let u=y(a.start);if(a.milestone)return{key:`${o}`,color:f,track:null,trackOpacity:1,progress:null,milestone:bt(u,U)?`M${u},${p-at} L${u+at},${p} L${u},${p+at} L${u-at},${p} Z`:null,top:v[o],height:h};let A=y(a.end??a.start),C=Math.max(2,A-u);return{key:`${o}`,color:f,track:Ct({x:u,y:b,width:C,height:N,radius:3}),trackOpacity:a.progress===null?1:Qt,progress:a.progress===null?null:Ct({x:u,y:p-N*kt/2,width:Math.max(0,C*Math.min(1,Math.max(0,a.progress))),height:N*kt,radius:2,round:"right"}),milestone:null,top:v[o],height:h}}),et=[];l.forEach((a,o)=>{if(a.start!==null)for(let b of a.dependsOn){let p=ut.get(b);if(p===void 0||p===o)continue;let f=l[p];if(f.start===null)continue;let u=y(f.end??f.start),A=v[p]+h/2,C=y(a.start),G=v[o]+h/2,F=Math.max(u+xt,C-xt);et.push({key:`${b}-${a.id}`,d:`M${u},${A} L${F},${A} L${F},${G} L${C-5},${G}`,head:`M${C},${G} L${C-5},${G-3.5} L${C-5},${G+3.5} Z`})}});let S=H.map(a=>({value:a,offset:y(a),label:Tt(a,M,w)})),R=O===null?null:y(O);return{rendered:gt,arrows:et,categoryPositions:v,categoryCenters:i.categoryCenters,bandwidth:h,categoryTicks:i.categoryTicks,valueTicks:S,valueScale:y,todayAt:R!==null&&bt(R,U)?R:null,innerWidth:U,innerHeight:mt,margin:i.margin}},[l,I,n,x,M,H,O,k,c,J,z,q,w,D]),st=ot(i=>{if($===!1||l.length===0)return;let y=i.currentTarget.getBoundingClientRect(),h=i.clientY-y.top-t.margin.top;L(Bt(t.categoryCenters,h))},[$,l.length,t.margin.top,t.categoryCenters]),K=ot(()=>{!E||d===null||E(l[d])},[E,d,l]),ct=ot(i=>zt(i,{count:l.length,current:d,axis:"y",onMove:L,pick:E?K:null}),[l.length,d,E,K]),m=d===null?null:l[d];return s(re,{children:[s("svg",{width:k,height:c,role:"img","aria-label":lt??l.map(i=>i.label).join(", "),tabIndex:0,className:`${Ft} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500`,onPointerMove:st,onPointerLeave:()=>L(null),onKeyDown:ct,onBlur:()=>L(null),onClick:K,children:[s("g",{transform:`translate(${t.margin.left}, ${t.margin.top})`,children:[r(Ot,{id:tt,width:t.innerWidth,height:t.innerHeight}),r(It,{width:t.innerWidth,height:t.innerHeight,vertical:W?t.valueTicks.map(i=>i.offset):void 0}),d!==null?r("rect",{x:0,y:t.categoryPositions[d],width:t.innerWidth,height:t.bandwidth,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,r(te,{tasks:t.rendered,arrows:t.arrows,clipId:tt}),t.todayAt!==null?s("g",{children:[r("line",{x1:t.todayAt,y1:0,x2:t.todayAt,y2:t.innerHeight,className:"stroke-gray-900 dark:stroke-white",strokeWidth:1,strokeDasharray:"4 4"}),r("text",{x:t.todayAt+4,y:8,className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:it})]}):null]}),r("g",{transform:`translate(${t.margin.left}, ${t.margin.top+t.innerHeight})`,children:r(yt,{orientation:"bottom",ticks:t.valueTicks,length:t.innerWidth,size:X})}),r("g",{transform:`translate(${t.margin.left}, ${t.margin.top})`,children:n.hidden?null:r(yt,{orientation:"left",ticks:t.categoryTicks,length:t.innerHeight,showLine:!1,tickSize:0,label:n.label,size:X})})]}),m&&d!==null&&$!==!1?r(Et,{x:t.margin.left+(m.start===null?t.innerWidth/2:Math.min(t.innerWidth,Math.max(0,t.valueScale(m.start)))),y:t.margin.top+t.categoryCenters[d],containerWidth:k,children:typeof $=="function"?$(m):s("div",{className:"flex flex-col gap-1",children:[r("div",{className:"font-medium text-gray-900 dark:text-gray-100",children:m.label}),s("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[r("span",{children:B.chartStart}),r("span",{className:"[font-variant-numeric:tabular-nums] text-gray-900 dark:text-gray-100",children:m.start===null?"\u2014":Q(m.start)})]}),m.milestone?null:s("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[r("span",{children:B.chartEnd}),r("span",{className:"[font-variant-numeric:tabular-nums] text-gray-900 dark:text-gray-100",children:m.end===null?"\u2014":Q(m.end)})]}),m.progress===null?null:s("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[r("span",{children:B.chartProgress}),r("span",{className:"[font-variant-numeric:tabular-nums] text-gray-900 dark:text-gray-100",children:$t(m.progress,{locale:w,maximumFractionDigits:0})})]})]})}):null]})}function Le({data:k,x:c,start:I,end:l,id:n,progress:x,milestone:M,dependencies:H,group:O,domain:W,today:X,ticks:z=6,barSize:q,rowSize:J=30,color:$,height:lt,width:it,size:w="md",grid:Q=!0,legend:D,tooltip:E=!0,tableView:V=!1,title:L,description:d,loading:B=!1,emptyState:tt,error:t=!1,errorState:st,onRetry:K,actions:ct,margin:m,locale:i,plotLabel:y,startLabel:h,endLabel:v,progressLabel:U,todayLabel:mt,formatDate:N,onTaskClick:ut,className:gt,...et}){let S=At(i),R=Pt(),a=P(()=>c.format??(e=>_t(e,S)),[c.format,S]),o=P(()=>k.map((e,g)=>{let Y=Vt(e,c.key,g),_=j(e[I]),T=l?j(e[l]):null,Z=T===null||(M?!!e[M]:!1),ft=H?e[H]:void 0;return{index:g,id:String(n?e[n]??g:g),x:Y,label:a(Y,g),start:_,end:Z?_:T??_,progress:x?Xt(e,x):null,milestone:Z,dependsOn:Array.isArray(ft)?ft.map(Lt=>String(Lt)):[],group:O?e[O]??null:null,datum:e}}),[k,c.key,I,l,n,x,M,H,O,a]),b=P(()=>{let e=[];for(let g of o)g.group!==null&&!e.includes(g.group)&&e.push(g.group);return e},[o]),p=ot(e=>e.group===null?dt(0,$):dt(b.indexOf(e.group)),[b,$]),f=P(()=>{if(W){let T=j(W[0]),Z=j(W[1]);if(T!==null&&Z!==null)return[T,Z]}let e=Kt(o.flatMap(T=>T.start===null?[]:[T.start,T.end??T.start]));if(e===null)return[0,1];let[g,Y]=e,_=Y-g||864e5;return[g-_*vt,Y+_*vt]},[W,o]),u=P(()=>Ut(f[0],f[1],z),[f,z]),A=P(()=>N??(e=>new Intl.DateTimeFormat(S,{day:"numeric",month:"short",year:"numeric"}).format(new Date(e))),[N,S]),C=P(()=>X===!1?null:j(X??Date.now()),[X]),G=P(()=>b.map((e,g)=>({key:e,label:e,color:dt(g),marker:"rect"})),[b]),F=lt??Math.max(120,o.length*J+48),wt=D===void 0?b.length>=2:D!==!1,pt=typeof D=="string"?D:"bottom";return r(Gt,{title:L,description:d,height:F,width:it,size:w,loading:B,empty:o.length===0,emptyState:tt,error:t,errorState:st,onRetry:K,actions:ct,tableView:V,legendPosition:pt,legend:wt&&G.length>0?r(Mt,{items:G,position:pt,marker:"rect",size:w}):void 0,table:V?r("div",{className:"w-full overflow-x-auto",children:s(Yt,{children:[typeof L=="string"?r("caption",{className:"sr-only",children:L}):null,s(jt,{children:[r(nt,{children:c.label??c.key}),r(nt,{className:"text-right",children:h??R.chartStart}),r(nt,{className:"text-right",children:v??R.chartEnd}),x?r(nt,{className:"text-right",children:U??R.chartProgress}):null]}),r(Zt,{children:o.map(e=>s(qt,{clickable:!1,children:[r(rt,{className:"font-medium text-gray-900 dark:text-gray-100",children:e.label}),r(rt,{className:ht,children:e.start===null?"\u2014":A(e.start)}),r(rt,{className:ht,children:e.milestone||e.end===null?"\u2014":A(e.end)}),x?r(rt,{className:ht,children:e.progress===null?"\u2014":$t(e.progress,{locale:S,maximumFractionDigits:0})}):null]},e.index))})]})}):void 0,className:gt,...et,children:({width:e})=>r(ee,{width:e,height:F,data:k,tasks:o,x:c,domain:f,unit:u.unit,timeTicks:u.values,today:C,grid:Q,size:w,barSize:q,colorOf:p,margin:m,tooltip:E,plotLabel:y,todayLabel:mt??R.chartToday,locale:S,formatDate:A,formatX:a,onTaskClick:ut})})}export{Le as GanttChart};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";"use client";var ne=Object.defineProperty;var
|
|
1
|
+
"use strict";"use client";var ne=Object.defineProperty;var we=Object.getOwnPropertyDescriptor;var ye=Object.getOwnPropertyNames;var ve=Object.prototype.hasOwnProperty;var Se=(o,r)=>{for(var e in r)ne(o,e,{get:r[e],enumerable:!0})},xe=(o,r,e,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let b of ye(r))!ve.call(o,b)&&b!==e&&ne(o,b,{get:()=>r[b],enumerable:!(t=we(r,b))||t.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 m=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"),O=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,Xe=12,Ee=16,se="cell:",le=!1,Re=(0,m.memo)(function({cells:r,radius:e}){return(0,n.jsx)("g",{children:r.map(t=>(0,n.jsxs)("g",{children:[(0,n.jsx)("rect",{x:t.x,y:t.y,width:t.width,height:t.height,rx:e,fill:t.missing?void 0:t.color,className:t.missing?"fill-gray-100 dark:fill-gray-800":void 0}),t.label?(0,n.jsx)("text",{x:t.x+t.width/2,y:t.y+t.height/2,textAnchor:"middle",dominantBaseline:"central",className:(0,ce.cn)("text-[10px] [font-variant-numeric:tabular-nums]",t.onDark?"fill-gray-50 dark:fill-gray-900":"fill-gray-900 dark:fill-gray-50"),children:t.label}):null]},t.key))})});function $e({width:o,height:r,columns:e,rows:t,lookup:b,colorScale:S,x:p,y:C,size:H,cellGap:y,cellRadius:B,showValues:U,tooltip:T,plotLabel:ee,formatValue:W,formatX:D,formatY:I,onCellClick:X}){let[R,N]=(0,m.useState)(null),s=R!==null&&R.column<e.length&&R.row<t.length?R:null,a=(0,m.useMemo)(()=>{let g=e.map((f,l)=>D(f,l)),d=t.map((f,l)=>I(f,l)),u={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)+Xe+(C.label?16:0)},c=Math.max(0,o-u.left-u.right),v=Math.max(0,r-u.top-u.bottom),h=(0,k.createBandScale)(e.map((f,l)=>l),[0,c],{paddingInner:0,paddingOuter:0}),x=(0,k.createBandScale)(t.map((f,l)=>l),[0,v],{paddingInner:0,paddingOuter:0}),Q=Math.max(0,h.bandwidth-y),L=Math.max(0,x.bandwidth-y),A=[];t.forEach((f,l)=>{e.forEach((j,K)=>{let E=b.get(`${(0,k.toKey)(j)}|${(0,k.toKey)(f)}`)?.value??null,i=null;if(U&&E!==null&&L>=Ee){let w=W(E);(0,V.estimateTextWidth)(w,10)+6<=Q&&(i=w)}A.push({key:`${K}-${l}`,column:K,row:l,x:h(K)+y/2,y:x(l)+y/2,width:Q,height:L,color:E===null?"transparent":S(E),label:i,onDark:E!==null&&S.onDark(E),missing:E===null})})});let F=(0,V.labelStride)(g.length,c,(0,V.widestLabel)(g)),P=(0,V.labelStride)(d.length,v,V.AXIS_FONT_SIZE+4),G=p.hidden?[]:g.map((f,l)=>({value:e[l],offset:h.center(l),label:f})).filter((f,l)=>l%F===0),Y=C.hidden?[]:d.map((f,l)=>({value:t[l],offset:x.center(l),label:f})).filter((f,l)=>l%P===0);return{margin:u,innerWidth:c,innerHeight:v,columnScale:h,rowScale:x,cells:A,columnTicks:G,rowTicks:Y}},[e,t,b,S,p,C,o,r,y,U,W,D,I]),_=(0,m.useCallback)((g,d)=>{let u=e[g],c=t[d],v=b.get(`${(0,k.toKey)(u)}|${(0,k.toKey)(c)}`),h=v?.value??null;return{x:u,y:c,xLabel:D(u,g),yLabel:I(c,d),value:h,formattedValue:h===null?"\u2014":W(h),color:h===null?"transparent":S(h),datum:v?.datum}},[e,t,b,S,W,D,I]),te=(0,m.useCallback)(g=>{if(T===!1||e.length===0||t.length===0)return;let d=g.currentTarget.getBoundingClientRect(),u=g.clientX-d.left-a.margin.left,c=g.clientY-d.top-a.margin.top,v=Math.floor(u/(a.columnScale.step||1)),h=Math.floor(c/(a.rowScale.step||1));if(v<0||v>=e.length||h<0||h>=t.length){N(null);return}N(x=>x?.column===v&&x.row===h?x:{column:v,row:h})},[T,e.length,t.length,a.margin,a.columnScale,a.rowScale]),q=(0,m.useCallback)(()=>{!X||!s||X(_(s.column,s.row))},[X,s,_]),ae=(0,m.useCallback)(g=>{if(e.length===0||t.length===0||(0,M.pressChartMark)(g,X&&s?q:null))return;let d=s?.column??null,u=s?.row??null,c;switch(g.key){case"ArrowRight":c={row:u??0,column:(0,M.stepChartCursor)(d,1,e.length)};break;case"ArrowLeft":c={row:u??0,column:(0,M.stepChartCursor)(d,-1,e.length)};break;case"ArrowDown":c={column:d??0,row:(0,M.stepChartCursor)(u,1,t.length)};break;case"ArrowUp":c={column:d??0,row:(0,M.stepChartCursor)(u,-1,t.length)};break;case"Home":c={row:u??0,column:0};break;case"End":c={row:u??0,column:e.length-1};break;case"Escape":if(s===null)return;c=null;break;default:return}g.preventDefault(),N(c)},[e.length,t.length,s,X,q]),$=s?_(s.column,s.row):null;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("svg",{width:o,height:r,role:"img","aria-label":ee??`${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:te,onPointerLeave:()=>N(null),onKeyDown:ae,onBlur:()=>N(null),onClick:q,children:[(0,n.jsxs)("g",{transform:`translate(${a.margin.left}, ${a.margin.top})`,children:[(0,n.jsx)(Re,{cells:a.cells,radius:B}),s?(0,n.jsx)("rect",{x:a.columnScale(s.column)+y/2,y:a.rowScale(s.row)+y/2,width:Math.max(0,a.columnScale.bandwidth-y),height:Math.max(0,a.rowScale.bandwidth-y),rx:B,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})})]}),s&&$&&T!==!1?(0,n.jsx)(fe.ChartTooltip,{x:a.margin.left+a.columnScale.center(s.column),y:a.margin.top+a.rowScale.center(s.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,e){if(e)return e;let t=new Map;return o.forEach((b,S)=>{let p=(0,O.readXValue)(b,r,S),C=(0,k.toKey)(p);t.has(C)||t.set(C,p)}),[...t.values()]}function Ae({data:o,x:r,y:e,value:t,format:b,domain:S,scale:p="sequential",center:C=0,steps:H,colors:y,xDomain:B,yDomain:U,cellGap:T=Ve,cellRadius:ee=He,showValues:W=!1,height:D=280,width:I,size:X="md",legend:R=!0,legendLabel:N,tooltip:s=!0,tableView:a=!1,title:_,description:te,loading:q=!1,emptyState:ae,error:$=!1,errorState:g,onRetry:d,actions:u,locale:c,plotLabel:v,onCellClick:h,className:x,...Q}){let L=(0,me.useUILocale)(c);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,m.useMemo)(()=>ue(o,r.key,B),[o,r.key,B]),F=(0,m.useMemo)(()=>ue(o,e.key,U),[o,e.key,U]),P=(0,m.useMemo)(()=>{let i=new Map;return o.forEach((w,Z)=>{let ie=(0,O.readNumber)(w,t);if(ie===null)return;let Ce=(0,O.readXValue)(w,r.key,Z),ke=(0,O.readXValue)(w,e.key,Z);i.set(`${(0,k.toKey)(Ce)}|${(0,k.toKey)(ke)}`,{value:ie,datum:w})}),i},[o,r.key,e.key,t]),G=(0,m.useMemo)(()=>b??(i=>(0,J.formatAuto)(i,L)),[b,L]),Y=(0,m.useMemo)(()=>r.format??(i=>(0,J.formatXValue)(i,L)),[r.format,L]),f=(0,m.useMemo)(()=>e.format??(i=>(0,J.formatXValue)(i,L)),[e.format,L]),l=(0,m.useMemo)(()=>{let i=S??(0,be.extent)([...P.values()].map(w=>w.value))??[0,1];return p==="diverging"?(0,z.createDivergingScale)(i,{center:C,steps:H,colors:y}):(0,z.createSequentialScale)(i,{steps:H,colors:y})},[S,P,p,C,H,y]),j=(0,m.useMemo)(()=>F.map(i=>{let w={[e.key]:i};return A.forEach(Z=>{w[`${se}${(0,k.toKey)(Z)}`]=P.get(`${(0,k.toKey)(Z)}|${(0,k.toKey)(i)}`)?.value??null}),w}),[F,A,P,e.key]),K=(0,m.useMemo)(()=>A.map((i,w)=>({key:`${se}${(0,k.toKey)(i)}`,label:Y(i,w)})),[A,Y]),oe=R!==!1,E=typeof R=="string"?R:"bottom";return(0,n.jsx)(he.ChartContainer,{title:_,description:te,height:D,width:I,size:X,loading:q,empty:P.size===0,emptyState:ae,error:$,errorState:g,onRetry:d,actions:u,exportSource:{data:j,series:K,xKey:e.key,xLabel:e.label??e.key,formatX:e.format},tableView:a,legendPosition:E,legend:oe?(0,n.jsx)(ge.ChartScaleLegend,{scale:l,label:N,format:G,size:X,locale:L}):void 0,table:a?(0,n.jsx)(de.ChartTableView,{data:j,series:K,xKey:e.key,xLabel:e.label??e.key,formatX:f,formatValue:G,caption:typeof _=="string"?_:void 0}):void 0,className:x,...Q,children:({width:i})=>(0,n.jsx)($e,{width:i,height:D,columns:A,rows:F,lookup:P,colorScale:l,x:r,y:e,size:X,cellGap:T,cellRadius:ee,showValues:W,tooltip:s,plotLabel:v,formatValue:G,formatX:Y,formatY:f,onCellClick:h})})}function Pe(){le=!1}0&&(module.exports={Heatmap,resetHeatmapWarnings});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{memo as fe,useCallback as
|
|
1
|
+
"use client";import{memo as fe,useCallback as Z,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 we}from"../chart/ChartScaleLegend.js";import{ChartTableView as ye}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 J}from"../chart/utils/keyboard.js";import{createBandScale as se,toKey as w}from"../chart/utils/scales.js";import{AXIS_FONT_SIZE as Xe,estimateTextWidth as Ee,labelStride as ue,widestLabel as ce}from"../chart/utils/text.js";import{extent as Re}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:e}){return h("g",{children:g.map(t=>_("g",{children:[h("rect",{x:t.x,y:t.y,width:t.width,height:t.height,rx:e,fill:t.missing?void 0:t.color,className:t.missing?"fill-gray-100 dark:fill-gray-800":void 0}),t.label?h("text",{x:t.x+t.width/2,y:t.y+t.height/2,textAnchor:"middle",dominantBaseline:"central",className:pe("text-[10px] [font-variant-numeric:tabular-nums]",t.onDark?"fill-gray-50 dark:fill-gray-900":"fill-gray-900 dark:fill-gray-50"),children:t.label}):null]},t.key))})});function _e({width:b,height:g,columns:e,rows:t,lookup:L,colorScale:y,x:d,y:f,size:V,cellGap:C,cellRadius:I,showValues:K,tooltip:P,plotLabel:Q,formatValue:M,formatX:T,formatY:z,onCellClick:H}){let[E,D]=be(null),l=E!==null&&E.column<e.length&&E.row<t.length?E:null,a=x(()=>{let u=e.map((m,n)=>T(m,n)),c=t.map((m,n)=>z(m,n)),o={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)},i=Math.max(0,b-o.left-o.right),k=Math.max(0,g-o.top-o.bottom),s=se(e.map((m,n)=>n),[0,i],{paddingInner:0,paddingOuter:0}),v=se(t.map((m,n)=>n),[0,k],{paddingInner:0,paddingOuter:0}),G=Math.max(0,s.bandwidth-C),S=Math.max(0,v.bandwidth-C),$=[];t.forEach((m,n)=>{e.forEach((Y,W)=>{let X=L.get(`${w(Y)}|${w(m)}`)?.value??null,r=null;if(K&&X!==null&&S>=De){let p=M(X);Ee(p,10)+6<=G&&(r=p)}$.push({key:`${W}-${n}`,column:W,row:n,x:s(W)+C/2,y:v(n)+C/2,width:G,height:S,color:X===null?"transparent":y(X),label:r,onDark:X!==null&&y.onDark(X),missing:X===null})})});let B=ue(u.length,i,ce(u)),A=ue(c.length,k,Xe+4),U=d.hidden?[]:u.map((m,n)=>({value:e[n],offset:s.center(n),label:m})).filter((m,n)=>n%B===0),q=f.hidden?[]:c.map((m,n)=>({value:t[n],offset:v.center(n),label:m})).filter((m,n)=>n%A===0);return{margin:o,innerWidth:i,innerHeight:k,columnScale:s,rowScale:v,cells:$,columnTicks:U,rowTicks:q}},[e,t,L,y,d,f,b,g,C,K,M,T,z]),N=Z((u,c)=>{let o=e[u],i=t[c],k=L.get(`${w(o)}|${w(i)}`),s=k?.value??null;return{x:o,y:i,xLabel:T(o,u),yLabel:z(i,c),value:s,formattedValue:s===null?"\u2014":M(s),color:s===null?"transparent":y(s),datum:k?.datum}},[e,t,L,y,M,T,z]),j=Z(u=>{if(P===!1||e.length===0||t.length===0)return;let c=u.currentTarget.getBoundingClientRect(),o=u.clientX-c.left-a.margin.left,i=u.clientY-c.top-a.margin.top,k=Math.floor(o/(a.columnScale.step||1)),s=Math.floor(i/(a.rowScale.step||1));if(k<0||k>=e.length||s<0||s>=t.length){D(null);return}D(v=>v?.column===k&&v.row===s?v:{column:k,row:s})},[P,e.length,t.length,a.margin,a.columnScale,a.rowScale]),O=Z(()=>{!H||!l||H(N(l.column,l.row))},[H,l,N]),ee=Z(u=>{if(e.length===0||t.length===0||He(u,H&&l?O:null))return;let c=l?.column??null,o=l?.row??null,i;switch(u.key){case"ArrowRight":i={row:o??0,column:J(c,1,e.length)};break;case"ArrowLeft":i={row:o??0,column:J(c,-1,e.length)};break;case"ArrowDown":i={column:c??0,row:J(o,1,t.length)};break;case"ArrowUp":i={column:c??0,row:J(o,-1,t.length)};break;case"Home":i={row:o??0,column:0};break;case"End":i={row:o??0,column:e.length-1};break;case"Escape":if(l===null)return;i=null;break;default:return}u.preventDefault(),D(i)},[e.length,t.length,l,H,O]),R=l?N(l.column,l.row):null;return _(Me,{children:[_("svg",{width:b,height:g,role:"img","aria-label":Q??`${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:j,onPointerLeave:()=>D(null),onKeyDown:ee,onBlur:()=>D(null),onClick:O,children:[_("g",{transform:`translate(${a.margin.left}, ${a.margin.top})`,children:[h(Ne,{cells:a.cells,radius:I}),l?h("rect",{x:a.columnScale(l.column)+C/2,y:a.rowScale(l.row)+C/2,width:Math.max(0,a.columnScale.bandwidth-C),height:Math.max(0,a.rowScale.bandwidth-C),rx:I,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})})]}),l&&R&&P!==!1?h(ve,{x:a.margin.left+a.columnScale.center(l.column),y:a.margin.top+a.rowScale.center(l.row),containerWidth:b,children:typeof P=="function"?P(R):_("div",{className:"flex flex-col gap-1",children:[_("div",{className:"font-medium text-gray-900 dark:text-gray-100",children:[R.yLabel," \xB7 ",R.xLabel]}),_("div",{className:"flex items-center gap-2",children:[h("span",{className:"h-2.5 w-2.5 shrink-0 rounded-sm",style:{backgroundColor:R.color},"aria-hidden":"true"}),h("span",{className:"font-semibold text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:R.formattedValue})]})]})}):null]})}function he(b,g,e){if(e)return e;let t=new Map;return b.forEach((L,y)=>{let d=te(L,g,y),f=w(d);t.has(f)||t.set(f,d)}),[...t.values()]}function tt({data:b,x:g,y:e,value:t,format:L,domain:y,scale:d="sequential",center:f=0,steps:V,colors:C,xDomain:I,yDomain:K,cellGap:P=Ae,cellRadius:Q=Pe,showValues:M=!1,height:T=280,width:z,size:H="md",legend:E=!0,legendLabel:D,tooltip:l=!0,tableView:a=!1,title:N,description:j,loading:O=!1,emptyState:ee,error:R=!1,errorState:u,onRetry:c,actions:o,locale:i,plotLabel:k,onCellClick:s,className:v,...G}){let S=Ce(i);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,I),[b,g.key,I]),B=x(()=>he(b,e.key,K),[b,e.key,K]),A=x(()=>{let r=new Map;return b.forEach((p,F)=>{let re=Le(p,t);if(re===null)return;let ge=te(p,g.key,F),de=te(p,e.key,F);r.set(`${w(ge)}|${w(de)}`,{value:re,datum:p})}),r},[b,g.key,e.key,t]),U=x(()=>L??(r=>Ve(r,S)),[L,S]),q=x(()=>g.format??(r=>ie(r,S)),[g.format,S]),m=x(()=>e.format??(r=>ie(r,S)),[e.format,S]),n=x(()=>{let r=y??Re([...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})},[y,A,d,f,V,C]),Y=x(()=>B.map(r=>{let p={[e.key]:r};return $.forEach(F=>{p[`${me}${w(F)}`]=A.get(`${w(F)}|${w(r)}`)?.value??null}),p}),[B,$,A,e.key]),W=x(()=>$.map((r,p)=>({key:`${me}${w(r)}`,label:q(r,p)})),[$,q]),ne=E!==!1,X=typeof E=="string"?E:"bottom";return h(ke,{title:N,description:j,height:T,width:z,size:H,loading:O,empty:A.size===0,emptyState:ee,error:R,errorState:u,onRetry:c,actions:o,exportSource:{data:Y,series:W,xKey:e.key,xLabel:e.label??e.key,formatX:e.format},tableView:a,legendPosition:X,legend:ne?h(we,{scale:n,label:D,format:U,size:H,locale:S}):void 0,table:a?h(ye,{data:Y,series:W,xKey:e.key,xLabel:e.label??e.key,formatX:m,formatValue:U,caption:typeof N=="string"?N:void 0}):void 0,className:v,...G,children:({width:r})=>h(_e,{width:r,height:T,columns:$,rows:B,lookup:A,colorScale:n,x:g,y:e,size:H,cellGap:P,cellRadius:Q,showValues:M,tooltip:l,plotLabel:k,formatValue:U,formatX:q,formatY:m,onCellClick:s})})}function at(){ae=!1}export{tt as Heatmap,at as resetHeatmapWarnings};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";"use client";var
|
|
1
|
+
"use strict";"use client";var I=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var Q=(r,e)=>{for(var s in e)I(r,s,{get:e[s],enumerable:!0})},X=(r,e,s,p)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of J(e))!V.call(r,o)&&o!==s&&I(r,o,{get:()=>e[o],enumerable:!(p=q(e,o))||p.enumerable});return r};var Y=r=>X(I({},"__esModule",{value:!0}),r);var te={};Q(te,{ImageUploader:()=>re});module.exports=Y(te);var t=require("react"),c=require("../../lib/i18n.cjs"),y=require("../../lib/accept.cjs"),a=require("react/jsx-runtime"),Z={"16/9":"aspect-[16/9]","4/3":"aspect-[4/3]","1/1":"aspect-square",auto:""},T="image/svg+xml",_=r=>(0,y.parseAccept)(r).some(e=>e===T||e===".svg"),ee=(r,e)=>new Promise((s,p)=>{let o=new FileReader;o.onload=i=>{let x=i.target?.result;s(x)},o.onerror=()=>{p(new Error(e))},o.readAsDataURL(r)});function re({value:r,onChange:e,onUpload:s,label:p,maxSize:o=5*1024*1024,accept:i="image/*",helpText:x,disabled:b=!1,className:M="",showUrlInput:A=!0,urlPlaceholder:H="https://example.com/image.jpg",labels:S,aspectRatio:N="16/9",locale:B}){let l=(0,c.useUILabels)(S),E=(0,c.useUILocale)(B),L=p??l.imageUploaderLabel,[U,F]=(0,t.useState)(!1),[P,d]=(0,t.useState)(null),f=(0,t.useRef)(null),C=(0,t.useId)(),v=(0,t.useMemo)(()=>new Intl.NumberFormat(E,{maximumFractionDigits:2}).format(o/(1024*1024)),[E,o]),g=r&&!r.startsWith("data:")?r:"",[h,R]=(0,t.useState)(g),[G,K]=(0,t.useState)(g);G!==g&&(K(g),R(g));let k=i==="image/*"?"JPG, PNG, GIF, WebP":i,O=(0,c.formatUILabel)(l.imageUploaderHelp,{formats:k,maxSize:v}),j=(0,t.useCallback)(async n=>{let D=n.target,m=D.files?.[0];if(D.value="",!!m){if(!m.type.startsWith("image/")){d(l.imageUploaderNotImage);return}if(!(0,y.matchesAccept)(m,i)||m.type.toLowerCase()===T&&!_(i)){d((0,c.formatUILabel)(l.imageUploaderTypeNotAccepted,{formats:k}));return}if(m.size>o){d((0,c.formatUILabel)(l.imageUploaderTooLarge,{maxSize:v}));return}F(!0),d(null);try{if(s){let u=await s(m);e(u)}else{let u=await ee(m,l.imageUploaderReadError);e(u)}}catch(u){console.error("Upload error:",u),d(u instanceof Error?u.message:l.imageUploaderUploadError)}finally{F(!1)}}},[i,k,o,v,e,s,l]),W=(0,t.useCallback)(()=>{e(""),f.current&&(f.current.value=""),d(null)},[e]),w=(0,t.useCallback)(()=>{let n=h.trim();return n===g?!1:(e(n),d(null),!0)},[h,g,e]),$=(0,t.useCallback)(()=>{f.current?.click()},[]),z=(0,t.useCallback)(n=>{n.key!=="Enter"||n.nativeEvent.isComposing||w()&&n.preventDefault()},[w]);return(0,a.jsxs)("div",{className:`space-y-2 ${M}`,children:[L&&(0,a.jsx)("label",{className:"block text-sm font-semibold text-gray-700 dark:text-gray-300",children:L}),r&&(0,a.jsxs)("div",{className:"relative w-full overflow-hidden rounded-lg border border-gray-300 dark:border-gray-600 bg-gray-50 dark:bg-gray-800/50",children:[(0,a.jsx)("div",{className:`relative ${Z[N]} ${N==="auto"?"max-h-64":""} flex items-center justify-center`,children:(0,a.jsx)("img",{src:r,alt:l.imageUploaderPreview,className:"w-full h-full object-contain"})}),(0,a.jsx)("button",{type:"button",onClick:W,disabled:b,className:"absolute top-2 right-2 bg-red-600 text-white rounded-full w-6 h-6 flex items-center justify-center text-xs hover:bg-red-700 transition-colors cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed",title:l.imageUploaderRemove,children:"\xD7"})]}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)("input",{ref:f,type:"file","aria-label":l.imageUploaderChoose,accept:i,onChange:j,className:"hidden",disabled:b||U}),(0,a.jsx)("button",{type:"button",onClick:$,disabled:b||U,className:"px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-md hover:bg-gray-50 dark:hover:bg-gray-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors cursor-pointer bg-white dark:bg-gray-800 text-gray-700 dark:text-gray-200",children:U?l.imageUploaderUploading:r?l.imageUploaderChangeButton:l.imageUploaderChooseButton})]}),A&&(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsx)("label",{htmlFor:C,className:"block text-xs text-gray-500 dark:text-gray-400",children:l.imageUploaderUrlLabel}),(0,a.jsx)("input",{id:C,type:"text",inputMode:"url",value:h,onChange:n=>{R(n.target.value),d(null)},onBlur:w,onKeyDown:z,placeholder:H,disabled:b,className:"w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-md focus:ring-2 focus:ring-synertech-primary-500 focus:border-synertech-primary-500 dark:bg-gray-800 dark:text-gray-200 disabled:opacity-50 disabled:cursor-not-allowed"})]}),P&&(0,a.jsxs)("div",{className:"text-red-700 dark:text-red-400 text-sm bg-red-50 dark:bg-red-900/20 p-2 rounded border border-red-200 dark:border-red-800",children:["\u274C ",P]}),(0,a.jsx)("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:x||O})]})}0&&(module.exports={ImageUploader});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{useState as f,useRef as
|
|
1
|
+
"use client";import{useState as f,useRef as q,useCallback as m,useMemo as J,useId as V}from"react";import{formatUILabel as I,useUILabels as Q,useUILocale as X}from"../../lib/i18n.js";import{matchesAccept as Y,parseAccept as Z}from"../../lib/accept.js";import{jsx as l,jsxs as u}from"react/jsx-runtime";var _={"16/9":"aspect-[16/9]","4/3":"aspect-[4/3]","1/1":"aspect-square",auto:""},T="image/svg+xml",ee=t=>Z(t).some(r=>r===T||r===".svg"),re=(t,r)=>new Promise((g,y)=>{let o=new FileReader;o.onload=s=>{let x=s.target?.result;g(x)},o.onerror=()=>{y(new Error(r))},o.readAsDataURL(t)});function oe({value:t,onChange:r,onUpload:g,label:y,maxSize:o=5*1024*1024,accept:s="image/*",helpText:x,disabled:p=!1,className:M="",showUrlInput:A=!0,urlPlaceholder:H="https://example.com/image.jpg",labels:S,aspectRatio:N="16/9",locale:B}){let e=Q(S),E=X(B),L=y??e.imageUploaderLabel,[U,F]=f(!1),[P,n]=f(null),b=q(null),C=V(),v=J(()=>new Intl.NumberFormat(E,{maximumFractionDigits:2}).format(o/(1024*1024)),[E,o]),i=t&&!t.startsWith("data:")?t:"",[h,R]=f(i),[G,K]=f(i);G!==i&&(K(i),R(i));let k=s==="image/*"?"JPG, PNG, GIF, WebP":s,O=I(e.imageUploaderHelp,{formats:k,maxSize:v}),j=m(async a=>{let D=a.target,d=D.files?.[0];if(D.value="",!!d){if(!d.type.startsWith("image/")){n(e.imageUploaderNotImage);return}if(!Y(d,s)||d.type.toLowerCase()===T&&!ee(s)){n(I(e.imageUploaderTypeNotAccepted,{formats:k}));return}if(d.size>o){n(I(e.imageUploaderTooLarge,{maxSize:v}));return}F(!0),n(null);try{if(g){let c=await g(d);r(c)}else{let c=await re(d,e.imageUploaderReadError);r(c)}}catch(c){console.error("Upload error:",c),n(c instanceof Error?c.message:e.imageUploaderUploadError)}finally{F(!1)}}},[s,k,o,v,r,g,e]),W=m(()=>{r(""),b.current&&(b.current.value=""),n(null)},[r]),w=m(()=>{let a=h.trim();return a===i?!1:(r(a),n(null),!0)},[h,i,r]),$=m(()=>{b.current?.click()},[]),z=m(a=>{a.key!=="Enter"||a.nativeEvent.isComposing||w()&&a.preventDefault()},[w]);return u("div",{className:`space-y-2 ${M}`,children:[L&&l("label",{className:"block text-sm font-semibold text-gray-700 dark:text-gray-300",children:L}),t&&u("div",{className:"relative w-full overflow-hidden rounded-lg border border-gray-300 dark:border-gray-600 bg-gray-50 dark:bg-gray-800/50",children:[l("div",{className:`relative ${_[N]} ${N==="auto"?"max-h-64":""} flex items-center justify-center`,children:l("img",{src:t,alt:e.imageUploaderPreview,className:"w-full h-full object-contain"})}),l("button",{type:"button",onClick:W,disabled:p,className:"absolute top-2 right-2 bg-red-600 text-white rounded-full w-6 h-6 flex items-center justify-center text-xs hover:bg-red-700 transition-colors cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed",title:e.imageUploaderRemove,children:"\xD7"})]}),u("div",{className:"flex gap-2",children:[l("input",{ref:b,type:"file","aria-label":e.imageUploaderChoose,accept:s,onChange:j,className:"hidden",disabled:p||U}),l("button",{type:"button",onClick:$,disabled:p||U,className:"px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-md hover:bg-gray-50 dark:hover:bg-gray-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors cursor-pointer bg-white dark:bg-gray-800 text-gray-700 dark:text-gray-200",children:U?e.imageUploaderUploading:t?e.imageUploaderChangeButton:e.imageUploaderChooseButton})]}),A&&u("div",{className:"space-y-1",children:[l("label",{htmlFor:C,className:"block text-xs text-gray-500 dark:text-gray-400",children:e.imageUploaderUrlLabel}),l("input",{id:C,type:"text",inputMode:"url",value:h,onChange:a=>{R(a.target.value),n(null)},onBlur:w,onKeyDown:z,placeholder:H,disabled:p,className:"w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-md focus:ring-2 focus:ring-synertech-primary-500 focus:border-synertech-primary-500 dark:bg-gray-800 dark:text-gray-200 disabled:opacity-50 disabled:cursor-not-allowed"})]}),P&&u("div",{className:"text-red-700 dark:text-red-400 text-sm bg-red-50 dark:bg-red-900/20 p-2 rounded border border-red-200 dark:border-red-800",children:["\u274C ",P]}),l("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:x||O})]})}export{oe as ImageUploader};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";"use client";var Re=Object.defineProperty;var $e=Object.getOwnPropertyDescriptor;var _e=Object.getOwnPropertyNames;var ze=Object.prototype.hasOwnProperty;var Ue=(u,a)=>{for(var r in a)Re(u,r,{get:a[r],enumerable:!0})},je=(u,a,r,s)=>{if(a&&typeof a=="object"||typeof a=="function")for(let d of _e(a))!ze.call(u,d)&&d!==r&&Re(u,d,{get:()=>a[d],enumerable:!(s=$e(a,d))||s.enumerable});return u};var Fe=u=>je(Re({},"__esModule",{value:!0}),u);var tt={};Ue(tt,{LineChart:()=>et});module.exports=Fe(tt);var l=require("react"),Te=require("../../lib/cn.cjs"),ie=require("../../lib/i18n.cjs"),q=require("../chart/ChartAnnotations.cjs"),we=require("../chart/ChartAxis.cjs"),le=require("../chart/ChartBrush.cjs"),Be=require("../chart/ChartContainer.cjs"),Ee=require("../chart/ChartGrid.cjs"),He=require("../chart/ChartLegend.cjs"),We=require("../chart/ChartSync.cjs"),Ie=require("../chart/ChartTableView.cjs"),he=require("../chart/ChartTooltip.cjs"),W=require("../chart/palette.cjs"),k=require("../chart/utils/cartesian.cjs"),J=require("../chart/utils/data.cjs"),ue=require("../chart/utils/decimate.cjs"),ce=require("../chart/utils/format.cjs"),de=require("../chart/utils/keyboard.cjs"),I=require("../chart/utils/path.cjs"),H=require("../chart/utils/scales.cjs"),Ne=require("../chart/utils/ticks.cjs"),De=require("../chart/utils/timestamp.cjs"),Ke=require("../chart/utils/touch.cjs"),n=require("react/jsx-runtime"),Ye=24,qe=10,Je=10,Qe=(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((d,C)=>(0,n.jsx)("circle",{cx:d.x,cy:d.y,r:3,fill:s.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},C))]},s.key))})});function Ze({width:u,height:a,data:r,resolvedSeries:s,x:d,y:C,grid:b,size:Q,curve:x,forecastFrom:M,forecastLabel:v,markers:P,connectNulls:L,referenceLines:me,annotations:S,annotationsLabel:fe,overlay:ge,maxPoints:R,brush:Z,onBrush:ee,brushLabel:pe,syncEnabled:ye,margin:te,tooltip:w,onPointClick:V,plotLabel:Ce,formatValue:A,formatX:N}){let[X,G]=(0,l.useState)(null),h=X!==null&&X<r.length?X:null,[be,xe]=(0,l.useState)(null),ke=(0,We.useChartSync)(),m=ye?ke:null,e=(0,l.useMemo)(()=>{let t=s.filter(f=>!f.hidden),o=(0,k.buildCartesianGeometry)({width:u,height:a,data:r,x:d,y:C,bounds:(0,Ne.extent)((0,J.collectAllValues)(r,t.map(f=>f.key))),margin:te,placement:"point",formatValue:A,formatX:N,extraTop:v?qe:0}),c=o.categoryCenters,E=o.valueScale,oe=M===void 0?-1:o.xValues.findIndex(f=>(0,H.toKey)(f)===(0,H.toKey)(M)),Me=t.map(f=>{let j=r.map((se,Oe)=>{let Se=(0,J.readNumber)(se,f.key);return{x:c[Oe],y:Se===null?Number.NaN:E(Se),defined:Se!==null}}),Ve={connectNulls:L},ae=oe>=0,Le=se=>R&&R>0?(0,ue.decimatePath)(se,R):se,F=f.dashed?[]:Le(ae?j.slice(0,oe+1):j),Y=f.dashed?Le(j):ae?Le(j.slice(oe)):[];R||(0,ue.warnPointBudget)("LineChart",j.length);let Ge=F[F.length-1],Ae=f.dashed?Y:ae?[...F,...Y[0]===Ge?Y.slice(1):Y]:F;return{key:f.key,color:f.color,solid:f.dashed?"":(0,I.buildLinePath)(F,x,Ve),dashed:f.dashed||ae?(0,I.buildLinePath)(Y,x,Ve):"",markers:Ae.filter(I.isDrawable),isolated:(0,I.isolatedPoints)(Ae,L)}}),Xe=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:a,data:r,series:t,formatValue:A,formatX:N}),xValues:o.xValues,xPositions:c,xTicks:o.categoryTicks,yTicks:o.valueTicks,yScale:E,innerWidth:o.innerWidth,innerHeight:o.innerHeight,margin:o.margin,lines:Me,forecastIndex:oe,showMarkers:P==="always"||P==="auto"&&Xe>=Ye&&r.length>1}},[r,s,d,C,u,a,te,x,L,M,v,P,R,A,N]),O=(0,l.useCallback)(t=>e.visible.map(o=>{let c=(0,J.readNumber)(r[t],o.key);return{seriesKey:o.key,seriesLabel:(0,W.getSeriesLabel)(o),color:o.color,value:c,formattedValue:c===null?"\u2014":A(c),datum:r[t]}}),[r,e.visible,A]),ne=m?m.brush:be,ve=(0,l.useCallback)(t=>{xe(t),m?.setBrush(t),ee?.(t)},[m,ee]),g=(0,le.useChartBrush)({enabled:Z,active:ne!==null,centers:e.xPositions,xValues:e.xValues,offset:e.margin.left,orientation:"vertical",onCommit:ve}),T=(0,l.useCallback)(t=>{if(g.onPointerMove(t),w===!1||r.length===0)return;let o=t.currentTarget.getBoundingClientRect(),c=t.clientX-o.left-e.margin.left,E=(0,H.nearestIndex)(e.xPositions,c);G(E>=0?E:null),m?.setHovered(E>=0?e.xValues[E]:null)},[g,w,r.length,e.margin.left,e.xPositions,e.xValues,m]),$=(0,l.useCallback)(()=>{G(null),m?.setHovered(null)},[m]),B=(0,l.useCallback)(()=>{if(!V||h===null)return;let[t]=O(h);t&&V({...t,index:h,x:e.xValues[h]})},[V,h,O,e.xValues]),Pe=(0,l.useCallback)(t=>{if(r.length===0)return;let o=V&&h!==null&&e.visible.length>0;if((0,de.pressChartMark)(t,o?B:null))return;g.onKeyDown(t,h);let c=(0,de.chartCursorTarget)(t.key,h,r.length,"x");c!==void 0&&(t.preventDefault(),G(c),m?.setHovered(c===null?null:e.xValues[c]))},[r.length,h,g,m,e.xValues,e.visible.length,V,B]),D=(0,l.useCallback)(()=>{g.consumedClick()||B()},[g,B]),re=h!==null||!m?.hovered?null:(()=>{let t=(0,H.toKey)(m.hovered),o=e.xValues.findIndex(c=>(0,H.toKey)(c)===t);return o<0?null:o})(),p=h??re,_=p===null?null:O(p),z=(_??[]).filter(t=>t.value!==null),K=g.dragging??ne,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,k.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,W.getSeriesLabel)(t)).join(", "),(0,q.describeAnnotations)(S,fe)].filter(Boolean).join(". "),tabIndex:0,className:(0,Te.cn)(Ke.CHART_TOUCH,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500",Z&&"select-none"),onPointerDown:g.onPointerDown,onPointerMove:T,onPointerUp:g.onPointerUp,onPointerCancel:g.onPointerUp,onPointerLeave:$,onKeyDown:Pe,onBlur:$,onClick:D,children:[(0,n.jsxs)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[(0,n.jsx)(Ee.ChartGrid,{width:e.innerWidth,height:e.innerHeight,horizontal:b==="y"||b==="both"?e.yTicks.map(t=>t.offset):void 0,vertical:b==="x"||b==="both"?e.xTicks.map(t=>t.offset):void 0}),S?(0,n.jsx)(q.ChartAnnotationLayer,{layer:"under",annotations:S,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),c=o<Je?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:c,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)(Qe,{lines:e.lines,showMarkers:e.showMarkers}),S?(0,n.jsx)(q.ChartAnnotationLayer,{annotations:S,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:d.hidden?null:(0,n.jsx)(we.ChartAxis,{orientation:"bottom",ticks:e.xTicks,length:e.innerWidth,label:d.label,size:Q})}),(0,n.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:C?.hidden?null:(0,n.jsx)(we.ChartAxis,{orientation:"left",ticks:e.yTicks,length:e.innerHeight,showLine:!1,label:C?.label,size:Q})})]}),y&&w!==!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 w=="function"?w(y):(0,n.jsx)(he.ChartTooltipContent,{title:y.xLabel,points:y.points})}):null]})}function et({data:u,series:a,x:r,y:s,height:d=240,width:C,size:b="md",grid:Q="y",legend:x,tooltip:M=!0,tableView:v=!1,emphasis:P,title:L,description:me,loading:S=!1,emptyState:fe,error:ge=!1,errorState:R,onRetry:Z,actions:ee,onPointClick:pe,curve:ye="monotone",forecastFrom:te,forecastLabel:w,markers:V="auto",connectNulls:Ce=!1,referenceLines:A,annotations:N,overlay:X,legendToggle:G=!0,maxPoints:h,brush:be=!1,onBrush:xe,brushLabel:ke,sync:m=!0,margin:e,locale:O,plotLabel:ne,className:ve,...g}){let T=(0,ie.useUILocale)(O),$=(0,ie.useUILabels)(),[B,Pe]=(0,l.useState)(()=>new Set),D=(0,l.useMemo)(()=>a.map((i,y)=>({...i,hidden:i.hidden||B.has(i.key),color:(0,W.resolveSeriesColor)(i,y,P)})),[a,B,P]),re=(0,l.useMemo)(()=>s?.format??(i=>(0,ce.formatAuto)(i,T)),[s?.format,T]),p=(0,l.useMemo)(()=>r.format??(i=>r.scale==="time"?(0,De.formatTimeValue)(i,T):(0,ce.formatXValue)(i,T)),[r.format,r.scale,T]),_=(0,l.useCallback)(i=>{Pe(y=>{let t=new Set(y);return t.has(i)?t.delete(i):t.add(i),t})},[]),z=x===void 0?a.length>=2:x!==!1,K=typeof x=="string"?x:"bottom",U=D.filter(i=>!i.hidden).length;return(0,n.jsx)(Be.ChartContainer,{title:L,description:me,height:d,width:C,size:b,loading:S,empty:u.length===0||U===0,emptyState:fe,error:ge,errorState:R,onRetry:Z,actions:ee,tableView:v,legendPosition:K,legend:z?(0,n.jsx)(He.ChartLegend,{items:(0,W.toLegendItems)(D,P),position:K,marker:"line",size:b,onToggle:G?_:void 0}):void 0,table:v?(0,n.jsx)(Ie.ChartTableView,{data:u,series:D,xKey:r.key,xLabel:r.label??r.key,formatX:p,formatValue:re,caption:typeof L=="string"?L:void 0}):void 0,className:ve,...g,children:({width:i})=>(0,n.jsx)(Ze,{width:i,height:d,data:u,resolvedSeries:D,x:r,y:s,grid:Q,size:b,curve:ye,forecastFrom:te,forecastLabel:w,markers:V,connectNulls:Ce,referenceLines:A,annotations:N,annotationsLabel:$.chartAnnotations,overlay:X,maxPoints:h,brush:be,onBrush:xe,brushLabel:ke??$.chartBrush,syncEnabled:m,margin:e,tooltip:M,onPointClick:pe,plotLabel:ne,formatValue:re,formatX:p})})}0&&(module.exports={LineChart});
|
|
1
|
+
"use strict";"use client";var Te=Object.defineProperty;var je=Object.getOwnPropertyDescriptor;var ze=Object.getOwnPropertyNames;var Fe=Object.prototype.hasOwnProperty;var Ye=(l,s)=>{for(var n in s)Te(l,n,{get:s[n],enumerable:!0})},qe=(l,s,n,a)=>{if(s&&typeof s=="object"||typeof s=="function")for(let c of ze(s))!Fe.call(l,c)&&c!==n&&Te(l,c,{get:()=>s[c],enumerable:!(a=je(s,c))||a.enumerable});return l};var Je=l=>qe(Te({},"__esModule",{value:!0}),l);var it={};Ye(it,{LineChart:()=>st,resetLineChartWarnings:()=>nt});module.exports=Je(it);var u=require("react"),Ne=require("../../lib/cn.cjs"),pe=require("../../lib/i18n.cjs"),Q=require("../chart/ChartAnnotations.cjs"),Be=require("../chart/ChartAxis.cjs"),G=require("../chart/ChartBrush.cjs"),Me=require("../chart/ChartContainer.cjs"),De=require("../chart/ChartGrid.cjs"),Ke=require("../chart/ChartLegend.cjs"),Xe=require("../chart/ChartSync.cjs"),Ge=require("../chart/ChartTableView.cjs"),ye=require("../chart/ChartTooltip.cjs"),P=require("../chart/palette.cjs"),m=require("../chart/utils/cartesian.cjs"),Z=require("../chart/utils/data.cjs"),Ce=require("../chart/utils/decimate.cjs"),O=require("../chart/utils/format.cjs"),be=require("../chart/utils/keyboard.cjs"),M=require("../chart/utils/path.cjs"),E=require("../chart/utils/scales.cjs"),Oe=require("../chart/utils/ticks.cjs"),ee=require("../chart/utils/timestamp.cjs"),_e=require("../chart/utils/touch.cjs"),o=require("react/jsx-runtime"),Qe=6,Ze=24,et=10,tt=10,He=!1;function nt(){He=!1}function rt(l,s){let n=(0,E.toKey)(s),a=l.findIndex(C=>(0,E.toKey)(C)===n);if(a>=0)return a;let c=(0,ee.toTimestamp)(s);return c===null?-1:l.findIndex(C=>{let b=(0,ee.toTimestamp)(C);return b!==null&&b>=c})}var ot=(0,u.memo)(function({lines:s,showMarkers:n}){return(0,o.jsx)("g",{children:s.map(a=>(0,o.jsxs)("g",{children:[a.solid?(0,o.jsx)("path",{d:a.solid,fill:"none",stroke:a.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}):null,a.dashed?(0,o.jsx)("path",{d:a.dashed,fill:"none",stroke:a.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"5 4"}):null,(n?a.markers:a.isolated).map((c,C)=>(0,o.jsx)("circle",{cx:c.x,cy:c.y,r:3,fill:a.color,strokeWidth:2,stroke:P.CHART_SURFACE_COLOR},C))]},a.key))})});function at({width:l,height:s,data:n,resolvedSeries:a,x:c,y:C,grid:b,size:te,curve:w,forecastFrom:T,forecastLabel:B,markers:H,connectNulls:W,referenceLines:_,annotations:L,annotationsLabel:xe,overlay:ve,maxPoints:I,brush:ne,onBrush:re,brushLabel:ke,syncEnabled:Pe,margin:oe,tooltip:N,onPointClick:S,plotLabel:Le,formatValue:$,formatExact:ae,formatX:D,locale:se}){let[U,j]=(0,u.useState)(null),d=U!==null&&U<n.length?U:null,[Se,we]=(0,u.useState)(null),Re=(0,Xe.useChartSync)(),f=Pe?Re:null,e=(0,u.useMemo)(()=>{let t=a.filter(p=>!p.hidden),r=(0,m.buildCartesianGeometry)({locale:se,width:l,height:s,data:n,x:c,y:C,bounds:(0,m.widenBounds)((0,Oe.extent)((0,Z.collectAllValues)(n,t.map(p=>p.key))),(0,m.annotationValues)(n,c.key,_,L)),margin:oe,placement:"point",formatValue:$,formatX:D,extraTop:B?et:0}),h=r.categoryCenters,g=r.valueScale,V=T===void 0?-1:rt(r.xValues,T);T!==void 0&&V<0&&n.length>0&&!He&&(He=!0,console.warn(`[@synertech/ui] LineChart was given \`forecastFrom\` = ${String(T)}, which no row is on or after. Nothing is drawn as a forecast: pass the x value of the first projected row, in the form the rows carry it.`));let me=t.map(p=>{let Y=n.map((ge,Ue)=>{let Ee=(0,Z.readNumber)(ge,p.key);return{x:h[Ue],y:Ee===null?Number.NaN:g(Ee),defined:Ee!==null}}),We={connectNulls:W},fe=V>=0,Ae=ge=>I&&I>0?(0,Ce.decimatePath)(ge,I):ge,q=p.dashed?[]:Ae(fe?Y.slice(0,V+1):Y),J=p.dashed?Ae(Y):fe?Ae(Y.slice(V)):[];I||(0,Ce.warnPointBudget)("LineChart",Y.length);let $e=q[q.length-1],Ie=p.dashed?J:fe?[...q,...J[0]===$e?J.slice(1):J]:q;return{key:p.key,color:p.color,solid:p.dashed?"":(0,M.buildLinePath)(q,w,We),dashed:p.dashed||fe?(0,M.buildLinePath)(J,w,We):"",markers:Ie.filter(M.isDrawable),isolated:(0,M.isolatedPoints)(Ie,W)}}),A=n.length>1?r.innerWidth/(n.length-1):0;return{visible:t,locate:(0,m.createCategoryLocator)(r),span:(0,m.createSpanLocator)(r),plot:(0,m.createPlotContext)({geometry:r,width:l,height:s,data:n,series:t,formatValue:$,formatX:D}),xValues:r.xValues,xPositions:h,xTicks:r.categoryTicks,yTicks:r.valueTicks,yScale:g,innerWidth:r.innerWidth,innerHeight:r.innerHeight,margin:r.margin,lines:me,forecastIndex:V,showMarkers:H==="always"||H==="auto"&&A>=Ze&&n.length>1}},[se,n,a,c,C,l,s,oe,w,W,T,B,H,I,_,L,$,D]),z=(0,u.useCallback)(t=>e.visible.map(r=>{let h=(0,Z.readNumber)(n[t],r.key);return{seriesKey:r.key,seriesLabel:(0,P.getSeriesLabel)(r),color:r.color,value:h,formattedValue:h===null?"\u2014":ae(h),datum:n[t]}}),[n,e.visible,ae]),ie=f?f.brush:Se,x=(0,u.useCallback)(t=>{we(t),f?.setBrush(t),re?.(t)},[f,re]),y=(0,G.useChartBrush)({enabled:ne,active:ie!==null,centers:e.xPositions,xValues:e.xValues,offset:e.margin.left,orientation:"vertical",onCommit:x}),le=(0,u.useCallback)(t=>{if(y.onPointerMove(t),N===!1||n.length===0)return;let r=t.currentTarget.getBoundingClientRect(),h=t.clientX-r.left-e.margin.left,g=(0,E.nearestIndex)(e.xPositions,h);j(g>=0?g:null),f?.setHovered(g>=0?e.xValues[g]:null)},[y,N,n.length,e.margin.left,e.xPositions,e.xValues,f]),ue=(0,u.useCallback)(()=>{j(null),f?.setHovered(null)},[f]),v=(0,u.useCallback)((t,r)=>{if(!S)return;let h=z(t),g=h.filter(A=>A.value!==null),V=A=>r===null?0:Math.abs(e.yScale(A.value)-r.y),me=g.length>0?g.reduce((A,p)=>V(p)<V(A)?p:A):h[0];me&&S({...me,index:t,x:e.xValues[t]})},[S,z,e.yScale,e.xValues]),Ve=(0,u.useCallback)(t=>{if(n.length===0)return;let r=S&&d!==null&&e.visible.length>0;if((0,be.pressChartMark)(t,r?()=>v(d,null):null))return;let h=y.onKeyDown(t,d),g=(0,be.chartCursorTarget)(t.key,d,n.length,"x");if(g===void 0){h&&t.preventDefault();return}t.preventDefault(),j(g),f?.setHovered(g===null?null:e.xValues[g])},[n.length,d,y,f,e.xValues,e.visible.length,S,v]),ce=(0,u.useCallback)(t=>{if(y.consumedClick()||!S||n.length===0)return;let r=(0,m.plotPointer)(t,e),h=d??(r===null?-1:(0,E.nearestIndex)(e.xPositions,r.x));h<0||v(h,r)},[y,S,n.length,e,d,v]),he=d!==null||f===null||f.hovered===null?null:(()=>{let t=(0,E.toKey)(f.hovered),r=e.xValues.findIndex(h=>(0,E.toKey)(h)===t);return r<0?null:r})(),R=d??he,F=R===null?null:z(R),K=(F??[]).filter(t=>t.value!==null),de=y.dragging??ie,i=de?(0,G.locateBrush)(de,e.xValues,e.xPositions,e.locate):null,X=(0,m.splitOverlay)(ve),k=d===null||F===null?null:{x:e.xValues[d],xLabel:D(e.xValues[d],d),index:d,points:F};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)("svg",{width:l,height:s,role:"img","aria-label":Le??[e.visible.map(t=>(0,P.getSeriesLabel)(t)).join(", "),(0,Q.describeAnnotations)(L,xe)].filter(Boolean).join(". "),tabIndex:0,className:(0,Ne.cn)(_e.CHART_TOUCH,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500",ne&&"select-none"),onPointerDown:y.onPointerDown,onPointerMove:le,onPointerUp:y.onPointerUp,onPointerCancel:y.onPointerUp,onPointerLeave:ue,onKeyDown:Ve,onBlur:ue,onClick:ce,children:[(0,o.jsxs)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[(0,o.jsx)(De.ChartGrid,{width:e.innerWidth,height:e.innerHeight,horizontal:b==="y"||b==="both"?e.yTicks.map(t=>t.offset):void 0,vertical:b==="x"||b==="both"?e.xTicks.map(t=>t.offset):void 0}),L?(0,o.jsx)(Q.ChartAnnotationLayer,{layer:"under",annotations:L,xAt:e.locate,spanAt:e.span,yAt:e.yScale,width:e.innerWidth,height:e.innerHeight}):null,i?(0,o.jsx)(G.ChartBrushLayer,{from:i.from,to:i.to,width:e.innerWidth,height:e.innerHeight,live:y.dragging!==null,label:ke,minSpan:Qe}):null,X.under?.(e.plot),_?.map(t=>{let r=e.yScale(t.value),h=r<tt?r+12:r-4;return(0,o.jsxs)("g",{children:[(0,o.jsx)("line",{x1:0,y1:r,x2:e.innerWidth,y2:r,stroke:t.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:t.dashed===!1?void 0:"4 4"}),t.label?(0,o.jsx)("text",{x:e.innerWidth,y:h,textAnchor:"end",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)}),e.forecastIndex>=0?(0,o.jsxs)("g",{children:[(0,o.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"}),B?(0,o.jsx)("text",{x:e.xPositions[e.forecastIndex]+4,y:-2,className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:B}):null]}):null,(0,o.jsx)(ot,{lines:e.lines,showMarkers:e.showMarkers}),L?(0,o.jsx)(Q.ChartAnnotationLayer,{annotations:L,xAt:e.locate,yAt:e.yScale,width:e.innerWidth,height:e.innerHeight}):null,X.over?.(e.plot),R!==null?(0,o.jsxs)("g",{"aria-hidden":"true",children:[(0,o.jsx)("line",{x1:e.xPositions[R],y1:0,x2:e.xPositions[R],y2:e.innerHeight,className:"stroke-gray-400 dark:stroke-gray-500",strokeWidth:1,strokeDasharray:d===null?"3 3":void 0}),K.map(t=>(0,o.jsx)("circle",{cx:e.xPositions[R],cy:e.yScale(t.value),r:4,fill:t.color,strokeWidth:2,stroke:P.CHART_SURFACE_COLOR},t.seriesKey))]}):null]}),(0,o.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:c.hidden?null:(0,o.jsx)(Be.ChartAxis,{orientation:"bottom",ticks:e.xTicks,length:e.innerWidth,label:c.label,size:te})}),(0,o.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:C?.hidden?null:(0,o.jsx)(Be.ChartAxis,{orientation:"left",ticks:e.yTicks,length:e.innerHeight,showLine:!1,label:C?.label,size:te})})]}),k&&N!==!1?(0,o.jsx)(ye.ChartTooltip,{x:e.margin.left+e.xPositions[k.index],y:e.margin.top+(K.length>0?Math.min(...K.map(t=>e.yScale(t.value))):e.innerHeight/2),containerWidth:l,children:typeof N=="function"?N(k):(0,o.jsx)(ye.ChartTooltipContent,{title:k.xLabel,points:k.points})}):null]})}function st({data:l,series:s,x:n,y:a,height:c=240,width:C,size:b="md",grid:te="y",legend:w,tooltip:T=!0,tableView:B=!1,emphasis:H,title:W,description:_,loading:L=!1,emptyState:xe,error:ve=!1,errorState:I,onRetry:ne,actions:re,onPointClick:ke,curve:Pe="monotone",forecastFrom:oe,forecastLabel:N,markers:S="auto",connectNulls:Le=!1,referenceLines:$,annotations:ae,overlay:D,legendToggle:se=!0,maxPoints:U,brush:j=!1,onBrush:d,brushLabel:Se,sync:we=!0,margin:Re,locale:f,plotLabel:e,className:z,...ie}){let x=(0,pe.useUILocale)(f),y=(0,pe.useUILabels)(),[le,ue]=(0,u.useState)(()=>new Set),v=(0,u.useMemo)(()=>s.map((i,X)=>({...i,hidden:i.hidden||le.has(i.key),color:(0,P.resolveSeriesColor)(i,X,H)})),[s,le,H]),Ve=(0,u.useMemo)(()=>a?.format??(i=>(0,O.formatAuto)(i,x)),[a?.format,x]),ce=(0,u.useMemo)(()=>a?.format??(i=>(0,O.formatExact)(i,x)),[a?.format,x]),he=(0,u.useMemo)(()=>n.format??(i=>n.scale==="time"?(0,ee.formatTimeValue)(i,x):(0,O.formatXValue)(i,x)),[n.format,n.scale,x]),R=(0,u.useCallback)(i=>{ue(X=>{let k=new Set(X);return k.has(i)?k.delete(i):k.add(i),k})},[]),F=w===void 0?s.length>=2:w!==!1,K=typeof w=="string"?w:"bottom",de=v.filter(i=>!i.hidden).length;return(0,o.jsx)(Me.ChartContainer,{title:W,description:_,height:c,width:C,size:b,loading:L,empty:l.length===0||de===0,emptyState:xe,error:ve,errorState:I,onRetry:ne,actions:re,exportSource:{data:l,series:v,xKey:n.key,xLabel:n.label??n.key,formatX:n.format},tableView:B,legendPosition:K,legend:F?(0,o.jsx)(Ke.ChartLegend,{items:(0,P.toLegendItems)(v,H),position:K,marker:"line",size:b,onToggle:se?R:void 0}):void 0,table:B?(0,o.jsx)(Ge.ChartTableView,{data:l,series:v,xKey:n.key,xLabel:n.label??n.key,formatX:he,formatValue:ce,caption:typeof W=="string"?W:void 0}):void 0,className:z,...ie,children:({width:i})=>(0,o.jsx)(at,{locale:x,width:i,height:c,data:l,resolvedSeries:v,x:n,y:a,grid:te,size:b,curve:Pe,forecastFrom:oe,forecastLabel:N,markers:S,connectNulls:Le,referenceLines:$,annotations:ae,annotationsLabel:y.chartAnnotations,overlay:D,maxPoints:U,brush:j,onBrush:d,brushLabel:Se??y.chartBrush,syncEnabled:we,margin:Re,tooltip:T,onPointClick:ke,plotLabel:e,formatValue:Ve,formatExact:ce,formatX:he})})}0&&(module.exports={LineChart,resetLineChartWarnings});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{memo as Ae,useCallback as x,useMemo as re,useState as ye}from"react";import{cn as Te}from"../../lib/cn.js";import{useUILabels as Be,useUILocale as Ee}from"../../lib/i18n.js";import{ChartAnnotationLayer as xe,describeAnnotations as He}from"../chart/ChartAnnotations.js";import{ChartAxis as ke}from"../chart/ChartAxis.js";import{ChartBrushLayer as We,useChartBrush as Ie}from"../chart/ChartBrush.js";import{ChartContainer as Ne}from"../chart/ChartContainer.js";import{ChartGrid as De}from"../chart/ChartGrid.js";import{ChartLegend as Ke}from"../chart/ChartLegend.js";import{useChartSync as Me}from"../chart/ChartSync.js";import{ChartTableView as Xe}from"../chart/ChartTableView.js";import{ChartTooltip as Ge,ChartTooltipContent as Oe}from"../chart/ChartTooltip.js";import{getSeriesLabel as ve,resolveSeriesColor as $e,toLegendItems as _e}from"../chart/palette.js";import{buildCartesianGeometry as ze,createCategoryLocator as Ue,createPlotContext as je,splitOverlay as Fe}from"../chart/utils/cartesian.js";import{collectAllValues as Ye,readNumber as Pe}from"../chart/utils/data.js";import{decimatePath as qe,warnPointBudget as Je}from"../chart/utils/decimate.js";import{formatAuto as Qe,formatXValue as Ze}from"../chart/utils/format.js";import{chartCursorTarget as et,pressChartMark as tt}from"../chart/utils/keyboard.js";import{buildLinePath as Le,isDrawable as nt,isolatedPoints as rt}from"../chart/utils/path.js";import{nearestIndex as ot,toKey as ne}from"../chart/utils/scales.js";import{extent as at}from"../chart/utils/ticks.js";import{formatTimeValue as st}from"../chart/utils/timestamp.js";import{CHART_TOUCH as it}from"../chart/utils/touch.js";import{Fragment as mt,jsx as o,jsxs as E}from"react/jsx-runtime";var lt=24,ht=10,ut=10,ct=Ae(function({lines:m,showMarkers:r}){return o("g",{children:m.map(i=>E("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((f,y)=>o("circle",{cx:f.x,cy:f.y,r:3,fill:i.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},y))]},i.key))})});function dt({width:d,height:m,data:r,resolvedSeries:i,x:f,y,grid:C,size:j,curve:b,forecastFrom:N,forecastLabel:k,markers:v,connectNulls:P,referenceLines:oe,annotations:L,annotationsLabel:ae,overlay:se,maxPoints:S,brush:F,onBrush:Y,brushLabel:ie,syncEnabled:le,margin:q,tooltip:R,onPointClick:w,plotLabel:he,formatValue:V,formatX:H}){let[D,K]=ye(null),s=D!==null&&D<r.length?D:null,[ue,ce]=ye(null),de=Me(),h=le?de:null,e=re(()=>{let t=i.filter(u=>!u.hidden),n=ze({width:d,height:m,data:r,x:f,y,bounds:at(Ye(r,t.map(u=>u.key))),margin:q,placement:"point",formatValue:V,formatX:H,extraTop:k?ht:0}),l=n.categoryCenters,B=n.valueScale,Z=N===void 0?-1:n.xValues.findIndex(u=>ne(u)===ne(N)),Se=t.map(u=>{let _=r.map((te,Ve)=>{let pe=Pe(te,u.key);return{x:l[Ve],y:pe===null?Number.NaN:B(pe),defined:pe!==null}}),Ce={connectNulls:P},ee=Z>=0,ge=te=>S&&S>0?qe(te,S):te,z=u.dashed?[]:ge(ee?_.slice(0,Z+1):_),U=u.dashed?ge(_):ee?ge(_.slice(Z)):[];S||Je("LineChart",_.length);let we=z[z.length-1],be=u.dashed?U:ee?[...z,...U[0]===we?U.slice(1):U]:z;return{key:u.key,color:u.color,solid:u.dashed?"":Le(z,b,Ce),dashed:u.dashed||ee?Le(U,b,Ce):"",markers:be.filter(nt),isolated:rt(be,P)}}),Re=r.length>1?n.innerWidth/(r.length-1):0;return{visible:t,locate:Ue(n),plot:je({geometry:n,width:d,height:m,data:r,series:t,formatValue:V,formatX:H}),xValues:n.xValues,xPositions:l,xTicks:n.categoryTicks,yTicks:n.valueTicks,yScale:B,innerWidth:n.innerWidth,innerHeight:n.innerHeight,margin:n.margin,lines:Se,forecastIndex:Z,showMarkers:v==="always"||v==="auto"&&Re>=lt&&r.length>1}},[r,i,f,y,d,m,q,b,P,N,k,v,S,V,H]),M=x(t=>e.visible.map(n=>{let l=Pe(r[t],n.key);return{seriesKey:n.key,seriesLabel:ve(n),color:n.color,value:l,formattedValue:l===null?"\u2014":V(l),datum:r[t]}}),[r,e.visible,V]),J=h?h.brush:ue,me=x(t=>{ce(t),h?.setBrush(t),Y?.(t)},[h,Y]),c=Ie({enabled:F,active:J!==null,centers:e.xPositions,xValues:e.xValues,offset:e.margin.left,orientation:"vertical",onCommit:me}),A=x(t=>{if(c.onPointerMove(t),R===!1||r.length===0)return;let n=t.currentTarget.getBoundingClientRect(),l=t.clientX-n.left-e.margin.left,B=ot(e.xPositions,l);K(B>=0?B:null),h?.setHovered(B>=0?e.xValues[B]:null)},[c,R,r.length,e.margin.left,e.xPositions,e.xValues,h]),X=x(()=>{K(null),h?.setHovered(null)},[h]),T=x(()=>{if(!w||s===null)return;let[t]=M(s);t&&w({...t,index:s,x:e.xValues[s]})},[w,s,M,e.xValues]),fe=x(t=>{if(r.length===0)return;let n=w&&s!==null&&e.visible.length>0;if(tt(t,n?T:null))return;c.onKeyDown(t,s);let l=et(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,w,T]),W=x(()=>{c.consumedClick()||T()},[c,T]),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=g===null?null:M(g),O=(G??[]).filter(t=>t.value!==null),I=c.dragging??J,$=(()=>{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=Fe(se),p=s===null||G===null?null:{x:e.xValues[s],xLabel:H(e.xValues[s],s),index:s,points:G};return E(mt,{children:[E("svg",{width:d,height:m,role:"img","aria-label":he??[e.visible.map(t=>ve(t)).join(", "),He(L,ae)].filter(Boolean).join(". "),tabIndex:0,className:Te(it,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500",F&&"select-none"),onPointerDown:c.onPointerDown,onPointerMove:A,onPointerUp:c.onPointerUp,onPointerCancel:c.onPointerUp,onPointerLeave:X,onKeyDown:fe,onBlur:X,onClick:W,children:[E("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[o(De,{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?o(xe,{layer:"under",annotations:L,xAt:e.locate,yAt:e.yScale,width:e.innerWidth,height:e.innerHeight}):null,$?o(We,{from:$.from,to:$.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<ut?n+12:n-4;return E("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?E("g",{children:[o("line",{x1:e.xPositions[e.forecastIndex],y1:0,x2:e.xPositions[e.forecastIndex],y2:e.innerHeight,className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1,strokeDasharray:"3 3"}),k?o("text",{x:e.xPositions[e.forecastIndex]+4,y:-2,className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:k}):null]}):null,o(ct,{lines:e.lines,showMarkers:e.showMarkers}),L?o(xe,{annotations:L,xAt:e.locate,yAt:e.yScale,width:e.innerWidth,height:e.innerHeight}):null,a.over?.(e.plot),g!==null?E("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}),O.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:f.hidden?null:o(ke,{orientation:"bottom",ticks:e.xTicks,length:e.innerWidth,label:f.label,size:j})}),o("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:y?.hidden?null:o(ke,{orientation:"left",ticks:e.yTicks,length:e.innerHeight,showLine:!1,label:y?.label,size:j})})]}),p&&R!==!1?o(Ge,{x:e.margin.left+e.xPositions[p.index],y:e.margin.top+(O.length>0?Math.min(...O.map(t=>e.yScale(t.value))):e.innerHeight/2),containerWidth:d,children:typeof R=="function"?R(p):o(Oe,{title:p.xLabel,points:p.points})}):null]})}function Dt({data:d,series:m,x:r,y:i,height:f=240,width:y,size:C="md",grid:j="y",legend:b,tooltip:N=!0,tableView:k=!1,emphasis:v,title:P,description:oe,loading:L=!1,emptyState:ae,error:se=!1,errorState:S,onRetry:F,actions:Y,onPointClick:ie,curve:le="monotone",forecastFrom:q,forecastLabel:R,markers:w="auto",connectNulls:he=!1,referenceLines:V,annotations:H,overlay:D,legendToggle:K=!0,maxPoints:s,brush:ue=!1,onBrush:ce,brushLabel:de,sync:h=!0,margin:e,locale:M,plotLabel:J,className:me,...c}){let A=Ee(M),X=Be(),[T,fe]=ye(()=>new Set),W=re(()=>m.map((a,p)=>({...a,hidden:a.hidden||T.has(a.key),color:$e(a,p,v)})),[m,T,v]),Q=re(()=>i?.format??(a=>Qe(a,A)),[i?.format,A]),g=re(()=>r.format??(a=>r.scale==="time"?st(a,A):Ze(a,A)),[r.format,r.scale,A]),G=x(a=>{fe(p=>{let t=new Set(p);return t.has(a)?t.delete(a):t.add(a),t})},[]),O=b===void 0?m.length>=2:b!==!1,I=typeof b=="string"?b:"bottom",$=W.filter(a=>!a.hidden).length;return o(Ne,{title:P,description:oe,height:f,width:y,size:C,loading:L,empty:d.length===0||$===0,emptyState:ae,error:se,errorState:S,onRetry:F,actions:Y,tableView:k,legendPosition:I,legend:O?o(Ke,{items:_e(W,v),position:I,marker:"line",size:C,onToggle:K?G:void 0}):void 0,table:k?o(Xe,{data:d,series:W,xKey:r.key,xLabel:r.label??r.key,formatX:g,formatValue:Q,caption:typeof P=="string"?P:void 0}):void 0,className:me,...c,children:({width:a})=>o(dt,{width:a,height:f,data:d,resolvedSeries:W,x:r,y:i,grid:j,size:C,curve:le,forecastFrom:q,forecastLabel:R,markers:w,connectNulls:he,referenceLines:V,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:J,formatValue:Q,formatX:g})})}export{Dt as LineChart};
|
|
1
|
+
"use client";import{memo as Ie,useCallback as R,useMemo as z,useState as ve}from"react";import{cn as Ne}from"../../lib/cn.js";import{useUILabels as Me,useUILocale as De}from"../../lib/i18n.js";import{ChartAnnotationLayer as Se,describeAnnotations as Ke}from"../chart/ChartAnnotations.js";import{ChartAxis as we}from"../chart/ChartAxis.js";import{ChartBrushLayer as Xe,locateBrush as Ge,useChartBrush as Oe}from"../chart/ChartBrush.js";import{ChartContainer as _e}from"../chart/ChartContainer.js";import{ChartGrid as $e}from"../chart/ChartGrid.js";import{ChartLegend as Ue}from"../chart/ChartLegend.js";import{useChartSync as je}from"../chart/ChartSync.js";import{ChartTableView as ze}from"../chart/ChartTableView.js";import{ChartTooltip as Fe,ChartTooltipContent as Ye}from"../chart/ChartTooltip.js";import{CHART_SURFACE_COLOR as Be,getSeriesLabel as Re,resolveSeriesColor as qe,toLegendItems as Je}from"../chart/palette.js";import{annotationValues as Qe,buildCartesianGeometry as Ze,createCategoryLocator as et,createPlotContext as tt,createSpanLocator as nt,plotPointer as rt,splitOverlay as ot,widenBounds as at}from"../chart/utils/cartesian.js";import{collectAllValues as st,readNumber as Ve}from"../chart/utils/data.js";import{decimatePath as it,warnPointBudget as lt}from"../chart/utils/decimate.js";import{formatAuto as ut,formatExact as ct,formatXValue as ht}from"../chart/utils/format.js";import{chartCursorTarget as dt,pressChartMark as mt}from"../chart/utils/keyboard.js";import{buildLinePath as Ae,isDrawable as ft,isolatedPoints as gt}from"../chart/utils/path.js";import{nearestIndex as Ee,toKey as ue}from"../chart/utils/scales.js";import{extent as pt}from"../chart/utils/ticks.js";import{formatTimeValue as yt,toTimestamp as Te}from"../chart/utils/timestamp.js";import{CHART_TOUCH as bt}from"../chart/utils/touch.js";import{Fragment as wt,jsx as o,jsxs as W}from"react/jsx-runtime";var Ct=6,xt=24,vt=10,kt=10,ke=!1;function qt(){ke=!1}function Pt(d,g){let n=ue(g),s=d.findIndex(p=>ue(p)===n);if(s>=0)return s;let m=Te(g);return m===null?-1:d.findIndex(p=>{let y=Te(p);return y!==null&&y>=m})}var Lt=Ie(function({lines:g,showMarkers:n}){return o("g",{children:g.map(s=>W("g",{children:[s.solid?o("path",{d:s.solid,fill:"none",stroke:s.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}):null,s.dashed?o("path",{d:s.dashed,fill:"none",stroke:s.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"5 4"}):null,(n?s.markers:s.isolated).map((m,p)=>o("circle",{cx:m.x,cy:m.y,r:3,fill:s.color,strokeWidth:2,stroke:Be},p))]},s.key))})});function St({width:d,height:g,data:n,resolvedSeries:s,x:m,y:p,grid:y,size:F,curve:P,forecastFrom:V,forecastLabel:A,markers:E,connectNulls:T,referenceLines:D,annotations:v,annotationsLabel:ce,overlay:he,maxPoints:B,brush:Y,onBrush:q,brushLabel:de,syncEnabled:me,margin:J,tooltip:H,onPointClick:k,plotLabel:fe,formatValue:K,formatExact:Q,formatX:I,locale:Z}){let[X,G]=ve(null),l=X!==null&&X<n.length?X:null,[ge,pe]=ve(null),ye=je(),u=me?ye:null,e=z(()=>{let t=s.filter(h=>!h.hidden),r=Ze({locale:Z,width:d,height:g,data:n,x:m,y:p,bounds:at(pt(st(n,t.map(h=>h.key))),Qe(n,m.key,D,v)),margin:J,placement:"point",formatValue:K,formatX:I,extraTop:A?vt:0}),i=r.categoryCenters,c=r.valueScale,S=V===void 0?-1:Pt(r.xValues,V);V!==void 0&&S<0&&n.length>0&&!ke&&(ke=!0,console.warn(`[@synertech/ui] LineChart was given \`forecastFrom\` = ${String(V)}, which no row is on or after. Nothing is drawn as a forecast: pass the x value of the first projected row, in the form the rows carry it.`));let se=t.map(h=>{let $=n.map((le,We)=>{let xe=Ve(le,h.key);return{x:i[We],y:xe===null?Number.NaN:c(xe),defined:xe!==null}}),Pe={connectNulls:T},ie=S>=0,be=le=>B&&B>0?it(le,B):le,U=h.dashed?[]:be(ie?$.slice(0,S+1):$),j=h.dashed?be($):ie?be($.slice(S)):[];B||lt("LineChart",$.length);let He=U[U.length-1],Le=h.dashed?j:ie?[...U,...j[0]===He?j.slice(1):j]:U;return{key:h.key,color:h.color,solid:h.dashed?"":Ae(U,P,Pe),dashed:h.dashed||ie?Ae(j,P,Pe):"",markers:Le.filter(ft),isolated:gt(Le,T)}}),w=n.length>1?r.innerWidth/(n.length-1):0;return{visible:t,locate:et(r),span:nt(r),plot:tt({geometry:r,width:d,height:g,data:n,series:t,formatValue:K,formatX:I}),xValues:r.xValues,xPositions:i,xTicks:r.categoryTicks,yTicks:r.valueTicks,yScale:c,innerWidth:r.innerWidth,innerHeight:r.innerHeight,margin:r.margin,lines:se,forecastIndex:S,showMarkers:E==="always"||E==="auto"&&w>=xt&&n.length>1}},[Z,n,s,m,p,d,g,J,P,T,V,A,E,B,D,v,K,I]),O=R(t=>e.visible.map(r=>{let i=Ve(n[t],r.key);return{seriesKey:r.key,seriesLabel:Re(r),color:r.color,value:i,formattedValue:i===null?"\u2014":Q(i),datum:n[t]}}),[n,e.visible,Q]),ee=u?u.brush:ge,C=R(t=>{pe(t),u?.setBrush(t),q?.(t)},[u,q]),f=Oe({enabled:Y,active:ee!==null,centers:e.xPositions,xValues:e.xValues,offset:e.margin.left,orientation:"vertical",onCommit:C}),te=R(t=>{if(f.onPointerMove(t),H===!1||n.length===0)return;let r=t.currentTarget.getBoundingClientRect(),i=t.clientX-r.left-e.margin.left,c=Ee(e.xPositions,i);G(c>=0?c:null),u?.setHovered(c>=0?e.xValues[c]:null)},[f,H,n.length,e.margin.left,e.xPositions,e.xValues,u]),ne=R(()=>{G(null),u?.setHovered(null)},[u]),b=R((t,r)=>{if(!k)return;let i=O(t),c=i.filter(w=>w.value!==null),S=w=>r===null?0:Math.abs(e.yScale(w.value)-r.y),se=c.length>0?c.reduce((w,h)=>S(h)<S(w)?h:w):i[0];se&&k({...se,index:t,x:e.xValues[t]})},[k,O,e.yScale,e.xValues]),Ce=R(t=>{if(n.length===0)return;let r=k&&l!==null&&e.visible.length>0;if(mt(t,r?()=>b(l,null):null))return;let i=f.onKeyDown(t,l),c=dt(t.key,l,n.length,"x");if(c===void 0){i&&t.preventDefault();return}t.preventDefault(),G(c),u?.setHovered(c===null?null:e.xValues[c])},[n.length,l,f,u,e.xValues,e.visible.length,k,b]),re=R(t=>{if(f.consumedClick()||!k||n.length===0)return;let r=rt(t,e),i=l??(r===null?-1:Ee(e.xPositions,r.x));i<0||b(i,r)},[f,k,n.length,e,l,b]),oe=l!==null||u===null||u.hovered===null?null:(()=>{let t=ue(u.hovered),r=e.xValues.findIndex(i=>ue(i)===t);return r<0?null:r})(),L=l??oe,_=L===null?null:O(L),N=(_??[]).filter(t=>t.value!==null),ae=f.dragging??ee,a=ae?Ge(ae,e.xValues,e.xPositions,e.locate):null,M=ot(he),x=l===null||_===null?null:{x:e.xValues[l],xLabel:I(e.xValues[l],l),index:l,points:_};return W(wt,{children:[W("svg",{width:d,height:g,role:"img","aria-label":fe??[e.visible.map(t=>Re(t)).join(", "),Ke(v,ce)].filter(Boolean).join(". "),tabIndex:0,className:Ne(bt,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500",Y&&"select-none"),onPointerDown:f.onPointerDown,onPointerMove:te,onPointerUp:f.onPointerUp,onPointerCancel:f.onPointerUp,onPointerLeave:ne,onKeyDown:Ce,onBlur:ne,onClick:re,children:[W("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[o($e,{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}),v?o(Se,{layer:"under",annotations:v,xAt:e.locate,spanAt:e.span,yAt:e.yScale,width:e.innerWidth,height:e.innerHeight}):null,a?o(Xe,{from:a.from,to:a.to,width:e.innerWidth,height:e.innerHeight,live:f.dragging!==null,label:de,minSpan:Ct}):null,M.under?.(e.plot),D?.map(t=>{let r=e.yScale(t.value),i=r<kt?r+12:r-4;return W("g",{children:[o("line",{x1:0,y1:r,x2:e.innerWidth,y2:r,stroke:t.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:t.dashed===!1?void 0:"4 4"}),t.label?o("text",{x:e.innerWidth,y:i,textAnchor:"end",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)}),e.forecastIndex>=0?W("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"}),A?o("text",{x:e.xPositions[e.forecastIndex]+4,y:-2,className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:A}):null]}):null,o(Lt,{lines:e.lines,showMarkers:e.showMarkers}),v?o(Se,{annotations:v,xAt:e.locate,yAt:e.yScale,width:e.innerWidth,height:e.innerHeight}):null,M.over?.(e.plot),L!==null?W("g",{"aria-hidden":"true",children:[o("line",{x1:e.xPositions[L],y1:0,x2:e.xPositions[L],y2:e.innerHeight,className:"stroke-gray-400 dark:stroke-gray-500",strokeWidth:1,strokeDasharray:l===null?"3 3":void 0}),N.map(t=>o("circle",{cx:e.xPositions[L],cy:e.yScale(t.value),r:4,fill:t.color,strokeWidth:2,stroke:Be},t.seriesKey))]}):null]}),o("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:m.hidden?null:o(we,{orientation:"bottom",ticks:e.xTicks,length:e.innerWidth,label:m.label,size:F})}),o("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:p?.hidden?null:o(we,{orientation:"left",ticks:e.yTicks,length:e.innerHeight,showLine:!1,label:p?.label,size:F})})]}),x&&H!==!1?o(Fe,{x:e.margin.left+e.xPositions[x.index],y:e.margin.top+(N.length>0?Math.min(...N.map(t=>e.yScale(t.value))):e.innerHeight/2),containerWidth:d,children:typeof H=="function"?H(x):o(Ye,{title:x.xLabel,points:x.points})}):null]})}function Jt({data:d,series:g,x:n,y:s,height:m=240,width:p,size:y="md",grid:F="y",legend:P,tooltip:V=!0,tableView:A=!1,emphasis:E,title:T,description:D,loading:v=!1,emptyState:ce,error:he=!1,errorState:B,onRetry:Y,actions:q,onPointClick:de,curve:me="monotone",forecastFrom:J,forecastLabel:H,markers:k="auto",connectNulls:fe=!1,referenceLines:K,annotations:Q,overlay:I,legendToggle:Z=!0,maxPoints:X,brush:G=!1,onBrush:l,brushLabel:ge,sync:pe=!0,margin:ye,locale:u,plotLabel:e,className:O,...ee}){let C=De(u),f=Me(),[te,ne]=ve(()=>new Set),b=z(()=>g.map((a,M)=>({...a,hidden:a.hidden||te.has(a.key),color:qe(a,M,E)})),[g,te,E]),Ce=z(()=>s?.format??(a=>ut(a,C)),[s?.format,C]),re=z(()=>s?.format??(a=>ct(a,C)),[s?.format,C]),oe=z(()=>n.format??(a=>n.scale==="time"?yt(a,C):ht(a,C)),[n.format,n.scale,C]),L=R(a=>{ne(M=>{let x=new Set(M);return x.has(a)?x.delete(a):x.add(a),x})},[]),_=P===void 0?g.length>=2:P!==!1,N=typeof P=="string"?P:"bottom",ae=b.filter(a=>!a.hidden).length;return o(_e,{title:T,description:D,height:m,width:p,size:y,loading:v,empty:d.length===0||ae===0,emptyState:ce,error:he,errorState:B,onRetry:Y,actions:q,exportSource:{data:d,series:b,xKey:n.key,xLabel:n.label??n.key,formatX:n.format},tableView:A,legendPosition:N,legend:_?o(Ue,{items:Je(b,E),position:N,marker:"line",size:y,onToggle:Z?L:void 0}):void 0,table:A?o(ze,{data:d,series:b,xKey:n.key,xLabel:n.label??n.key,formatX:oe,formatValue:re,caption:typeof T=="string"?T:void 0}):void 0,className:O,...ee,children:({width:a})=>o(St,{locale:C,width:a,height:m,data:d,resolvedSeries:b,x:n,y:s,grid:F,size:y,curve:me,forecastFrom:J,forecastLabel:H,markers:k,connectNulls:fe,referenceLines:K,annotations:Q,annotationsLabel:f.chartAnnotations,overlay:I,maxPoints:X,brush:G,onBrush:l,brushLabel:ge??f.chartBrush,syncEnabled:pe,margin:ye,tooltip:V,onPointClick:de,plotLabel:e,formatValue:Ce,formatExact:re,formatX:oe})})}export{Jt as LineChart,qt as resetLineChartWarnings};
|