I have a data set which has parent and child nodes. Parent nodes can link with other parent nodes and child nodes can link with their parent nodes. What I want to do is to put child nodes radially placed around parent nodes. The nodes look something like this
parent: [{
id: 1,
type: 'parent',
x: ,
y: ,
vx: ,
vy: ,
}, {
id: 2
x: ,
y: ,
vx: ,
vy: ,
}]
child: [{
id: 1,
type: 'child',
parent_node: {
id: 1,
x: ,
y: ,
vx: ,
vy: ,
},
x: ,
y: ,
vx: ,
vy: ,
}]
So I have the details of the parent node such as its x and y inside the child nodes.
I tried to assign x
and y
(as in the centre) dynamically but could not find a way to do it:
force('radial', d3.forceRadial()
.radius(node => {
if (node.type === 'child') {
return 10
}
return 0
})
.x(node => {
if (node.type === 'child') {
return node.parent_node.x
}
return 0
})
.y(node => {
if (node.type === 'child') {
return node.parent_node.y
}
return 0
})
)
Can something like this be done? So that the centre for each child node can be provided dynamically, based on their parent's position?