Using the C converted to python Radial Positions algorithm from this question, I have been successful in creating a radial graph based on a root node, all the way to the last child of each node. Now I have a new problem where I have multiple root nodes and will need them to be centered around the first root found, or at least a center point.
The closest example I've found is this graph:
So far all I could think of was for each root node found, multiply it by it's index and add the x position with a y radius. So far it hasn't worked out too well as I the children nodes do not follow it. I've been stumped on this for a few days now.
def RadialPositions(node, id):
children_in_node = len(timelinedatta.neighbors(id, mode="out"))
def rotate_node(x, y, nangle):
nx = x * math.cos(nangle) - y * math.sin(nangle)
ny = x * math.sin(nangle) + y * math.cos(nangle)
return nx, ny
def get_depth(id):
count = 0
for v in timelinedatta.bfsiter(id, mode="in", advanced=True):
count = count + 1
return count - 1
if len(timelinedatta.neighbors(id, mode="out")) > 0 and len(timelinedatta.neighbors(id, mode="in")) == 0:
node["positions"] = (0, 0)
node["depth"] = get_depth(id)
node_children_list = []
for child in timelinedatta.neighbors(id, mode="out"):
node_children_list.append((child, timelinedatta.vs[child]))
for idx, (child_node_id, child_node) in enumerate(node_children_list, start=0):
centerAdjust = 0
if timelinedatta.neighbors(id, mode="in"):
centerAdjust = (-node["angleRange"] + node["angleRange"] / children_in_node) / 2
child_node["depth"] = get_depth(child_node_id)
child_depth = child_node["depth"]
child_node["nodeAngle"] = node["nodeAngle"] + node["angleRange"] / children_in_node * idx + centerAdjust
child_node["angleRange"] = node["angleRange"] / children_in_node
nx = rotate_node(40 * child_depth, 0, child_node["nodeAngle"])[0]
ny = rotate_node(40 * child_depth, 0, child_node["nodeAngle"])[1]
child_node["positions"] = [2 * nx, 2 * ny]
RadialPositions(child_node, child_node_id)
I have an example of my graph here on pastebin as well

