Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
better naming
Browse files Browse the repository at this point in the history
  • Loading branch information
iopapamanoglou committed Sep 19, 2024
1 parent cf18853 commit 62c672e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/faebryk/core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,11 @@ def get_graph(self):
def get_parent(self):
return self.parent.get_parent()

def get_name(self):
def get_name(self, accept_no_parent: bool = False):
p = self.get_parent()
if not p:
if accept_no_parent:
return f"<{hex(id(self))[-4:].upper()}>"
raise NodeNoParent(self, "Parent required for name")
return p[1]

Expand Down
10 changes: 6 additions & 4 deletions src/faebryk/exporters/visualize/interactive_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _group(node: Node):
return {
"data": {
"id": id(node),
"label": f"{node.get_full_name()}\n({typename(node)})",
"label": f"{node.get_name(accept_no_parent=True)}\n({typename(node)})",
"type": "group",
"subtype": typename(subtype),
"parent": id(node.get_parent()[0]) if node.get_parent() else None,
Expand All @@ -76,7 +76,7 @@ def _group(node: Node):


def _with_pastels[T](iterable: Collection[T]):
return zip(iterable, generate_pastel_palette(len(iterable)))
return zip(sorted(iterable), generate_pastel_palette(len(iterable)))


class _Stylesheet:
Expand Down Expand Up @@ -216,6 +216,7 @@ def interactive_subgraph(
edges: Iterable[tuple[GraphInterface, GraphInterface, Link]],
gifs: list[GraphInterface],
nodes: Iterable[Node],
height: int | None = None,
):
links = [link for _, _, link in edges]
link_types = {typename(link) for link in links}
Expand Down Expand Up @@ -269,14 +270,15 @@ def interactive_subgraph(
console.print(table)

#
app.run(jupyter_height=1800)
app.run(jupyter_height=height or 1000)


def interactive_graph(
G: Graph,
node_types: tuple[type[Node], ...] | None = None,
depth: int = 0,
filter_unconnected: bool = True,
height: int | None = None,
):
if node_types is None:
node_types = (Node,)
Expand All @@ -295,4 +297,4 @@ def interactive_graph(
for edge in G.edges
if edge[0] in gifs and edge[1] in gifs
]
return interactive_subgraph(edges, gifs, nodes)
return interactive_subgraph(edges, gifs, nodes, height=height)

0 comments on commit 62c672e

Please sign in to comment.