<jupyter_start><jupyter_text>🦌 ELK Transformer 🤖A transformer object that will convert some input source into valid Elk Json.This example using a transformer around a networkx graph.<jupyter_code>import networkx, elk, elk.nx, elk.tools, ipywidgets, pathlib, json<jupyter_output><empty_output><jupyter_text>Flat structureA `networkx.MultiDiagraph` can be used to create a flat graph.> _TODO: There should be an option to specify if ports should be created or only connect edges between the nodes_<jupyter_code>flat_graph = networkx.readwrite.json_graph.node_link_graph(
    json.loads(pathlib.Path("flat_graph.json").read_text())
)

flat_xelk = elk.nx.XELK(source=(flat_graph, None))
flat_elk = elk.ElkDiagram(flat_xelk.to_dict())
flat_elk<jupyter_output><empty_output><jupyter_text>Hierarchical Diagram with Ports<jupyter_code>hier_tree = networkx.readwrite.json_graph.node_link_graph(
    json.loads(pathlib.Path("hier_tree.json").read_text())
)
hier_ports = networkx.readwrite.json_graph.node_link_graph(
    json.loads(pathlib.Path("hier_ports.json").read_text())
)

hier_xelk = elk.nx.XELK(source=(hier_ports, hier_tree))
hier_elk = elk.ElkDiagram(hier_xelk.to_dict())

toggle = ipywidgets.Button(description="Toggle Collapsed")

@toggle.on_click
def toggle_node(widget):
    for element_id in hier_elk.selected:
        if element_id in hier_tree:
            for child in hier_tree.neighbors(element_id):
                state = hier_tree.nodes[child].get('hidden', False)
                hier_tree.nodes[child]['hidden'] = not state
            hier_elk.value = hier_xelk.to_dict()

ipywidgets.VBox([
    ipywidgets.HBox([
        ipywidgets.HTML("<h2>👇 click a group node then click 👉</h2>"), 
        toggle
    ]), 
    hier_elk
])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11067193675889328, 'fraction_numerical': 0.001129305477131564, 'mean_word_length': 4.926421404682274, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '575019', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 650, 'n_tokens_neox': 639, 'n_words': 121, 'path': 'examples/02_Transformer.ipynb', 'repo_name': 'nrbgt/ipyelk', 'size': '1771'}