Skip to content

Commit

Permalink
clearer visualization, added detailed labels to nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
lschoonheid committed Jan 18, 2023
1 parent f848ee5 commit 1c72917
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions code/visualisation/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ def visualize(self, print_nodes: bool = False, plot: bool = False):

# Define iterables for hierarchal structure
shown_nodes = [
self.schedule.students.values(),
self.schedule.courses.values(),
self.schedule.activities.values(),
self.schedule.timeslots.values(),
self.schedule.students.values(),
]
hidden_nodes = [
self.schedule.courses.values(),
self.schedule.rooms.values(),
]
hidden_nodes = [self.schedule.rooms.values()]
colors = ["blue", "red", "orange", "green", "purple"]
assert len(colors) >= len(shown_nodes), "Not enough colors available for levels."

Expand All @@ -53,6 +55,12 @@ def visualize(self, print_nodes: bool = False, plot: bool = False):
Type: {type(node).__name__}
label: {str(node)}
"""
for neighbor_tag in ["activities", "students", "timeslots"]:
if hasattr(node, neighbor_tag):
title += f"{neighbor_tag}: [\n"
for neighbor in getattr(node, neighbor_tag).values():
title += f" {neighbor.id}: {neighbor} \n"
title += "]\n"
G.add_node(node.id, title=title, label=str(node), color=color, level=level)

# Add hidden nodes
Expand All @@ -65,9 +73,12 @@ def visualize(self, print_nodes: bool = False, plot: bool = False):

# Output interactive visualization to html file with pyvis
net = PyvisNetwork(layout=True, height="900px")
net.from_nx(G)
net.options.physics.enabled = True
net.repulsion()
net.options.edges.smooth.enabled = False
net.options.layout.set_separation(500)
net.from_nx(G)
net.options.layout.hierarchical.sortMethod = "directed"
net.show("output/graph.html")
print("View output/graph.html in your browser")

Expand Down

0 comments on commit 1c72917

Please sign in to comment.