@@ -10,18 +10,60 @@ const white = '#ffffff';
10
10
export const green = '#79d259' ;
11
11
const aqua = '#37ac8c' ;
12
12
const merlinsbeard = '#f7f7f3' ;
13
- export const background = '#306c90 ' ;
13
+ export const background = '#242529 ' ;
14
14
15
15
// interface NodeShape {
16
16
// name: string;
17
17
// children?: NodeShape[];
18
- //
18
+ //
19
+
20
+ function clusterDataPopulate ( props ) {
21
+ let data = { } ;
22
+
23
+ let atomCompObj = reorganizedObj ( props ) ;
24
+
25
+ console . log ( atomCompObj ) ;
26
+ console . log ( props ) ;
27
+
28
+ if ( props [ 0 ] . name ) {
29
+ console . log ( 'entered' )
30
+ data . name = props [ 0 ] . name ;
31
+ }
32
+
33
+ for ( let key in atomCompObj ) {
34
+ if ( ! data . children ) {
35
+ data . children = [ ]
36
+ data . children . push ( { name : key } )
37
+ } else {
38
+ data . children . push ( { name : key } )
39
+ }
40
+ }
41
+ console . log ( data )
42
+ }
43
+
44
+ function reorganizedObj ( props ) {
45
+ let atomsComponentObj = props [ 0 ] . atomsComponents ;
46
+ let reorganizedObj = { } ;
47
+
48
+ for ( const key in atomsComponentObj ) {
49
+ for ( let i = 0 ; i < atomsComponentObj [ key ] . length ; i ++ ) {
50
+ if ( ! reorganizedObj [ atomsComponentObj [ key ] [ i ] ] ) {
51
+ reorganizedObj [ atomsComponentObj [ key ] [ i ] ] = [ key ] ;
52
+ } else {
53
+ reorganizedObj [ atomsComponentObj [ key ] [ i ] ] . push ( key ) ;
54
+ }
55
+ }
56
+ }
57
+
58
+ return reorganizedObj ;
59
+ }
19
60
20
61
const clusterData = {
21
- name : '$' ,
62
+ name : 'root' ,
63
+
22
64
children : [
23
65
{
24
- name : 'A ' ,
66
+ name : 'darkMode ' ,
25
67
children : [
26
68
{ name : 'A1' } ,
27
69
{ name : 'A2' } ,
@@ -35,10 +77,12 @@ const clusterData = {
35
77
} ,
36
78
] ,
37
79
} ,
80
+
38
81
{
39
82
name : 'B' ,
40
83
children : [ { name : 'B1' } , { name : 'B2' } , { name : 'B3' } ] ,
41
84
} ,
85
+
42
86
{
43
87
name : 'X' ,
44
88
children : [
@@ -90,7 +134,13 @@ function RootNode({ node }) {
90
134
91
135
return (
92
136
< Group top = { node . y } left = { node . x } >
93
- < rect width = { width } height = { height } y = { centerY } x = { centerX } fill = "url('#top')" />
137
+ < rect
138
+ width = { width }
139
+ height = { height }
140
+ y = { centerY }
141
+ x = { centerX }
142
+ fill = "url('#top')"
143
+ />
94
144
< text
95
145
dy = ".33em"
96
146
fontSize = { 9 }
@@ -113,17 +163,24 @@ const defaultMargin = { top: 40, left: 50, right: 50, bottom: 40 };
113
163
// margin?: { top: number; right: number; bottom: number; left: number };
114
164
// };
115
165
116
- export default function Example ( { width, height, margin = defaultMargin } ) {
166
+ export default function Example ( {
167
+ width,
168
+ height,
169
+ margin = defaultMargin ,
170
+ snapshots,
171
+ } ) {
117
172
const data = useMemo ( ( ) => hierarchy ( clusterData ) , [ ] ) ;
118
173
const xMax = width - margin . left - margin . right ;
119
174
const yMax = height - margin . top - margin . bottom ;
120
175
176
+ clusterDataPopulate ( snapshots ) ;
177
+
121
178
return width < 10 ? null : (
122
179
< svg width = { width } height = { height } >
123
180
< LinearGradient id = "top" from = { green } to = { aqua } />
124
181
< rect width = { width } height = { height } rx = { 14 } fill = { background } />
125
182
< Cluster root = { data } size = { [ xMax , yMax ] } >
126
- { cluster => (
183
+ { ( cluster ) => (
127
184
< Group top = { margin . top } left = { margin . left } >
128
185
{ cluster . links ( ) . map ( ( link , i ) => (
129
186
< LinkVertical
@@ -142,4 +199,5 @@ export default function Example({ width, height, margin = defaultMargin }) {
142
199
) }
143
200
</ Cluster >
144
201
</ svg >
145
- ) } ;
202
+ ) ;
203
+ }
0 commit comments