Skip to content

Commit 6d5139f

Browse files
committed
Added logic to extract children names (atom) for D3
1 parent 0cac6ef commit 6d5139f

File tree

2 files changed

+68
-9
lines changed

2 files changed

+68
-9
lines changed

src/app/components/AtomsRelationship.jsx

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,60 @@ const white = '#ffffff';
1010
export const green = '#79d259';
1111
const aqua = '#37ac8c';
1212
const merlinsbeard = '#f7f7f3';
13-
export const background = '#306c90';
13+
export const background = '#242529';
1414

1515
// interface NodeShape {
1616
// name: string;
1717
// 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+
}
1960

2061
const clusterData = {
21-
name: '$',
62+
name: 'root',
63+
2264
children: [
2365
{
24-
name: 'A',
66+
name: 'darkMode',
2567
children: [
2668
{ name: 'A1' },
2769
{ name: 'A2' },
@@ -35,10 +77,12 @@ const clusterData = {
3577
},
3678
],
3779
},
80+
3881
{
3982
name: 'B',
4083
children: [{ name: 'B1' }, { name: 'B2' }, { name: 'B3' }],
4184
},
85+
4286
{
4387
name: 'X',
4488
children: [
@@ -90,7 +134,13 @@ function RootNode({ node }) {
90134

91135
return (
92136
<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+
/>
94144
<text
95145
dy=".33em"
96146
fontSize={9}
@@ -113,17 +163,24 @@ const defaultMargin = { top: 40, left: 50, right: 50, bottom: 40 };
113163
// margin?: { top: number; right: number; bottom: number; left: number };
114164
// };
115165

116-
export default function Example({ width, height, margin = defaultMargin }) {
166+
export default function Example({
167+
width,
168+
height,
169+
margin = defaultMargin,
170+
snapshots,
171+
}) {
117172
const data = useMemo(() => hierarchy(clusterData), []);
118173
const xMax = width - margin.left - margin.right;
119174
const yMax = height - margin.top - margin.bottom;
120175

176+
clusterDataPopulate(snapshots);
177+
121178
return width < 10 ? null : (
122179
<svg width={width} height={height}>
123180
<LinearGradient id="top" from={green} to={aqua} />
124181
<rect width={width} height={height} rx={14} fill={background} />
125182
<Cluster root={data} size={[xMax, yMax]}>
126-
{cluster => (
183+
{(cluster) => (
127184
<Group top={margin.top} left={margin.left}>
128185
{cluster.links().map((link, i) => (
129186
<LinkVertical
@@ -142,4 +199,5 @@ export default function Example({ width, height, margin = defaultMargin }) {
142199
)}
143200
</Cluster>
144201
</svg>
145-
)};
202+
);
203+
}

src/app/components/StateRoute.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ const StateRoute = (props: StateRouteProps) => {
8787
<ParentSize>{({ width, height }) =>
8888
<Example
8989
width={width}
90-
height={height} />}
90+
height={height}
91+
snapshots = {snapshots} />}
9192
</ParentSize>
9293

9394
// atomsComponents={snapshot.atomsComponents}

0 commit comments

Comments
 (0)