@@ -28,18 +28,22 @@ export interface ChartProps {
2828 height ?: number | string ;
2929 className ?: string ;
3030 valueFormatter ?: ( value : number ) => string ;
31+ scrollable ?: boolean ;
32+ minWidth ?: number | string ;
3133}
3234
3335export const AreaChart = ( {
3436 data,
3537 categories,
3638 index,
3739 variant = "primary" ,
38- shape = "minimal" , // Extracted but visual impact on Area is minimal
40+ shape = "minimal" ,
3941 colors,
4042 height = 300 ,
4143 className,
4244 valueFormatter = ( value ) => `${ value } ` ,
45+ scrollable = false ,
46+ minWidth = 500 ,
4347} : ChartProps ) => {
4448 const chartId = useId ( ) ;
4549 const isGhost = variant === "ghost" ;
@@ -48,102 +52,110 @@ export const AreaChart = ({
4852 return (
4953 < div
5054 className = { clsx (
51- "outline-none[&_.recharts-surface]:outline-none" ,
55+ "outline-none [&_.recharts-surface]:outline-none" ,
56+ scrollable && "overflow-x-auto scrollbar-thin" ,
5257 className ,
5358 ) }
5459 style = { { height } }
5560 >
56- < ResponsiveContainer width = "100%" height = "100%" >
57- < RechartsAreaChart
58- data = { data }
59- margin = {
60- isGhost
61- ? { top : 0 , right : 0 , bottom : 0 , left : 0 }
62- : { top : 10 , right : 10 , bottom : 0 , left : 0 }
63- }
64- >
65- < defs >
66- { categories . map ( ( category , i ) => {
67- const color = colors ?. [ i ] || getColorForIndex ( i ) ;
68- return (
69- < linearGradient
70- key = { `${ chartId } -${ category } ` }
71- id = { `gradient-${ chartId } -${ i } ` }
72- x1 = "0"
73- y1 = "0"
74- x2 = "0"
75- y2 = "1"
76- >
77- < stop
78- offset = "100%"
79- stopColor = { color }
80- stopOpacity = { isGhost ? 0.2 : 0.4 }
81- />
82- < stop offset = "95%" stopColor = { color } stopOpacity = { 0 } />
83- </ linearGradient >
84- ) ;
85- } ) }
86- </ defs >
87-
88- { ! isGhost && (
89- < CartesianGrid
90- { ...chartGridConfig }
91- vertical = { false }
92- horizontal = { ! isSecondary }
93- />
94- ) }
61+ < div
62+ style = { {
63+ minWidth : scrollable ? minWidth : undefined ,
64+ height : "100%" ,
65+ } }
66+ >
67+ < ResponsiveContainer width = "100%" height = "100%" >
68+ < RechartsAreaChart
69+ data = { data }
70+ margin = {
71+ isGhost
72+ ? { top : 0 , right : 0 , bottom : 0 , left : 0 }
73+ : { top : 10 , right : 10 , bottom : 0 , left : 0 }
74+ }
75+ >
76+ < defs >
77+ { categories . map ( ( category , i ) => {
78+ const color = colors ?. [ i ] || getColorForIndex ( i ) ;
79+ return (
80+ < linearGradient
81+ key = { `${ chartId } -${ category } ` }
82+ id = { `gradient-${ chartId } -${ i } ` }
83+ x1 = "0"
84+ y1 = "0"
85+ x2 = "0"
86+ y2 = "1"
87+ >
88+ < stop
89+ offset = "100%"
90+ stopColor = { color }
91+ stopOpacity = { isGhost ? 0.2 : 0.4 }
92+ />
93+ < stop offset = "95%" stopColor = { color } stopOpacity = { 0 } />
94+ </ linearGradient >
95+ ) ;
96+ } ) }
97+ </ defs >
9598
96- { ! isGhost && < XAxis dataKey = { index } { ...chartAxisConfig } /> }
99+ { ! isGhost && (
100+ < CartesianGrid
101+ { ...chartGridConfig }
102+ vertical = { false }
103+ horizontal = { ! isSecondary }
104+ />
105+ ) }
97106
98- { ! isGhost && (
99- < YAxis
100- { ...chartAxisConfig }
101- tickFormatter = { valueFormatter }
102- hide = { isSecondary }
103- width = { 45 }
104- />
105- ) }
107+ { ! isGhost && < XAxis dataKey = { index } { ...chartAxisConfig } /> }
106108
107- { ! isGhost && (
108- < Tooltip
109- content = { < ChartTooltip /> }
110- cursor = { {
111- stroke : "var(--md-sys-color-outline-variant)" ,
112- strokeWidth : 1 ,
113- strokeDasharray : "4 4" ,
114- } }
115- />
116- ) }
109+ { ! isGhost && (
110+ < YAxis
111+ { ...chartAxisConfig }
112+ tickFormatter = { valueFormatter }
113+ hide = { isSecondary }
114+ width = { 45 }
115+ />
116+ ) }
117117
118- { categories . map ( ( category , i ) => {
119- const color = colors ?. [ i ] || getColorForIndex ( i ) ;
120- return (
121- < Area
122- key = { category }
123- type = "monotone"
124- dataKey = { category }
125- stroke = { color }
126- fill = { `url(#gradient-${ chartId } -${ i } )` }
127- strokeWidth = { isGhost ? 1 : 2 }
128- fillOpacity = { 1 }
129- animationDuration = { 1500 }
130- animationEasing = "ease-in-out"
131- activeDot = {
132- ! isGhost
133- ? {
134- r : 4 ,
135- strokeWidth : 2 ,
136- stroke : "var(--md-sys-color-surface)" ,
137- fill : color ,
138- }
139- : false
140- }
141- isAnimationActive = { true }
118+ { ! isGhost && (
119+ < Tooltip
120+ content = { < ChartTooltip /> }
121+ cursor = { {
122+ stroke : "var(--md-sys-color-outline-variant)" ,
123+ strokeWidth : 1 ,
124+ strokeDasharray : "4 4" ,
125+ } }
142126 />
143- ) ;
144- } ) }
145- </ RechartsAreaChart >
146- </ ResponsiveContainer >
127+ ) }
128+
129+ { categories . map ( ( category , i ) => {
130+ const color = colors ?. [ i ] || getColorForIndex ( i ) ;
131+ return (
132+ < Area
133+ key = { category }
134+ type = "monotone"
135+ dataKey = { category }
136+ stroke = { color }
137+ fill = { `url(#gradient-${ chartId } -${ i } )` }
138+ strokeWidth = { isGhost ? 1 : 2 }
139+ fillOpacity = { 1 }
140+ animationDuration = { 1500 }
141+ animationEasing = "ease-in-out"
142+ activeDot = {
143+ ! isGhost
144+ ? {
145+ r : 4 ,
146+ strokeWidth : 2 ,
147+ stroke : "var(--md-sys-color-surface)" ,
148+ fill : color ,
149+ }
150+ : false
151+ }
152+ isAnimationActive = { true }
153+ />
154+ ) ;
155+ } ) }
156+ </ RechartsAreaChart >
157+ </ ResponsiveContainer >
158+ </ div >
147159 </ div >
148160 ) ;
149161} ;
0 commit comments