@baseline-ui/charts 0.60.1 → 0.62.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/dist/index.d.mts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +1 -1
- package/dist/index.mjs +2 -2
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { NumberFormatProps } from '@baseline-ui/core';
|
|
2
3
|
import { CSSProperties } from 'react';
|
|
3
4
|
import { LineProps } from 'recharts';
|
|
4
5
|
|
|
@@ -69,6 +70,13 @@ interface CartesianChartBaseProps extends ChartBaseProps {
|
|
|
69
70
|
showXAxis?: boolean;
|
|
70
71
|
/** Whether to show the Y axis. @default true */
|
|
71
72
|
showYAxis?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Props passed to `NumberFormat` for formatting numeric values in the
|
|
75
|
+
* Y-axis ticks and tooltip entries (e.g.
|
|
76
|
+
* `{ style: "currency", currency: "USD" }`). When omitted, values render
|
|
77
|
+
* as raw numbers in both the tooltip and on the Y axis.
|
|
78
|
+
*/
|
|
79
|
+
numberFormatterProps?: Omit<NumberFormatProps, "value">;
|
|
72
80
|
}
|
|
73
81
|
|
|
74
82
|
interface BarChartBar {
|
|
@@ -112,7 +120,7 @@ interface BarChartProps extends CartesianChartBaseProps {
|
|
|
112
120
|
barRadius?: number;
|
|
113
121
|
}
|
|
114
122
|
|
|
115
|
-
declare function BarChart({ data, bars, xAxisDataKey, variant, barSize, barGap, barRadius, width, height, showTooltip, showLegend, showGrid, showXAxis, showYAxis, className, style, dir, ...ariaProps }: BarChartProps): react_jsx_runtime.JSX.Element;
|
|
123
|
+
declare function BarChart({ data, bars, xAxisDataKey, variant, barSize, barGap, barRadius, width, height, showTooltip, showLegend, showGrid, showXAxis, showYAxis, numberFormatterProps, className, style, dir, ...ariaProps }: BarChartProps): react_jsx_runtime.JSX.Element;
|
|
116
124
|
|
|
117
125
|
type CurveType = NonNullable<LineProps["type"]>;
|
|
118
126
|
interface LineChartLine {
|
|
@@ -145,7 +153,7 @@ interface LineChartProps extends CartesianChartBaseProps {
|
|
|
145
153
|
variant?: LineChartVariant;
|
|
146
154
|
}
|
|
147
155
|
|
|
148
|
-
declare function LineChart({ data, lines, xAxisDataKey, variant, width, height, showTooltip, showLegend, showGrid, showXAxis, showYAxis, className, style, dir, ...ariaProps }: LineChartProps): react_jsx_runtime.JSX.Element;
|
|
156
|
+
declare function LineChart({ data, lines, xAxisDataKey, variant, width, height, showTooltip, showLegend, showGrid, showXAxis, showYAxis, numberFormatterProps, className, style, dir, ...ariaProps }: LineChartProps): react_jsx_runtime.JSX.Element;
|
|
149
157
|
|
|
150
158
|
interface PieChartSlice {
|
|
151
159
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { NumberFormatProps } from '@baseline-ui/core';
|
|
2
3
|
import { CSSProperties } from 'react';
|
|
3
4
|
import { LineProps } from 'recharts';
|
|
4
5
|
|
|
@@ -69,6 +70,13 @@ interface CartesianChartBaseProps extends ChartBaseProps {
|
|
|
69
70
|
showXAxis?: boolean;
|
|
70
71
|
/** Whether to show the Y axis. @default true */
|
|
71
72
|
showYAxis?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Props passed to `NumberFormat` for formatting numeric values in the
|
|
75
|
+
* Y-axis ticks and tooltip entries (e.g.
|
|
76
|
+
* `{ style: "currency", currency: "USD" }`). When omitted, values render
|
|
77
|
+
* as raw numbers in both the tooltip and on the Y axis.
|
|
78
|
+
*/
|
|
79
|
+
numberFormatterProps?: Omit<NumberFormatProps, "value">;
|
|
72
80
|
}
|
|
73
81
|
|
|
74
82
|
interface BarChartBar {
|
|
@@ -112,7 +120,7 @@ interface BarChartProps extends CartesianChartBaseProps {
|
|
|
112
120
|
barRadius?: number;
|
|
113
121
|
}
|
|
114
122
|
|
|
115
|
-
declare function BarChart({ data, bars, xAxisDataKey, variant, barSize, barGap, barRadius, width, height, showTooltip, showLegend, showGrid, showXAxis, showYAxis, className, style, dir, ...ariaProps }: BarChartProps): react_jsx_runtime.JSX.Element;
|
|
123
|
+
declare function BarChart({ data, bars, xAxisDataKey, variant, barSize, barGap, barRadius, width, height, showTooltip, showLegend, showGrid, showXAxis, showYAxis, numberFormatterProps, className, style, dir, ...ariaProps }: BarChartProps): react_jsx_runtime.JSX.Element;
|
|
116
124
|
|
|
117
125
|
type CurveType = NonNullable<LineProps["type"]>;
|
|
118
126
|
interface LineChartLine {
|
|
@@ -145,7 +153,7 @@ interface LineChartProps extends CartesianChartBaseProps {
|
|
|
145
153
|
variant?: LineChartVariant;
|
|
146
154
|
}
|
|
147
155
|
|
|
148
|
-
declare function LineChart({ data, lines, xAxisDataKey, variant, width, height, showTooltip, showLegend, showGrid, showXAxis, showYAxis, className, style, dir, ...ariaProps }: LineChartProps): react_jsx_runtime.JSX.Element;
|
|
156
|
+
declare function LineChart({ data, lines, xAxisDataKey, variant, width, height, showTooltip, showLegend, showGrid, showXAxis, showYAxis, numberFormatterProps, className, style, dir, ...ariaProps }: LineChartProps): react_jsx_runtime.JSX.Element;
|
|
149
157
|
|
|
150
158
|
interface PieChartSlice {
|
|
151
159
|
/**
|
package/dist/index.js
CHANGED
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* This notice may not be removed from this file.
|
|
8
8
|
*
|
|
9
9
|
*/
|
|
10
|
-
var ie="_1yep5z6is _1yep5z6it _1yep5z6iu _1yep5z6j4 _1yep5z6j5 _1yep5z6j6 _1yep5z6jg _1yep5z6jh _1yep5z6ji",se="ofrh9o1 _1yep5z6is _1yep5z6it _1yep5z6iu _1yep5z6j1 _1yep5z6j2 _1yep5z6j3 _1yep5z6jj _1yep5z6jk _1yep5z6jl _1yep5z6le",le="_1yep5z6iv _1yep5z6iw _1yep5z6ix _1yep5z6jj _1yep5z6jk _1yep5z6jl _1yep5z69f _1yep5z69g _1yep5z69h",ce="ofrh9o2 _1yep5z6ai _1yep5z6aj _1yep5z6ak _1yep5z6b6 _1yep5z6b7 _1yep5z6b8 _1yep5z6bu _1yep5z6bv _1yep5z6bw _1yep5z6ci _1yep5z6cj _1yep5z6ck _1yep5z6lk",pe="ofrh9o0",ue="_1yep5z66 _1yep5z67 _1yep5z68 _1yep5z62i _1yep5z62j _1yep5z62k _1yep5z63o _1yep5z63p _1yep5z63q _1yep5z61c _1yep5z61d _1yep5z61e _1yep5z6al _1yep5z6am _1yep5z6an _1yep5z6b9 _1yep5z6ba _1yep5z6bb _1yep5z6bx _1yep5z6by _1yep5z6bz _1yep5z6cl _1yep5z6cm _1yep5z6cn _1yep5z6is _1yep5z6it _1yep5z6iu _1yep5z6j4 _1yep5z6j5 _1yep5z6j6 _1yep5z69f _1yep5z69g _1yep5z69h _1yep5z6lz _1yep5z6m1 _1yep5z6g1 _1yep5z6h4 _1yep5z6d7",me="_1yep5z6is _1yep5z6it _1yep5z6iu _1yep5z6jj _1yep5z6jk _1yep5z6jl _1yep5z69f _1yep5z69g _1yep5z69h",fe="_1yep5z6is _1yep5z6it _1yep5z6iu _1yep5z6j4 _1yep5z6j5 _1yep5z6j6 _1yep5z69c _1yep5z69d _1yep5z69e",de="ofrh9o3 _1yep5z6ai _1yep5z6aj _1yep5z6ak _1yep5z6b6 _1yep5z6b7 _1yep5z6b8 _1yep5z6bu _1yep5z6bv _1yep5z6bw _1yep5z6ci _1yep5z6cj _1yep5z6ck _1yep5z6lk";function E({rootClassName:e,className:t,style:o,width:r,height:n,variant:a,dir:i,legend:y,surfaceRef:u,surfaceStyle:d,children:c,...b}){return jsxRuntime.jsxs("div",{...b,className:core.classNames(ie,e,t),"data-variant":a,dir:i,style:{width:r,height:n,...o},children:[y,jsxRuntime.jsx("div",{ref:u,className:core.classNames(pe,"BaselineUI-Chart-Surface"),style:d,children:c})]})}function A({series:e,resolveColor:t,paddingInlineStart:o}){return jsxRuntime.jsx("ul",{className:`${se} BaselineUI-Chart-Legend`,style:o==null?void 0:{paddingInlineStart:o},children:e.map((r,n)=>jsxRuntime.jsxs("li",{className:`${le} BaselineUI-Chart-LegendItem`,children:[jsxRuntime.jsx("span",{className:`${ce} BaselineUI-Chart-LegendSwatch`,style:{backgroundColor:t(r,n)}}),jsxRuntime.jsx(core.Text,{type:"label",size:"sm",children:r.name??r.dataKey})]},r.dataKey))})}var Oe=e=>{if(typeof e=="number")return Number.isFinite(e)?e:null;if(typeof e=="string"&&e.trim()!==""){let t=Number(e);return Number.isFinite(t)?t:null}return null},Be=(e,t)=>{if(!t)return e;let o=Oe(e);return o==null?(process.env.NODE_ENV!=="production"&&e!=null&&core.devWarnOnce("ChartTooltip:nonNumeric",`[ChartTooltip] \`formatterProps\` was provided but a non-numeric value was received (got ${JSON.stringify(e)}). The value will render unformatted.`),e):jsxRuntime.jsx(core.NumberFormat,{value:o,...t})};function D({active:e,payload:t,label:o,formatterProps:r}){return !e||!t?.length?null:jsxRuntime.jsxs("div",{className:`${ue} BaselineUI-Chart-Tooltip`,children:[o==null?null:jsxRuntime.jsx(core.Text,{elementType:"div",type:"label",size:"sm",children:String(o)}),jsxRuntime.jsx("div",{className:fe,children:t.map(n=>jsxRuntime.jsxs("div",{className:`${me} BaselineUI-Chart-TooltipItem`,children:[jsxRuntime.jsx("span",{className:`${de} BaselineUI-Chart-TooltipSwatch`,style:{backgroundColor:n.color}}),jsxRuntime.jsxs(core.Text,{type:"label",size:"sm",children:[n.name,": ",Be(n.value,r)]})]},String(n.dataKey)))})]})}function k(e){let{direction:t}=core.useLocale();return e??t}function O(e,t){let o=null,r=()=>{o==null&&(o=requestAnimationFrame(()=>{o=null,t();}));};t();let n=new ResizeObserver(r);n.observe(e);let a=new MutationObserver(r);return a.observe(e,{childList:true,subtree:true}),()=>{o!=null&&cancelAnimationFrame(o),n.disconnect(),a.disconnect();}}var Z=".recharts-yAxis-tick-labels .recharts-cartesian-axis-tick-value";function j(e,t){let[o,r]=react.useState(0);return react.useLayoutEffect(()=>{let n=e.current;if(!n)return;let a=false,i=false,y=false,u=false,d=0,c=m=>{r(h=>h===m?h:m);};c(0);let b=()=>{process.env.NODE_ENV!=="production"&&!i&&!a&&d>5&&(i=true,console.warn(`[useLeftmostYAxisLabelOffset] Could not find "${Z}" \u2014 Recharts may have renamed its internals. Legend will fall back to flush alignment.`));},L=()=>{process.env.NODE_ENV!=="production"&&!u&&a&&(u=true,console.warn("[useLeftmostYAxisLabelOffset] Y-axis labels disappeared after a successful measurement \u2014 falling back to flush alignment. This may indicate a Recharts upgrade or an unexpected empty render."));},v=()=>{process.env.NODE_ENV!=="production"&&!y&&(y=true,console.warn(`[useLeftmostYAxisLabelOffset] Found "${Z}" but no label returned a finite bounding rect \u2014 Recharts' measurement contract may have changed. Legend will fall back to flush alignment.`));};return O(n,()=>{let m=n.querySelectorAll(Z);if(m.length===0){d+=1,a?L():b(),c(0);return}a=true;let h=n.getBoundingClientRect();if(t==="rtl"){let f=-1/0;for(let s of m){let l=s.getBoundingClientRect();l.width===0&&l.height===0||(f=Math.max(f,l.right));}if(!Number.isFinite(f)){v(),c(0);return}c(Math.max(0,h.right-f));return}let p=1/0;for(let f of m){let s=f.getBoundingClientRect();s.width===0&&s.height===0||(p=Math.min(p,s.left));}if(!Number.isFinite(p)){v(),c(0);return}c(Math.max(0,p-h.left));})},[e,t]),o}var Ce=".recharts-cartesian-grid";function Q(e){let[t,o]=react.useState(0);return react.useLayoutEffect(()=>{let r=e.current;if(!r)return;let n=false,a=false,i=0;return O(r,()=>{let u=r.querySelector(Ce);if(!u){i+=1,process.env.NODE_ENV!=="production"&&!a&&!n&&i>5&&(a=true,console.warn(`[usePlotAreaWidth] Could not find "${Ce}" \u2014 Recharts may have renamed its internals. Bar layouts will fall back to requested sizes.`));return}n=true;let d=u.getBoundingClientRect().width;o(c=>Math.abs(c-d)<.5?c:d);})},[e]),t}var ee=".recharts-yAxis-tick-labels .recharts-cartesian-axis-tick-value";function V(e,t){let[o,r]=react.useState(0);return react.useLayoutEffect(()=>{let n=e.current;if(!n)return;let a=false,i=false,y=false,u=false,d=0,c=m=>{r(h=>h===m?h:m);};c(0);let b=()=>{process.env.NODE_ENV!=="production"&&!i&&!a&&d>5&&(i=true,console.warn(`[useYAxisLeftOverflow] Could not find "${ee}" \u2014 Recharts may have renamed its internals. The focus outline will not extend over overflowing axis labels.`));},L=()=>{process.env.NODE_ENV!=="production"&&!u&&a&&(u=true,console.warn("[useYAxisLeftOverflow] Y-axis labels disappeared after a successful measurement \u2014 focus outline will no longer extend over overflowing labels. This may indicate a Recharts upgrade or an unexpected empty render."));},v=()=>{process.env.NODE_ENV!=="production"&&!y&&(y=true,console.warn(`[useYAxisLeftOverflow] Found "${ee}" but no label returned a finite bounding rect \u2014 Recharts' measurement contract may have changed. The focus outline will not extend over overflowing axis labels.`));};return O(n,()=>{let m=n.querySelectorAll(ee);if(m.length===0){d+=1,a?L():b(),c(0);return}a=true;let h=n.getBoundingClientRect();if(t==="rtl"){let f=-1/0;for(let s of m){let l=s.getBoundingClientRect();l.width===0&&l.height===0||(f=Math.max(f,l.right));}if(!Number.isFinite(f)){v(),c(0);return}c(Math.max(0,Math.ceil(f-h.right)));return}let p=1/0;for(let f of m){let s=f.getBoundingClientRect();s.width===0&&s.height===0||(p=Math.min(p,s.left));}if(!Number.isFinite(p)){v(),c(0);return}c(Math.max(0,Math.ceil(h.left-p)));})},[e,t]),o}var te="_1o5hr0b0 _1yep5z6dy",ge="_1yep5z69r _1yep5z69s _1yep5z69t";var G=[tokens.themeVars.color.support.info.medium,tokens.themeVars.color.support.success.medium,tokens.themeVars.color.support.warning.medium,tokens.themeVars.color.support.error.medium],tt=12,rt=2,ot=4,F=1,nt={width:1,height:1},at=({plotWidth:e,categoryCount:t,barCount:o,barSize:r,barGap:n})=>{if(e<=0||t<=0||o<=0)return {barSize:r,barGap:n};let a=e/t-F,i=o-1;if(o*r+i*n<=a)return {barSize:r,barGap:n};let u=o*r+i*F;if(i>0&&u<=a){let c=Math.floor((a-o*r)/i);return {barSize:r,barGap:Math.max(F,c)}}let d=Math.floor((a-i*F)/o);return {barSize:Math.max(1,d),barGap:F}},_e=(e,t)=>e.color??G[t%G.length],it=e=>{if(process.env.NODE_ENV==="production")return;let t=e.length>G.length,o=e.some(r=>r.color==null);t&&o&&core.devWarnOnce("BarChart:paletteWrap",`[BarChart] More than ${G.length} bar series with default colors \u2014 colors will repeat and series may become visually indistinguishable. Set an explicit \`color\` on each bar.`);},re=(e,t)=>{if(e.stackId!=null)return e.stackId;if(t==="stacked")return "default"},st=(e,t)=>{let o=new Map,r=new Map;for(let[n,a]of e.entries()){let i=re(a,t);i==null?o.set(n,true):r.set(i,n);}for(let n of r.values())o.set(n,true);return o},be=false,lt=({offset:e,xAxis:t})=>{process.env.NODE_ENV!=="production"&&!be&&(!e||!t||typeof t.scale?.domain!="function")&&(be=true,console.warn("[BarChart] Recharts passed an unexpected shape to verticalCoordinatesGenerator (missing offset/xAxis/scale.domain). Vertical grid lines will not render \u2014 likely caused by a Recharts upgrade."));let o=t?.scale?.domain?.(),r=Array.isArray(o)?o.length:0,n=e?.width??0;if(r===0||n===0)return [];let a=e?.left??0,i=n/r;return Array.from({length:r},(y,u)=>a+i*(u+1))};function ct({data:e,bars:t,xAxisDataKey:o,variant:r="default",barSize:n=tt,barGap:a=ot,barRadius:i=rt,width:y="100%",height:u=300,showTooltip:d=true,showLegend:c=false,showGrid:b=true,showXAxis:L=true,showYAxis:v=true,className:N,style:m,dir:h,...p}){it(t);let f=k(h),s=f==="rtl",l=react.useRef(null),w=j(l,f),I=Q(l),C=V(l,f),g=react.useMemo(()=>st(t,r),[t,r]),H=react.useMemo(()=>{let _=new Set,M=0;for(let ae of t){let $=re(ae,r);$==null?M+=1:_.add($);}return M+_.size},[t,r]),{barSize:W,barGap:x}=at({plotWidth:I,categoryCount:e.length,barCount:H,barSize:n,barGap:a});return jsxRuntime.jsx(E,{...p,rootClassName:core.classNames("BaselineUI-BarChart",ge),className:N,style:m,width:y,height:u,variant:r,dir:f,legend:c?jsxRuntime.jsx(A,{series:t,resolveColor:_e,paddingInlineStart:w}):null,surfaceRef:l,surfaceStyle:{"--chart-focus-left-overflow":s?"0px":`${C}px`,"--chart-focus-right-overflow":s?`${C}px`:"0px"},children:jsxRuntime.jsx(recharts.ResponsiveContainer,{width:"100%",height:"100%",initialDimension:nt,children:jsxRuntime.jsxs(recharts.BarChart,{accessibilityLayer:true,barGap:x,data:e,children:[b?jsxRuntime.jsx(recharts.CartesianGrid,{stroke:tokens.themeVars.color.border.strong,strokeDasharray:"3 3",verticalCoordinatesGenerator:lt}):null,L?jsxRuntime.jsx(recharts.XAxis,{dataKey:o,reversed:s,stroke:tokens.themeVars.color.border.inverse,tick:{className:te}}):null,v?jsxRuntime.jsx(recharts.YAxis,{orientation:s?"right":"left",stroke:tokens.themeVars.color.border.inverse,tick:{className:te}}):null,d?jsxRuntime.jsx(recharts.Tooltip,{content:D,cursor:{fill:tokens.themeVars.color.background.overlay.interactive}}):null,t.map((_,M)=>{let $=g.get(M)??false?[i,i,0,0]:[0,0,0,0];return jsxRuntime.jsx(recharts.Bar,{barSize:W,dataKey:_.dataKey,fill:_e(_,M),name:_.name??_.dataKey,radius:$,stackId:re(_,r)},_.dataKey)})]})})})}var oe="_1ojkdm40 _1yep5z6dy",xe="_1yep5z69r _1yep5z69s _1yep5z69t";var K=[tokens.themeVars.color.support.info.medium,tokens.themeVars.color.support.success.medium,tokens.themeVars.color.support.warning.medium,tokens.themeVars.color.support.error.medium],Y={width:40,height:20,strokeWidth:1,margin:{top:1,right:1,bottom:1,left:1}},bt={width:1,height:1},ne=(e,t)=>e.color??K[t%K.length],xt=e=>{if(process.env.NODE_ENV==="production")return;let t=e.length>K.length,o=e.some(r=>r.color==null);t&&o&&core.devWarnOnce("LineChart:paletteWrap",`[LineChart] More than ${K.length} line series with default colors \u2014 colors will repeat and series may become visually indistinguishable. Set an explicit \`color\` on each line.`);};function zt({data:e,lines:t,xAxisDataKey:o,variant:r="default",width:n,height:a,showTooltip:i,showLegend:y=false,showGrid:u,showXAxis:d,showYAxis:c,className:b,style:L,dir:v,...N}){xt(t);let m=k(v),h=m==="rtl",p=r==="sparkline",f=n??(p?Y.width:"100%"),s=a??(p?Y.height:300),l=i??!p,w=u??!p,I=d??!p,C=c??!p,g=react.useRef(null),H=j(g,m),W=V(g,m);return jsxRuntime.jsx(E,{...N,rootClassName:core.classNames("BaselineUI-LineChart",xe),className:b,style:L,width:f,height:s,variant:r,dir:m,legend:y?jsxRuntime.jsx(A,{series:t,resolveColor:ne,paddingInlineStart:H}):null,surfaceRef:g,surfaceStyle:{"--chart-focus-left-overflow":h?"0px":`${W}px`,"--chart-focus-right-overflow":h?`${W}px`:"0px"},children:jsxRuntime.jsx(recharts.ResponsiveContainer,{width:"100%",height:"100%",initialDimension:bt,children:jsxRuntime.jsxs(recharts.LineChart,{accessibilityLayer:!p,data:e,margin:p?Y.margin:void 0,children:[w?jsxRuntime.jsx(recharts.CartesianGrid,{stroke:tokens.themeVars.color.border.strong,strokeDasharray:"3 3"}):null,I?jsxRuntime.jsx(recharts.XAxis,{dataKey:o,reversed:h,stroke:tokens.themeVars.color.border.inverse,tick:{className:oe}}):null,C?jsxRuntime.jsx(recharts.YAxis,{orientation:h?"right":"left",stroke:tokens.themeVars.color.border.inverse,tick:{className:oe}}):null,l?jsxRuntime.jsx(recharts.Tooltip,{content:D,cursor:{stroke:tokens.themeVars.color.border.interactive.enabled,strokeDasharray:"3 3"}}):null,t.map((x,_)=>jsxRuntime.jsx(recharts.Line,{activeDot:p?false:{r:4,strokeWidth:2,stroke:tokens.themeVars.color.background.positive.subtle,fill:ne(x,_),style:{filter:"drop-shadow(0 0 4px rgba(0,0,0,0.4))"}},dataKey:x.dataKey,dot:x.dot??false,name:x.name??x.dataKey,stroke:ne(x,_),strokeWidth:x.strokeWidth??(p?Y.strokeWidth:2),type:x.type??"monotone"},x.dataKey))]})})})}var ze="_1yep5z69o _1yep5z69p _1yep5z69q",we="_1sy8dya1",Le="_1sy8dya0 _1yep5z6dy";var q=[tokens.themeVars.color.support.info.medium,tokens.themeVars.color.support.success.medium,tokens.themeVars.color.support.error.medium,tokens.themeVars.color.support.warning.medium],Ot=90,Bt=-270,Mt=.05,jt={width:1,height:1},Se=(e,t)=>e.color??q[t%q.length],Vt=e=>{if(process.env.NODE_ENV==="production")return;let t=e.length>q.length,o=e.some(r=>r.color==null);t&&o&&core.devWarnOnce("PieChart:paletteWrap",`[PieChart] More than ${q.length} slices with default colors \u2014 colors will repeat and slices may become visually indistinguishable. Set an explicit \`color\` on each slice.`);},Ft=({cx:e,cy:t,midAngle:o,innerRadius:r=0,outerRadius:n=0,percent:a=0})=>{if(e==null||t==null||o==null||a<Mt)return null;let i=r+(n-r)*.65,y=-o*(Math.PI/180),u=e+i*Math.cos(y),d=t+i*Math.sin(y);return jsxRuntime.jsx("text",{className:Le,x:u,y:d,textAnchor:"middle",dominantBaseline:"central",children:jsxRuntime.jsx(core.NumberFormat,{value:a,style:"percent",maximumFractionDigits:0})})},Wt={style:"percent",maximumFractionDigits:0},$t=3,Ut=({cx:e,cy:t,innerRadius:o,outerRadius:r=0,startAngle:n,endAngle:a,fill:i})=>jsxRuntime.jsxs("g",{children:[jsxRuntime.jsx(recharts.Sector,{cx:e,cy:t,innerRadius:o,outerRadius:r+$t,startAngle:n,endAngle:a,fill:i}),jsxRuntime.jsx(recharts.Sector,{cx:e,cy:t,innerRadius:o,outerRadius:r,startAngle:n,endAngle:a,fill:i,stroke:tokens.themeVars.color.focused.inset,strokeWidth:1})]}),Pe=new WeakSet;function Gt({data:e,width:t="100%",height:o=300,innerRadius:r,outerRadius:n,showTooltip:a=true,showLegend:i=true,showLabels:y=true,className:u,style:d,dir:c,...b}){Vt(e);let L=k(c),v=react.useRef(null),{sortedData:N,sliceData:m}=react.useMemo(()=>{let s=e.filter(C=>C.value>=0);process.env.NODE_ENV!=="production"&&s.length!==e.length&&console.warn("[PieChart] Negative slice values were dropped. PieChart expects all `value`s to be >= 0.");let l=s.toSorted((C,g)=>g.value-C.value),w=l.reduce((C,g)=>C+g.value,0);process.env.NODE_ENV!=="production"&&w<=0&&e.length>0&&!Pe.has(e)&&(Pe.add(e),console.warn("[PieChart] Received data with a non-positive total. The chart will render empty."));let I=l.map(C=>({...C,fraction:w>0?C.value/w:0}));return {sortedData:l,sliceData:I}},[e]);react.useEffect(()=>{let s=v.current;if(!s)return;let l=()=>{let C=s.querySelector(".recharts-active-shape")?.parentElement,g=C?.parentElement;C&&g&&g.lastElementChild!==C&&g.append(C);};l();let w=new MutationObserver(l);return w.observe(s,{subtree:true,attributes:true,attributeFilter:["class"]}),()=>{w.disconnect();}},[]);let h=n??"100%",p=r??0,f=N.map((s,l)=>({dataKey:`${s.name}-${l}`,name:s.name}));return jsxRuntime.jsx(E,{...b,rootClassName:core.classNames("BaselineUI-PieChart",ze),className:u,style:d,width:t,height:o,variant:"default",dir:L,legend:i?jsxRuntime.jsx(A,{series:f,resolveColor:(s,l)=>Se(N[l],l)}):null,surfaceRef:v,children:jsxRuntime.jsx(recharts.ResponsiveContainer,{width:"100%",height:"100%",initialDimension:jt,children:jsxRuntime.jsxs(recharts.PieChart,{accessibilityLayer:true,children:[a?jsxRuntime.jsx(recharts.Tooltip,{content:s=>jsxRuntime.jsx(D,{...s,formatterProps:Wt})}):null,jsxRuntime.jsx(recharts.Pie,{data:m,dataKey:"fraction",nameKey:"name",innerRadius:p,outerRadius:h,startAngle:Ot,endAngle:Bt,isAnimationActive:false,label:y?Ft:false,labelLine:false,stroke:tokens.themeVars.color.focused.inset,strokeWidth:1,activeShape:Ut,rootTabIndex:-1,children:N.map((s,l)=>jsxRuntime.jsx(recharts.Cell,{className:we,fill:Se(s,l)},`${s.name}-${l}`))})]})})})}exports.BarChart=ct;exports.LineChart=zt;exports.PieChart=Gt;
|
|
10
|
+
var ue="_1yep5z6is _1yep5z6it _1yep5z6iu _1yep5z6j4 _1yep5z6j5 _1yep5z6j6 _1yep5z6jg _1yep5z6jh _1yep5z6ji",me="ofrh9o1 _1yep5z6is _1yep5z6it _1yep5z6iu _1yep5z6j1 _1yep5z6j2 _1yep5z6j3 _1yep5z6jj _1yep5z6jk _1yep5z6jl _1yep5z6le",fe="_1yep5z6iv _1yep5z6iw _1yep5z6ix _1yep5z6jj _1yep5z6jk _1yep5z6jl _1yep5z69f _1yep5z69g _1yep5z69h",de="ofrh9o2 _1yep5z6ai _1yep5z6aj _1yep5z6ak _1yep5z6b6 _1yep5z6b7 _1yep5z6b8 _1yep5z6bu _1yep5z6bv _1yep5z6bw _1yep5z6ci _1yep5z6cj _1yep5z6ck _1yep5z6lk",he="ofrh9o0",ye="_1yep5z66 _1yep5z67 _1yep5z68 _1yep5z62i _1yep5z62j _1yep5z62k _1yep5z63o _1yep5z63p _1yep5z63q _1yep5z61c _1yep5z61d _1yep5z61e _1yep5z6al _1yep5z6am _1yep5z6an _1yep5z6b9 _1yep5z6ba _1yep5z6bb _1yep5z6bx _1yep5z6by _1yep5z6bz _1yep5z6cl _1yep5z6cm _1yep5z6cn _1yep5z6is _1yep5z6it _1yep5z6iu _1yep5z6j4 _1yep5z6j5 _1yep5z6j6 _1yep5z69f _1yep5z69g _1yep5z69h _1yep5z6lz _1yep5z6m1 _1yep5z6g1 _1yep5z6h4 _1yep5z6d7",Ce="_1yep5z6is _1yep5z6it _1yep5z6iu _1yep5z6jj _1yep5z6jk _1yep5z6jl _1yep5z69f _1yep5z69g _1yep5z69h",ge="_1yep5z6is _1yep5z6it _1yep5z6iu _1yep5z6j4 _1yep5z6j5 _1yep5z6j6 _1yep5z69c _1yep5z69d _1yep5z69e",ve="ofrh9o3 _1yep5z6ai _1yep5z6aj _1yep5z6ak _1yep5z6b6 _1yep5z6b7 _1yep5z6b8 _1yep5z6bu _1yep5z6bv _1yep5z6bw _1yep5z6ci _1yep5z6cj _1yep5z6ck _1yep5z6lk";function E({rootClassName:e,className:t,style:o,width:r,height:n,variant:a,dir:i,legend:d,surfaceRef:u,surfaceStyle:m,children:p,...v}){return jsxRuntime.jsxs("div",{...v,className:core.classNames(ue,e,t),"data-variant":a,dir:i,style:{width:r,height:n,...o},children:[d,jsxRuntime.jsx("div",{ref:u,className:core.classNames(he,"BaselineUI-Chart-Surface"),style:m,children:p})]})}function A({series:e,resolveColor:t,paddingInlineStart:o}){return jsxRuntime.jsx("ul",{className:`${me} BaselineUI-Chart-Legend`,style:o==null?void 0:{paddingInlineStart:o},children:e.map((r,n)=>jsxRuntime.jsxs("li",{className:`${fe} BaselineUI-Chart-LegendItem`,children:[jsxRuntime.jsx("span",{className:`${de} BaselineUI-Chart-LegendSwatch`,style:{backgroundColor:t(r,n)}}),jsxRuntime.jsx(core.Text,{type:"label",size:"sm",children:r.name??r.dataKey})]},r.dataKey))})}var Fe=e=>{if(typeof e=="number")return Number.isFinite(e)?e:null;if(typeof e=="string"&&e.trim()!==""){let t=Number(e);return Number.isFinite(t)?t:null}return null},Ve=(e,t)=>{if(!t)return e;let o=Fe(e);return o==null?(process.env.NODE_ENV!=="production"&&e!=null&&core.devWarnOnce("ChartTooltip:nonNumeric",`[ChartTooltip] \`numberFormatterProps\` was provided but a non-numeric value was received (got ${JSON.stringify(e)}). The value will render unformatted.`),e):jsxRuntime.jsx(core.NumberFormat,{value:o,...t})};function k({active:e,payload:t,label:o,numberFormatterProps:r}){return !e||!t?.length?null:jsxRuntime.jsxs("div",{className:`${ye} BaselineUI-Chart-Tooltip`,children:[o==null?null:jsxRuntime.jsx(core.Text,{elementType:"div",type:"label",size:"sm",children:String(o)}),jsxRuntime.jsx("div",{className:ge,children:t.map(n=>jsxRuntime.jsxs("div",{className:`${Ce} BaselineUI-Chart-TooltipItem`,children:[jsxRuntime.jsx("span",{className:`${ve} BaselineUI-Chart-TooltipSwatch`,style:{backgroundColor:n.color}}),jsxRuntime.jsxs(core.Text,{type:"label",size:"sm",children:[n.name,": ",Ve(n.value,r)]})]},String(n.dataKey)))})]})}function D(e){let{direction:t}=core.useLocale();return e??t}function B(e,t){let o=null,r=()=>{o==null&&(o=requestAnimationFrame(()=>{o=null,t();}));};t();let n=new ResizeObserver(r);n.observe(e);let a=new MutationObserver(r);return a.observe(e,{childList:true,subtree:true}),()=>{o!=null&&cancelAnimationFrame(o),n.disconnect(),a.disconnect();}}var re=".recharts-yAxis-tick-labels .recharts-cartesian-axis-tick-value";function F(e,t){let[o,r]=react.useState(0);return react.useLayoutEffect(()=>{let n=e.current;if(!n)return;let a=false,i=false,d=false,u=false,m=0,p=h=>{r(f=>f===h?f:h);};p(0);let v=()=>{process.env.NODE_ENV!=="production"&&!i&&!a&&m>5&&(i=true,console.warn(`[useLeftmostYAxisLabelOffset] Could not find "${re}" \u2014 Recharts may have renamed its internals. Legend will fall back to flush alignment.`));},N=()=>{process.env.NODE_ENV!=="production"&&!u&&a&&(u=true,console.warn("[useLeftmostYAxisLabelOffset] Y-axis labels disappeared after a successful measurement \u2014 falling back to flush alignment. This may indicate a Recharts upgrade or an unexpected empty render."));},z=()=>{process.env.NODE_ENV!=="production"&&!d&&(d=true,console.warn(`[useLeftmostYAxisLabelOffset] Found "${re}" but no label returned a finite bounding rect \u2014 Recharts' measurement contract may have changed. Legend will fall back to flush alignment.`));};return B(n,()=>{let h=n.querySelectorAll(re);if(h.length===0){m+=1,a?N():v(),p(0);return}a=true;let f=n.getBoundingClientRect();if(t==="rtl"){let c=-1/0;for(let s of h){let l=s.getBoundingClientRect();l.width===0&&l.height===0||(c=Math.max(c,l.right));}if(!Number.isFinite(c)){z(),p(0);return}p(Math.max(0,f.right-c));return}let y=1/0;for(let c of h){let s=c.getBoundingClientRect();s.width===0&&s.height===0||(y=Math.min(y,s.left));}if(!Number.isFinite(y)){z(),p(0);return}p(Math.max(0,y-f.left));})},[e,t]),o}var xe=".recharts-cartesian-grid";function oe(e){let[t,o]=react.useState(0);return react.useLayoutEffect(()=>{let r=e.current;if(!r)return;let n=false,a=false,i=0;return B(r,()=>{let u=r.querySelector(xe);if(!u){i+=1,process.env.NODE_ENV!=="production"&&!a&&!n&&i>5&&(a=true,console.warn(`[usePlotAreaWidth] Could not find "${xe}" \u2014 Recharts may have renamed its internals. Bar layouts will fall back to requested sizes.`));return}n=true;let m=u.getBoundingClientRect().width;o(p=>Math.abs(p-m)<.5?p:m);})},[e]),t}var ne=".recharts-yAxis-tick-labels .recharts-cartesian-axis-tick-value";function V(e,t){let[o,r]=react.useState(0);return react.useLayoutEffect(()=>{let n=e.current;if(!n)return;let a=false,i=false,d=false,u=false,m=0,p=h=>{r(f=>f===h?f:h);};p(0);let v=()=>{process.env.NODE_ENV!=="production"&&!i&&!a&&m>5&&(i=true,console.warn(`[useYAxisLeftOverflow] Could not find "${ne}" \u2014 Recharts may have renamed its internals. The focus outline will not extend over overflowing axis labels.`));},N=()=>{process.env.NODE_ENV!=="production"&&!u&&a&&(u=true,console.warn("[useYAxisLeftOverflow] Y-axis labels disappeared after a successful measurement \u2014 focus outline will no longer extend over overflowing labels. This may indicate a Recharts upgrade or an unexpected empty render."));},z=()=>{process.env.NODE_ENV!=="production"&&!d&&(d=true,console.warn(`[useYAxisLeftOverflow] Found "${ne}" but no label returned a finite bounding rect \u2014 Recharts' measurement contract may have changed. The focus outline will not extend over overflowing axis labels.`));};return B(n,()=>{let h=n.querySelectorAll(ne);if(h.length===0){m+=1,a?N():v(),p(0);return}a=true;let f=n.getBoundingClientRect();if(t==="rtl"){let c=-1/0;for(let s of h){let l=s.getBoundingClientRect();l.width===0&&l.height===0||(c=Math.max(c,l.right));}if(!Number.isFinite(c)){z(),p(0);return}p(Math.max(0,Math.ceil(c-f.right)));return}let y=1/0;for(let c of h){let s=c.getBoundingClientRect();s.width===0&&s.height===0||(y=Math.min(y,s.left));}if(!Number.isFinite(y)){z(),p(0);return}p(Math.max(0,Math.ceil(f.left-y)));})},[e,t]),o}var ae="_1o5hr0b0 _1yep5z6dy",ze="_1yep5z69r _1yep5z69s _1yep5z69t";var K=[tokens.themeVars.color.support.info.medium,tokens.themeVars.color.support.success.medium,tokens.themeVars.color.support.warning.medium,tokens.themeVars.color.support.error.medium],st=12,lt=2,ct=4,W=1,pt={width:1,height:1},ut=({plotWidth:e,categoryCount:t,barCount:o,barSize:r,barGap:n})=>{if(e<=0||t<=0||o<=0)return {barSize:r,barGap:n};let a=e/t-W,i=o-1;if(o*r+i*n<=a)return {barSize:r,barGap:n};let u=o*r+i*W;if(i>0&&u<=a){let p=Math.floor((a-o*r)/i);return {barSize:r,barGap:Math.max(W,p)}}let m=Math.floor((a-i*W)/o);return {barSize:Math.max(1,m),barGap:W}},we=(e,t)=>e.color??K[t%K.length],mt=e=>{if(process.env.NODE_ENV==="production")return;let t=e.length>K.length,o=e.some(r=>r.color==null);t&&o&&core.devWarnOnce("BarChart:paletteWrap",`[BarChart] More than ${K.length} bar series with default colors \u2014 colors will repeat and series may become visually indistinguishable. Set an explicit \`color\` on each bar.`);},se=(e,t)=>{if(e.stackId!=null)return e.stackId;if(t==="stacked")return "default"},ft=(e,t)=>{let o=new Map,r=new Map;for(let[n,a]of e.entries()){let i=se(a,t);i==null?o.set(n,true):r.set(i,n);}for(let n of r.values())o.set(n,true);return o},Le=false,dt=({offset:e,xAxis:t})=>{process.env.NODE_ENV!=="production"&&!Le&&(!e||!t||typeof t.scale?.domain!="function")&&(Le=true,console.warn("[BarChart] Recharts passed an unexpected shape to verticalCoordinatesGenerator (missing offset/xAxis/scale.domain). Vertical grid lines will not render \u2014 likely caused by a Recharts upgrade."));let o=t?.scale?.domain?.(),r=Array.isArray(o)?o.length:0,n=e?.width??0;if(r===0||n===0)return [];let a=e?.left??0,i=n/r;return Array.from({length:r},(d,u)=>a+i*(u+1))};function ht({data:e,bars:t,xAxisDataKey:o,variant:r="default",barSize:n=st,barGap:a=ct,barRadius:i=lt,width:d="100%",height:u=300,showTooltip:m=true,showLegend:p=false,showGrid:v=true,showXAxis:N=true,showYAxis:z=true,numberFormatterProps:b,className:h,style:f,dir:y,...c}){mt(t);let s=D(y),l=s==="rtl",x=react.useRef(null),I=F(x,s),C=oe(x),w=V(x,s),O=core.useNumberFormatter(b),J=react.useMemo(()=>b?g=>O.format(g):void 0,[b,O]),$=react.useCallback(g=>jsxRuntime.jsx(k,{...g,numberFormatterProps:b}),[b]),U=react.useMemo(()=>ft(t,r),[t,r]),Z=react.useMemo(()=>{let g=new Set,j=0;for(let pe of t){let G=se(pe,r);G==null?j+=1:g.add(G);}return j+g.size},[t,r]),{barSize:Q,barGap:_}=ut({plotWidth:C,categoryCount:e.length,barCount:Z,barSize:n,barGap:a});return jsxRuntime.jsx(E,{...c,rootClassName:core.classNames("BaselineUI-BarChart",ze),className:h,style:f,width:d,height:u,variant:r,dir:s,legend:p?jsxRuntime.jsx(A,{series:t,resolveColor:we,paddingInlineStart:I}):null,surfaceRef:x,surfaceStyle:{"--chart-focus-left-overflow":l?"0px":`${w}px`,"--chart-focus-right-overflow":l?`${w}px`:"0px"},children:jsxRuntime.jsx(recharts.ResponsiveContainer,{width:"100%",height:"100%",initialDimension:pt,children:jsxRuntime.jsxs(recharts.BarChart,{accessibilityLayer:true,barGap:_,data:e,children:[v?jsxRuntime.jsx(recharts.CartesianGrid,{stroke:tokens.themeVars.color.border.strong,strokeDasharray:"3 3",verticalCoordinatesGenerator:dt}):null,N?jsxRuntime.jsx(recharts.XAxis,{dataKey:o,reversed:l,stroke:tokens.themeVars.color.border.inverse,tick:{className:ae}}):null,z?jsxRuntime.jsx(recharts.YAxis,{orientation:l?"right":"left",stroke:tokens.themeVars.color.border.inverse,tick:{className:ae},tickFormatter:J}):null,m?jsxRuntime.jsx(recharts.Tooltip,{content:$,cursor:{fill:tokens.themeVars.color.background.overlay.interactive}}):null,t.map((g,j)=>{let G=U.get(j)??false?[i,i,0,0]:[0,0,0,0];return jsxRuntime.jsx(recharts.Bar,{barSize:Q,dataKey:g.dataKey,fill:we(g,j),name:g.name??g.dataKey,radius:G,stackId:se(g,r)},g.dataKey)})]})})})}var le="_1ojkdm40 _1yep5z6dy",Ne="_1yep5z69r _1yep5z69s _1yep5z69t";var H=[tokens.themeVars.color.support.info.medium,tokens.themeVars.color.support.success.medium,tokens.themeVars.color.support.warning.medium,tokens.themeVars.color.support.error.medium],q={width:40,height:20,strokeWidth:1,margin:{top:1,right:1,bottom:1,left:1}},Pt={width:1,height:1},ce=(e,t)=>e.color??H[t%H.length],Et=e=>{if(process.env.NODE_ENV==="production")return;let t=e.length>H.length,o=e.some(r=>r.color==null);t&&o&&core.devWarnOnce("LineChart:paletteWrap",`[LineChart] More than ${H.length} line series with default colors \u2014 colors will repeat and series may become visually indistinguishable. Set an explicit \`color\` on each line.`);};function At({data:e,lines:t,xAxisDataKey:o,variant:r="default",width:n,height:a,showTooltip:i,showLegend:d=false,showGrid:u,showXAxis:m,showYAxis:p,numberFormatterProps:v,className:N,style:z,dir:b,...h}){Et(t);let f=D(b),y=f==="rtl",c=r==="sparkline",s=n??(c?q.width:"100%"),l=a??(c?q.height:300),x=i??!c,I=u??!c,C=m??!c,w=p??!c,O=react.useRef(null),J=F(O,f),$=V(O,f),U=core.useNumberFormatter(v),Z=react.useMemo(()=>v?_=>U.format(_):void 0,[v,U]),Q=react.useCallback(_=>jsxRuntime.jsx(k,{..._,numberFormatterProps:v}),[v]);return jsxRuntime.jsx(E,{...h,rootClassName:core.classNames("BaselineUI-LineChart",Ne),className:N,style:z,width:s,height:l,variant:r,dir:f,legend:d?jsxRuntime.jsx(A,{series:t,resolveColor:ce,paddingInlineStart:J}):null,surfaceRef:O,surfaceStyle:{"--chart-focus-left-overflow":y?"0px":`${$}px`,"--chart-focus-right-overflow":y?`${$}px`:"0px"},children:jsxRuntime.jsx(recharts.ResponsiveContainer,{width:"100%",height:"100%",initialDimension:Pt,children:jsxRuntime.jsxs(recharts.LineChart,{accessibilityLayer:!c,data:e,margin:c?q.margin:void 0,children:[I?jsxRuntime.jsx(recharts.CartesianGrid,{stroke:tokens.themeVars.color.border.strong,strokeDasharray:"3 3"}):null,C?jsxRuntime.jsx(recharts.XAxis,{dataKey:o,reversed:y,stroke:tokens.themeVars.color.border.inverse,tick:{className:le}}):null,w?jsxRuntime.jsx(recharts.YAxis,{orientation:y?"right":"left",stroke:tokens.themeVars.color.border.inverse,tick:{className:le},tickFormatter:Z}):null,x?jsxRuntime.jsx(recharts.Tooltip,{content:Q,cursor:{stroke:tokens.themeVars.color.border.interactive.enabled,strokeDasharray:"3 3"}}):null,t.map((_,g)=>jsxRuntime.jsx(recharts.Line,{activeDot:c?false:{r:4,strokeWidth:2,stroke:tokens.themeVars.color.background.positive.subtle,fill:ce(_,g),style:{filter:"drop-shadow(0 0 4px rgba(0,0,0,0.4))"}},dataKey:_.dataKey,dot:_.dot??false,name:_.name??_.dataKey,stroke:ce(_,g),strokeWidth:_.strokeWidth??(c?q.strokeWidth:2),type:_.type??"monotone"},_.dataKey))]})})})}var Se="_1yep5z69o _1yep5z69p _1yep5z69q",Te="_1sy8dya1",Re="_1sy8dya0 _1yep5z6dy";var X=[tokens.themeVars.color.support.info.medium,tokens.themeVars.color.support.success.medium,tokens.themeVars.color.support.error.medium,tokens.themeVars.color.support.warning.medium],Gt=90,Yt=-270,Kt=.05,qt={width:1,height:1},Ee=(e,t)=>e.color??X[t%X.length],Ht=e=>{if(process.env.NODE_ENV==="production")return;let t=e.length>X.length,o=e.some(r=>r.color==null);t&&o&&core.devWarnOnce("PieChart:paletteWrap",`[PieChart] More than ${X.length} slices with default colors \u2014 colors will repeat and slices may become visually indistinguishable. Set an explicit \`color\` on each slice.`);},Xt=({cx:e,cy:t,midAngle:o,innerRadius:r=0,outerRadius:n=0,percent:a=0})=>{if(e==null||t==null||o==null||a<Kt)return null;let i=r+(n-r)*.65,d=-o*(Math.PI/180),u=e+i*Math.cos(d),m=t+i*Math.sin(d);return jsxRuntime.jsx("text",{className:Re,x:u,y:m,textAnchor:"middle",dominantBaseline:"central",children:jsxRuntime.jsx(core.NumberFormat,{value:a,style:"percent",maximumFractionDigits:0})})},Jt={style:"percent",maximumFractionDigits:0},Zt=3,Qt=({cx:e,cy:t,innerRadius:o,outerRadius:r=0,startAngle:n,endAngle:a,fill:i})=>jsxRuntime.jsxs("g",{children:[jsxRuntime.jsx(recharts.Sector,{cx:e,cy:t,innerRadius:o,outerRadius:r+Zt,startAngle:n,endAngle:a,fill:i}),jsxRuntime.jsx(recharts.Sector,{cx:e,cy:t,innerRadius:o,outerRadius:r,startAngle:n,endAngle:a,fill:i,stroke:tokens.themeVars.color.focused.inset,strokeWidth:1})]}),Ae=new WeakSet;function er({data:e,width:t="100%",height:o=300,innerRadius:r,outerRadius:n,showTooltip:a=true,showLegend:i=true,showLabels:d=true,className:u,style:m,dir:p,...v}){Ht(e);let N=D(p),z=react.useRef(null),{sortedData:b,sliceData:h}=react.useMemo(()=>{let s=e.filter(C=>C.value>=0);process.env.NODE_ENV!=="production"&&s.length!==e.length&&console.warn("[PieChart] Negative slice values were dropped. PieChart expects all `value`s to be >= 0.");let l=s.toSorted((C,w)=>w.value-C.value),x=l.reduce((C,w)=>C+w.value,0);process.env.NODE_ENV!=="production"&&x<=0&&e.length>0&&!Ae.has(e)&&(Ae.add(e),console.warn("[PieChart] Received data with a non-positive total. The chart will render empty."));let I=l.map(C=>({...C,fraction:x>0?C.value/x:0}));return {sortedData:l,sliceData:I}},[e]);react.useEffect(()=>{let s=z.current;if(!s)return;let l=()=>{let C=s.querySelector(".recharts-active-shape")?.parentElement,w=C?.parentElement;C&&w&&w.lastElementChild!==C&&w.append(C);};l();let x=new MutationObserver(l);return x.observe(s,{subtree:true,attributes:true,attributeFilter:["class"]}),()=>{x.disconnect();}},[]);let f=n??"100%",y=r??0,c=b.map((s,l)=>({dataKey:`${s.name}-${l}`,name:s.name}));return jsxRuntime.jsx(E,{...v,rootClassName:core.classNames("BaselineUI-PieChart",Se),className:u,style:m,width:t,height:o,variant:"default",dir:N,legend:i?jsxRuntime.jsx(A,{series:c,resolveColor:(s,l)=>Ee(b[l],l)}):null,surfaceRef:z,children:jsxRuntime.jsx(recharts.ResponsiveContainer,{width:"100%",height:"100%",initialDimension:qt,children:jsxRuntime.jsxs(recharts.PieChart,{accessibilityLayer:true,children:[a?jsxRuntime.jsx(recharts.Tooltip,{content:s=>jsxRuntime.jsx(k,{...s,numberFormatterProps:Jt})}):null,jsxRuntime.jsx(recharts.Pie,{data:h,dataKey:"fraction",nameKey:"name",innerRadius:y,outerRadius:f,startAngle:Gt,endAngle:Yt,isAnimationActive:false,label:d?Xt:false,labelLine:false,stroke:tokens.themeVars.color.focused.inset,strokeWidth:1,activeShape:Qt,rootTabIndex:-1,children:b.map((s,l)=>jsxRuntime.jsx(recharts.Cell,{className:Te,fill:Ee(s,l)},`${s.name}-${l}`))})]})})})}exports.BarChart=ht;exports.LineChart=At;exports.PieChart=er;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {classNames,devWarnOnce,useLocale,Text,NumberFormat}from'@baseline-ui/core';import {themeVars}from'@baseline-ui/tokens';import {useRef,useMemo,useEffect,useState,useLayoutEffect}from'react';import {ResponsiveContainer,BarChart,CartesianGrid,XAxis,YAxis,Tooltip,Bar,LineChart,Line,PieChart,Pie,Cell,Sector}from'recharts';import {jsx,jsxs}from'react/jsx-runtime';/**
|
|
1
|
+
import {useNumberFormatter,classNames,devWarnOnce,useLocale,Text,NumberFormat}from'@baseline-ui/core';import {themeVars}from'@baseline-ui/tokens';import {useRef,useMemo,useCallback,useEffect,useState,useLayoutEffect}from'react';import {ResponsiveContainer,BarChart,CartesianGrid,XAxis,YAxis,Tooltip,Bar,LineChart,Line,PieChart,Pie,Cell,Sector}from'recharts';import {jsx,jsxs}from'react/jsx-runtime';/**
|
|
2
2
|
* Copyright (c) 2023-2024 PSPDFKit GmbH. All rights reserved.
|
|
3
3
|
*
|
|
4
4
|
* THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
|
|
@@ -7,4 +7,4 @@ import {classNames,devWarnOnce,useLocale,Text,NumberFormat}from'@baseline-ui/cor
|
|
|
7
7
|
* This notice may not be removed from this file.
|
|
8
8
|
*
|
|
9
9
|
*/
|
|
10
|
-
var ie="_1yep5z6is _1yep5z6it _1yep5z6iu _1yep5z6j4 _1yep5z6j5 _1yep5z6j6 _1yep5z6jg _1yep5z6jh _1yep5z6ji",se="ofrh9o1 _1yep5z6is _1yep5z6it _1yep5z6iu _1yep5z6j1 _1yep5z6j2 _1yep5z6j3 _1yep5z6jj _1yep5z6jk _1yep5z6jl _1yep5z6le",le="_1yep5z6iv _1yep5z6iw _1yep5z6ix _1yep5z6jj _1yep5z6jk _1yep5z6jl _1yep5z69f _1yep5z69g _1yep5z69h",ce="ofrh9o2 _1yep5z6ai _1yep5z6aj _1yep5z6ak _1yep5z6b6 _1yep5z6b7 _1yep5z6b8 _1yep5z6bu _1yep5z6bv _1yep5z6bw _1yep5z6ci _1yep5z6cj _1yep5z6ck _1yep5z6lk",pe="ofrh9o0",ue="_1yep5z66 _1yep5z67 _1yep5z68 _1yep5z62i _1yep5z62j _1yep5z62k _1yep5z63o _1yep5z63p _1yep5z63q _1yep5z61c _1yep5z61d _1yep5z61e _1yep5z6al _1yep5z6am _1yep5z6an _1yep5z6b9 _1yep5z6ba _1yep5z6bb _1yep5z6bx _1yep5z6by _1yep5z6bz _1yep5z6cl _1yep5z6cm _1yep5z6cn _1yep5z6is _1yep5z6it _1yep5z6iu _1yep5z6j4 _1yep5z6j5 _1yep5z6j6 _1yep5z69f _1yep5z69g _1yep5z69h _1yep5z6lz _1yep5z6m1 _1yep5z6g1 _1yep5z6h4 _1yep5z6d7",me="_1yep5z6is _1yep5z6it _1yep5z6iu _1yep5z6jj _1yep5z6jk _1yep5z6jl _1yep5z69f _1yep5z69g _1yep5z69h",fe="_1yep5z6is _1yep5z6it _1yep5z6iu _1yep5z6j4 _1yep5z6j5 _1yep5z6j6 _1yep5z69c _1yep5z69d _1yep5z69e",de="ofrh9o3 _1yep5z6ai _1yep5z6aj _1yep5z6ak _1yep5z6b6 _1yep5z6b7 _1yep5z6b8 _1yep5z6bu _1yep5z6bv _1yep5z6bw _1yep5z6ci _1yep5z6cj _1yep5z6ck _1yep5z6lk";function E({rootClassName:e,className:t,style:o,width:r,height:n,variant:a,dir:i,legend:y,surfaceRef:u,surfaceStyle:d,children:c,...b}){return jsxs("div",{...b,className:classNames(ie,e,t),"data-variant":a,dir:i,style:{width:r,height:n,...o},children:[y,jsx("div",{ref:u,className:classNames(pe,"BaselineUI-Chart-Surface"),style:d,children:c})]})}function A({series:e,resolveColor:t,paddingInlineStart:o}){return jsx("ul",{className:`${se} BaselineUI-Chart-Legend`,style:o==null?void 0:{paddingInlineStart:o},children:e.map((r,n)=>jsxs("li",{className:`${le} BaselineUI-Chart-LegendItem`,children:[jsx("span",{className:`${ce} BaselineUI-Chart-LegendSwatch`,style:{backgroundColor:t(r,n)}}),jsx(Text,{type:"label",size:"sm",children:r.name??r.dataKey})]},r.dataKey))})}var Oe=e=>{if(typeof e=="number")return Number.isFinite(e)?e:null;if(typeof e=="string"&&e.trim()!==""){let t=Number(e);return Number.isFinite(t)?t:null}return null},Be=(e,t)=>{if(!t)return e;let o=Oe(e);return o==null?(process.env.NODE_ENV!=="production"&&e!=null&&devWarnOnce("ChartTooltip:nonNumeric",`[ChartTooltip] \`formatterProps\` was provided but a non-numeric value was received (got ${JSON.stringify(e)}). The value will render unformatted.`),e):jsx(NumberFormat,{value:o,...t})};function D({active:e,payload:t,label:o,formatterProps:r}){return !e||!t?.length?null:jsxs("div",{className:`${ue} BaselineUI-Chart-Tooltip`,children:[o==null?null:jsx(Text,{elementType:"div",type:"label",size:"sm",children:String(o)}),jsx("div",{className:fe,children:t.map(n=>jsxs("div",{className:`${me} BaselineUI-Chart-TooltipItem`,children:[jsx("span",{className:`${de} BaselineUI-Chart-TooltipSwatch`,style:{backgroundColor:n.color}}),jsxs(Text,{type:"label",size:"sm",children:[n.name,": ",Be(n.value,r)]})]},String(n.dataKey)))})]})}function k(e){let{direction:t}=useLocale();return e??t}function O(e,t){let o=null,r=()=>{o==null&&(o=requestAnimationFrame(()=>{o=null,t();}));};t();let n=new ResizeObserver(r);n.observe(e);let a=new MutationObserver(r);return a.observe(e,{childList:true,subtree:true}),()=>{o!=null&&cancelAnimationFrame(o),n.disconnect(),a.disconnect();}}var Z=".recharts-yAxis-tick-labels .recharts-cartesian-axis-tick-value";function j(e,t){let[o,r]=useState(0);return useLayoutEffect(()=>{let n=e.current;if(!n)return;let a=false,i=false,y=false,u=false,d=0,c=m=>{r(h=>h===m?h:m);};c(0);let b=()=>{process.env.NODE_ENV!=="production"&&!i&&!a&&d>5&&(i=true,console.warn(`[useLeftmostYAxisLabelOffset] Could not find "${Z}" \u2014 Recharts may have renamed its internals. Legend will fall back to flush alignment.`));},L=()=>{process.env.NODE_ENV!=="production"&&!u&&a&&(u=true,console.warn("[useLeftmostYAxisLabelOffset] Y-axis labels disappeared after a successful measurement \u2014 falling back to flush alignment. This may indicate a Recharts upgrade or an unexpected empty render."));},v=()=>{process.env.NODE_ENV!=="production"&&!y&&(y=true,console.warn(`[useLeftmostYAxisLabelOffset] Found "${Z}" but no label returned a finite bounding rect \u2014 Recharts' measurement contract may have changed. Legend will fall back to flush alignment.`));};return O(n,()=>{let m=n.querySelectorAll(Z);if(m.length===0){d+=1,a?L():b(),c(0);return}a=true;let h=n.getBoundingClientRect();if(t==="rtl"){let f=-1/0;for(let s of m){let l=s.getBoundingClientRect();l.width===0&&l.height===0||(f=Math.max(f,l.right));}if(!Number.isFinite(f)){v(),c(0);return}c(Math.max(0,h.right-f));return}let p=1/0;for(let f of m){let s=f.getBoundingClientRect();s.width===0&&s.height===0||(p=Math.min(p,s.left));}if(!Number.isFinite(p)){v(),c(0);return}c(Math.max(0,p-h.left));})},[e,t]),o}var Ce=".recharts-cartesian-grid";function Q(e){let[t,o]=useState(0);return useLayoutEffect(()=>{let r=e.current;if(!r)return;let n=false,a=false,i=0;return O(r,()=>{let u=r.querySelector(Ce);if(!u){i+=1,process.env.NODE_ENV!=="production"&&!a&&!n&&i>5&&(a=true,console.warn(`[usePlotAreaWidth] Could not find "${Ce}" \u2014 Recharts may have renamed its internals. Bar layouts will fall back to requested sizes.`));return}n=true;let d=u.getBoundingClientRect().width;o(c=>Math.abs(c-d)<.5?c:d);})},[e]),t}var ee=".recharts-yAxis-tick-labels .recharts-cartesian-axis-tick-value";function V(e,t){let[o,r]=useState(0);return useLayoutEffect(()=>{let n=e.current;if(!n)return;let a=false,i=false,y=false,u=false,d=0,c=m=>{r(h=>h===m?h:m);};c(0);let b=()=>{process.env.NODE_ENV!=="production"&&!i&&!a&&d>5&&(i=true,console.warn(`[useYAxisLeftOverflow] Could not find "${ee}" \u2014 Recharts may have renamed its internals. The focus outline will not extend over overflowing axis labels.`));},L=()=>{process.env.NODE_ENV!=="production"&&!u&&a&&(u=true,console.warn("[useYAxisLeftOverflow] Y-axis labels disappeared after a successful measurement \u2014 focus outline will no longer extend over overflowing labels. This may indicate a Recharts upgrade or an unexpected empty render."));},v=()=>{process.env.NODE_ENV!=="production"&&!y&&(y=true,console.warn(`[useYAxisLeftOverflow] Found "${ee}" but no label returned a finite bounding rect \u2014 Recharts' measurement contract may have changed. The focus outline will not extend over overflowing axis labels.`));};return O(n,()=>{let m=n.querySelectorAll(ee);if(m.length===0){d+=1,a?L():b(),c(0);return}a=true;let h=n.getBoundingClientRect();if(t==="rtl"){let f=-1/0;for(let s of m){let l=s.getBoundingClientRect();l.width===0&&l.height===0||(f=Math.max(f,l.right));}if(!Number.isFinite(f)){v(),c(0);return}c(Math.max(0,Math.ceil(f-h.right)));return}let p=1/0;for(let f of m){let s=f.getBoundingClientRect();s.width===0&&s.height===0||(p=Math.min(p,s.left));}if(!Number.isFinite(p)){v(),c(0);return}c(Math.max(0,Math.ceil(h.left-p)));})},[e,t]),o}var te="_1o5hr0b0 _1yep5z6dy",ge="_1yep5z69r _1yep5z69s _1yep5z69t";var G=[themeVars.color.support.info.medium,themeVars.color.support.success.medium,themeVars.color.support.warning.medium,themeVars.color.support.error.medium],tt=12,rt=2,ot=4,F=1,nt={width:1,height:1},at=({plotWidth:e,categoryCount:t,barCount:o,barSize:r,barGap:n})=>{if(e<=0||t<=0||o<=0)return {barSize:r,barGap:n};let a=e/t-F,i=o-1;if(o*r+i*n<=a)return {barSize:r,barGap:n};let u=o*r+i*F;if(i>0&&u<=a){let c=Math.floor((a-o*r)/i);return {barSize:r,barGap:Math.max(F,c)}}let d=Math.floor((a-i*F)/o);return {barSize:Math.max(1,d),barGap:F}},_e=(e,t)=>e.color??G[t%G.length],it=e=>{if(process.env.NODE_ENV==="production")return;let t=e.length>G.length,o=e.some(r=>r.color==null);t&&o&&devWarnOnce("BarChart:paletteWrap",`[BarChart] More than ${G.length} bar series with default colors \u2014 colors will repeat and series may become visually indistinguishable. Set an explicit \`color\` on each bar.`);},re=(e,t)=>{if(e.stackId!=null)return e.stackId;if(t==="stacked")return "default"},st=(e,t)=>{let o=new Map,r=new Map;for(let[n,a]of e.entries()){let i=re(a,t);i==null?o.set(n,true):r.set(i,n);}for(let n of r.values())o.set(n,true);return o},be=false,lt=({offset:e,xAxis:t})=>{process.env.NODE_ENV!=="production"&&!be&&(!e||!t||typeof t.scale?.domain!="function")&&(be=true,console.warn("[BarChart] Recharts passed an unexpected shape to verticalCoordinatesGenerator (missing offset/xAxis/scale.domain). Vertical grid lines will not render \u2014 likely caused by a Recharts upgrade."));let o=t?.scale?.domain?.(),r=Array.isArray(o)?o.length:0,n=e?.width??0;if(r===0||n===0)return [];let a=e?.left??0,i=n/r;return Array.from({length:r},(y,u)=>a+i*(u+1))};function ct({data:e,bars:t,xAxisDataKey:o,variant:r="default",barSize:n=tt,barGap:a=ot,barRadius:i=rt,width:y="100%",height:u=300,showTooltip:d=true,showLegend:c=false,showGrid:b=true,showXAxis:L=true,showYAxis:v=true,className:N,style:m,dir:h,...p}){it(t);let f=k(h),s=f==="rtl",l=useRef(null),w=j(l,f),I=Q(l),C=V(l,f),g=useMemo(()=>st(t,r),[t,r]),H=useMemo(()=>{let _=new Set,M=0;for(let ae of t){let $=re(ae,r);$==null?M+=1:_.add($);}return M+_.size},[t,r]),{barSize:W,barGap:x}=at({plotWidth:I,categoryCount:e.length,barCount:H,barSize:n,barGap:a});return jsx(E,{...p,rootClassName:classNames("BaselineUI-BarChart",ge),className:N,style:m,width:y,height:u,variant:r,dir:f,legend:c?jsx(A,{series:t,resolveColor:_e,paddingInlineStart:w}):null,surfaceRef:l,surfaceStyle:{"--chart-focus-left-overflow":s?"0px":`${C}px`,"--chart-focus-right-overflow":s?`${C}px`:"0px"},children:jsx(ResponsiveContainer,{width:"100%",height:"100%",initialDimension:nt,children:jsxs(BarChart,{accessibilityLayer:true,barGap:x,data:e,children:[b?jsx(CartesianGrid,{stroke:themeVars.color.border.strong,strokeDasharray:"3 3",verticalCoordinatesGenerator:lt}):null,L?jsx(XAxis,{dataKey:o,reversed:s,stroke:themeVars.color.border.inverse,tick:{className:te}}):null,v?jsx(YAxis,{orientation:s?"right":"left",stroke:themeVars.color.border.inverse,tick:{className:te}}):null,d?jsx(Tooltip,{content:D,cursor:{fill:themeVars.color.background.overlay.interactive}}):null,t.map((_,M)=>{let $=g.get(M)??false?[i,i,0,0]:[0,0,0,0];return jsx(Bar,{barSize:W,dataKey:_.dataKey,fill:_e(_,M),name:_.name??_.dataKey,radius:$,stackId:re(_,r)},_.dataKey)})]})})})}var oe="_1ojkdm40 _1yep5z6dy",xe="_1yep5z69r _1yep5z69s _1yep5z69t";var K=[themeVars.color.support.info.medium,themeVars.color.support.success.medium,themeVars.color.support.warning.medium,themeVars.color.support.error.medium],Y={width:40,height:20,strokeWidth:1,margin:{top:1,right:1,bottom:1,left:1}},bt={width:1,height:1},ne=(e,t)=>e.color??K[t%K.length],xt=e=>{if(process.env.NODE_ENV==="production")return;let t=e.length>K.length,o=e.some(r=>r.color==null);t&&o&&devWarnOnce("LineChart:paletteWrap",`[LineChart] More than ${K.length} line series with default colors \u2014 colors will repeat and series may become visually indistinguishable. Set an explicit \`color\` on each line.`);};function zt({data:e,lines:t,xAxisDataKey:o,variant:r="default",width:n,height:a,showTooltip:i,showLegend:y=false,showGrid:u,showXAxis:d,showYAxis:c,className:b,style:L,dir:v,...N}){xt(t);let m=k(v),h=m==="rtl",p=r==="sparkline",f=n??(p?Y.width:"100%"),s=a??(p?Y.height:300),l=i??!p,w=u??!p,I=d??!p,C=c??!p,g=useRef(null),H=j(g,m),W=V(g,m);return jsx(E,{...N,rootClassName:classNames("BaselineUI-LineChart",xe),className:b,style:L,width:f,height:s,variant:r,dir:m,legend:y?jsx(A,{series:t,resolveColor:ne,paddingInlineStart:H}):null,surfaceRef:g,surfaceStyle:{"--chart-focus-left-overflow":h?"0px":`${W}px`,"--chart-focus-right-overflow":h?`${W}px`:"0px"},children:jsx(ResponsiveContainer,{width:"100%",height:"100%",initialDimension:bt,children:jsxs(LineChart,{accessibilityLayer:!p,data:e,margin:p?Y.margin:void 0,children:[w?jsx(CartesianGrid,{stroke:themeVars.color.border.strong,strokeDasharray:"3 3"}):null,I?jsx(XAxis,{dataKey:o,reversed:h,stroke:themeVars.color.border.inverse,tick:{className:oe}}):null,C?jsx(YAxis,{orientation:h?"right":"left",stroke:themeVars.color.border.inverse,tick:{className:oe}}):null,l?jsx(Tooltip,{content:D,cursor:{stroke:themeVars.color.border.interactive.enabled,strokeDasharray:"3 3"}}):null,t.map((x,_)=>jsx(Line,{activeDot:p?false:{r:4,strokeWidth:2,stroke:themeVars.color.background.positive.subtle,fill:ne(x,_),style:{filter:"drop-shadow(0 0 4px rgba(0,0,0,0.4))"}},dataKey:x.dataKey,dot:x.dot??false,name:x.name??x.dataKey,stroke:ne(x,_),strokeWidth:x.strokeWidth??(p?Y.strokeWidth:2),type:x.type??"monotone"},x.dataKey))]})})})}var ze="_1yep5z69o _1yep5z69p _1yep5z69q",we="_1sy8dya1",Le="_1sy8dya0 _1yep5z6dy";var q=[themeVars.color.support.info.medium,themeVars.color.support.success.medium,themeVars.color.support.error.medium,themeVars.color.support.warning.medium],Ot=90,Bt=-270,Mt=.05,jt={width:1,height:1},Se=(e,t)=>e.color??q[t%q.length],Vt=e=>{if(process.env.NODE_ENV==="production")return;let t=e.length>q.length,o=e.some(r=>r.color==null);t&&o&&devWarnOnce("PieChart:paletteWrap",`[PieChart] More than ${q.length} slices with default colors \u2014 colors will repeat and slices may become visually indistinguishable. Set an explicit \`color\` on each slice.`);},Ft=({cx:e,cy:t,midAngle:o,innerRadius:r=0,outerRadius:n=0,percent:a=0})=>{if(e==null||t==null||o==null||a<Mt)return null;let i=r+(n-r)*.65,y=-o*(Math.PI/180),u=e+i*Math.cos(y),d=t+i*Math.sin(y);return jsx("text",{className:Le,x:u,y:d,textAnchor:"middle",dominantBaseline:"central",children:jsx(NumberFormat,{value:a,style:"percent",maximumFractionDigits:0})})},Wt={style:"percent",maximumFractionDigits:0},$t=3,Ut=({cx:e,cy:t,innerRadius:o,outerRadius:r=0,startAngle:n,endAngle:a,fill:i})=>jsxs("g",{children:[jsx(Sector,{cx:e,cy:t,innerRadius:o,outerRadius:r+$t,startAngle:n,endAngle:a,fill:i}),jsx(Sector,{cx:e,cy:t,innerRadius:o,outerRadius:r,startAngle:n,endAngle:a,fill:i,stroke:themeVars.color.focused.inset,strokeWidth:1})]}),Pe=new WeakSet;function Gt({data:e,width:t="100%",height:o=300,innerRadius:r,outerRadius:n,showTooltip:a=true,showLegend:i=true,showLabels:y=true,className:u,style:d,dir:c,...b}){Vt(e);let L=k(c),v=useRef(null),{sortedData:N,sliceData:m}=useMemo(()=>{let s=e.filter(C=>C.value>=0);process.env.NODE_ENV!=="production"&&s.length!==e.length&&console.warn("[PieChart] Negative slice values were dropped. PieChart expects all `value`s to be >= 0.");let l=s.toSorted((C,g)=>g.value-C.value),w=l.reduce((C,g)=>C+g.value,0);process.env.NODE_ENV!=="production"&&w<=0&&e.length>0&&!Pe.has(e)&&(Pe.add(e),console.warn("[PieChart] Received data with a non-positive total. The chart will render empty."));let I=l.map(C=>({...C,fraction:w>0?C.value/w:0}));return {sortedData:l,sliceData:I}},[e]);useEffect(()=>{let s=v.current;if(!s)return;let l=()=>{let C=s.querySelector(".recharts-active-shape")?.parentElement,g=C?.parentElement;C&&g&&g.lastElementChild!==C&&g.append(C);};l();let w=new MutationObserver(l);return w.observe(s,{subtree:true,attributes:true,attributeFilter:["class"]}),()=>{w.disconnect();}},[]);let h=n??"100%",p=r??0,f=N.map((s,l)=>({dataKey:`${s.name}-${l}`,name:s.name}));return jsx(E,{...b,rootClassName:classNames("BaselineUI-PieChart",ze),className:u,style:d,width:t,height:o,variant:"default",dir:L,legend:i?jsx(A,{series:f,resolveColor:(s,l)=>Se(N[l],l)}):null,surfaceRef:v,children:jsx(ResponsiveContainer,{width:"100%",height:"100%",initialDimension:jt,children:jsxs(PieChart,{accessibilityLayer:true,children:[a?jsx(Tooltip,{content:s=>jsx(D,{...s,formatterProps:Wt})}):null,jsx(Pie,{data:m,dataKey:"fraction",nameKey:"name",innerRadius:p,outerRadius:h,startAngle:Ot,endAngle:Bt,isAnimationActive:false,label:y?Ft:false,labelLine:false,stroke:themeVars.color.focused.inset,strokeWidth:1,activeShape:Ut,rootTabIndex:-1,children:N.map((s,l)=>jsx(Cell,{className:we,fill:Se(s,l)},`${s.name}-${l}`))})]})})})}export{ct as BarChart,zt as LineChart,Gt as PieChart};
|
|
10
|
+
var ue="_1yep5z6is _1yep5z6it _1yep5z6iu _1yep5z6j4 _1yep5z6j5 _1yep5z6j6 _1yep5z6jg _1yep5z6jh _1yep5z6ji",me="ofrh9o1 _1yep5z6is _1yep5z6it _1yep5z6iu _1yep5z6j1 _1yep5z6j2 _1yep5z6j3 _1yep5z6jj _1yep5z6jk _1yep5z6jl _1yep5z6le",fe="_1yep5z6iv _1yep5z6iw _1yep5z6ix _1yep5z6jj _1yep5z6jk _1yep5z6jl _1yep5z69f _1yep5z69g _1yep5z69h",de="ofrh9o2 _1yep5z6ai _1yep5z6aj _1yep5z6ak _1yep5z6b6 _1yep5z6b7 _1yep5z6b8 _1yep5z6bu _1yep5z6bv _1yep5z6bw _1yep5z6ci _1yep5z6cj _1yep5z6ck _1yep5z6lk",he="ofrh9o0",ye="_1yep5z66 _1yep5z67 _1yep5z68 _1yep5z62i _1yep5z62j _1yep5z62k _1yep5z63o _1yep5z63p _1yep5z63q _1yep5z61c _1yep5z61d _1yep5z61e _1yep5z6al _1yep5z6am _1yep5z6an _1yep5z6b9 _1yep5z6ba _1yep5z6bb _1yep5z6bx _1yep5z6by _1yep5z6bz _1yep5z6cl _1yep5z6cm _1yep5z6cn _1yep5z6is _1yep5z6it _1yep5z6iu _1yep5z6j4 _1yep5z6j5 _1yep5z6j6 _1yep5z69f _1yep5z69g _1yep5z69h _1yep5z6lz _1yep5z6m1 _1yep5z6g1 _1yep5z6h4 _1yep5z6d7",Ce="_1yep5z6is _1yep5z6it _1yep5z6iu _1yep5z6jj _1yep5z6jk _1yep5z6jl _1yep5z69f _1yep5z69g _1yep5z69h",ge="_1yep5z6is _1yep5z6it _1yep5z6iu _1yep5z6j4 _1yep5z6j5 _1yep5z6j6 _1yep5z69c _1yep5z69d _1yep5z69e",ve="ofrh9o3 _1yep5z6ai _1yep5z6aj _1yep5z6ak _1yep5z6b6 _1yep5z6b7 _1yep5z6b8 _1yep5z6bu _1yep5z6bv _1yep5z6bw _1yep5z6ci _1yep5z6cj _1yep5z6ck _1yep5z6lk";function E({rootClassName:e,className:t,style:o,width:r,height:n,variant:a,dir:i,legend:d,surfaceRef:u,surfaceStyle:m,children:p,...v}){return jsxs("div",{...v,className:classNames(ue,e,t),"data-variant":a,dir:i,style:{width:r,height:n,...o},children:[d,jsx("div",{ref:u,className:classNames(he,"BaselineUI-Chart-Surface"),style:m,children:p})]})}function A({series:e,resolveColor:t,paddingInlineStart:o}){return jsx("ul",{className:`${me} BaselineUI-Chart-Legend`,style:o==null?void 0:{paddingInlineStart:o},children:e.map((r,n)=>jsxs("li",{className:`${fe} BaselineUI-Chart-LegendItem`,children:[jsx("span",{className:`${de} BaselineUI-Chart-LegendSwatch`,style:{backgroundColor:t(r,n)}}),jsx(Text,{type:"label",size:"sm",children:r.name??r.dataKey})]},r.dataKey))})}var Fe=e=>{if(typeof e=="number")return Number.isFinite(e)?e:null;if(typeof e=="string"&&e.trim()!==""){let t=Number(e);return Number.isFinite(t)?t:null}return null},Ve=(e,t)=>{if(!t)return e;let o=Fe(e);return o==null?(process.env.NODE_ENV!=="production"&&e!=null&&devWarnOnce("ChartTooltip:nonNumeric",`[ChartTooltip] \`numberFormatterProps\` was provided but a non-numeric value was received (got ${JSON.stringify(e)}). The value will render unformatted.`),e):jsx(NumberFormat,{value:o,...t})};function k({active:e,payload:t,label:o,numberFormatterProps:r}){return !e||!t?.length?null:jsxs("div",{className:`${ye} BaselineUI-Chart-Tooltip`,children:[o==null?null:jsx(Text,{elementType:"div",type:"label",size:"sm",children:String(o)}),jsx("div",{className:ge,children:t.map(n=>jsxs("div",{className:`${Ce} BaselineUI-Chart-TooltipItem`,children:[jsx("span",{className:`${ve} BaselineUI-Chart-TooltipSwatch`,style:{backgroundColor:n.color}}),jsxs(Text,{type:"label",size:"sm",children:[n.name,": ",Ve(n.value,r)]})]},String(n.dataKey)))})]})}function D(e){let{direction:t}=useLocale();return e??t}function B(e,t){let o=null,r=()=>{o==null&&(o=requestAnimationFrame(()=>{o=null,t();}));};t();let n=new ResizeObserver(r);n.observe(e);let a=new MutationObserver(r);return a.observe(e,{childList:true,subtree:true}),()=>{o!=null&&cancelAnimationFrame(o),n.disconnect(),a.disconnect();}}var re=".recharts-yAxis-tick-labels .recharts-cartesian-axis-tick-value";function F(e,t){let[o,r]=useState(0);return useLayoutEffect(()=>{let n=e.current;if(!n)return;let a=false,i=false,d=false,u=false,m=0,p=h=>{r(f=>f===h?f:h);};p(0);let v=()=>{process.env.NODE_ENV!=="production"&&!i&&!a&&m>5&&(i=true,console.warn(`[useLeftmostYAxisLabelOffset] Could not find "${re}" \u2014 Recharts may have renamed its internals. Legend will fall back to flush alignment.`));},N=()=>{process.env.NODE_ENV!=="production"&&!u&&a&&(u=true,console.warn("[useLeftmostYAxisLabelOffset] Y-axis labels disappeared after a successful measurement \u2014 falling back to flush alignment. This may indicate a Recharts upgrade or an unexpected empty render."));},z=()=>{process.env.NODE_ENV!=="production"&&!d&&(d=true,console.warn(`[useLeftmostYAxisLabelOffset] Found "${re}" but no label returned a finite bounding rect \u2014 Recharts' measurement contract may have changed. Legend will fall back to flush alignment.`));};return B(n,()=>{let h=n.querySelectorAll(re);if(h.length===0){m+=1,a?N():v(),p(0);return}a=true;let f=n.getBoundingClientRect();if(t==="rtl"){let c=-1/0;for(let s of h){let l=s.getBoundingClientRect();l.width===0&&l.height===0||(c=Math.max(c,l.right));}if(!Number.isFinite(c)){z(),p(0);return}p(Math.max(0,f.right-c));return}let y=1/0;for(let c of h){let s=c.getBoundingClientRect();s.width===0&&s.height===0||(y=Math.min(y,s.left));}if(!Number.isFinite(y)){z(),p(0);return}p(Math.max(0,y-f.left));})},[e,t]),o}var xe=".recharts-cartesian-grid";function oe(e){let[t,o]=useState(0);return useLayoutEffect(()=>{let r=e.current;if(!r)return;let n=false,a=false,i=0;return B(r,()=>{let u=r.querySelector(xe);if(!u){i+=1,process.env.NODE_ENV!=="production"&&!a&&!n&&i>5&&(a=true,console.warn(`[usePlotAreaWidth] Could not find "${xe}" \u2014 Recharts may have renamed its internals. Bar layouts will fall back to requested sizes.`));return}n=true;let m=u.getBoundingClientRect().width;o(p=>Math.abs(p-m)<.5?p:m);})},[e]),t}var ne=".recharts-yAxis-tick-labels .recharts-cartesian-axis-tick-value";function V(e,t){let[o,r]=useState(0);return useLayoutEffect(()=>{let n=e.current;if(!n)return;let a=false,i=false,d=false,u=false,m=0,p=h=>{r(f=>f===h?f:h);};p(0);let v=()=>{process.env.NODE_ENV!=="production"&&!i&&!a&&m>5&&(i=true,console.warn(`[useYAxisLeftOverflow] Could not find "${ne}" \u2014 Recharts may have renamed its internals. The focus outline will not extend over overflowing axis labels.`));},N=()=>{process.env.NODE_ENV!=="production"&&!u&&a&&(u=true,console.warn("[useYAxisLeftOverflow] Y-axis labels disappeared after a successful measurement \u2014 focus outline will no longer extend over overflowing labels. This may indicate a Recharts upgrade or an unexpected empty render."));},z=()=>{process.env.NODE_ENV!=="production"&&!d&&(d=true,console.warn(`[useYAxisLeftOverflow] Found "${ne}" but no label returned a finite bounding rect \u2014 Recharts' measurement contract may have changed. The focus outline will not extend over overflowing axis labels.`));};return B(n,()=>{let h=n.querySelectorAll(ne);if(h.length===0){m+=1,a?N():v(),p(0);return}a=true;let f=n.getBoundingClientRect();if(t==="rtl"){let c=-1/0;for(let s of h){let l=s.getBoundingClientRect();l.width===0&&l.height===0||(c=Math.max(c,l.right));}if(!Number.isFinite(c)){z(),p(0);return}p(Math.max(0,Math.ceil(c-f.right)));return}let y=1/0;for(let c of h){let s=c.getBoundingClientRect();s.width===0&&s.height===0||(y=Math.min(y,s.left));}if(!Number.isFinite(y)){z(),p(0);return}p(Math.max(0,Math.ceil(f.left-y)));})},[e,t]),o}var ae="_1o5hr0b0 _1yep5z6dy",ze="_1yep5z69r _1yep5z69s _1yep5z69t";var K=[themeVars.color.support.info.medium,themeVars.color.support.success.medium,themeVars.color.support.warning.medium,themeVars.color.support.error.medium],st=12,lt=2,ct=4,W=1,pt={width:1,height:1},ut=({plotWidth:e,categoryCount:t,barCount:o,barSize:r,barGap:n})=>{if(e<=0||t<=0||o<=0)return {barSize:r,barGap:n};let a=e/t-W,i=o-1;if(o*r+i*n<=a)return {barSize:r,barGap:n};let u=o*r+i*W;if(i>0&&u<=a){let p=Math.floor((a-o*r)/i);return {barSize:r,barGap:Math.max(W,p)}}let m=Math.floor((a-i*W)/o);return {barSize:Math.max(1,m),barGap:W}},we=(e,t)=>e.color??K[t%K.length],mt=e=>{if(process.env.NODE_ENV==="production")return;let t=e.length>K.length,o=e.some(r=>r.color==null);t&&o&&devWarnOnce("BarChart:paletteWrap",`[BarChart] More than ${K.length} bar series with default colors \u2014 colors will repeat and series may become visually indistinguishable. Set an explicit \`color\` on each bar.`);},se=(e,t)=>{if(e.stackId!=null)return e.stackId;if(t==="stacked")return "default"},ft=(e,t)=>{let o=new Map,r=new Map;for(let[n,a]of e.entries()){let i=se(a,t);i==null?o.set(n,true):r.set(i,n);}for(let n of r.values())o.set(n,true);return o},Le=false,dt=({offset:e,xAxis:t})=>{process.env.NODE_ENV!=="production"&&!Le&&(!e||!t||typeof t.scale?.domain!="function")&&(Le=true,console.warn("[BarChart] Recharts passed an unexpected shape to verticalCoordinatesGenerator (missing offset/xAxis/scale.domain). Vertical grid lines will not render \u2014 likely caused by a Recharts upgrade."));let o=t?.scale?.domain?.(),r=Array.isArray(o)?o.length:0,n=e?.width??0;if(r===0||n===0)return [];let a=e?.left??0,i=n/r;return Array.from({length:r},(d,u)=>a+i*(u+1))};function ht({data:e,bars:t,xAxisDataKey:o,variant:r="default",barSize:n=st,barGap:a=ct,barRadius:i=lt,width:d="100%",height:u=300,showTooltip:m=true,showLegend:p=false,showGrid:v=true,showXAxis:N=true,showYAxis:z=true,numberFormatterProps:b,className:h,style:f,dir:y,...c}){mt(t);let s=D(y),l=s==="rtl",x=useRef(null),I=F(x,s),C=oe(x),w=V(x,s),O=useNumberFormatter(b),J=useMemo(()=>b?g=>O.format(g):void 0,[b,O]),$=useCallback(g=>jsx(k,{...g,numberFormatterProps:b}),[b]),U=useMemo(()=>ft(t,r),[t,r]),Z=useMemo(()=>{let g=new Set,j=0;for(let pe of t){let G=se(pe,r);G==null?j+=1:g.add(G);}return j+g.size},[t,r]),{barSize:Q,barGap:_}=ut({plotWidth:C,categoryCount:e.length,barCount:Z,barSize:n,barGap:a});return jsx(E,{...c,rootClassName:classNames("BaselineUI-BarChart",ze),className:h,style:f,width:d,height:u,variant:r,dir:s,legend:p?jsx(A,{series:t,resolveColor:we,paddingInlineStart:I}):null,surfaceRef:x,surfaceStyle:{"--chart-focus-left-overflow":l?"0px":`${w}px`,"--chart-focus-right-overflow":l?`${w}px`:"0px"},children:jsx(ResponsiveContainer,{width:"100%",height:"100%",initialDimension:pt,children:jsxs(BarChart,{accessibilityLayer:true,barGap:_,data:e,children:[v?jsx(CartesianGrid,{stroke:themeVars.color.border.strong,strokeDasharray:"3 3",verticalCoordinatesGenerator:dt}):null,N?jsx(XAxis,{dataKey:o,reversed:l,stroke:themeVars.color.border.inverse,tick:{className:ae}}):null,z?jsx(YAxis,{orientation:l?"right":"left",stroke:themeVars.color.border.inverse,tick:{className:ae},tickFormatter:J}):null,m?jsx(Tooltip,{content:$,cursor:{fill:themeVars.color.background.overlay.interactive}}):null,t.map((g,j)=>{let G=U.get(j)??false?[i,i,0,0]:[0,0,0,0];return jsx(Bar,{barSize:Q,dataKey:g.dataKey,fill:we(g,j),name:g.name??g.dataKey,radius:G,stackId:se(g,r)},g.dataKey)})]})})})}var le="_1ojkdm40 _1yep5z6dy",Ne="_1yep5z69r _1yep5z69s _1yep5z69t";var H=[themeVars.color.support.info.medium,themeVars.color.support.success.medium,themeVars.color.support.warning.medium,themeVars.color.support.error.medium],q={width:40,height:20,strokeWidth:1,margin:{top:1,right:1,bottom:1,left:1}},Pt={width:1,height:1},ce=(e,t)=>e.color??H[t%H.length],Et=e=>{if(process.env.NODE_ENV==="production")return;let t=e.length>H.length,o=e.some(r=>r.color==null);t&&o&&devWarnOnce("LineChart:paletteWrap",`[LineChart] More than ${H.length} line series with default colors \u2014 colors will repeat and series may become visually indistinguishable. Set an explicit \`color\` on each line.`);};function At({data:e,lines:t,xAxisDataKey:o,variant:r="default",width:n,height:a,showTooltip:i,showLegend:d=false,showGrid:u,showXAxis:m,showYAxis:p,numberFormatterProps:v,className:N,style:z,dir:b,...h}){Et(t);let f=D(b),y=f==="rtl",c=r==="sparkline",s=n??(c?q.width:"100%"),l=a??(c?q.height:300),x=i??!c,I=u??!c,C=m??!c,w=p??!c,O=useRef(null),J=F(O,f),$=V(O,f),U=useNumberFormatter(v),Z=useMemo(()=>v?_=>U.format(_):void 0,[v,U]),Q=useCallback(_=>jsx(k,{..._,numberFormatterProps:v}),[v]);return jsx(E,{...h,rootClassName:classNames("BaselineUI-LineChart",Ne),className:N,style:z,width:s,height:l,variant:r,dir:f,legend:d?jsx(A,{series:t,resolveColor:ce,paddingInlineStart:J}):null,surfaceRef:O,surfaceStyle:{"--chart-focus-left-overflow":y?"0px":`${$}px`,"--chart-focus-right-overflow":y?`${$}px`:"0px"},children:jsx(ResponsiveContainer,{width:"100%",height:"100%",initialDimension:Pt,children:jsxs(LineChart,{accessibilityLayer:!c,data:e,margin:c?q.margin:void 0,children:[I?jsx(CartesianGrid,{stroke:themeVars.color.border.strong,strokeDasharray:"3 3"}):null,C?jsx(XAxis,{dataKey:o,reversed:y,stroke:themeVars.color.border.inverse,tick:{className:le}}):null,w?jsx(YAxis,{orientation:y?"right":"left",stroke:themeVars.color.border.inverse,tick:{className:le},tickFormatter:Z}):null,x?jsx(Tooltip,{content:Q,cursor:{stroke:themeVars.color.border.interactive.enabled,strokeDasharray:"3 3"}}):null,t.map((_,g)=>jsx(Line,{activeDot:c?false:{r:4,strokeWidth:2,stroke:themeVars.color.background.positive.subtle,fill:ce(_,g),style:{filter:"drop-shadow(0 0 4px rgba(0,0,0,0.4))"}},dataKey:_.dataKey,dot:_.dot??false,name:_.name??_.dataKey,stroke:ce(_,g),strokeWidth:_.strokeWidth??(c?q.strokeWidth:2),type:_.type??"monotone"},_.dataKey))]})})})}var Se="_1yep5z69o _1yep5z69p _1yep5z69q",Te="_1sy8dya1",Re="_1sy8dya0 _1yep5z6dy";var X=[themeVars.color.support.info.medium,themeVars.color.support.success.medium,themeVars.color.support.error.medium,themeVars.color.support.warning.medium],Gt=90,Yt=-270,Kt=.05,qt={width:1,height:1},Ee=(e,t)=>e.color??X[t%X.length],Ht=e=>{if(process.env.NODE_ENV==="production")return;let t=e.length>X.length,o=e.some(r=>r.color==null);t&&o&&devWarnOnce("PieChart:paletteWrap",`[PieChart] More than ${X.length} slices with default colors \u2014 colors will repeat and slices may become visually indistinguishable. Set an explicit \`color\` on each slice.`);},Xt=({cx:e,cy:t,midAngle:o,innerRadius:r=0,outerRadius:n=0,percent:a=0})=>{if(e==null||t==null||o==null||a<Kt)return null;let i=r+(n-r)*.65,d=-o*(Math.PI/180),u=e+i*Math.cos(d),m=t+i*Math.sin(d);return jsx("text",{className:Re,x:u,y:m,textAnchor:"middle",dominantBaseline:"central",children:jsx(NumberFormat,{value:a,style:"percent",maximumFractionDigits:0})})},Jt={style:"percent",maximumFractionDigits:0},Zt=3,Qt=({cx:e,cy:t,innerRadius:o,outerRadius:r=0,startAngle:n,endAngle:a,fill:i})=>jsxs("g",{children:[jsx(Sector,{cx:e,cy:t,innerRadius:o,outerRadius:r+Zt,startAngle:n,endAngle:a,fill:i}),jsx(Sector,{cx:e,cy:t,innerRadius:o,outerRadius:r,startAngle:n,endAngle:a,fill:i,stroke:themeVars.color.focused.inset,strokeWidth:1})]}),Ae=new WeakSet;function er({data:e,width:t="100%",height:o=300,innerRadius:r,outerRadius:n,showTooltip:a=true,showLegend:i=true,showLabels:d=true,className:u,style:m,dir:p,...v}){Ht(e);let N=D(p),z=useRef(null),{sortedData:b,sliceData:h}=useMemo(()=>{let s=e.filter(C=>C.value>=0);process.env.NODE_ENV!=="production"&&s.length!==e.length&&console.warn("[PieChart] Negative slice values were dropped. PieChart expects all `value`s to be >= 0.");let l=s.toSorted((C,w)=>w.value-C.value),x=l.reduce((C,w)=>C+w.value,0);process.env.NODE_ENV!=="production"&&x<=0&&e.length>0&&!Ae.has(e)&&(Ae.add(e),console.warn("[PieChart] Received data with a non-positive total. The chart will render empty."));let I=l.map(C=>({...C,fraction:x>0?C.value/x:0}));return {sortedData:l,sliceData:I}},[e]);useEffect(()=>{let s=z.current;if(!s)return;let l=()=>{let C=s.querySelector(".recharts-active-shape")?.parentElement,w=C?.parentElement;C&&w&&w.lastElementChild!==C&&w.append(C);};l();let x=new MutationObserver(l);return x.observe(s,{subtree:true,attributes:true,attributeFilter:["class"]}),()=>{x.disconnect();}},[]);let f=n??"100%",y=r??0,c=b.map((s,l)=>({dataKey:`${s.name}-${l}`,name:s.name}));return jsx(E,{...v,rootClassName:classNames("BaselineUI-PieChart",Se),className:u,style:m,width:t,height:o,variant:"default",dir:N,legend:i?jsx(A,{series:c,resolveColor:(s,l)=>Ee(b[l],l)}):null,surfaceRef:z,children:jsx(ResponsiveContainer,{width:"100%",height:"100%",initialDimension:qt,children:jsxs(PieChart,{accessibilityLayer:true,children:[a?jsx(Tooltip,{content:s=>jsx(k,{...s,numberFormatterProps:Jt})}):null,jsx(Pie,{data:h,dataKey:"fraction",nameKey:"name",innerRadius:y,outerRadius:f,startAngle:Gt,endAngle:Yt,isAnimationActive:false,label:d?Xt:false,labelLine:false,stroke:themeVars.color.focused.inset,strokeWidth:1,activeShape:Qt,rootTabIndex:-1,children:b.map((s,l)=>jsx(Cell,{className:Te,fill:Ee(s,l)},`${s.name}-${l}`))})]})})})}export{ht as BarChart,At as LineChart,er as PieChart};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baseline-ui/charts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.62.0",
|
|
4
4
|
"description": "Chart components for Baseline UI",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"dist"
|
|
11
11
|
],
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@baseline-ui/core": "0.
|
|
14
|
-
"@baseline-ui/tokens": "0.
|
|
13
|
+
"@baseline-ui/core": "0.62.0",
|
|
14
|
+
"@baseline-ui/tokens": "0.62.0"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
17
|
"react": "^18.0.0",
|