Skip to content

Commit 7d5f852

Browse files
committed
Fixed centering issue with root node
1 parent 7225d36 commit 7d5f852

File tree

1 file changed

+19
-24
lines changed

1 file changed

+19
-24
lines changed

src/app/components/AtomsRelationship.jsx

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,33 @@ let memoizeObj = {};
2222

2323
function clusterDataPopulate(props) {
2424
let atomCompObj = reorganizedObj(props);
25-
console.log(atomCompObj)
2625

2726
if (props[0].name) {
2827
clusterData.name = props[0].name;
2928
}
30-
31-
let counter = 0;
3229

30+
let counter = 0;
3331
for (let key in atomCompObj) {
34-
3532
if (atomCompObj[key].length) {
36-
3733
for (let i = 0; i < atomCompObj[key].length; i++) {
38-
3934
if (!memoizeObj[key]) {
4035
memoizeObj[key] = [];
4136
if (!clusterData.children) clusterData.children = [];
4237
clusterData.children.push({ name: key });
4338
}
44-
4539
if (!memoizeObj[key].includes(atomCompObj[key][i])) {
46-
47-
if (!clusterData.children[counter].children) clusterData.children[counter].children = []
48-
clusterData.children[counter].children.push({name: atomCompObj[key][i]});
49-
}
50-
memoizeObj[key].push(atomCompObj[key][i]);
51-
}
52-
}
53-
counter++;
40+
if (!clusterData.children[counter].children)
41+
clusterData.children[counter].children = [];
42+
clusterData.children[counter].children.push({
43+
name: atomCompObj[key][i],
44+
});
45+
}
46+
memoizeObj[key].push(atomCompObj[key][i]);
47+
}
5448
}
55-
console.log(clusterData)
49+
counter++;
5650
}
57-
51+
}
5852

5953
function reorganizedObj(props) {
6054
let atomsComponentObj = props[0].atomsComponents;
@@ -70,8 +64,7 @@ function reorganizedObj(props) {
7064
}
7165
}
7266
return reorganizedObj;
73-
}
74-
67+
}
7568

7669
function Node({ node }) {
7770
const isRoot = node.depth === 0;
@@ -86,9 +79,9 @@ function Node({ node }) {
8679
r={12}
8780
fill={background}
8881
stroke={isParent ? white : citrus}
89-
onClick={() => {
90-
alert(`clicked: ${JSON.stringify(node.data.name)}`);
91-
}}
82+
// onClick={() => {
83+
// alert(`clicked: ${JSON.stringify(node.data.name)}`);
84+
// }}
9285
/>
9386
)}
9487
<text
@@ -112,7 +105,7 @@ function RootNode({ node }) {
112105
const centerY = -height / 2;
113106

114107
return (
115-
<Group top={node.y} left={node.x}>
108+
<Group top = {node.y} left = {node.x}>
116109
<rect
117110
width={width}
118111
height={height}
@@ -122,6 +115,8 @@ function RootNode({ node }) {
122115
/>
123116
<text
124117
dy=".33em"
118+
top= {node.y}
119+
left = {node.x}
125120
fontSize={9}
126121
fontFamily="Arial"
127122
textAnchor="middle"
@@ -134,7 +129,7 @@ function RootNode({ node }) {
134129
);
135130
}
136131

137-
const defaultMargin = { top: 40, left: 50, right: 50, bottom: 40 };
132+
const defaultMargin = { top: 40, left: 0, right: 0, bottom: 40};
138133

139134
// export type DendrogramProps = {
140135
// width: number;

0 commit comments

Comments
 (0)