@object-ui/plugin-charts 16.1.0 → 17.1.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/CHANGELOG.md +376 -1
- package/dist/AdvancedChartImpl.d.ts +65 -11
- package/dist/ChartRenderer.d.ts +46 -0
- package/dist/ObjectChart.d.ts +17 -1
- package/dist/index.js +1132 -726
- package/dist/index.umd.cjs +2 -2
- package/dist/normalizeChartSchema.d.ts +207 -0
- package/package.json +9 -8
package/dist/index.umd.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@object-ui/core"),require("react"),require("@object-ui/components"),require("react/jsx-runtime"),require("recharts"),require("@object-ui/react"),require("lucide-react"),require("@object-ui/i18n")):typeof define==`function`&&define.amd?define([`exports`,`@object-ui/core`,`react`,`@object-ui/components`,`react/jsx-runtime`,`recharts`,`@object-ui/react`,`lucide-react`,`@object-ui/i18n`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginCharts={},e.ObjectUICore,e.React,e.ObjectUIComponents,e.react_jsx_runtime,e.recharts,e.ObjectUIReact,e.lucide_react,e._object_ui_i18n))})(this,function(e,t,n,r,i,a,o,s,c){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var l=Object.create,u=Object.defineProperty,d=Object.getOwnPropertyDescriptor,f=Object.getOwnPropertyNames,p=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty,h=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},g=(e,t)=>{let n={};for(var r in e)u(n,r,{get:e[r],enumerable:!0});return t||u(n,Symbol.toStringTag,{value:`Module`}),n},_=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=f(t),a=0,o=i.length,s;a<o;a++)s=i[a],!m.call(e,s)&&s!==n&&u(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=d(t,s))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:l(p(e)),_(t||!e||!e.__esModule?u(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);var v=g({default:()=>x});function y(e,t=14){return e.length>t?`${e.slice(0,t-1)}…`:e}function b({x:e,y:t,payload:n}){let r=String(n?.value??``),a=y(r);return(0,i.jsx)(`g`,{transform:`translate(${e},${t})`,children:(0,i.jsxs)(`text`,{dy:10,textAnchor:`end`,transform:`rotate(-32)`,fill:`hsl(var(--muted-foreground))`,fontSize:11,fontFamily:`monospace`,children:[r!==a&&(0,i.jsx)(`title`,{children:r}),a]})})}function x({data:e=[],dataKey:t=`value`,xAxisKey:n=`name`,height:r=400,className:o=``,color:s=`hsl(var(--primary))`}){let c=e.map(e=>String(e?.[n]??``)),l=c.length>4||c.some(e=>e.length>8);return(0,i.jsx)(`div`,{className:`p-2 sm:p-3 md:p-4 rounded-xl border border-border bg-card/40 backdrop-blur-sm shadow-lg shadow-background/5 ${o}`,children:(0,i.jsx)(a.ResponsiveContainer,{width:`100%`,height:r,children:(0,i.jsxs)(a.BarChart,{data:e,margin:{top:10,right:10,left:10,bottom:l?24:5},children:[(0,i.jsxs)(`defs`,{children:[(0,i.jsxs)(`linearGradient`,{id:`barGradient`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,i.jsx)(`stop`,{offset:`0%`,stopColor:s,stopOpacity:1}),(0,i.jsx)(`stop`,{offset:`90%`,stopColor:s,stopOpacity:.6}),(0,i.jsx)(`stop`,{offset:`100%`,stopColor:s,stopOpacity:.3})]}),(0,i.jsxs)(`filter`,{id:`glow`,height:`130%`,children:[(0,i.jsx)(`feGaussianBlur`,{in:`SourceAlpha`,stdDeviation:`3`,result:`blur`}),(0,i.jsx)(`feOffset`,{in:`blur`,dx:`0`,dy:`0`,result:`offsetBlur`}),(0,i.jsx)(`feFlood`,{floodColor:s,floodOpacity:`0.5`,result:`offsetColor`}),(0,i.jsx)(`feComposite`,{in:`offsetColor`,in2:`offsetBlur`,operator:`in`,result:`offsetBlur`}),(0,i.jsxs)(`feMerge`,{children:[(0,i.jsx)(`feMergeNode`,{in:`offsetBlur`}),(0,i.jsx)(`feMergeNode`,{in:`SourceGraphic`})]})]})]}),(0,i.jsx)(a.CartesianGrid,{strokeDasharray:`3 3`,stroke:`hsl(var(--border))`,vertical:!1}),(0,i.jsx)(a.XAxis,{dataKey:n,tick:l?(0,i.jsx)(b,{}):{fill:`hsl(var(--muted-foreground))`,fontSize:12,fontFamily:`monospace`},tickLine:!1,axisLine:{stroke:`hsl(var(--border))`},interval:0,height:l?56:void 0,dy:l?void 0:10}),(0,i.jsx)(a.YAxis,{tick:{fill:`hsl(var(--muted-foreground))`,fontSize:12,fontFamily:`monospace`},tickLine:!1,axisLine:!1}),(0,i.jsx)(a.Tooltip,{cursor:{fill:`hsl(var(--muted))`,opacity:.2},contentStyle:{backgroundColor:`hsl(var(--popover))`,borderColor:`hsl(var(--border))`,color:`hsl(var(--popover-foreground))`,borderRadius:`8px`,fontFamily:`monospace`,boxShadow:`0 4px 6px -1px rgb(0 0 0 / 0.1)`},itemStyle:{color:`hsl(var(--primary))`}}),(0,i.jsx)(a.Legend,{wrapperStyle:{paddingTop:`20px`,fontFamily:`monospace`}}),(0,i.jsx)(a.Bar,{dataKey:t,fill:`url(#barGradient)`,radius:[4,4,0,0],filter:`url(#glow)`,animationDuration:1500})]})})})}var S=h((()=>{}));function C(){let e=n.useContext(A);if(!e)throw Error(`useChart must be used within a <ChartContainer />`);return e}function w({id:e,className:t,children:r,config:o,disableSettleRemount:s,...c}){let l=n.useId(),u=`chart-${e||l.replace(/:/g,``)}`,d=n.useRef(null),[f,p]=n.useState(0);return n.useEffect(()=>{if(s)return;let e=d.current;if(e==null||typeof ResizeObserver>`u`)return;let t=!1,n,r=new ResizeObserver(e=>{if(t)return;let i=e[0]?.contentRect;i==null||i.width<=0||i.height<=0||(n!=null&&clearTimeout(n),n=setTimeout(()=>{t=!0,r.disconnect(),p(e=>e+1)},80))});return r.observe(e),()=>{t=!0,n!=null&&clearTimeout(n),r.disconnect()}},[s]),(0,i.jsx)(A.Provider,{value:{config:o},children:(0,i.jsxs)(`div`,{ref:d,"data-slot":`chart`,"data-chart":u,className:O(`block w-full h-[350px] text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground`,t),style:{minHeight:280,minWidth:0,...c.style},...c,children:[(0,i.jsx)(j,{id:u,config:o}),(0,i.jsx)(a.ResponsiveContainer,{width:`100%`,height:`100%`,children:r},f)]})})}function T({active:e,payload:t,className:r,indicator:a=`dot`,hideLabel:o=!1,hideIndicator:s=!1,label:c,labelFormatter:l,labelClassName:u,formatter:d,color:f,nameKey:p,labelKey:m}){let{config:h}=C(),g=n.useMemo(()=>{if(o||!t?.length)return null;let[e]=t,n=`${m||e?.dataKey||e?.name||`value`}`,r=D(h,e,n),a=!m&&typeof c==`string`?h[c]?.label||c:r?.label;return l?(0,i.jsx)(`div`,{className:O(`font-medium`,u),children:l(a,t)}):a?(0,i.jsx)(`div`,{className:O(`font-medium`,u),children:a}):null},[c,l,t,o,u,h,m]);if(!e||!t?.length)return null;let _=t.length===1&&a!==`dot`;return(0,i.jsxs)(`div`,{className:O(`border-border/50 bg-background grid min-w-[8rem] items-start gap-1.5 rounded-lg border px-2.5 py-1.5 text-xs shadow-xl`,r),children:[_?null:g,(0,i.jsx)(`div`,{className:`grid gap-1.5`,children:t.filter(e=>e.type!==`none`).map((e,t)=>{let n=`${p||e.name||e.dataKey||`value`}`,r=D(h,e,n),o=f||e.payload.fill||e.color;return(0,i.jsx)(`div`,{className:O(`[&>svg]:text-muted-foreground flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5`,a===`dot`?`items-center`:``),children:d&&e?.value!==void 0&&e.name?d(e.value,e.name,e,t,e.payload):(0,i.jsxs)(i.Fragment,{children:[r?.icon?(0,i.jsx)(r.icon,{}):!s&&(0,i.jsx)(`div`,{className:O(`shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)`,a===`dot`?`h-2.5 w-2.5`:``,a===`line`?`w-1`:``,a===`dashed`?`w-0 border-[1.5px] border-dashed bg-transparent`:``,_&&a===`dashed`?`my-0.5`:``),style:{"--color-bg":o,"--color-border":o}}),(0,i.jsxs)(`div`,{className:O(`flex flex-1 justify-between leading-none`,_?`items-end`:`items-center`),children:[(0,i.jsxs)(`div`,{className:`grid gap-1.5`,children:[_?g:null,(0,i.jsx)(`span`,{className:`text-muted-foreground`,children:r?.label||e.name})]}),e.value&&(0,i.jsx)(`span`,{className:`text-foreground font-mono font-medium tabular-nums`,children:e.value.toLocaleString()})]})]})},e.dataKey)})})]})}function E({className:e,hideIcon:t=!1,payload:n,verticalAlign:r=`bottom`,nameKey:a}){let{config:o}=C();return n?.length?(0,i.jsx)(`div`,{className:O(`flex items-center justify-center gap-4`,r===`top`?`pb-3`:`pt-3`,e),children:n.filter(e=>e.type!==`none`).map(e=>{let n=`${a||e.dataKey||`value`}`,r=D(o,e,n);return(0,i.jsxs)(`div`,{className:O(`[&>svg]:text-muted-foreground flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3`),children:[r?.icon&&!t?(0,i.jsx)(r.icon,{}):(0,i.jsx)(`div`,{className:`h-2 w-2 shrink-0 rounded-[2px]`,style:{backgroundColor:e.color}}),r?.label]},e.value)})}):null}function D(e,t,n){if(typeof t!=`object`||!t)return;let r=`payload`in t&&typeof t.payload==`object`&&t.payload!==null?t.payload:void 0,i=n;return n in t&&typeof t[n]==`string`?i=t[n]:r&&n in r&&typeof r[n]==`string`&&(i=r[n]),i in e?e[i]:e[n]}var O,k,A,j,M,N,P=h((()=>{O=(...e)=>e.filter(Boolean).join(` `),k={light:``,dark:`.dark`},A=n.createContext(null),j=({id:e,config:t})=>{let n=Object.entries(t).filter(([,e])=>e.theme||e.color);return n.length?(0,i.jsx)(`style`,{dangerouslySetInnerHTML:{__html:Object.entries(k).map(([t,r])=>`
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@object-ui/core"),require("react"),require("@object-ui/components"),require("react/jsx-runtime"),require("recharts"),require("@object-ui/react"),require("lucide-react"),require("@object-ui/i18n")):typeof define==`function`&&define.amd?define([`exports`,`@object-ui/core`,`react`,`@object-ui/components`,`react/jsx-runtime`,`recharts`,`@object-ui/react`,`lucide-react`,`@object-ui/i18n`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginCharts={},e.ObjectUICore,e.React,e.ObjectUIComponents,e.react_jsx_runtime,e.recharts,e.ObjectUIReact,e.lucide_react,e._object_ui_i18n))})(this,function(e,t,n,r,i,a,o,s,c){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var l=Object.create,u=Object.defineProperty,d=Object.getOwnPropertyDescriptor,f=Object.getOwnPropertyNames,p=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty,h=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},g=(e,t)=>{let n={};for(var r in e)u(n,r,{get:e[r],enumerable:!0});return t||u(n,Symbol.toStringTag,{value:`Module`}),n},_=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=f(t),a=0,o=i.length,s;a<o;a++)s=i[a],!m.call(e,s)&&s!==n&&u(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=d(t,s))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:l(p(e)),_(t||!e||!e.__esModule?u(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);function v(e){let t=w(e);if(t)return t;if(C(e))return Object.values(e).find(e=>typeof e==`string`&&e)}function y(e){if(!C(e))return;let t={},n=w(e.field);n&&(t.field=n);let r=w(e.format);r&&(t.format=r);let i=T(e.min);i!==void 0&&(t.min=i);let a=T(e.max);a!==void 0&&(t.max=a);let o=T(e.stepSize);o!==void 0&&o>0&&(t.stepSize=o),typeof e.showGridLines==`boolean`&&(t.showGridLines=e.showGridLines),typeof e.logarithmic==`boolean`&&(t.logarithmic=e.logarithmic);let s=w(e.position);(s===`left`||s===`right`||s===`top`||s===`bottom`)&&(t.position=s);let c=v(e.title);return c&&(t.title=c),t}function b(e){if(!C(e)){let t=w(e);return t?{dataKey:t}:void 0}let t=w(e.dataKey)??w(e.name);if(!t)return;let n={dataKey:t},r=v(e.label);r&&(n.label=r);let i=w(e.chartType)??w(e.type);(i===`bar`||i===`line`||i===`area`)&&(n.chartType=i);let a=w(e.variant);(a===`comparison`||a===`current`||a===`primary`)&&(n.variant=a);let o=T(e.opacity);o!==void 0&&(n.opacity=o);let s=w(e.dashArray);s&&(n.dashArray=s);let c=w(e.stack);c&&(n.stack=c);let l=w(e.yAxis);(l===`left`||l===`right`)&&(n.yAxis=l);let u=w(e.color);return u&&(n.color=u),n}function ee(e){if(!C(e))return{};let t={},n=w(e.type),r=w(e.chartType)??w(e.specType)??(n&&se.has(n)?n:void 0);r&&ae.has(r)&&(t.chartType=r);let i=e.xAxis,a=y(i);a&&(a.format||a.title||a.showGridLines!==void 0)&&(t.xAxis=a);let o=w(e.xAxisKey)??a?.field??w(i);o&&(t.xAxisKey=o);let s=(Array.isArray(e.yAxis)?e.yAxis:e.yAxis===void 0?[]:[e.yAxis]).map(e=>y(e)??(w(e)?{field:w(e)}:void 0)).filter(e=>!!e);s.length&&(t.yAxes=s);let c=(Array.isArray(e.series)?e.series:Array.isArray(e.categories)?e.categories:void 0)?.map(b).filter(e=>!!e);if(!c?.length){let e=s.filter(e=>e.field).map((e,t)=>({dataKey:e.field,...e.title?{label:e.title}:{},...t>0||e.position===`right`?{yAxis:`right`}:{}}));e.length&&(c=e)}c?.length&&(t.series=c),typeof e.showLegend==`boolean`&&(t.showLegend=e.showLegend),typeof e.showDataLabels==`boolean`&&(t.showDataLabels=e.showDataLabels);let l=v(e.title);l&&(t.title=l);let u=v(e.subtitle);u&&(t.subtitle=u);let d=v(e.description);d&&(t.description=d);let f=T(e.height);return f!==void 0&&f>0&&(t.height=f),Array.isArray(e.annotations)&&e.annotations.length&&(t.annotations=e.annotations.filter(C)),C(e.interaction)&&(t.interaction=e.interaction),t}function te(e){if(e===`bar`||e===`column`)return`bar`;if(e===`line`)return`line`;if(e===`area`)return`area`}function ne(e,t){if(e===`combo`)return`combo`;let n=te(e);if(!n||!t||t.length<2)return e;let r=t.map(e=>e.chartType??n);return new Set(r).size>1?`combo`:e}function x(e){if(!e)return;let t=e.includes(`%`),n=/^([$£€¥₹])/.exec(e),r=e.includes(`,`),i=/\.(0+)/.exec(e)?.[1].length??0,a={$:`USD`,"£":`GBP`,"€":`EUR`,"¥":`CNY`,"₹":`INR`};if(!t&&!n&&!r&&i===0)return;let o={minimumFractionDigits:i,maximumFractionDigits:i,useGrouping:r};return t?o.style=`percent`:n&&(o.style=`currency`,o.currency=a[n[1]]??`USD`),e=>{let t=typeof e==`number`?e:Number(e);if(!Number.isFinite(t))return e==null?``:String(e);try{return new Intl.NumberFormat(void 0,o).format(t)}catch{return String(t)}}}function re(e,t){let n=e?.stepSize;if(!n||n<=0)return;let r=t.filter(e=>Number.isFinite(e)),i=r.length?Math.min(...r):void 0,a=r.length?Math.max(...r):void 0,o=e.min??Math.min(0,i??0),s=e.max??a;if(s===void 0||!Number.isFinite(o)||!Number.isFinite(s)||s<o)return;let c=Math.floor(o/n)*n,l=e.max===void 0?Math.ceil(s/n)*n:e.max,u=Math.floor((l-c)/n+1e-9)+1;if(u<1||u>E)return;let d=[];for(let e=0;e<u;e++)d.push(Number((c+e*n).toPrecision(12)));return e.max!==void 0&&d[d.length-1]<e.max&&d.push(e.max),d}function ie(e){if(!e)return;let{min:t,max:n}=e;if(!(t===void 0&&n===void 0))return[t??`auto`,n??`auto`]}var ae,S,oe,se,C,w,T,E,D=h((()=>{ae=new Set([`bar`,`column`,`horizontal-bar`,`line`,`area`,`pie`,`donut`,`funnel`,`radar`,`scatter`,`treemap`,`sankey`,`combo`]),S=new Set([`gauge`,`solid-gauge`,`metric`,`kpi`,`bullet`]),oe=new Set([`table`,`pivot`]),se=new Set([...ae,...S,...oe]),C=e=>!!e&&typeof e==`object`&&!Array.isArray(e),w=e=>typeof e==`string`&&e?e:void 0,T=e=>typeof e==`number`&&Number.isFinite(e)?e:void 0,E=200})),O=g({default:()=>j});function k(e,t=14){return e.length>t?`${e.slice(0,t-1)}…`:e}function A({x:e,y:t,payload:n}){let r=String(n?.value??``),a=k(r);return(0,i.jsx)(`g`,{transform:`translate(${e},${t})`,children:(0,i.jsxs)(`text`,{dy:10,textAnchor:`end`,transform:`rotate(-32)`,fill:`hsl(var(--muted-foreground))`,fontSize:11,fontFamily:`monospace`,children:[r!==a&&(0,i.jsx)(`title`,{children:r}),a]})})}function j({data:e=[],dataKey:t=`value`,xAxisKey:n=`name`,height:r=400,className:o=``,color:s=`hsl(var(--primary))`}){let c=e.map(e=>String(e?.[n]??``)),l=c.length>4||c.some(e=>e.length>8);return(0,i.jsx)(`div`,{className:`p-2 sm:p-3 md:p-4 rounded-xl border border-border bg-card/40 backdrop-blur-sm shadow-lg shadow-background/5 ${o}`,children:(0,i.jsx)(a.ResponsiveContainer,{width:`100%`,height:r,children:(0,i.jsxs)(a.BarChart,{data:e,margin:{top:10,right:10,left:10,bottom:l?24:5},children:[(0,i.jsxs)(`defs`,{children:[(0,i.jsxs)(`linearGradient`,{id:`barGradient`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,i.jsx)(`stop`,{offset:`0%`,stopColor:s,stopOpacity:1}),(0,i.jsx)(`stop`,{offset:`90%`,stopColor:s,stopOpacity:.6}),(0,i.jsx)(`stop`,{offset:`100%`,stopColor:s,stopOpacity:.3})]}),(0,i.jsxs)(`filter`,{id:`glow`,height:`130%`,children:[(0,i.jsx)(`feGaussianBlur`,{in:`SourceAlpha`,stdDeviation:`3`,result:`blur`}),(0,i.jsx)(`feOffset`,{in:`blur`,dx:`0`,dy:`0`,result:`offsetBlur`}),(0,i.jsx)(`feFlood`,{floodColor:s,floodOpacity:`0.5`,result:`offsetColor`}),(0,i.jsx)(`feComposite`,{in:`offsetColor`,in2:`offsetBlur`,operator:`in`,result:`offsetBlur`}),(0,i.jsxs)(`feMerge`,{children:[(0,i.jsx)(`feMergeNode`,{in:`offsetBlur`}),(0,i.jsx)(`feMergeNode`,{in:`SourceGraphic`})]})]})]}),(0,i.jsx)(a.CartesianGrid,{strokeDasharray:`3 3`,stroke:`hsl(var(--border))`,vertical:!1}),(0,i.jsx)(a.XAxis,{dataKey:n,tick:l?(0,i.jsx)(A,{}):{fill:`hsl(var(--muted-foreground))`,fontSize:12,fontFamily:`monospace`},tickLine:!1,axisLine:{stroke:`hsl(var(--border))`},interval:0,height:l?56:void 0,dy:l?void 0:10}),(0,i.jsx)(a.YAxis,{tick:{fill:`hsl(var(--muted-foreground))`,fontSize:12,fontFamily:`monospace`},tickLine:!1,axisLine:!1}),(0,i.jsx)(a.Tooltip,{cursor:{fill:`hsl(var(--muted))`,opacity:.2},contentStyle:{backgroundColor:`hsl(var(--popover))`,borderColor:`hsl(var(--border))`,color:`hsl(var(--popover-foreground))`,borderRadius:`8px`,fontFamily:`monospace`,boxShadow:`0 4px 6px -1px rgb(0 0 0 / 0.1)`},itemStyle:{color:`hsl(var(--primary))`}}),(0,i.jsx)(a.Legend,{wrapperStyle:{paddingTop:`20px`,fontFamily:`monospace`}}),(0,i.jsx)(a.Bar,{dataKey:t,fill:`url(#barGradient)`,radius:[4,4,0,0],filter:`url(#glow)`,animationDuration:1500})]})})})}var M=h((()=>{}));function N(){let e=n.useContext(z);if(!e)throw Error(`useChart must be used within a <ChartContainer />`);return e}function P({id:e,className:t,children:r,config:o,disableSettleRemount:s,...c}){let l=n.useId(),u=`chart-${e||l.replace(/:/g,``)}`,d=n.useRef(null),[f,p]=n.useState(0);return n.useEffect(()=>{if(s)return;let e=d.current;if(e==null||typeof ResizeObserver>`u`)return;let t=!1,n,r=new ResizeObserver(e=>{if(t)return;let i=e[0]?.contentRect;i==null||i.width<=0||i.height<=0||(n!=null&&clearTimeout(n),n=setTimeout(()=>{t=!0,r.disconnect(),p(e=>e+1)},80))});return r.observe(e),()=>{t=!0,n!=null&&clearTimeout(n),r.disconnect()}},[s]),(0,i.jsx)(z.Provider,{value:{config:o},children:(0,i.jsxs)(`div`,{ref:d,"data-slot":`chart`,"data-chart":u,className:R(`block w-full h-[350px] text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground`,t),style:{minHeight:280,minWidth:0,...c.style},...c,children:[(0,i.jsx)(B,{id:u,config:o}),(0,i.jsx)(a.ResponsiveContainer,{width:`100%`,height:`100%`,children:r},f)]})})}function F({active:e,payload:t,className:r,indicator:a=`dot`,hideLabel:o=!1,hideIndicator:s=!1,label:c,labelFormatter:l,labelClassName:u,formatter:d,color:f,nameKey:p,labelKey:m}){let{config:h}=N(),g=n.useMemo(()=>{if(o||!t?.length)return null;let[e]=t,n=`${m||e?.dataKey||e?.name||`value`}`,r=L(h,e,n),a=!m&&typeof c==`string`?h[c]?.label||c:r?.label;return l?(0,i.jsx)(`div`,{className:R(`font-medium`,u),children:l(a,t)}):a?(0,i.jsx)(`div`,{className:R(`font-medium`,u),children:a}):null},[c,l,t,o,u,h,m]);if(!e||!t?.length)return null;let _=t.length===1&&a!==`dot`;return(0,i.jsxs)(`div`,{className:R(`border-border/50 bg-background grid min-w-[8rem] items-start gap-1.5 rounded-lg border px-2.5 py-1.5 text-xs shadow-xl`,r),children:[_?null:g,(0,i.jsx)(`div`,{className:`grid gap-1.5`,children:t.filter(e=>e.type!==`none`).map((e,t)=>{let n=`${p||e.name||e.dataKey||`value`}`,r=L(h,e,n),o=f||e.payload.fill||e.color;return(0,i.jsx)(`div`,{className:R(`[&>svg]:text-muted-foreground flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5`,a===`dot`?`items-center`:``),children:d&&e?.value!==void 0&&e.name?d(e.value,e.name,e,t,e.payload):(0,i.jsxs)(i.Fragment,{children:[r?.icon?(0,i.jsx)(r.icon,{}):!s&&(0,i.jsx)(`div`,{className:R(`shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)`,a===`dot`?`h-2.5 w-2.5`:``,a===`line`?`w-1`:``,a===`dashed`?`w-0 border-[1.5px] border-dashed bg-transparent`:``,_&&a===`dashed`?`my-0.5`:``),style:{"--color-bg":o,"--color-border":o}}),(0,i.jsxs)(`div`,{className:R(`flex flex-1 justify-between leading-none`,_?`items-end`:`items-center`),children:[(0,i.jsxs)(`div`,{className:`grid gap-1.5`,children:[_?g:null,(0,i.jsx)(`span`,{className:`text-muted-foreground`,children:r?.label||e.name})]}),e.value&&(0,i.jsx)(`span`,{className:`text-foreground font-mono font-medium tabular-nums`,children:e.value.toLocaleString()})]})]})},e.dataKey)})})]})}function I({className:e,hideIcon:t=!1,payload:n,verticalAlign:r=`bottom`,nameKey:a}){let{config:o}=N();return n?.length?(0,i.jsx)(`div`,{className:R(`flex items-center justify-center gap-4`,r===`top`?`pb-3`:`pt-3`,e),children:n.filter(e=>e.type!==`none`).map(e=>{let n=`${a||e.dataKey||`value`}`,r=L(o,e,n);return(0,i.jsxs)(`div`,{className:R(`[&>svg]:text-muted-foreground flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3`),children:[r?.icon&&!t?(0,i.jsx)(r.icon,{}):(0,i.jsx)(`div`,{className:`h-2 w-2 shrink-0 rounded-[2px]`,style:{backgroundColor:e.color}}),r?.label]},e.value)})}):null}function L(e,t,n){if(typeof t!=`object`||!t)return;let r=`payload`in t&&typeof t.payload==`object`&&t.payload!==null?t.payload:void 0,i=n;return n in t&&typeof t[n]==`string`?i=t[n]:r&&n in r&&typeof r[n]==`string`&&(i=r[n]),i in e?e[i]:e[n]}var R,ce,z,B,V,H,le=h((()=>{R=(...e)=>e.filter(Boolean).join(` `),ce={light:``,dark:`.dark`},z=n.createContext(null),B=({id:e,config:t})=>{let n=Object.entries(t).filter(([,e])=>e.theme||e.color);return n.length?(0,i.jsx)(`style`,{dangerouslySetInnerHTML:{__html:Object.entries(ce).map(([t,r])=>`
|
|
2
2
|
${r} [data-chart=${e}] {
|
|
3
3
|
${n.map(([e,n])=>{let r=n.theme?.[t]||n.color;return r?` --color-${e}: ${r};`:null}).join(`
|
|
4
4
|
`)}
|
|
5
5
|
}
|
|
6
6
|
`).join(`
|
|
7
|
-
`)}}):null},M=a.Tooltip,N=a.Legend}));function F(e){return e?.[0]?.dataKey||`value`}function I(e,t,n){if(!e)return null;let r=e.payload??e,i=r?.[t];if(i==null)return null;let a=F(n);return{category:String(i),series:a,value:typeof r?.[a]==`number`?r[a]:void 0}}function L(e,t){if(!e)return null;let n=e.name??e.payload?.name??e.root?.name;if(n==null)return null;let r=e.value??e.size??e.payload?.size;return{category:String(n),series:F(t),value:typeof r==`number`?r:void 0}}function R(e,t){if(!e)return null;let n=e.payload??e,r=n?.name;return r==null||n?.depth===0?null:{category:String(r),series:F(t),value:typeof n?.value==`number`?n.value:void 0}}var z=h((()=>{})),B=g({default:()=>H});function V(e){let{x:t,y:n,width:r,height:a,name:o,fill:s}=e;return r<=0||a<=0?null:(0,i.jsxs)(`g`,{children:[(0,i.jsx)(`rect`,{x:t,y:n,width:r,height:a,fill:s,stroke:`hsl(var(--background))`,strokeWidth:2}),r>48&&a>18?(0,i.jsx)(`text`,{x:t+6,y:n+18,fill:`#fff`,fontSize:12,className:`pointer-events-none`,children:o}):null]})}function H({chartType:e=`bar`,data:t=[],config:r={},xAxisKey:o=`name`,series:s=[],className:c=``,colors:l,categoryColors:u,onChartClick:d,isAnimationActive:f}){let p=e===`column`?`bar`:e,m=Array.isArray(t)?t:[],h=f===!1?{isAnimationActive:!1}:{},g=f===!1?{disableSettleRemount:!0}:{},[_,v]=n.useState(!1),y=n.useCallback(e=>{if(!d||!e)return;let t=Array.isArray(e.activePayload)?e.activePayload[0]:void 0;d({category:e.activeLabel==null?void 0:String(e.activeLabel),series:t?.dataKey?String(t.dataKey):void 0,value:typeof t?.value==`number`?t.value:void 0})},[d]),b=n.useCallback(e=>{if(!d||!e)return;let t=e.payload?.[o],n=s[0]?.dataKey||`value`;d({category:t==null?void 0:String(t),series:n,value:typeof e.payload?.[n]==`number`?e.payload[n]:void 0})},[d,o,s]),x=d?{onClick:y,style:{cursor:`pointer`}}:{},S=d?{onClick:b,style:{cursor:`pointer`}}:{},C=n.useCallback((e,t,n)=>u&&u[e==null?``:String(e)]||n[t%n.length],[u]),D=n.useCallback(e=>{if(!d)return;let t=I(e,o,s);t&&d(t)},[d,o,s]),O=n.useCallback(e=>{if(!d)return;let t=L(e,s);t&&d(t)},[d,s]),k=n.useCallback(e=>{if(!d)return;let t=R(e,s);t&&d(t)},[d,s]),A=d?{onClick:D,cursor:`pointer`}:{},j=d?{onClick:O,style:{cursor:`pointer`}}:{},P=d?{onClick:k,style:{cursor:`pointer`}}:{};n.useEffect(()=>{let e=()=>v(window.innerWidth<640);return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]);let F={bar:a.BarChart,"horizontal-bar":a.BarChart,line:a.LineChart,area:a.AreaChart,pie:a.PieChart,donut:a.PieChart,radar:a.RadarChart,scatter:a.ScatterChart,funnel:a.FunnelChart,combo:a.BarChart,treemap:a.BarChart,sankey:a.BarChart}[p]||a.BarChart,z=n.useCallback(e=>{if(e==null||e===``)return``;let t=r?.[String(e)]?.label;if(t!=null)return String(t);let n=typeof e==`string`?e:String(e);if(/^\d{4}-\d{2}-\d{2}/.test(n)){let e=new Date(n);if(!Number.isNaN(e.getTime())){let t=(m.length>1?Math.abs(new Date(String(m[m.length-1][o]??``)).getTime()-new Date(String(m[0][o]??``)).getTime()):0)/(1e3*60*60*24);try{return t<=62?e.toLocaleDateString(void 0,{month:`short`,day:`numeric`}):e.toLocaleDateString(void 0,{month:`short`,year:`numeric`})}catch{return e.toISOString().slice(0,10)}}}return _&&n.length>8?n.slice(0,8)+`…`:n},[m,o,_,r]),B=n.useMemo(()=>m.some(e=>String(e[o]||``).length>5),[m,o]),H=()=>Array.isArray(l)&&l.length>0?l:[`hsl(var(--chart-1))`,`hsl(var(--chart-2))`,`hsl(var(--chart-3))`,`hsl(var(--chart-4))`,`hsl(var(--chart-5))`],W=n.useCallback(e=>{if(e==null||e===``)return``;let t=typeof e==`number`?e:Number(e);if(!Number.isFinite(t))return String(e);try{return new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:1}).format(t)}catch{return String(t)}},[]),q=n.useMemo(()=>({tickLine:!1,tickMargin:10,axisLine:!1,interval:`preserveStartEnd`,minTickGap:_?32:48,tickFormatter:z,...!_&&B&&{angle:-35,textAnchor:`end`,height:60}}),[_,B,z]);if(p===`pie`||p===`donut`){let e=p===`donut`?`52%`:0,t=H(),n={...r};return m.forEach((e,r)=>{let i=e?.[o];if(i==null||i===``)return;let a=String(i);n[a]||(n[a]={label:a,color:C(i,r,t)})}),(0,i.jsx)(w,{config:n,className:c,...g,children:(0,i.jsxs)(a.PieChart,{children:[(0,i.jsx)(M,{cursor:!1,content:(0,i.jsx)(T,{hideLabel:!0})}),(0,i.jsx)(a.Pie,{data:m,dataKey:s[0]?.dataKey||`value`,nameKey:o||`name`,innerRadius:e,strokeWidth:5,paddingAngle:2,outerRadius:`85%`,...h,...S,children:m.map((e,n)=>{let r=C(e?.[o],n,t);return(0,i.jsx)(a.Cell,{fill:G(r)},`cell-${n}`)})}),(0,i.jsx)(N,{verticalAlign:`bottom`,wrapperStyle:{fontSize:_?`11px`:`12px`,paddingTop:`8px`},content:(0,i.jsx)(E,{nameKey:o,className:`flex-wrap`})})]})})}if(p===`funnel`){let e=s[0]?.dataKey||`value`,t=H(),n=d?t=>{t&&d({category:t?.payload?.[o]??t?.[o],value:t?.payload?.[e]??t?.[e]})}:void 0,l=n?{onClick:n,style:{cursor:`pointer`}}:{},u=[...m].sort((t,n)=>{let r=Number(t?.[e]??0);return Number(n?.[e]??0)-r});return(0,i.jsx)(w,{config:r,className:c,...g,children:(0,i.jsxs)(a.FunnelChart,{children:[(0,i.jsx)(M,{content:(0,i.jsx)(T,{})}),(0,i.jsxs)(a.Funnel,{dataKey:e,data:u,nameKey:o,...h,...l,children:[(0,i.jsx)(a.LabelList,{position:`right`,fill:`hsl(var(--foreground))`,stroke:`none`,dataKey:o}),u.map((e,n)=>(0,i.jsx)(a.Cell,{fill:G(t[n%t.length])},`funnel-cell-${n}`))]})]})})}if(p===`treemap`){let e=s[0]?.dataKey||`value`,t=H(),n=m.map((n,r)=>({name:String(n?.[o]??``),size:Number(n?.[e])||0,fill:G(t[r%t.length])}));return(0,i.jsx)(w,{config:r,className:c,...g,children:(0,i.jsx)(a.Treemap,{data:n,dataKey:`size`,nameKey:`name`,...h,content:(0,i.jsx)(V,{}),...j,children:(0,i.jsx)(a.Tooltip,{})})})}if(p===`sankey`){let e=s[0]?.dataKey||`value`,t=s[0]?.label||e,n=m.filter(t=>(Number(t?.[e])||0)>0),l=[{name:t},...n.map(e=>({name:String(e?.[o]??``)}))],u=n.map((t,n)=>({source:0,target:n+1,value:Number(t?.[e])||0}));return u.length===0?(0,i.jsx)(`div`,{className:c}):(0,i.jsx)(w,{config:r,className:c,...g,children:(0,i.jsx)(a.Sankey,{data:{nodes:l,links:u},nodePadding:24,link:{stroke:`hsl(var(--muted-foreground))`,strokeOpacity:.25},node:{fill:`hsl(var(--chart-1))`},...P,children:(0,i.jsx)(a.Tooltip,{})})})}if(p===`radar`)return(0,i.jsx)(w,{config:r,className:c,...g,children:(0,i.jsxs)(a.RadarChart,{data:m,children:[(0,i.jsx)(a.PolarGrid,{}),(0,i.jsx)(a.PolarAngleAxis,{dataKey:o}),(0,i.jsx)(a.PolarRadiusAxis,{}),(0,i.jsx)(M,{content:(0,i.jsx)(T,{})}),(0,i.jsx)(N,{content:(0,i.jsx)(E,{}),..._&&{verticalAlign:`bottom`,wrapperStyle:{fontSize:`11px`,paddingTop:`8px`}}}),s.map(e=>{let t=G(r[e.dataKey]?.color||U);return(0,i.jsx)(a.Radar,{dataKey:e.dataKey,stroke:t,fill:t,fillOpacity:.6,...h},e.dataKey)})]})});if(p===`scatter`)return(0,i.jsx)(w,{config:r,className:c,...g,children:(0,i.jsxs)(a.ScatterChart,{children:[(0,i.jsx)(a.CartesianGrid,{vertical:!1}),(0,i.jsx)(a.XAxis,{type:`number`,dataKey:o,name:String(r[o]?.label||o),tickLine:!1,axisLine:!1,minTickGap:_?32:48}),(0,i.jsx)(a.YAxis,{type:`number`,dataKey:s[0]?.dataKey||`value`,name:String(r[s[0]?.dataKey]?.label||s[0]?.dataKey),tickLine:!1,axisLine:!1,tickFormatter:W,width:48}),(0,i.jsx)(a.ZAxis,{type:`number`,range:[60,400]}),(0,i.jsx)(M,{content:(0,i.jsx)(T,{})}),(0,i.jsx)(N,{content:(0,i.jsx)(E,{}),..._&&{verticalAlign:`bottom`,wrapperStyle:{fontSize:`11px`,paddingTop:`8px`}}}),s.map((e,t)=>{let n=H(),o=G(r[e.dataKey]?.color||n[t%n.length]),s=K(e,`scatter`);return(0,i.jsx)(a.Scatter,{name:r[e.dataKey]?.label||e.dataKey,data:m,fill:o,fillOpacity:s?.fillOpacity,...h,...A},e.dataKey)})]})});if(p===`combo`)return(0,i.jsx)(w,{config:r,className:c,...g,children:(0,i.jsxs)(a.BarChart,{data:m,children:[(0,i.jsx)(a.CartesianGrid,{vertical:!1}),(0,i.jsx)(a.XAxis,{dataKey:o,...q}),(0,i.jsx)(a.YAxis,{yAxisId:`left`,tickLine:!1,axisLine:!1,tickFormatter:W,width:48}),(0,i.jsx)(a.YAxis,{yAxisId:`right`,orientation:`right`,tickLine:!1,axisLine:!1,tickFormatter:W,width:48}),(0,i.jsx)(M,{content:(0,i.jsx)(T,{})}),(0,i.jsx)(N,{content:(0,i.jsx)(E,{}),..._&&{verticalAlign:`bottom`,wrapperStyle:{fontSize:`11px`,paddingTop:`8px`}}}),s.map((e,t)=>{let n=G(r[e.dataKey]?.color||U),o=e.chartType||(t===0?`bar`:`line`),s=o===`bar`?`left`:`right`,c=K(e,o);return o===`line`?(0,i.jsx)(a.Line,{yAxisId:s,type:`monotone`,dataKey:e.dataKey,stroke:n,strokeWidth:2,dot:!1,strokeOpacity:c?.strokeOpacity,strokeDasharray:c?.strokeDasharray,...h},e.dataKey):o===`area`?(0,i.jsx)(a.Area,{yAxisId:s,type:`monotone`,dataKey:e.dataKey,fill:n,stroke:n,fillOpacity:c?.fillOpacity??.4,strokeOpacity:c?.strokeOpacity,strokeDasharray:c?.strokeDasharray,...h},e.dataKey):(0,i.jsx)(a.Bar,{yAxisId:s,dataKey:e.dataKey,fill:n,radius:4,fillOpacity:c?.fillOpacity,...h},e.dataKey)})]})});let J=p===`horizontal-bar`,Y=H(),X=u?Object.values(u).map(e=>G(String(e))):[],Z=Array.from(new Set([...Y,...X,...s.map((e,t)=>G(r[e.dataKey]?.color||Y[t%Y.length]||U))])),Q=e=>`g`+e.replace(/[^a-zA-Z0-9]/g,``);return(0,i.jsx)(w,{config:r,className:c,...g,children:(0,i.jsxs)(F,{data:m,layout:J?`vertical`:`horizontal`,...x,children:[(0,i.jsx)(`defs`,{children:Z.map(e=>(0,i.jsxs)(n.Fragment,{children:[(0,i.jsxs)(`linearGradient`,{id:`bg-${Q(e)}`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,i.jsx)(`stop`,{offset:`0%`,style:{stopColor:e},stopOpacity:.95}),(0,i.jsx)(`stop`,{offset:`100%`,style:{stopColor:e},stopOpacity:.5})]}),(0,i.jsxs)(`linearGradient`,{id:`ag-${Q(e)}`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,i.jsx)(`stop`,{offset:`0%`,style:{stopColor:e},stopOpacity:.5}),(0,i.jsx)(`stop`,{offset:`95%`,style:{stopColor:e},stopOpacity:.05})]})]},Q(e)))}),(0,i.jsx)(a.CartesianGrid,{vertical:!1}),J?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(a.XAxis,{type:`number`,tickLine:!1,axisLine:!1,tickFormatter:W}),(0,i.jsx)(a.YAxis,{type:`category`,dataKey:o,tickLine:!1,axisLine:!1,width:Math.min(140,Math.max(60,Math.max(...m.map(e=>String(e[o]??``).length))*7)),tickFormatter:z})]}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(a.XAxis,{dataKey:o,...q}),(0,i.jsx)(a.YAxis,{tickLine:!1,axisLine:!1,tickFormatter:W,width:48})]}),(0,i.jsx)(M,{content:(0,i.jsx)(T,{})}),(0,i.jsx)(N,{content:(0,i.jsx)(E,{}),..._&&{verticalAlign:`bottom`,wrapperStyle:{fontSize:`11px`,paddingTop:`8px`}}}),s.map((e,t)=>{let n=H(),c=e.variant===`comparison`,l=c?s.slice(0,t).find(e=>e.variant!==`comparison`)||s[0]:e,u=c?s.indexOf(l):t,d=G(r[l.dataKey]?.color||n[u%n.length]||U);if(p===`bar`||p===`horizontal-bar`){let t=s.filter(e=>e.variant!==`comparison`).length===1&&!c&&s.length===1&&m.length>1,r=K(e,`bar`);return(0,i.jsx)(a.Bar,{dataKey:e.dataKey,fill:`url(#bg-${Q(d)})`,radius:4,fillOpacity:r?.fillOpacity,...h,children:t&&m.map((e,t)=>(0,i.jsx)(a.Cell,{fill:`url(#bg-${Q(G(C(e?.[o],t,n)))})`},`cell-${t}`))},e.dataKey)}if(p===`line`){let t=K(e,`line`);return(0,i.jsx)(a.Line,{type:`monotone`,dataKey:e.dataKey,stroke:d,strokeWidth:2,dot:!1,strokeOpacity:t?.strokeOpacity,strokeDasharray:t?.strokeDasharray,...h},e.dataKey)}if(p===`area`){let t=K(e,`area`);return(0,i.jsx)(a.Area,{type:`monotone`,dataKey:e.dataKey,fill:`url(#ag-${Q(d)})`,stroke:d,strokeWidth:2,fillOpacity:t?.fillOpacity??1,strokeOpacity:t?.strokeOpacity,strokeDasharray:t?.strokeDasharray,...h},e.dataKey)}return null})]})})}var U,W,G,K,q=h((()=>{P(),z(),U=`hsl(var(--primary))`,W={slate:`#64748b`,gray:`#6b7280`,zinc:`#71717a`,neutral:`#737373`,stone:`#78716c`,red:`#ef4444`,orange:`#f97316`,amber:`#f59e0b`,yellow:`#eab308`,lime:`#84cc16`,green:`#22c55e`,emerald:`#10b981`,teal:`#14b8a6`,cyan:`#06b6d4`,sky:`#0ea5e9`,blue:`#3b82f6`,indigo:`#6366f1`,violet:`#8b5cf6`,purple:`#a855f7`,fuchsia:`#d946ef`,pink:`#ec4899`,rose:`#f43f5e`},G=e=>W[e]||e,K=(e,t)=>e?.variant===`comparison`?{strokeOpacity:typeof e.opacity==`number`?e.opacity:t===`line`||t===`scatter`?.5:.6,fillOpacity:typeof e.opacity==`number`?e.opacity:t===`bar`?.4:t===`area`?.2:.5,strokeDasharray:e.dashArray??(t===`line`||t===`area`?`4 4`:void 0)}:null})),J=n.default.lazy(()=>Promise.resolve().then(()=>(S(),v))),Y=n.default.lazy(()=>Promise.resolve().then(()=>(q(),B))),X=({schema:e})=>(0,i.jsx)(n.Suspense,{fallback:(0,i.jsx)(r.Skeleton,{className:`w-full h-48 sm:h-64 md:h-80 lg:h-[400px]`}),children:(0,i.jsx)(J,{data:e.data,dataKey:e.dataKey,xAxisKey:e.xAxisKey,height:e.height,className:e.className,color:e.color})}),Z=({schema:e,onChartClick:t})=>{let a=n.default.useMemo(()=>{let t=e.series,n=e.xAxisKey,r=e.config;if(n||(e.index?n=e.index:e.category&&(n=e.category)),t||(e.categories?t=e.categories.map(e=>({dataKey:e})):e.value&&(t=[{dataKey:e.value}])),!r&&t){let n=e.colors||[`hsl(var(--chart-1))`,`hsl(var(--chart-2))`,`hsl(var(--chart-3))`],i={};t.forEach((e,t)=>{i[e.dataKey]={label:e.label||e.dataKey,color:n[t%n.length]}}),r=i}return{chartType:e.chartType,data:Array.isArray(e.data)?e.data:[],config:r,xAxisKey:n,series:t,className:e.className}},[e]);return(0,i.jsx)(n.Suspense,{fallback:(0,i.jsx)(r.Skeleton,{className:`w-full h-48 sm:h-64 md:h-80 lg:h-[400px]`}),children:(0,i.jsx)(Y,{chartType:a.chartType,data:a.data,config:a.config,xAxisKey:a.xAxisKey,series:a.series,className:a.className,colors:Array.isArray(e.colors)?e.colors:void 0,categoryColors:e.categoryColors,isAnimationActive:e.isAnimationActive,onChartClick:t})})};function Q(e){return e.replace(/[_-]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function ee(e,t){let{field:n,function:r,groupBy:i}=t,a={};for(let t of e){let e=String(t[i]??`Unknown`);a[e]||(a[e]=[]),a[e].push(t)}return Object.entries(a).map(([e,t])=>{let a=t.map(e=>Number(e[n])||0),o;switch(r){case`count`:o=t.length;break;case`avg`:o=a.length>0?a.reduce((e,t)=>e+t,0)/a.length:0;break;case`min`:o=a.length>0?Math.min(...a):0;break;case`max`:o=a.length>0?Math.max(...a):0;break;default:o=a.reduce((e,t)=>e+t,0);break}return{[i]:e,[n]:o}})}async function te(e,n,r,i,a){if(!e.length||!n)return e;let o=a||((e,t)=>t),s=`__raw_${n}`,c=r?.fields?.[n];if(!c){let t=/^\d{4}-\d{2}-\d{2}/;return e.map(e=>{let r=e[n],i=String(r??``),a=t.test(i)?i:Q(i);return{...e,[n]:o(i,a),[s]:r}})}let l=c.type;if(l===`select`||l===`picklist`||l===`dropdown`){let t=c.options||[];if(t.length===0)return e.map(e=>{let t=e[n],r=String(t??``),i=Q(r);return{...e,[n]:o(r,i),[s]:t}});let r={};for(let e of t)typeof e==`string`?r[e]=e:e&&typeof e==`object`&&(r[String(e.value)]=e.label||String(e.value));return e.map(e=>{let t=e[n],i=String(t??``),a=r[i]||Q(i);return{...e,[n]:o(i,a),[s]:t}})}if(l===`lookup`||l===`master_detail`){let r=c.reference_to||c.reference;if(!r||!i||typeof i.find!=`function`)return e.map(e=>({...e,[s]:e[n]}));let a=[...new Set(e.map(e=>e[n]).filter(e=>e!=null))];if(a.length===0)return e.map(e=>({...e,[s]:e[n]}));let o=c.id_field||`id`;try{let l=(0,t.extractRecords)(await i.find(r,{$filter:{[o]:{$in:a}},$top:a.length})),u=c.reference_field||c.display_field||`name`,d={};for(let e of l){let t=String(e[o]??e.id??e._id??``),n=e[u]||e.name||e.label||e.title||t;t&&(d[t]=String(n))}return e.map(e=>{let t=e[n],r=String(t??``);return{...e,[n]:d[r]||r,[s]:t}})}catch(t){return console.warn(`[ObjectChart] Failed to resolve lookup labels:`,t),e.map(e=>({...e,[s]:e[n]}))}}if(l===`date`||l===`datetime`||l===`date_time`||l===`timestamp`||l===`time`)return e.map(e=>({...e,[s]:e[n]}));let u=/^\d{4}-\d{2}-\d{2}/;return e.map(e=>{let t=e[n],r=String(t??``);return{...e,[n]:u.test(r)?r:Q(r),[s]:t}})}var $=e=>{let{schema:a}=e,l=e.onSegmentClick,u=(0,n.useContext)(o.SchemaRendererContext),d=e.dataSource||u?.dataSource,f=(0,o.useDataScope)(a.bind),{fieldOptionLabel:p}=(0,c.useSafeFieldLabel)(),m=(0,n.useRef)(p);(0,n.useEffect)(()=>{m.current=p},[p]);let[h,g]=(0,n.useState)([]),[_,v]=(0,n.useState)(null),[y,b]=(0,n.useState)(()=>!(Array.isArray(a.data)&&a.data.length>0)&&(!!a.objectName||!!a.dataset)),[x,S]=(0,n.useState)(null),[C,w]=(0,n.useState)(null),[T,E]=(0,n.useState)(null),[D,O]=(0,n.useState)(null),{openRecordList:k}=(0,o.useDrillNavigation)(),A=(0,c.useSafeTranslate)(),j=(0,n.useMemo)(()=>a.aggregate?JSON.stringify(a.aggregate):``,[a.aggregate]),M=(0,n.useMemo)(()=>a.filter?JSON.stringify(a.filter):``,[a.filter]),N=(0,n.useMemo)(()=>a.compareTo?JSON.stringify(a.compareTo):``,[a.compareTo]),P=(0,n.useMemo)(()=>a.dataset?JSON.stringify({d:a.dataset,dim:a.dimensions??[],val:a.values??[]}):``,[a.dataset,a.dimensions,a.values]),F=e=>e!==`pie`&&e!==`donut`&&e!==`funnel`;(0,n.useEffect)(()=>{let e=!1;return(async()=>{try{let n={headers:{accept:`application/json`},credentials:`include`},r=a.objectName,i,o=null,s=a.aggregate?.groupBy;if(r)i=s&&typeof s==`object`&&!Array.isArray(s)?s.field:typeof s==`string`?s:a.xAxisKey;else if(a.dataset){let e=Array.isArray(a.dimensions)&&a.dimensions.length?a.dimensions[0]:void 0,t=await(await fetch(`/api/v1/meta/dataset/${encodeURIComponent(a.dataset)}`,n)).json().catch(()=>null);o=t?.item??t?.data??t,r=o?.object,i=((o?.dimensions||[]).find(t=>t?.name===e)??(o?.dimensions||[])[0])?.field??e}if(!r||!i){e||(E(null),O(null));return}let c=await(await fetch(`/api/v1/meta/object/${encodeURIComponent(r)}`,n)).json().catch(()=>null),l=c?.item??c?.data??c,u=(0,t.buildOptionColorMap)(l?.fields?.[i]?.options),d=null;if(a.dataset&&Array.isArray(a.dimensions)){let e={};for(let n of a.dimensions){let r=(o?.dimensions||[]).find(e=>e?.name===n)?.field??n,i=(0,t.buildDimensionLabelMap)(l?.fields?.[r]?.options);i&&(e[n]=i)}Object.keys(e).length>0&&(d=e)}e||(E(u),O(d))}catch{e||(E(null),O(null))}})(),()=>{e=!0}},[a.objectName,a.dataset,P,j,a.xAxisKey]);let I=(0,n.useCallback)(async(e,n)=>{if(a.aggregate&&typeof e.aggregate==`function`){let t=a.aggregate.groupBy;if(t&&typeof t==`object`&&!Array.isArray(t)){let r=a.aggregate.field,i=a.aggregate.function,o={function:i,alias:r||i};i!==`count`&&r&&(o.field=r);let s=await e.aggregate(a.objectName,{groupBy:[t],aggregations:[o],where:n});return Array.isArray(s)?s:[]}let r=await e.aggregate(a.objectName,{field:a.aggregate.field,function:a.aggregate.function,groupBy:t,filter:n});return Array.isArray(r)?r:[]}if(typeof e.find==`function`){let r=(0,t.extractRecords)(await e.find(a.objectName,{$filter:n}));return a.aggregate&&r.length>0&&(r=ee(r,a.aggregate)),r}return[]},[a.objectName,j]),L=(0,n.useCallback)(async(e,n)=>{if(!e||!a.objectName&&!a.dataset){n.current&&b(!1);return}n.current&&(b(!0),S(null));try{if(a.dataset&&typeof e.queryDataset==`function`){let r=(0,t.resolveDateMacros)(a.filter),i=await e.queryDataset(a.dataset,{dimensions:Array.isArray(a.dimensions)?a.dimensions:[],measures:Array.isArray(a.values)?a.values:[],...r?{runtimeFilter:r}:{}});n.current&&(g(Array.isArray(i?.rows)?i.rows:[]),v(Array.isArray(i?.fields)?i.fields:null));return}let r=(0,t.resolveDateMacros)(a.filter),i=a.compareTo,o=!!i&&F(a.chartType),s=o?(0,t.shiftFilterByCompareTo)(a.filter,i):null,[c,l]=await Promise.all([I(e,r),s?I(e,s):Promise.resolve([])]),u=c,d=a.aggregate?.groupBy,f=d&&typeof d==`object`&&!Array.isArray(d)?d.alias||d.field:d||a.xAxisKey;if(o&&l.length>0&&a.aggregate){let e=a.aggregate.field,t=a.aggregate.function,n=n=>{if(n==null)return null;let r=`${e}_${t}`;return r in n?Number(n[r]):t===`count`&&`${e}_count`in n?Number(n[`${e}_count`]):e in n?Number(n[e]):`value`in n?Number(n.value):`count`in n?Number(n.count):null},r=`${e}__comparison`,i=f;if(i&&u.some(e=>e[i]!=null)&&l.some(e=>e[i]!=null)){let e=new Map;for(let t of l){let r=String(t[i]??``);e.set(r,n(t))}u=u.map(t=>{let n=String(t[i]??``),a=e.get(n);return a==null?t:{...t,[r]:a}});let t=new Set(u.map(e=>String(e[i]??``)));for(let e of l){let a=String(e[i]??``);t.has(a)||u.push({[i]:a,[r]:n(e)})}}else{let e=Math.max(u.length,l.length),t=[];for(let i=0;i<e;i++){let e=u[i]||{},a=l[i];t.push(a?{...e,[r]:n(a)}:e)}u=t}}if(f&&typeof e.getObjectSchema==`function`)try{let t=await e.getObjectSchema(a.objectName);u=await te(u,f,t,e,(e,t)=>m.current(a.objectName,f,e,t))}catch{}n.current&&g(u)}catch(e){console.error(`[ObjectChart] Fetch error:`,e),n.current&&S(e instanceof Error?e.message:`Failed to load chart data`)}finally{n.current&&b(!1)}},[a.objectName,P,j,M,N,a.xAxisKey,a.chartType,I]);(0,n.useEffect)(()=>{let e={current:!0};return(a.objectName||a.dataset)&&!f&&!a.data?L(d,e):e.current&&b(!1),()=>{e.current=!1}},[a.objectName,P,d,f,a.data,M,j,N,L]);let R=f||a.data||h,z=Array.isArray(R)?R:[],B=a.drillDown,V=a.aggregate?.groupBy||a.xAxisKey,H=(0,n.useMemo)(()=>{if(!V)return new Map;let e=new Map,t=`__raw_${V}`;for(let n of z){let r=n?.[V];if(r==null)continue;let i=t in(n||{})?n[t]:r;e.set(String(r),i)}return e},[z,V]),U=a.compareTo,W=!!U&&F(a.chartType)&&!!a.aggregate&&z.some(e=>e[`${a.aggregate.field}__comparison`]!=null),G=(0,n.useMemo)(()=>{let e=Array.isArray(a.series)?a.series:null;if(!W)return e;let n=e||[{dataKey:a.aggregate.field}],r={vsLastWeek:`Previous week`,vsLastMonth:`Previous month`,vsLastQuarter:`Previous quarter`,vsLastYear:`Previous year`,vsYesterday:`Yesterday`,vsPreviousPeriod:`Previous period`}[(0,t.compareToTrendLabelKey)(U,a.filter)]||`Previous period`;return[...n.map(e=>({...e,variant:e.variant||`current`})),{dataKey:`${a.aggregate.field}__comparison`,label:r,variant:`comparison`}]},[W,a.series,a.aggregate,a.filter,U]),K=a.dataset?(0,t.buildChartSeries)((0,t.relabelDimensions)(z,D),a.dimensions,a.values,_):null,q=K?{...a,data:K.data,xAxisKey:K.xAxisKey,series:K.series}:{...a,data:z,...G?{series:G}:{}},J=a.colors&&!Array.isArray(a.colors)&&typeof a.colors==`object`?a.colors:null,Y=Array.isArray(a.colors)?a.colors:void 0,X=T||J?{...T||{},...J||{}}:void 0,Q={...q,colors:Y,...X?{categoryColors:X}:{}};if(y&&z.length===0)return(0,i.jsxs)(`div`,{className:`p-2 `+(a.className||``),"data-testid":`chart-loading`,role:`status`,"aria-busy":`true`,"aria-live":`polite`,children:[(0,i.jsx)(`span`,{className:`sr-only`,children:`Loading chart data…`}),(0,i.jsx)(r.ChartSkeleton,{className:`h-full`})]});if(x)return(0,i.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-2 p-4 `+(a.className||``),"data-testid":`chart-error`,role:`alert`,children:[(0,i.jsx)(s.AlertCircle,{className:`h-6 w-6 text-destructive opacity-60`}),(0,i.jsx)(`p`,{className:`text-xs text-destructive font-medium`,children:`Failed to load chart data`}),(0,i.jsx)(`p`,{className:`text-xs text-muted-foreground max-w-xs text-center`,children:x})]});if(!d&&a.objectName&&z.length===0)return(0,i.jsxs)(`div`,{className:`flex items-center justify-center text-muted-foreground text-sm p-4 `+(a.className||``),"data-testid":`chart-no-datasource`,children:[`No data source available for “`,a.objectName,`”`]});let $=(0,t.isDrillEnabled)(B)?e=>{let t=e.category,n=t!=null&&H.has(String(t))?H.get(String(t)):t;w({...e,category:n,categoryLabel:t,scope:`cell`})}:void 0,ne=l??$,re=!l&&C&&a.objectName?(()=>{let e=(0,t.computeDrillFilter)(B,C,{groupByField:V}),n={...a.filter||{},...e},c=(0,t.resolveDrillTitle)(B,C,a.title||`Details`),l=B?.target??`drawer`,u=(0,i.jsx)(`div`,{className:`overflow-auto`,"data-testid":`chart-drill-body`,children:(0,i.jsx)(o.SchemaRenderer,{schema:{type:`object-data-table`,objectName:a.objectName,filter:n,pagination:!0,pageSize:B?.maxRows,columns:B?.columns?.map(e=>({accessorKey:e,header:e})),drillDown:{enabled:!0,mode:`record`,target:`dialog`}},dataSource:d})}),f=k&&a.objectName?(0,i.jsxs)(r.Button,{type:`button`,variant:`ghost`,size:`sm`,"data-testid":`drill-open-in-list`,onClick:()=>{k(a.objectName,n),w(null)},children:[A(`dashboard.openInList`,`Open in list`),(0,i.jsx)(s.ArrowUpRight,{className:`ml-1 h-3.5 w-3.5`})]}):null;return l===`dialog`?(0,i.jsx)(r.Dialog,{open:!0,onOpenChange:e=>!e&&w(null),children:(0,i.jsxs)(r.DialogContent,{className:`max-w-4xl`,children:[(0,i.jsxs)(r.DialogHeader,{className:`flex-row items-center justify-between gap-4 pr-8`,children:[(0,i.jsx)(r.DialogTitle,{children:c}),f]}),u]})}):(0,i.jsx)(r.Sheet,{open:!0,onOpenChange:e=>!e&&w(null),children:(0,i.jsxs)(r.SheetContent,{side:`right`,className:`w-full sm:max-w-2xl md:max-w-3xl lg:max-w-4xl flex flex-col`,children:[(0,i.jsxs)(r.SheetHeader,{className:`flex-row items-center justify-between gap-4 pr-8`,children:[(0,i.jsx)(r.SheetTitle,{children:c}),f]}),(0,i.jsx)(`div`,{className:`flex-1 overflow-hidden mt-2`,children:u})]})})})():null;return(0,i.jsxs)(`div`,{className:`relative`,children:[(0,i.jsx)(r.RefreshIndicator,{active:y&&z.length>0}),(0,i.jsx)(Z,{...e,schema:Q,onChartClick:ne}),re]})};t.ComponentRegistry.register(`object-chart`,$,{namespace:`plugin-charts`,label:`Object Chart`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`data`,type:`array`,label:`Data`,description:`Optional static data`},{name:`filter`,type:`array`,label:`Filter`},{name:`aggregate`,type:`object`,label:`Aggregate`,description:`Aggregation config: { field, function, groupBy }`}]});var ne={"bar-chart":X,chart:Z};t.ComponentRegistry.register(`bar-chart`,X,{namespace:`plugin-charts`,label:`Bar Chart`,category:`plugin`,inputs:[{name:`data`,type:`array`,label:`Data`,required:!0},{name:`dataKey`,type:`string`,label:`Data Key`,defaultValue:`value`},{name:`xAxisKey`,type:`string`,label:`X-Axis Key`,defaultValue:`name`},{name:`height`,type:`number`,label:`Height`,defaultValue:400},{name:`color`,type:`color`,label:`Color`,defaultValue:`#8884d8`}],defaultProps:{data:[{name:`Jan`,value:400},{name:`Feb`,value:300},{name:`Mar`,value:600},{name:`Apr`,value:800},{name:`May`,value:500}],dataKey:`value`,xAxisKey:`name`,height:400,color:`#8884d8`}}),t.ComponentRegistry.register(`chart`,$,{namespace:`view`,category:`view`,label:`Chart`,skipFallback:!0,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`type`,type:`string`,label:`Chart Type`},{name:`categoryField`,type:`string`,label:`Category Field`},{name:`valueField`,type:`string`,label:`Value Field`}]}),t.ComponentRegistry.register(`chart`,Z,{namespace:`plugin-charts`,label:`Chart`,category:`plugin`,inputs:[{name:`chartType`,type:`enum`,label:`Chart Type`,enum:[{label:`Bar`,value:`bar`},{label:`Line`,value:`line`},{label:`Area`,value:`area`},{label:`Pie`,value:`pie`},{label:`Donut`,value:`donut`},{label:`Radar`,value:`radar`},{label:`Scatter`,value:`scatter`}],defaultValue:`bar`},{name:`data`,type:`code`,label:`Data (JSON)`,required:!0},{name:`config`,type:`code`,label:`Config (JSON)`},{name:`xAxisKey`,type:`string`,label:`X Axis Key`,defaultValue:`name`},{name:`series`,type:`code`,label:`Series (JSON Array)`,required:!0},{name:`className`,type:`string`,label:`CSS Class`}],defaultProps:{chartType:`bar`,data:[{name:`Jan`,sales:400,revenue:240},{name:`Feb`,sales:300,revenue:139},{name:`Mar`,sales:600,revenue:380},{name:`Apr`,sales:800,revenue:430},{name:`May`,sales:500,revenue:220}],config:{sales:{label:`Sales`,color:`#8884d8`},revenue:{label:`Revenue`,color:`#82ca9d`}},xAxisKey:`name`,series:[{dataKey:`sales`},{dataKey:`revenue`}]}}),t.ComponentRegistry.register(`chart:bar`,Z,{namespace:`plugin-charts`,label:`Bar Chart (Alias)`,category:`plugin`,defaultProps:{chartType:`bar`}}),t.ComponentRegistry.register(`pie-chart`,Z,{namespace:`plugin-charts`,label:`Pie Chart`,category:`plugin`,defaultProps:{chartType:`pie`}}),t.ComponentRegistry.register(`donut-chart`,Z,{namespace:`plugin-charts`,label:`Donut Chart`,category:`plugin`,defaultProps:{chartType:`donut`}}),t.ComponentRegistry.register(`radar-chart`,Z,{namespace:`plugin-charts`,label:`Radar Chart`,category:`plugin`,defaultProps:{chartType:`radar`}}),t.ComponentRegistry.register(`scatter-chart`,Z,{namespace:`plugin-charts`,label:`Scatter Chart`,category:`plugin`,defaultProps:{chartType:`scatter`}}),e.ChartBarRenderer=X,e.ChartRenderer=Z,e.ObjectChart=$,e.chartComponents=ne});
|
|
7
|
+
`)}}):null},V=a.Tooltip,H=a.Legend}));function U(e){return e?.[0]?.dataKey||`value`}function ue(e,t,n){if(!e)return null;let r=e.payload??e,i=r?.[t];if(i==null)return null;let a=U(n);return{category:String(i),series:a,value:typeof r?.[a]==`number`?r[a]:void 0}}function de(e,t){if(!e)return null;let n=e.name??e.payload?.name??e.root?.name;if(n==null)return null;let r=e.value??e.size??e.payload?.size;return{category:String(n),series:U(t),value:typeof r==`number`?r:void 0}}function fe(e,t){if(!e)return null;let n=e.payload??e,r=n?.name;return r==null||n?.depth===0?null:{category:String(r),series:U(t),value:typeof n?.value==`number`?n.value:void 0}}var pe=h((()=>{})),me=g({default:()=>ye});function he(e){let{x:t,y:n,width:r,height:a,name:o,fill:s}=e;return r<=0||a<=0?null:(0,i.jsxs)(`g`,{children:[(0,i.jsx)(`rect`,{x:t,y:n,width:r,height:a,fill:s,stroke:`hsl(var(--background))`,strokeWidth:2}),r>48&&a>18?(0,i.jsx)(`text`,{x:t+6,y:n+18,fill:`#fff`,fontSize:12,className:`pointer-events-none`,children:o}):null]})}function ge({title:e,subtitle:t,children:n}){return!e&&!t?(0,i.jsx)(i.Fragment,{children:n}):(0,i.jsxs)(`div`,{className:`flex h-full w-full flex-col`,children:[(0,i.jsxs)(`div`,{className:`mb-2 shrink-0`,children:[e?(0,i.jsx)(`div`,{className:`text-sm font-medium leading-tight text-foreground`,children:e}):null,t?(0,i.jsx)(`div`,{className:`text-xs leading-tight text-muted-foreground`,children:t}):null]}),(0,i.jsx)(`div`,{className:`min-h-0 flex-1`,children:n})]})}function _e({chartType:e=`bar`,data:r=[],config:o={},xAxisKey:s=`name`,series:c=[],className:l=``,colors:u,categoryColors:d,categoryOrder:f,onChartClick:p,isAnimationActive:m,xAxis:h,yAxes:g,showLegend:_,showDataLabels:v,title:y,subtitle:b,description:ee,height:se,annotations:C,interaction:w}){let T=e===`column`?`bar`:e,E=ne(T,c),D=te(T),O=Array.isArray(r)?r:[],k=m===!1?{isAnimationActive:!1}:{},A={...m===!1?{disableSettleRemount:!0}:{},...se?{style:{height:se}}:{},...ee?{role:`img`,"aria-label":ee}:{}},[j,M]=n.useState(!1),N=n.useCallback(e=>{if(!p||!e)return;let t=Array.isArray(e.activePayload)?e.activePayload[0]:void 0;p({category:e.activeLabel==null?void 0:String(e.activeLabel),series:t?.dataKey?String(t.dataKey):void 0,value:typeof t?.value==`number`?t.value:void 0})},[p]),L=n.useCallback(e=>{if(!p||!e)return;let t=e.payload?.[s],n=c[0]?.dataKey||`value`;p({category:t==null?void 0:String(t),series:n,value:typeof e.payload?.[n]==`number`?e.payload[n]:void 0})},[p,s,c]),R=p?{onClick:N,style:{cursor:`pointer`}}:{},ce=p?{onClick:L,style:{cursor:`pointer`}}:{},z=n.useCallback((e,t,n)=>d&&d[e==null?``:String(e)]||n[t%n.length],[d]),B=n.useCallback(e=>{if(!p)return;let t=ue(e,s,c);t&&p(t)},[p,s,c]),le=n.useCallback(e=>{if(!p)return;let t=de(e,c);t&&p(t)},[p,c]),U=n.useCallback(e=>{if(!p)return;let t=fe(e,c);t&&p(t)},[p,c]),pe=p?{onClick:B,cursor:`pointer`}:{},me=p?{onClick:le,style:{cursor:`pointer`}}:{},_e=p?{onClick:U,style:{cursor:`pointer`}}:{};n.useEffect(()=>{let e=()=>M(window.innerWidth<640);return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]);let ve={bar:a.BarChart,"horizontal-bar":a.BarChart,line:a.LineChart,area:a.AreaChart,pie:a.PieChart,donut:a.PieChart,radar:a.RadarChart,scatter:a.ScatterChart,funnel:a.FunnelChart,combo:a.ComposedChart,treemap:a.BarChart,sankey:a.BarChart}[E]||a.BarChart,ye=n.useCallback(e=>{if(e==null||e===``)return``;let t=o?.[String(e)]?.label;if(t!=null)return String(t);let n=typeof e==`string`?e:String(e);if(/^\d{4}-\d{2}-\d{2}/.test(n)){let e=new Date(n);if(!Number.isNaN(e.getTime())){let t=(O.length>1?Math.abs(new Date(String(O[O.length-1][s]??``)).getTime()-new Date(String(O[0][s]??``)).getTime()):0)/(1e3*60*60*24);try{return t<=62?e.toLocaleDateString(void 0,{month:`short`,day:`numeric`}):e.toLocaleDateString(void 0,{month:`short`,year:`numeric`})}catch{return e.toISOString().slice(0,10)}}}return j&&n.length>8?n.slice(0,8)+`…`:n},[O,s,j,o]),xe=n.useMemo(()=>O.some(e=>String(e[s]||``).length>5),[O,s]),K=()=>Array.isArray(u)&&u.length>0?u:[`hsl(var(--chart-1))`,`hsl(var(--chart-2))`,`hsl(var(--chart-3))`,`hsl(var(--chart-4))`,`hsl(var(--chart-5))`],q=n.useCallback(e=>{if(e==null||e===``)return``;let t=typeof e==`number`?e:Number(e);if(!Number.isFinite(t))return String(e);try{return new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:1}).format(t)}catch{return String(t)}},[]),J=g?.[0],Y=g&&g.length>1?g[1]:J?.position===`right`?J:void 0,X=!!g&&g.length>1,Z=n.useMemo(()=>x(h?.format)??ye,[h?.format,ye]),Q=n.useMemo(()=>x(J?.format)??q,[J?.format,q]),$=n.useMemo(()=>x(Y?.format)??q,[Y?.format,q]),Se=n.useCallback(e=>{let t=c.filter(t=>X?(t.yAxis===`right`?`right`:`left`)===e:e===`left`).map(e=>e.dataKey),n=[];for(let e of O)for(let r of t){let t=Number(e?.[r]);Number.isFinite(t)&&n.push(t)}return n},[O,c,X]),Ce=n.useCallback((e,t=`left`)=>{if(!e)return{};let n=ie(e),r=re(e,Se(t));return{...r?{ticks:r}:{},...n?{domain:n}:{},...n?{allowDataOverflow:!0}:{},...e.logarithmic?{scale:`log`,domain:n??[1,`auto`]}:{},...e.title?{label:{value:e.title,angle:-90,position:`insideLeft`}}:{}}},[Se]),we=J?.showGridLines!==!1,Te={vertical:h?.showGridLines===!0,horizontal:we},Ee=_!==!1,De=n.useMemo(()=>{if(!Array.isArray(C)||C.length===0)return null;let e={solid:void 0,dashed:`4 4`,dotted:`1 4`};return C.map((t,n)=>{let r=t?.axis===`x`,o=W(String(t?.color||`hsl(var(--muted-foreground))`)),s=e[String(t?.style??`dashed`)],c=typeof t?.label==`string`?t.label:void 0,l=c?{label:{value:c,position:`insideTopRight`,fill:o,fontSize:11}}:{};return t?.type===`region`?(0,i.jsx)(a.ReferenceArea,{...r?{x1:t.value,x2:t.endValue}:{y1:t.value,y2:t.endValue},...X&&!r?{yAxisId:`left`}:{},fill:o,fillOpacity:.12,stroke:o,strokeOpacity:.35,...l},`ann-${n}`):(0,i.jsx)(a.ReferenceLine,{...r?{x:t?.value}:{y:t?.value},...X&&!r?{yAxisId:`left`}:{},stroke:o,strokeDasharray:s,...l},`ann-${n}`)})},[C,X]),Oe=w?.tooltips!==!1,ke=w?.brush===!0?(0,i.jsx)(a.Brush,{dataKey:s,height:24,travellerWidth:8,stroke:`hsl(var(--muted-foreground))`}):null,Ae=e=>v?(0,i.jsx)(a.LabelList,{position:`top`,className:`fill-foreground`,fontSize:11,...e?{formatter:e}:{}}):null,je=n.useMemo(()=>({tickLine:!1,tickMargin:10,axisLine:!1,interval:`preserveStartEnd`,minTickGap:j?32:48,tickFormatter:Z,...h?.title?{label:{value:h.title,position:`insideBottom`,offset:-4}}:{},...!j&&xe&&{angle:-35,textAnchor:`end`,height:60}}),[j,xe,Z,h?.title]);if(E&&S.has(E)){let e=c[0]?.dataKey||`value`,t=O[0]?.[e],n=typeof t==`number`?t:Number(t),r=c[0]?.label??o?.[e]?.label??e;return(0,i.jsx)(`div`,{className:l,"data-testid":`advanced-chart-single-value`,children:(0,i.jsxs)(`div`,{className:`flex flex-col gap-1 py-4`,children:[(0,i.jsx)(`span`,{className:`text-3xl font-semibold tabular-nums`,children:Number.isFinite(n)?new Intl.NumberFormat().format(n):String(t??`—`)}),(0,i.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:String(r)})]})})}if(E&&oe.has(E))return(0,i.jsxs)(`div`,{className:`rounded-md border border-dashed bg-muted/20 px-3 py-2 text-xs text-muted-foreground ${l??``}`,"data-testid":`advanced-chart-tabular-notice`,role:`note`,children:[`Chart type “`,E,`” is tabular — render it with the data-table / pivot components; a chart block draws series charts.`]});if(E&&!ae.has(E))return(0,i.jsxs)(`div`,{className:`rounded-md border border-dashed bg-muted/20 px-3 py-2 text-xs text-muted-foreground ${l??``}`,"data-testid":`advanced-chart-unknown-type`,role:`note`,children:[`Chart type “`,E,`” is not a spec chart type — nothing was drawn.`]});if(E===`pie`||E===`donut`){let e=E===`donut`?`52%`:0,t=K(),n={...o};return O.forEach((e,r)=>{let i=e?.[s];if(i==null||i===``)return;let a=String(i);n[a]||(n[a]={label:a,color:z(i,r,t)})}),(0,i.jsx)(P,{config:n,className:l,...A,children:(0,i.jsxs)(a.PieChart,{children:[(0,i.jsx)(V,{cursor:!1,content:(0,i.jsx)(F,{hideLabel:!0})}),(0,i.jsx)(a.Pie,{data:O,dataKey:c[0]?.dataKey||`value`,nameKey:s||`name`,innerRadius:e,strokeWidth:5,paddingAngle:2,outerRadius:`85%`,...k,...ce,children:O.map((e,n)=>{let r=z(e?.[s],n,t);return(0,i.jsx)(a.Cell,{fill:W(r)},`cell-${n}`)})}),(0,i.jsx)(H,{verticalAlign:`bottom`,wrapperStyle:{fontSize:j?`11px`:`12px`,paddingTop:`8px`},content:(0,i.jsx)(I,{nameKey:s,className:`flex-wrap`})})]})})}if(E===`funnel`){let e=c[0]?.dataKey||`value`,n=K(),r=p?t=>{t&&p({category:t?.payload?.[s]??t?.[s],value:t?.payload?.[e]??t?.[e]})}:void 0,u=r?{onClick:r,style:{cursor:`pointer`}}:{},d=(0,t.buildCategoryRank)(f),m=d?[...O].sort((e,t)=>(d.get(String(e?.[s]??``))??2**53-1)-(d.get(String(t?.[s]??``))??2**53-1)):[...O].sort((t,n)=>{let r=Number(t?.[e]??0);return Number(n?.[e]??0)-r});return(0,i.jsx)(P,{config:o,className:l,...A,children:(0,i.jsxs)(a.FunnelChart,{children:[(0,i.jsx)(V,{content:(0,i.jsx)(F,{})}),(0,i.jsxs)(a.Funnel,{dataKey:e,data:m,nameKey:s,...k,...u,children:[(0,i.jsx)(a.LabelList,{position:`right`,fill:`hsl(var(--foreground))`,stroke:`none`,dataKey:s}),m.map((e,t)=>(0,i.jsx)(a.Cell,{fill:W(n[t%n.length])},`funnel-cell-${t}`))]})]})})}if(E===`treemap`){let e=c[0]?.dataKey||`value`,t=K(),n=O.map((n,r)=>({name:String(n?.[s]??``),size:Number(n?.[e])||0,fill:W(t[r%t.length])}));return(0,i.jsx)(P,{config:o,className:l,...A,children:(0,i.jsx)(a.Treemap,{data:n,dataKey:`size`,nameKey:`name`,...k,content:(0,i.jsx)(he,{}),...me,children:(0,i.jsx)(a.Tooltip,{})})})}if(E===`sankey`){let e=c[0]?.dataKey||`value`,t=c[0]?.label||e,n=O.filter(t=>(Number(t?.[e])||0)>0),r=[{name:t},...n.map(e=>({name:String(e?.[s]??``)}))],u=n.map((t,n)=>({source:0,target:n+1,value:Number(t?.[e])||0}));return u.length===0?(0,i.jsx)(`div`,{className:l}):(0,i.jsx)(P,{config:o,className:l,...A,children:(0,i.jsx)(a.Sankey,{data:{nodes:r,links:u},nodePadding:24,link:{stroke:`hsl(var(--muted-foreground))`,strokeOpacity:.25},node:{fill:`hsl(var(--chart-1))`},..._e,children:(0,i.jsx)(a.Tooltip,{})})})}if(E===`radar`)return(0,i.jsx)(P,{config:o,className:l,...A,children:(0,i.jsxs)(a.RadarChart,{data:O,children:[(0,i.jsx)(a.PolarGrid,{}),(0,i.jsx)(a.PolarAngleAxis,{dataKey:s}),(0,i.jsx)(a.PolarRadiusAxis,{}),(0,i.jsx)(V,{content:(0,i.jsx)(F,{})}),(0,i.jsx)(H,{content:(0,i.jsx)(I,{}),...j&&{verticalAlign:`bottom`,wrapperStyle:{fontSize:`11px`,paddingTop:`8px`}}}),c.map(e=>{let t=W(o[e.dataKey]?.color||be);return(0,i.jsx)(a.Radar,{dataKey:e.dataKey,stroke:t,fill:t,fillOpacity:.6,...k},e.dataKey)})]})});if(E===`scatter`)return(0,i.jsx)(P,{config:o,className:l,...A,children:(0,i.jsxs)(a.ScatterChart,{children:[(0,i.jsx)(a.CartesianGrid,{vertical:!1}),(0,i.jsx)(a.XAxis,{type:`number`,dataKey:s,name:String(o[s]?.label||s),tickLine:!1,axisLine:!1,minTickGap:j?32:48}),(0,i.jsx)(a.YAxis,{type:`number`,dataKey:c[0]?.dataKey||`value`,name:String(o[c[0]?.dataKey]?.label||c[0]?.dataKey),tickLine:!1,axisLine:!1,tickFormatter:q,width:48}),(0,i.jsx)(a.ZAxis,{type:`number`,range:[60,400]}),(0,i.jsx)(V,{content:(0,i.jsx)(F,{})}),(0,i.jsx)(H,{content:(0,i.jsx)(I,{}),...j&&{verticalAlign:`bottom`,wrapperStyle:{fontSize:`11px`,paddingTop:`8px`}}}),c.map((e,t)=>{let n=K(),r=W(o[e.dataKey]?.color||n[t%n.length]),s=G(e,`scatter`);return(0,i.jsx)(a.Scatter,{name:o[e.dataKey]?.label||e.dataKey,data:O,fill:r,fillOpacity:s?.fillOpacity,...k,...pe},e.dataKey)})]})});if(E===`combo`)return(0,i.jsx)(ge,{title:y,subtitle:b,children:(0,i.jsx)(P,{config:o,className:l,...A,children:(0,i.jsxs)(a.ComposedChart,{data:O,children:[(0,i.jsx)(a.CartesianGrid,{...Te}),(0,i.jsx)(a.XAxis,{dataKey:s,...je}),(0,i.jsx)(a.YAxis,{yAxisId:`left`,tickLine:!1,axisLine:!1,tickFormatter:Q,width:48,...Ce(J)}),(0,i.jsx)(a.YAxis,{yAxisId:`right`,orientation:`right`,tickLine:!1,axisLine:!1,tickFormatter:$,width:48,...Ce(Y,`right`)}),Oe?(0,i.jsx)(V,{content:(0,i.jsx)(F,{})}):null,Ee?(0,i.jsx)(H,{content:(0,i.jsx)(I,{}),...j&&{verticalAlign:`bottom`,wrapperStyle:{fontSize:`11px`,paddingTop:`8px`}}}):null,De,ke,c.map((e,t)=>{let n=W(o[e.dataKey]?.color||be),r=e.chartType||D||(t===0?`bar`:`line`),s=e.yAxis===`right`||e.yAxis===`left`?e.yAxis:D||r===`bar`?`left`:`right`,c=G(e,r),l=e.stack?{stackId:String(e.stack)}:{},u=x((s===`right`?Y:J)?.format);return r===`line`?(0,i.jsx)(a.Line,{yAxisId:s,type:`monotone`,dataKey:e.dataKey,stroke:n,strokeWidth:2,dot:!1,strokeOpacity:c?.strokeOpacity,strokeDasharray:c?.strokeDasharray,...k,children:Ae(u)},e.dataKey):r===`area`?(0,i.jsx)(a.Area,{yAxisId:s,type:`monotone`,dataKey:e.dataKey,fill:n,stroke:n,fillOpacity:c?.fillOpacity??.4,strokeOpacity:c?.strokeOpacity,strokeDasharray:c?.strokeDasharray,...l,...k,children:Ae(u)},e.dataKey):(0,i.jsx)(a.Bar,{yAxisId:s,dataKey:e.dataKey,fill:n,radius:4,fillOpacity:c?.fillOpacity,...l,...k,children:Ae(u)},e.dataKey)})]})})});let Me=E===`horizontal-bar`,Ne=K(),Pe=d?Object.values(d).map(e=>W(String(e))):[],Fe=Array.from(new Set([...Ne,...Pe,...c.map((e,t)=>W(o[e.dataKey]?.color||Ne[t%Ne.length]||be))])),Ie=e=>`g`+e.replace(/[^a-zA-Z0-9]/g,``);return(0,i.jsx)(ge,{title:y,subtitle:b,children:(0,i.jsx)(P,{config:o,className:l,...A,children:(0,i.jsxs)(ve,{data:O,layout:Me?`vertical`:`horizontal`,...R,children:[(0,i.jsx)(`defs`,{children:Fe.map(e=>(0,i.jsxs)(n.Fragment,{children:[(0,i.jsxs)(`linearGradient`,{id:`bg-${Ie(e)}`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,i.jsx)(`stop`,{offset:`0%`,style:{stopColor:e},stopOpacity:.95}),(0,i.jsx)(`stop`,{offset:`100%`,style:{stopColor:e},stopOpacity:.5})]}),(0,i.jsxs)(`linearGradient`,{id:`ag-${Ie(e)}`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,i.jsx)(`stop`,{offset:`0%`,style:{stopColor:e},stopOpacity:.5}),(0,i.jsx)(`stop`,{offset:`95%`,style:{stopColor:e},stopOpacity:.05})]})]},Ie(e)))}),(0,i.jsx)(a.CartesianGrid,{...Te}),Me?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(a.XAxis,{type:`number`,tickLine:!1,axisLine:!1,tickFormatter:Q,...Ce(J)}),(0,i.jsx)(a.YAxis,{type:`category`,dataKey:s,tickLine:!1,axisLine:!1,width:Math.min(140,Math.max(60,Math.max(...O.map(e=>String(e[s]??``).length))*7)),tickFormatter:Z})]}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(a.XAxis,{dataKey:s,...je}),(0,i.jsx)(a.YAxis,{...X?{yAxisId:`left`}:{},tickLine:!1,axisLine:!1,tickFormatter:Q,width:48,...Ce(J)}),X?(0,i.jsx)(a.YAxis,{yAxisId:`right`,orientation:`right`,tickLine:!1,axisLine:!1,tickFormatter:$,width:48,...Ce(Y,`right`)}):null]}),Oe?(0,i.jsx)(V,{content:(0,i.jsx)(F,{})}):null,Ee?(0,i.jsx)(H,{content:(0,i.jsx)(I,{}),...j&&{verticalAlign:`bottom`,wrapperStyle:{fontSize:`11px`,paddingTop:`8px`}}}):null,De,ke,c.map((e,t)=>{let n=K(),r=e.variant===`comparison`,l=r?c.slice(0,t).find(e=>e.variant!==`comparison`)||c[0]:e,u=r?c.indexOf(l):t,d=W(o[l.dataKey]?.color||n[u%n.length]||be),f=X?{yAxisId:e.yAxis===`right`?`right`:`left`}:{},p=e.stack?{stackId:String(e.stack)}:{},m=x((e.yAxis===`right`?Y:J)?.format);if(E===`bar`||E===`horizontal-bar`){let t=c.filter(e=>e.variant!==`comparison`).length===1&&!r&&c.length===1&&O.length>1,o=G(e,`bar`);return(0,i.jsxs)(a.Bar,{dataKey:e.dataKey,fill:`url(#bg-${Ie(d)})`,radius:4,fillOpacity:o?.fillOpacity,...p,...f,...k,children:[t&&O.map((e,t)=>(0,i.jsx)(a.Cell,{fill:`url(#bg-${Ie(W(z(e?.[s],t,n)))})`},`cell-${t}`)),Ae(m)]},e.dataKey)}if(E===`line`){let t=G(e,`line`);return(0,i.jsx)(a.Line,{type:`monotone`,dataKey:e.dataKey,stroke:d,strokeWidth:2,dot:!1,strokeOpacity:t?.strokeOpacity,strokeDasharray:t?.strokeDasharray,...f,...k,children:Ae(m)},e.dataKey)}if(E===`area`){let t=G(e,`area`);return(0,i.jsx)(a.Area,{type:`monotone`,dataKey:e.dataKey,fill:`url(#ag-${Ie(d)})`,stroke:d,strokeWidth:2,fillOpacity:t?.fillOpacity??1,strokeOpacity:t?.strokeOpacity,strokeDasharray:t?.strokeDasharray,...p,...f,...k,children:Ae(m)},e.dataKey)}return null})]})})})}function ve(e){let t=e.chartType===`column`?`bar`:e.chartType??`bar`,n=Array.isArray(e.data)?e.data:[],r=e.xAxisKey??`name`;return K.has(t)&&n.length>0&&!n.some(e=>typeof e==`object`&&!!e&&r in e)}function ye(e){let t=ve(e),r=e.xAxisKey??`name`,a=n.useMemo(()=>Object.keys((Array.isArray(e.data)?e.data[0]:void 0)??{}),[e.data]);return n.useEffect(()=>{t&&console.warn(`[chart] no row has the category key "${r}" — rendering an explanatory placeholder instead of an empty axis. Row keys: ${JSON.stringify(a)}. A dataset query must PROJECT the dimension it groups by (framework#4033).`)},[t,r,a]),t?(0,i.jsx)(`div`,{className:`flex h-full min-h-[120px] w-full items-center justify-center p-4 text-center text-sm text-muted-foreground ${e.className??``}`,role:`status`,"data-chart-error":`missing-category-key`,children:(0,i.jsxs)(`span`,{children:[`This chart cannot plot its category axis: no row has a`,` `,(0,i.jsx)(`code`,{className:`font-mono`,children:r}),` field.`]})}):(0,i.jsx)(_e,{...e})}var be,xe,W,G,K,q=h((()=>{le(),pe(),D(),be=`hsl(var(--primary))`,xe={slate:`#64748b`,gray:`#6b7280`,zinc:`#71717a`,neutral:`#737373`,stone:`#78716c`,red:`#ef4444`,orange:`#f97316`,amber:`#f59e0b`,yellow:`#eab308`,lime:`#84cc16`,green:`#22c55e`,emerald:`#10b981`,teal:`#14b8a6`,cyan:`#06b6d4`,sky:`#0ea5e9`,blue:`#3b82f6`,indigo:`#6366f1`,violet:`#8b5cf6`,purple:`#a855f7`,fuchsia:`#d946ef`,pink:`#ec4899`,rose:`#f43f5e`},W=e=>xe[e]||e,G=(e,t)=>e?.variant===`comparison`?{strokeOpacity:typeof e.opacity==`number`?e.opacity:t===`line`||t===`scatter`?.5:.6,fillOpacity:typeof e.opacity==`number`?e.opacity:t===`bar`?.4:t===`area`?.2:.5,strokeDasharray:e.dashArray??(t===`line`||t===`area`?`4 4`:void 0)}:null,K=new Set([`bar`,`horizontal-bar`,`line`,`area`,`pie`,`donut`,`radar`,`funnel`,`combo`])}));D();var J=n.default.lazy(()=>Promise.resolve().then(()=>(M(),O))),Y=n.default.lazy(()=>Promise.resolve().then(()=>(q(),me))),X=({schema:e})=>(0,i.jsx)(n.Suspense,{fallback:(0,i.jsx)(r.Skeleton,{className:`w-full h-48 sm:h-64 md:h-80 lg:h-[400px]`}),children:(0,i.jsx)(J,{data:e.data,dataKey:e.dataKey,xAxisKey:e.xAxisKey,height:e.height,className:e.className,color:e.color})}),Z=({schema:e,onChartClick:t})=>{let a=n.default.useMemo(()=>{let t=ee(e),n=Array.isArray(e.series)?e.series:void 0,r=(n?.length&&n.every(e=>!!e&&typeof e==`object`&&`dataKey`in e)?n:t.series)??n,i=e.xAxisKey??t.xAxisKey,a=e.config;if(i||(e.index?i=e.index:e.category&&(i=e.category)),r||(e.categories?r=e.categories.map(e=>({dataKey:e})):e.value&&(r=[{dataKey:e.value}])),!a&&r){let t=e.colors||[`hsl(var(--chart-1))`,`hsl(var(--chart-2))`,`hsl(var(--chart-3))`],n={};r.forEach((e,r)=>{n[e.dataKey]={label:e.label||e.dataKey,color:e.color||t[r%t.length]}}),a=n}return{chartType:e.chartType??t.chartType,data:Array.isArray(e.data)?e.data:[],config:a,xAxisKey:i,series:r,className:e.className,spec:t}},[e]);return(0,i.jsx)(n.Suspense,{fallback:(0,i.jsx)(r.Skeleton,{className:`w-full h-48 sm:h-64 md:h-80 lg:h-[400px]`}),children:(0,i.jsx)(Y,{chartType:a.chartType,data:a.data,config:a.config,xAxisKey:a.xAxisKey,series:a.series,className:a.className,colors:Array.isArray(e.colors)?e.colors:void 0,categoryColors:e.categoryColors,categoryOrder:e.categoryOrder,isAnimationActive:e.isAnimationActive,onChartClick:t,xAxis:a.spec.xAxis,yAxes:a.spec.yAxes,showLegend:a.spec.showLegend,showDataLabels:a.spec.showDataLabels,title:a.spec.title,subtitle:a.spec.subtitle,description:a.spec.description,height:a.spec.height??e.height,annotations:a.spec.annotations,interaction:a.spec.interaction})})};function Q(e){return e.replace(/[_-]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function $(e){return e.field||e.function||`count`}var Se=`__comparison`;function Ce(e,t){let{field:n,function:r,groupBy:i}=t,a=$(t),o={};for(let t of e){let e=String(t[i]??`Unknown`);o[e]||(o[e]=[]),o[e].push(t)}return Object.entries(o).map(([e,t])=>{let o=n?t.map(e=>Number(e[n])||0):[],s;switch(r){case`count`:s=t.length;break;case`avg`:s=o.length>0?o.reduce((e,t)=>e+t,0)/o.length:0;break;case`min`:s=o.length>0?Math.min(...o):0;break;case`max`:s=o.length>0?Math.max(...o):0;break;default:s=o.reduce((e,t)=>e+t,0);break}return{[i]:e,[a]:s}})}async function we(e,n,r,i,a){if(!e.length||!n)return e;let o=a||((e,t)=>t),s=`__raw_${n}`,c=r?.fields?.[n];if(!c){let t=/^\d{4}-\d{2}-\d{2}/;return e.map(e=>{let r=e[n],i=String(r??``),a=t.test(i)?i:Q(i);return{...e,[n]:o(i,a),[s]:r}})}let l=c.type;if(l===`select`||l===`picklist`||l===`dropdown`){let t=c.options||[];if(t.length===0)return e.map(e=>{let t=e[n],r=String(t??``),i=Q(r);return{...e,[n]:o(r,i),[s]:t}});let r={};for(let e of t)typeof e==`string`?r[e]=e:e&&typeof e==`object`&&(r[String(e.value)]=e.label||String(e.value));return e.map(e=>{let t=e[n],i=String(t??``),a=r[i]||Q(i);return{...e,[n]:o(i,a),[s]:t}})}if(l===`lookup`||l===`master_detail`){let r=c.reference_to||c.reference;if(!r||!i||typeof i.find!=`function`)return e.map(e=>({...e,[s]:e[n]}));let a=[...new Set(e.map(e=>e[n]).filter(e=>e!=null))];if(a.length===0)return e.map(e=>({...e,[s]:e[n]}));let o=c.id_field||`id`;try{let l=(0,t.extractRecords)(await i.find(r,{$filter:{[o]:{$in:a}},$top:a.length})),u=c.reference_field||c.display_field||`name`,d={};for(let e of l){let t=String(e[o]??e.id??e._id??``),n=e[u]||e.name||e.label||e.title||t;t&&(d[t]=String(n))}return e.map(e=>{let t=e[n],r=String(t??``);return{...e,[n]:d[r]||r,[s]:t}})}catch(t){return console.warn(`[ObjectChart] Failed to resolve lookup labels:`,t),e.map(e=>({...e,[s]:e[n]}))}}if(l===`date`||l===`datetime`||l===`date_time`||l===`timestamp`||l===`time`)return e.map(e=>({...e,[s]:e[n]}));let u=/^\d{4}-\d{2}-\d{2}/;return e.map(e=>{let t=e[n],r=String(t??``);return{...e,[n]:u.test(r)?r:Q(r),[s]:t}})}var Te=e=>{let{schema:a}=e,l=e.onSegmentClick,u=(0,n.useContext)(o.SchemaRendererContext),d=e.dataSource||u?.dataSource,f=(0,o.useDataScope)(a.bind),{fieldOptionLabel:p}=(0,c.useSafeFieldLabel)(),m=(0,n.useRef)(p);(0,n.useEffect)(()=>{m.current=p},[p]);let[h,g]=(0,n.useState)([]),[_,v]=(0,n.useState)(null),[y,b]=(0,n.useState)(()=>!(Array.isArray(a.data)&&a.data.length>0)&&(!!a.objectName||!!a.dataset)),[ee,te]=(0,n.useState)(null),[ne,x]=(0,n.useState)(null),[re,ie]=(0,n.useState)(null),[ae,S]=(0,n.useState)(null),{openRecordList:oe}=(0,o.useDrillNavigation)(),se=(0,c.useSafeTranslate)(),C=(0,n.useMemo)(()=>a.aggregate?JSON.stringify(a.aggregate):``,[a.aggregate]),w=(0,n.useMemo)(()=>a.filter?JSON.stringify(a.filter):``,[a.filter]),T=(0,n.useMemo)(()=>a.compareTo?JSON.stringify(a.compareTo):``,[a.compareTo]),E=(0,n.useMemo)(()=>a.dataset?JSON.stringify({d:a.dataset,dim:a.dimensions??[],val:a.values??[]}):``,[a.dataset,a.dimensions,a.values]),D=e=>e!==`pie`&&e!==`donut`&&e!==`funnel`;(0,n.useEffect)(()=>{let e=!1;return(async()=>{try{let n={headers:{accept:`application/json`},credentials:`include`},r=a.objectName,i,o=null,s=a.aggregate?.groupBy;if(r)i=s&&typeof s==`object`&&!Array.isArray(s)?s.field:typeof s==`string`?s:a.xAxisKey;else if(a.dataset){let e=Array.isArray(a.dimensions)&&a.dimensions.length?a.dimensions[0]:void 0,t=await(await fetch(`/api/v1/meta/dataset/${encodeURIComponent(a.dataset)}`,n)).json().catch(()=>null);o=t?.item??t?.data??t,r=o?.object,i=((o?.dimensions||[]).find(t=>t?.name===e)??(o?.dimensions||[])[0])?.field??e}if(!r||!i){e||(ie(null),S(null));return}let c=await(await fetch(`/api/v1/meta/object/${encodeURIComponent(r)}`,n)).json().catch(()=>null),l=c?.item??c?.data??c,u=(0,t.buildOptionColorMap)(l?.fields?.[i]?.options),d=null;if(a.dataset&&Array.isArray(a.dimensions)){let e={};for(let n of a.dimensions){let r=(o?.dimensions||[]).find(e=>e?.name===n)?.field??n,i=(0,t.buildDimensionLabelMap)(l?.fields?.[r]?.options);i&&(e[n]=i)}Object.keys(e).length>0&&(d=e)}e||(ie(u),S(d))}catch{e||(ie(null),S(null))}})(),()=>{e=!0}},[a.objectName,a.dataset,E,C,a.xAxisKey]);let O=(0,n.useCallback)(async(e,n)=>{if(a.aggregate&&typeof e.aggregate==`function`){let t=a.aggregate.groupBy;if(t&&typeof t==`object`&&!Array.isArray(t)){let r=a.aggregate.field,i=a.aggregate.function,o={function:i,alias:$(a.aggregate)};i!==`count`&&r&&(o.field=r);let s=await e.aggregate(a.objectName,{groupBy:[t],aggregations:[o],where:n});return Array.isArray(s)?s:[]}let r=await e.aggregate(a.objectName,{field:a.aggregate.field,function:a.aggregate.function,groupBy:t,filter:n});return Array.isArray(r)?r:[]}if(typeof e.find==`function`){let r=(0,t.extractRecords)(await e.find(a.objectName,{$filter:n}));return a.aggregate&&r.length>0&&(r=Ce(r,a.aggregate)),r}return[]},[a.objectName,C]),k=(0,o.useFilterScope)(),A=(0,n.useCallback)(async(e,n)=>{if(!e||!a.objectName&&!a.dataset){n.current&&b(!1);return}n.current&&(b(!0),te(null));try{if(a.dataset&&typeof e.queryDataset==`function`){let r=(0,t.resolveFilterPlaceholders)(a.filter,k),i=await e.queryDataset(a.dataset,{dimensions:Array.isArray(a.dimensions)?a.dimensions:[],measures:Array.isArray(a.values)?a.values:[],...r?{runtimeFilter:r}:{}});n.current&&(g(Array.isArray(i?.rows)?i.rows:[]),v(Array.isArray(i?.fields)?i.fields:null));return}let r=(0,t.resolveFilterPlaceholders)(a.filter,k),i=a.compareTo,o=!!i&&D(a.chartType),s=o?(0,t.resolveContextTokens)((0,t.shiftFilterByCompareTo)(a.filter,i),k):null,[c,l]=await Promise.all([O(e,r),s?O(e,s):Promise.resolve([])]),u=c,d=a.aggregate?.groupBy,f=d&&typeof d==`object`&&!Array.isArray(d)?d.alias||d.field:d||a.xAxisKey;if(o&&l.length>0&&a.aggregate){let e=a.aggregate.field,t=a.aggregate.function,n=$(a.aggregate),r=r=>{if(r==null)return null;if(e){let n=`${e}_${t}`;if(n in r)return Number(r[n]);if(t===`count`&&`${e}_count`in r)return Number(r[`${e}_count`])}return n in r?Number(r[n]):`value`in r?Number(r.value):`count`in r?Number(r.count):null},i=`${n}${Se}`,o=f;if(o&&u.some(e=>e[o]!=null)&&l.some(e=>e[o]!=null)){let e=new Map;for(let t of l){let n=String(t[o]??``);e.set(n,r(t))}u=u.map(t=>{let n=String(t[o]??``),r=e.get(n);return r==null?t:{...t,[i]:r}});let t=new Set(u.map(e=>String(e[o]??``)));for(let e of l){let n=String(e[o]??``);t.has(n)||u.push({[o]:n,[i]:r(e)})}}else{let e=Math.max(u.length,l.length),t=[];for(let n=0;n<e;n++){let e=u[n]||{},a=l[n];t.push(a?{...e,[i]:r(a)}:e)}u=t}}if(f&&typeof e.getObjectSchema==`function`)try{let t=await e.getObjectSchema(a.objectName);u=await we(u,f,t,e,(e,t)=>m.current(a.objectName,f,e,t))}catch{}n.current&&g(u)}catch(e){console.error(`[ObjectChart] Fetch error:`,e),n.current&&te(e instanceof Error?e.message:`Failed to load chart data`)}finally{n.current&&b(!1)}},[a.objectName,E,C,w,T,a.xAxisKey,a.chartType,O,k]);(0,n.useEffect)(()=>{let e={current:!0};return(a.objectName||a.dataset)&&!f&&!a.data?A(d,e):e.current&&b(!1),()=>{e.current=!1}},[a.objectName,E,d,f,a.data,w,C,T,A]);let j=f||a.data||h,M=Array.isArray(j)?j:[],N=a.drillDown,P=a.aggregate?.groupBy||a.xAxisKey,F=(0,n.useMemo)(()=>{if(!P)return new Map;let e=new Map,t=`__raw_${P}`;for(let n of M){let r=n?.[P];if(r==null)continue;let i=t in(n||{})?n[t]:r;e.set(String(r),i)}return e},[M,P]),I=a.compareTo,L=a.aggregate?$(a.aggregate):void 0,R=L?`${L}${Se}`:void 0,ce=!!I&&D(a.chartType)&&!!R&&M.some(e=>e[R]!=null),z=(0,n.useMemo)(()=>{let e=Array.isArray(a.series)?a.series:null;if(!ce)return e;let n=e||[{dataKey:L}],r={vsLastWeek:`Previous week`,vsLastMonth:`Previous month`,vsLastQuarter:`Previous quarter`,vsLastYear:`Previous year`,vsYesterday:`Yesterday`,vsPreviousPeriod:`Previous period`}[(0,t.compareToTrendLabelKey)(I,a.filter)]||`Previous period`;return[...n.map(e=>({...e,variant:e.variant||`current`})),{dataKey:R,label:r,variant:`comparison`}]},[ce,a.series,L,R,a.filter,I]),B=a.dataset?(0,t.buildChartSeries)((0,t.relabelDimensions)(M,ae),a.dimensions,a.values,_):null,V=B?{...a,data:B.data,xAxisKey:B.xAxisKey,series:B.series}:{...a,data:M,...z?{series:z}:{}},H=a.colors&&!Array.isArray(a.colors)&&typeof a.colors==`object`?a.colors:null,le=Array.isArray(a.colors)?a.colors:void 0,U=re||H?{...re||{},...H||{}}:void 0,ue={...V,colors:le,...U?{categoryColors:U}:{}};if(y&&M.length===0)return(0,i.jsxs)(`div`,{className:`p-2 `+(a.className||``),"data-testid":`chart-loading`,role:`status`,"aria-busy":`true`,"aria-live":`polite`,children:[(0,i.jsx)(`span`,{className:`sr-only`,children:`Loading chart data…`}),(0,i.jsx)(r.ChartSkeleton,{className:`h-full`})]});if(ee)return(0,i.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-2 p-4 `+(a.className||``),"data-testid":`chart-error`,role:`alert`,children:[(0,i.jsx)(s.AlertCircle,{className:`h-6 w-6 text-destructive opacity-60`}),(0,i.jsx)(`p`,{className:`text-xs text-destructive font-medium`,children:`Failed to load chart data`}),(0,i.jsx)(`p`,{className:`text-xs text-muted-foreground max-w-xs text-center`,children:ee})]});if(!d&&a.objectName&&M.length===0)return(0,i.jsxs)(`div`,{className:`flex items-center justify-center text-muted-foreground text-sm p-4 `+(a.className||``),"data-testid":`chart-no-datasource`,children:[`No data source available for “`,a.objectName,`”`]});let de=(0,t.isDrillEnabled)(N)?e=>{let t=e.category,n=t!=null&&F.has(String(t))?F.get(String(t)):t;x({...e,category:n,categoryLabel:t,scope:`cell`})}:void 0,fe=l??de,pe=!l&&ne&&a.objectName?(()=>{let e=(0,t.computeDrillFilter)(N,ne,{groupByField:P}),n={...a.filter||{},...e},c=(0,t.resolveDrillTitle)(N,ne,a.title||`Details`),l=N?.target??`drawer`,u=(0,i.jsx)(`div`,{className:`overflow-auto`,"data-testid":`chart-drill-body`,children:(0,i.jsx)(o.SchemaRenderer,{schema:{type:`object-data-table`,objectName:a.objectName,filter:n,pagination:!0,pageSize:N?.maxRows,columns:N?.columns?.map(e=>({accessorKey:e,header:e})),drillDown:{enabled:!0,mode:`record`,target:`dialog`}},dataSource:d})}),f=oe&&a.objectName?(0,i.jsxs)(r.Button,{type:`button`,variant:`ghost`,size:`sm`,"data-testid":`drill-open-in-list`,onClick:()=>{oe(a.objectName,n),x(null)},children:[se(`dashboard.openInList`,`Open in list`),(0,i.jsx)(s.ArrowUpRight,{className:`ml-1 h-3.5 w-3.5`})]}):null;return l===`dialog`?(0,i.jsx)(r.Dialog,{open:!0,onOpenChange:e=>!e&&x(null),children:(0,i.jsxs)(r.DialogContent,{className:`max-w-4xl`,children:[(0,i.jsxs)(r.DialogHeader,{className:`flex-row items-center justify-between gap-4 pr-8`,children:[(0,i.jsx)(r.DialogTitle,{children:c}),f]}),u]})}):(0,i.jsx)(r.Sheet,{open:!0,onOpenChange:e=>!e&&x(null),children:(0,i.jsxs)(r.SheetContent,{side:`right`,className:`w-full sm:max-w-2xl md:max-w-3xl lg:max-w-4xl flex flex-col`,children:[(0,i.jsxs)(r.SheetHeader,{className:`flex-row items-center justify-between gap-4 pr-8`,children:[(0,i.jsx)(r.SheetTitle,{children:c}),f]}),(0,i.jsx)(`div`,{className:`flex-1 overflow-hidden mt-2`,children:u})]})})})():null;return(0,i.jsxs)(`div`,{className:`relative`,children:[(0,i.jsx)(r.RefreshIndicator,{active:y&&M.length>0}),(0,i.jsx)(Z,{...e,schema:ue,onChartClick:fe}),pe]})};t.ComponentRegistry.register(`object-chart`,Te,{namespace:`plugin-charts`,label:`Object Chart`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`data`,type:`array`,label:`Data`,description:`Optional static data`},{name:`filter`,type:`array`,label:`Filter`},{name:`aggregate`,type:`object`,label:`Aggregate`,description:`Aggregation config: { field, function, groupBy }`}]});var Ee={"bar-chart":X,chart:Z};t.ComponentRegistry.register(`bar-chart`,X,{namespace:`plugin-charts`,label:`Bar Chart`,category:`plugin`,inputs:[{name:`data`,type:`array`,label:`Data`,required:!0},{name:`dataKey`,type:`string`,label:`Data Key`,defaultValue:`value`},{name:`xAxisKey`,type:`string`,label:`X-Axis Key`,defaultValue:`name`},{name:`height`,type:`number`,label:`Height`,defaultValue:400},{name:`color`,type:`color`,label:`Color`,defaultValue:`#8884d8`}],defaultProps:{data:[{name:`Jan`,value:400},{name:`Feb`,value:300},{name:`Mar`,value:600},{name:`Apr`,value:800},{name:`May`,value:500}],dataKey:`value`,xAxisKey:`name`,height:400,color:`#8884d8`}}),t.ComponentRegistry.register(`chart`,Te,{namespace:`view`,category:`view`,label:`Chart`,skipFallback:!0,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`type`,type:`string`,label:`Chart Type`},{name:`categoryField`,type:`string`,label:`Category Field`},{name:`valueField`,type:`string`,label:`Value Field`}]}),t.ComponentRegistry.register(`chart`,Z,{namespace:`plugin-charts`,label:`Chart`,category:`plugin`,inputs:[{name:`chartType`,type:`enum`,label:`Chart Type`,enum:[{label:`Bar`,value:`bar`},{label:`Line`,value:`line`},{label:`Area`,value:`area`},{label:`Pie`,value:`pie`},{label:`Donut`,value:`donut`},{label:`Radar`,value:`radar`},{label:`Scatter`,value:`scatter`}],defaultValue:`bar`},{name:`data`,type:`code`,label:`Data (JSON)`,required:!0},{name:`config`,type:`code`,label:`Config (JSON)`},{name:`xAxisKey`,type:`string`,label:`X Axis Key`,defaultValue:`name`},{name:`series`,type:`code`,label:`Series (JSON Array)`,required:!0},{name:`className`,type:`string`,label:`CSS Class`}],defaultProps:{chartType:`bar`,data:[{name:`Jan`,sales:400,revenue:240},{name:`Feb`,sales:300,revenue:139},{name:`Mar`,sales:600,revenue:380},{name:`Apr`,sales:800,revenue:430},{name:`May`,sales:500,revenue:220}],config:{sales:{label:`Sales`,color:`#8884d8`},revenue:{label:`Revenue`,color:`#82ca9d`}},xAxisKey:`name`,series:[{dataKey:`sales`},{dataKey:`revenue`}]}}),t.ComponentRegistry.register(`chart:bar`,Z,{namespace:`plugin-charts`,label:`Bar Chart (Alias)`,category:`plugin`,defaultProps:{chartType:`bar`}}),t.ComponentRegistry.register(`pie-chart`,Z,{namespace:`plugin-charts`,label:`Pie Chart`,category:`plugin`,defaultProps:{chartType:`pie`}}),t.ComponentRegistry.register(`donut-chart`,Z,{namespace:`plugin-charts`,label:`Donut Chart`,category:`plugin`,defaultProps:{chartType:`donut`}}),t.ComponentRegistry.register(`radar-chart`,Z,{namespace:`plugin-charts`,label:`Radar Chart`,category:`plugin`,defaultProps:{chartType:`radar`}}),t.ComponentRegistry.register(`scatter-chart`,Z,{namespace:`plugin-charts`,label:`Scatter Chart`,category:`plugin`,defaultProps:{chartType:`scatter`}}),e.ChartBarRenderer=X,e.ChartRenderer=Z,e.ObjectChart=Te,e.chartComponents=Ee});
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The ONE place the spec's author-facing chart shape is translated into the
|
|
10
|
+
* renderer's internal pipeline contract (framework#3729 / objectui#2880).
|
|
11
|
+
*
|
|
12
|
+
* ## Why this exists
|
|
13
|
+
*
|
|
14
|
+
* `ChartConfigSchema` (`@objectstack/spec/ui`) is the chart protocol — axes are
|
|
15
|
+
* `{ field, format, min, max, logarithmic, … }` objects and series are
|
|
16
|
+
* `{ name, stack, yAxis, … }`. The renderer, however, grew a Recharts-flavoured
|
|
17
|
+
* internal shape: `chartType`, `xAxisKey` (a bare string) and
|
|
18
|
+
* `series[].dataKey`. Everything an author wrote in the SPEC shape reached the
|
|
19
|
+
* renderer and was silently dropped — precisely what ADR-0078 forbids.
|
|
20
|
+
*
|
|
21
|
+
* This module closes that gap by NORMALIZING at the boundary, rather than by
|
|
22
|
+
* sprinkling `??` fallbacks through the render tree. That distinction matters
|
|
23
|
+
* (framework PD #12): a lone normalization layer is a translation from one
|
|
24
|
+
* declared contract to another, whereas scattered fallbacks fossilize a second
|
|
25
|
+
* de-facto dialect at every read site.
|
|
26
|
+
*
|
|
27
|
+
* **Internal props win.** `DashboardRenderer`, `ObjectView` and the dataset
|
|
28
|
+
* path already speak the internal shape; passing `xAxisKey`/`series[].dataKey`
|
|
29
|
+
* explicitly keeps working byte-for-byte, so there is no migration.
|
|
30
|
+
*
|
|
31
|
+
* ## The `type` collision
|
|
32
|
+
*
|
|
33
|
+
* `ChartConfig.type` is the chart family (`'bar' | 'line' | …`). But on every
|
|
34
|
+
* surface that FLATTENS chart config into a component props bag — the react
|
|
35
|
+
* tier's injected blocks especially — `type` is already taken: it is the SDUI
|
|
36
|
+
* envelope's component discriminator (`{ type: 'object-chart', … }`). An author
|
|
37
|
+
* writing `type="bar"` would replace the discriminator and the block would not
|
|
38
|
+
* resolve at all.
|
|
39
|
+
*
|
|
40
|
+
* The collision is created by the flattening, so it is resolved there: the
|
|
41
|
+
* react-page wrapper preserves an author-supplied `type` under `specType`
|
|
42
|
+
* before stamping the discriminator (see `react-page.tsx`). This module reads
|
|
43
|
+
* it back. Surfaces where chart config is properly NESTED (a dashboard
|
|
44
|
+
* widget's `chartConfig`) never collide and pass `type` through untouched.
|
|
45
|
+
*/
|
|
46
|
+
/**
|
|
47
|
+
* A chart family this renderer actually draws.
|
|
48
|
+
*
|
|
49
|
+
* Every member is a `@objectstack/spec` `ChartTypeSchema` value except
|
|
50
|
+
* **`combo`**, which is renderer-local and is NOT a spec chart type (#2945).
|
|
51
|
+
* The spec models a combo chart per-series instead — `ChartSeries.type`, whose
|
|
52
|
+
* field comment reads *"Series type override (combo charts)"* — exactly as it
|
|
53
|
+
* models stacking with `ChartSeries.stack` rather than a `stacked-bar` family:
|
|
54
|
+
*
|
|
55
|
+
* > stacking is not a chart family, it is a property of the series … One `bar`
|
|
56
|
+
* > family plus a series-level stack group expresses all three without
|
|
57
|
+
* > multiplying the taxonomy. — `spec/src/ui/chart.zod.ts`
|
|
58
|
+
*
|
|
59
|
+
* So `combo` is not a name an author should have to reach for. It is what "the
|
|
60
|
+
* series disagree about their family" looks like from the renderer's side, and
|
|
61
|
+
* {@link effectiveChartFamily} derives it. It stays in the union because
|
|
62
|
+
* internal-shape callers pass it explicitly today (`DatasetPreview`) and
|
|
63
|
+
* because dropping a name that is already authored breaks those charts.
|
|
64
|
+
*/
|
|
65
|
+
export type ChartFamily = 'bar' | 'column' | 'horizontal-bar' | 'line' | 'area' | 'pie' | 'donut' | 'funnel' | 'radar' | 'scatter' | 'treemap' | 'sankey' | 'combo';
|
|
66
|
+
export declare const RENDERABLE: Set<string>;
|
|
67
|
+
/**
|
|
68
|
+
* Every value the spec's `ChartTypeSchema` admits — a superset of
|
|
69
|
+
* {@link RENDERABLE}, because single-value families (`metric`, `kpi`, `gauge`,
|
|
70
|
+
* …) and tabular ones render through other components entirely.
|
|
71
|
+
*
|
|
72
|
+
* Recognition is broader than rendering on purpose: this set is what decides
|
|
73
|
+
* whether a bare `type` is a chart family or the SDUI envelope's component
|
|
74
|
+
* discriminator, and getting THAT wrong would break the block outright.
|
|
75
|
+
*/
|
|
76
|
+
/**
|
|
77
|
+
* The spec's single-value chart families (`ChartTypeSchema`, whose own
|
|
78
|
+
* comment calls gauge/solid-gauge/bullet "honest single-value variants
|
|
79
|
+
* pending a real dial/target renderer"). The chart draws these as a number —
|
|
80
|
+
* they used to fall through the cartesian component map's `|| BarChart` into
|
|
81
|
+
* a bar SHELL whose series marks all returned null: grid, axes, tooltip and
|
|
82
|
+
* legend rendered with no data marks, indistinguishable from an empty
|
|
83
|
+
* dataset (#2942). Exported for the dispatch and the spec-parity test.
|
|
84
|
+
*/
|
|
85
|
+
export declare const SINGLE_VALUE_CHART_TYPES: ReadonlySet<string>;
|
|
86
|
+
/**
|
|
87
|
+
* The spec's tabular chart families — a table is not a series chart; these
|
|
88
|
+
* render through the data-table / pivot components, and the chart block says
|
|
89
|
+
* so instead of drawing the same silent empty plot (#2942).
|
|
90
|
+
*/
|
|
91
|
+
export declare const TABULAR_CHART_TYPES: ReadonlySet<string>;
|
|
92
|
+
export type AnyRec = Record<string, any>;
|
|
93
|
+
/** A y-axis (or the x-axis) after normalization — spec `ChartAxis`, resolved. */
|
|
94
|
+
export interface NormalizedAxis {
|
|
95
|
+
/** Result column this axis reads (y-axis only; the x-axis field becomes `xAxisKey`). */
|
|
96
|
+
field?: string;
|
|
97
|
+
/** d3-style format string, e.g. `"$0,0.00"` / `"0.0%"`. */
|
|
98
|
+
format?: string;
|
|
99
|
+
min?: number;
|
|
100
|
+
max?: number;
|
|
101
|
+
/** Distance between ticks on this axis. */
|
|
102
|
+
stepSize?: number;
|
|
103
|
+
/** Default true, per the spec schema. */
|
|
104
|
+
showGridLines?: boolean;
|
|
105
|
+
logarithmic?: boolean;
|
|
106
|
+
position?: 'left' | 'right' | 'top' | 'bottom';
|
|
107
|
+
/** Axis title (already resolved to a plain string). */
|
|
108
|
+
title?: string;
|
|
109
|
+
}
|
|
110
|
+
/** The families that compose on one cartesian plot — see {@link SeriesFamily}. */
|
|
111
|
+
export type SeriesFamily = 'bar' | 'line' | 'area';
|
|
112
|
+
export interface NormalizedSeries {
|
|
113
|
+
dataKey: string;
|
|
114
|
+
label?: string;
|
|
115
|
+
/**
|
|
116
|
+
* Per-series family override — spec `ChartSeries.type`.
|
|
117
|
+
*
|
|
118
|
+
* The spec types it as the full `ChartTypeSchema`, but only the cartesian
|
|
119
|
+
* families compose on one plot (a `pie` series inside a bar chart names
|
|
120
|
+
* nothing), so recognition stops at bar/line/area.
|
|
121
|
+
*/
|
|
122
|
+
chartType?: SeriesFamily;
|
|
123
|
+
variant?: 'current' | 'comparison' | 'primary';
|
|
124
|
+
opacity?: number;
|
|
125
|
+
dashArray?: string;
|
|
126
|
+
/** Stack group id — series sharing one id stack together. */
|
|
127
|
+
stack?: string;
|
|
128
|
+
/** Which y-axis this series binds to (dual-axis charts). */
|
|
129
|
+
yAxis?: 'left' | 'right';
|
|
130
|
+
color?: string;
|
|
131
|
+
}
|
|
132
|
+
export interface NormalizedChartSchema {
|
|
133
|
+
chartType?: ChartFamily;
|
|
134
|
+
xAxisKey?: string;
|
|
135
|
+
series?: NormalizedSeries[];
|
|
136
|
+
/** X-axis presentation config (its `field` is hoisted to `xAxisKey`). */
|
|
137
|
+
xAxis?: NormalizedAxis;
|
|
138
|
+
/** Y-axes, in declaration order. Index 0 is the primary (left) axis. */
|
|
139
|
+
yAxes?: NormalizedAxis[];
|
|
140
|
+
showLegend?: boolean;
|
|
141
|
+
showDataLabels?: boolean;
|
|
142
|
+
title?: string;
|
|
143
|
+
subtitle?: string;
|
|
144
|
+
/** Accessibility description — announced to screen readers. */
|
|
145
|
+
description?: string;
|
|
146
|
+
/** Fixed plot height in pixels. */
|
|
147
|
+
height?: number;
|
|
148
|
+
annotations?: AnyRec[];
|
|
149
|
+
interaction?: AnyRec;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Translate a chart schema — spec shape, internal shape, or a mix — into the
|
|
153
|
+
* renderer's internal contract. Only keys that resolve to something are
|
|
154
|
+
* present on the result, so callers can spread it over their own defaults.
|
|
155
|
+
*/
|
|
156
|
+
export declare function normalizeChartSchema(schema: unknown): NormalizedChartSchema;
|
|
157
|
+
/**
|
|
158
|
+
* Which family an un-annotated series takes when the chart is drawn as a combo,
|
|
159
|
+
* or `undefined` when the chart's own family has no per-series meaning.
|
|
160
|
+
*
|
|
161
|
+
* `undefined` therefore doubles as "this combo was authored, not derived":
|
|
162
|
+
* only a cartesian family can be widened into a combo, so a chart that reaches
|
|
163
|
+
* the combo renderer with no base family got there by being named `combo`.
|
|
164
|
+
*/
|
|
165
|
+
export declare function comboBaseFamily(chartType: string | undefined): SeriesFamily | undefined;
|
|
166
|
+
/**
|
|
167
|
+
* The family the renderer should actually draw.
|
|
168
|
+
*
|
|
169
|
+
* `ChartSeries.type` is the spec's own way to say "this series is a line on an
|
|
170
|
+
* otherwise-bar chart", and until now it was parsed, carried through
|
|
171
|
+
* normalization, and then dropped: only the renderer's `chartType === 'combo'`
|
|
172
|
+
* branch reads `series[].chartType`, so a chart authored in the spec shape
|
|
173
|
+
*
|
|
174
|
+
* ```ts
|
|
175
|
+
* { type: 'bar', series: [{ name: 'revenue' }, { name: 'margin', type: 'line' }] }
|
|
176
|
+
* ```
|
|
177
|
+
*
|
|
178
|
+
* drew `margin` as a bar. Silently — the value was right at every layer except
|
|
179
|
+
* the last. That is the failure this widens: an author writing the protocol got
|
|
180
|
+
* the wrong picture unless they also knew to write objectui's non-spec `combo`.
|
|
181
|
+
*
|
|
182
|
+
* Only a disagreement derives a combo. A chart whose series all resolve to the
|
|
183
|
+
* same family keeps its own family, so nothing that renders correctly today
|
|
184
|
+
* changes; and an explicit `combo` is returned untouched.
|
|
185
|
+
*
|
|
186
|
+
* Pass the chart's EFFECTIVE family (defaults already applied) — the answer
|
|
187
|
+
* depends on what an un-annotated series would otherwise have drawn.
|
|
188
|
+
*/
|
|
189
|
+
export declare function effectiveChartFamily<T extends ChartFamily | undefined>(chartType: T, series: readonly Pick<NormalizedSeries, 'chartType'>[] | undefined): T | 'combo';
|
|
190
|
+
/**
|
|
191
|
+
* Build a tick formatter from a spec `ChartAxis.format` string.
|
|
192
|
+
*
|
|
193
|
+
* The spec documents "d3-format or similar" (`"$0,0.00"`, `"0.0%"`). Rather
|
|
194
|
+
* than pull in d3-format for a handful of patterns, this reads the shape of
|
|
195
|
+
* the string — currency prefix, percent suffix, thousands separator, decimal
|
|
196
|
+
* places — and drives `Intl.NumberFormat`, which is already loaded and
|
|
197
|
+
* locale-aware. An unrecognized format returns `undefined`, so the caller
|
|
198
|
+
* keeps its own default formatting rather than rendering something wrong.
|
|
199
|
+
*/
|
|
200
|
+
export declare function formatterFor(format: string | undefined): ((value: any) => string) | undefined;
|
|
201
|
+
export declare function ticksFor(axis: NormalizedAxis | undefined, values: number[]): number[] | undefined;
|
|
202
|
+
/**
|
|
203
|
+
* Recharts `domain` for an axis, or `undefined` to keep the auto domain.
|
|
204
|
+
* A half-open range (only `min`, only `max`) pins that end and leaves the
|
|
205
|
+
* other automatic.
|
|
206
|
+
*/
|
|
207
|
+
export declare function domainFor(axis: NormalizedAxis | undefined): [any, any] | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@object-ui/plugin-charts",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "17.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Chart components plugin for Object UI, powered by Recharts",
|
|
@@ -25,21 +25,22 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"lucide-react": "^1.25.0",
|
|
28
|
-
"recharts": "^3.
|
|
29
|
-
"@object-ui/components": "
|
|
30
|
-
"@object-ui/core": "
|
|
31
|
-
"@object-ui/i18n": "
|
|
32
|
-
"@object-ui/react": "
|
|
33
|
-
"@object-ui/types": "
|
|
28
|
+
"recharts": "^3.10.1",
|
|
29
|
+
"@object-ui/components": "17.1.0",
|
|
30
|
+
"@object-ui/core": "17.1.0",
|
|
31
|
+
"@object-ui/i18n": "17.1.0",
|
|
32
|
+
"@object-ui/react": "17.1.0",
|
|
33
|
+
"@object-ui/types": "17.1.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"react": "^18.0.0 || ^19.0.0",
|
|
37
37
|
"react-dom": "^18.0.0 || ^19.0.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
+
"@objectstack/spec": "^17.0.0-rc.0",
|
|
40
41
|
"@types/react": "19.2.17",
|
|
41
42
|
"@types/react-dom": "19.2.3",
|
|
42
|
-
"@vitejs/plugin-react": "^6.0.
|
|
43
|
+
"@vitejs/plugin-react": "^6.0.4",
|
|
43
44
|
"typescript": "^6.0.3",
|
|
44
45
|
"vite": "^8.1.5",
|
|
45
46
|
"vite-plugin-dts": "^5.0.3"
|