1- import React , { useEffect } from 'react' ;
1+ import React , { useEffect , useState } from 'react' ;
22import { useStore } from 'react-redux' ;
33import { Chart } from 'react-google-charts' ;
4+ import Grid from '@mui/material/Grid' ;
45
56const DisplayContainer = ( ) => {
67 const store = useStore ( ) ;
8+ const { allContext } = store . getState ( ) . contextSlice ;
9+ const [ contextData , setContextData ] = useState ( [ ] ) ;
710
811 useEffect ( ( ) => {
9- console . log ( store . getState ( ) . contextSlice ) ;
12+ transformData ( allContext ) ;
1013 } , [ ] ) ;
1114
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+ } ;
1225
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- ] ;
3426 const options = {
3527 wordtree : {
3628 format : 'implicit' ,
37- word : 'cats' ,
38- } ,
29+ word : 'App'
30+ }
3931 } ;
32+ console . log ( contextData ) ;
4033 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 >
4845 ) ;
4946} ;
50- export default DisplayContainer ;
47+ export default DisplayContainer ;
0 commit comments