1
- import React , { useEffect } from 'react' ;
1
+ import React , { useEffect , useState } from 'react' ;
2
2
import { useStore } from 'react-redux' ;
3
3
import { Chart } from 'react-google-charts' ;
4
+ import Grid from '@mui/material/Grid' ;
4
5
5
6
const DisplayContainer = ( ) => {
6
7
const store = useStore ( ) ;
8
+ const { allContext } = store . getState ( ) . contextSlice ;
9
+ const [ contextData , setContextData ] = useState ( [ ] ) ;
7
10
8
11
useEffect ( ( ) => {
9
- console . log ( store . getState ( ) . contextSlice ) ;
12
+ transformData ( allContext ) ;
10
13
} , [ ] ) ;
11
14
15
+ const transformData = contexts => {
16
+ const formattedData = contexts
17
+ . map ( el => {
18
+ return el . components . map ( component => {
19
+ return [ `App ${ el . name } ${ component } ` ] ;
20
+ } ) ;
21
+ } )
22
+ . flat ( ) ;
23
+ setContextData ( [ [ 'Phrases' ] , ...formattedData ] ) ;
24
+ } ;
12
25
13
- const data = [
14
- [ 'Phrases' ] ,
15
- [ 'cats are better than dogs' ] ,
16
- [ 'cats eat kibble' ] ,
17
- [ 'cats are better than hamsters' ] ,
18
- [ 'cats are awesome' ] ,
19
- [ 'cats are people too' ] ,
20
- [ 'cats eat mice' ] ,
21
- [ 'cats meowing' ] ,
22
- [ 'cats in the cradle' ] ,
23
- [ 'cats eat mice' ] ,
24
- [ 'cats in the cradle lyrics' ] ,
25
- [ 'cats eat kibble' ] ,
26
- [ 'cats for adoption' ] ,
27
- [ 'cats are family' ] ,
28
- [ 'cats eat mice' ] ,
29
- [ 'cats are better than kittens' ] ,
30
- [ 'cats are evil' ] ,
31
- [ 'cats are weird' ] ,
32
- [ 'cats eat mice' ] ,
33
- ] ;
34
26
const options = {
35
27
wordtree : {
36
28
format : 'implicit' ,
37
- word : 'cats' ,
38
- } ,
29
+ word : 'App'
30
+ }
39
31
} ;
32
+ console . log ( contextData ) ;
40
33
return (
41
- < Chart
42
- chartType = 'WordTree'
43
- width = '100%'
44
- height = '400px'
45
- data = { data }
46
- options = { options }
47
- />
34
+ < Grid container display = "flex" justifyContent = "center" >
35
+ < Grid item >
36
+ < Chart
37
+ chartType = "WordTree"
38
+ width = "100%"
39
+ height = "500px"
40
+ data = { contextData }
41
+ options = { options }
42
+ />
43
+ </ Grid >
44
+ </ Grid >
48
45
) ;
49
46
} ;
50
- export default DisplayContainer ;
47
+ export default DisplayContainer ;
0 commit comments