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

Commit

Permalink
depth filter; better legend
Browse files Browse the repository at this point in the history
  • Loading branch information
iopapamanoglou committed Sep 19, 2024
1 parent 314b72d commit 6d3a9ee
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/faebryk/exporters/visualize/interactive_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from typing import Collection, Iterable

import dash_cytoscape as cyto
import rich
import rich.text
from dash import Dash, html
from rich.console import Console
from rich.table import Table

import faebryk.library._F as F
from faebryk.core.graphinterface import Graph, GraphInterface
Expand Down Expand Up @@ -248,31 +248,40 @@ def interactive_subgraph(
app.layout = _Layout(stylesheet, elements)

# Print legend
def legend_block(text: str, color: str):
colored_blocks = rich.text.Text(" " * 5)
colored_blocks.style = f"on {color}"
rich.print(colored_blocks, text)
console = Console()

for typegroup, colors in [
("Node", gif_type_colors),
("GIF", gif_type_colors),
("Link", link_type_colors),
("Group", group_types_colors),
("Node", group_types_colors),
]:
print(f"{typegroup} types:")
table = Table(title="Legend")
table.add_column("Type", style="cyan")
table.add_column("Color", style="green")
table.add_column("Name")

for text, color in colors:
legend_block(text, color)
print("\n")
table.add_row(typegroup, f"[on {color}] [/]", text)

console.print(table)

#
app.run(jupyter_height=1800)


def interactive_graph(G: Graph, node_types: tuple[type[Node], ...] | None = None):
def interactive_graph(
G: Graph,
node_types: tuple[type[Node], ...] | None = None,
depth: int = 0,
):
if node_types is None:
node_types = (Node,)

# Build elements
nodes = G.nodes_of_types(node_types)
if depth > 0:
nodes = [node for node in nodes if len(node.get_hierarchy()) <= depth]

gifs = [gif for gif in G if gif.node in nodes]
edges = [
(edge[0], edge[1], edge[2])
Expand Down

0 comments on commit 6d3a9ee

Please sign in to comment.