@@ -11,18 +11,23 @@ import { ValidIndicatorData } from "@/components/chart/types";
1111
1212type RankingChartSection = {
1313 data : ValidIndicatorData [ ] ;
14- title : string ;
1514 type : "bars" | "list" ;
16- unit : string ;
15+ title ?: string ;
16+ unit ?: string ;
1717} ;
1818interface Props {
1919 data : Array < ValidIndicatorData > ;
2020}
2121
22- const RankingChartSectionHeader : FC < { title : string ; unit : string } > = ( { title, unit } ) => (
23- < header className = "text-2xs mb-1 flex items-center justify-between py-1 leading-[22px] uppercase" >
24- < h3 className = "font-medium" > { title } </ h3 >
25- < p className = "font-normal" > { unit } </ p >
22+ const RankingChartSectionHeader : FC < { title ?: string ; unit ?: string } > = ( { title, unit } ) => (
23+ < header
24+ className = { cn ( {
25+ "text-2xs mb-1 flex items-center justify-end py-1 leading-[22px] uppercase" : true ,
26+ "justify-between" : ! ! title && ! ! unit ,
27+ } ) }
28+ >
29+ { ! ! title && < h3 className = "font-medium" > { title } </ h3 > }
30+ { ! ! unit && < p className = "font-normal" > { unit } </ p > }
2631 </ header >
2732) ;
2833
@@ -31,7 +36,7 @@ const RankingChartList: FC<Props & { title?: string; unit?: string }> = ({ data,
3136
3237 return (
3338 < section >
34- { title && unit && < RankingChartSectionHeader title = { title } unit = { unit } /> }
39+ < RankingChartSectionHeader title = { title } unit = { unit } />
3540 < ul className = "space-y-3" >
3641 { data
3742 . sort ( ( a , b ) => b . value - a . value )
@@ -49,7 +54,11 @@ const RankingChartList: FC<Props & { title?: string; unit?: string }> = ({ data,
4954 ) ;
5055} ;
5156
52- const RankingChartBars : FC < Props & { title : string ; unit : string } > = ( { data, title, unit } ) => {
57+ const RankingChartCategorizedBars : FC < Props & { title ?: string ; unit ?: string } > = ( {
58+ data,
59+ title,
60+ unit,
61+ } ) => {
5362 const scale = useMemo ( ( ) => {
5463 const maxValue = Math . max ( ...data . map ( ( item ) => item . value ) ) ;
5564 return ( value : number ) => ( value / maxValue ) * 100 ; // Scale to percentage
@@ -58,7 +67,7 @@ const RankingChartBars: FC<Props & { title: string; unit: string }> = ({ data, t
5867 if ( data . length === 0 ) return null ;
5968
6069 return (
61- < section className = "border-t border-dashed" >
70+ < section className = { cn ( { "border-t border-dashed" : ! ! title } ) } >
6271 < RankingChartSectionHeader title = { title } unit = { unit } />
6372 < ul className = "space-y-4" >
6473 { data
@@ -114,31 +123,12 @@ const RankingSection: FC<{
114123 return (
115124 < >
116125 { type === "bars" ? (
117- < RankingChartBars data = { data } title = { title } unit = { unit } />
126+ < RankingChartCategorizedBars data = { data } title = { title } unit = { unit } />
118127 ) : type === "list" ? (
119128 < RankingChartList data = { data } title = { title } unit = { unit } />
120129 ) : null }
121130 </ >
122131 ) ;
123132} ;
124133
125- const RankingChart : FC < {
126- sections ?: Array < RankingChartSection > ;
127- data ?: ValidIndicatorData [ ] ;
128- withLegend ?: boolean ;
129- } > = ( { sections, data, withLegend } ) => {
130- return (
131- < div className = "w-full space-y-7" >
132- { data ? (
133- < RankingChartList data = { data } />
134- ) : sections ? (
135- sections . map ( ( section ) => (
136- < RankingSection key = { `ranking-chart-section-${ section . title } ` } section = { section } />
137- ) )
138- ) : null }
139- { withLegend && < RankingChartLegend /> }
140- </ div >
141- ) ;
142- } ;
143-
144- export { RankingChart , RankingChartLegend , type RankingChartSection } ;
134+ export { RankingSection , RankingChartList , RankingChartLegend , type RankingChartSection } ;
0 commit comments