44 FlexItem ,
55 Text ,
66 TextVariants ,
7- Tooltip
7+ Tooltip ,
88} from '@patternfly/react-core' ;
99import { Table , Tbody , Td , Tr } from '@patternfly/react-table' ;
1010
@@ -21,40 +21,73 @@ interface MigrationChartProps {
2121 maxHeight ?: string ;
2222}
2323
24- type DLength = 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 60 | 70 | 80 | 90 | 100 ;
24+ type DLength =
25+ | 10
26+ | 15
27+ | 20
28+ | 25
29+ | 30
30+ | 35
31+ | 40
32+ | 45
33+ | 50
34+ | 60
35+ | 70
36+ | 80
37+ | 90
38+ | 100 ;
2539
2640const legendColors = [ '#28a745' , '#f0ad4e' , '#d9534f' , '#C9190B' ] ;
2741
28- const MigrationChart : React . FC < MigrationChartProps > = ( { data, legend, dataLength= 40 , maxHeight= '200px' } : MigrationChartProps ) => {
42+ const MigrationChart : React . FC < MigrationChartProps > = ( {
43+ data,
44+ legend,
45+ dataLength = 40 ,
46+ maxHeight = '200px' ,
47+ } : MigrationChartProps ) => {
2948 const dynamicLegend = useMemo ( ( ) => {
30- return data . reduce ( ( acc , current ) => {
31- const key = `${ current . legendCategory } ` ;
32- if ( ! acc . seen . has ( key ) ) {
33- acc . seen . add ( key ) ;
34- acc . result . push ( { [ key ] : legendColors [ acc . seen . size - 1 ] } ) ;
35- }
36- return acc ;
37- } , { seen : new Set ( ) , result : [ ] } ) . result ;
49+ return data . reduce (
50+ ( acc , current ) => {
51+ const key = `${ current . legendCategory } ` ;
52+ if ( ! acc . seen . has ( key ) ) {
53+ acc . seen . add ( key ) ;
54+ acc . result . push ( { [ key ] : legendColors [ acc . seen . size - 1 ] } ) ;
55+ }
56+ return acc ;
57+ } ,
58+ { seen : new Set ( ) , result : [ ] } ,
59+ ) . result ;
3860 } , [ data , legendColors ] ) ;
39-
61+
4062 const chartLegend = legend ? legend : Object . assign ( { } , ...dynamicLegend ) ;
41- const getColor = ( name : string ) : string => chartLegend [ name ] ;
63+ const getColor = ( name : string ) : string => chartLegend [ name ] ;
4264
4365 return (
44- < Flex direction = { { default : 'column' } } spaceItems = { { default : 'spaceItemsLg' } } >
66+ < Flex
67+ direction = { { default : 'column' } }
68+ spaceItems = { { default : 'spaceItemsLg' } }
69+ >
4570 { /* Legend */ }
4671 < FlexItem >
47- < Flex spaceItems = { { default : 'spaceItemsLg' } } justifyContent = { { default : 'justifyContentFlexEnd' } } >
48- { Object . entries ( chartLegend ) . map ( ( [ key , color ] ) => (
72+ < Flex
73+ spaceItems = { { default : 'spaceItemsLg' } }
74+ justifyContent = { { default : 'justifyContentFlexEnd' } }
75+ >
76+ { Object . entries ( chartLegend ) . map ( ( [ key , color ] ) => (
4977 < FlexItem key = { key } >
50- < Flex alignItems = { { default : 'alignItemsCenter' } } spaceItems = { { default : 'spaceItemsSm' } } >
78+ < Flex
79+ alignItems = { { default : 'alignItemsCenter' } }
80+ spaceItems = { { default : 'spaceItemsSm' } }
81+ >
5182 < FlexItem >
52- < div style = { {
53- width : '12px' ,
54- height : '12px' ,
55- backgroundColor : color as string ,
56- borderRadius : '2px'
57- } } />
83+ < div
84+ style = { {
85+ width : '12px' ,
86+ height : '12px' ,
87+ backgroundColor : color as string ,
88+ borderRadius : '2px' ,
89+ } }
90+ />
5891 </ FlexItem >
5992 < FlexItem >
6093 < Text component = { TextVariants . small } > { key } </ Text >
@@ -66,59 +99,77 @@ const MigrationChart: React.FC<MigrationChartProps> = ({ data, legend, dataLengt
6699 </ FlexItem >
67100 { /* Chart Area */ }
68101 < FlexItem >
69- < Flex direction = { { default : 'column' } } spaceItems = { { default : 'spaceItemsMd' } } >
70- < div style = { { maxHeight : maxHeight , overflowY : 'auto' } } >
102+ < Flex
103+ direction = { { default : 'column' } }
104+ spaceItems = { { default : 'spaceItemsMd' } }
105+ >
106+ < div style = { { maxHeight : maxHeight , overflowY : 'auto' } } >
71107 < Table variant = "compact" borders = { false } >
72108 < Tbody >
73109 { data . map ( ( item , index ) => (
74- < Tr key = { index } >
75- < Td width = { dataLength } style = { { paddingLeft : '0px' } } >
76- < Tooltip content = { < div > { item . name } </ div > } exitDelay = { 0 } >
77- < Text component = { TextVariants . p }
78- style = { { fontSize : 'clamp(0.4rem, 0.7vw, 1.1rem)' ,
79- overflow : 'hidden' ,
80- textOverflow : 'ellipsis' ,
81- wordBreak : 'break-word' ,
82- display : '-webkit-box' ,
83- WebkitLineClamp : 1 , // Number of lines to show
84- textTransform : 'capitalize' ,
85- WebkitBoxOrient : 'vertical' } } > { item . name } </ Text >
86- </ Tooltip >
87- </ Td >
88- < Td >
110+ < Tr key = { index } >
111+ < Td width = { dataLength } style = { { paddingLeft : '0px' } } >
112+ < Tooltip content = { < div > { item . name } </ div > } exitDelay = { 0 } >
113+ < Text
114+ component = { TextVariants . p }
115+ style = { {
116+ fontSize : 'clamp(0.4rem, 0.7vw, 1.1rem)' ,
117+ overflow : 'hidden' ,
118+ textOverflow : 'ellipsis' ,
119+ wordBreak : 'break-word' ,
120+ display : '-webkit-box' ,
121+ WebkitLineClamp : 1 , // Number of lines to show
122+ textTransform : 'capitalize' ,
123+ WebkitBoxOrient : 'vertical' ,
124+ } }
125+ >
126+ { item . name }
127+ </ Text >
128+ </ Tooltip >
129+ </ Td >
130+ < Td >
89131 { /* Visual Bar */ }
90132 < div >
91- < div style = { {
92- position : 'relative' ,
93- height : '8px' ,
94- backgroundColor : '#F5F5F5' ,
95- overflow : 'hidden'
96- } } >
97- < div style = { {
98- height : '100%' ,
99- width : `${ item . count } %` ,
100- backgroundColor : `${ getColor ( item . legendCategory ) } ` ,
101- transition : 'width 0.3s ease'
102- } } />
133+ < div
134+ style = { {
135+ position : 'relative' ,
136+ height : '8px' ,
137+ backgroundColor : '#F5F5F5' ,
138+ overflow : 'hidden' ,
139+ } }
140+ >
141+ < div
142+ style = { {
143+ height : '100%' ,
144+ width : `${ item . count } %` ,
145+ backgroundColor : `${ getColor (
146+ item . legendCategory ,
147+ ) } `,
148+ transition : 'width 0.3s ease' ,
149+ } }
150+ />
103151 </ div >
104152 </ div >
105- </ Td >
106- < Td width = { 10 } style = { { paddingRight : '0px' , textAlign : 'center' } } >
107- < Text style = { { fontSize : 'clamp(0.4rem, 0.7vw, 1.1rem)' } } > { item . count } </ Text >
108- </ Td >
109- </ Tr >
110- ) ) }
153+ </ Td >
154+ < Td
155+ width = { 10 }
156+ style = { { paddingRight : '0px' , textAlign : 'center' } }
157+ >
158+ < Text
159+ style = { { fontSize : 'clamp(0.4rem, 0.7vw, 1.1rem)' } }
160+ >
161+ { item . count }
162+ </ Text >
163+ </ Td >
164+ </ Tr >
165+ ) ) }
111166 </ Tbody >
112167 </ Table >
113168 </ div >
114169 </ Flex >
115170 </ FlexItem >
116-
117-
118171 </ Flex >
119172 ) ;
120173} ;
121174
122175export default MigrationChart ;
123-
124-
0 commit comments