arrows.app icon indicating copy to clipboard operation
arrows.app copied to clipboard

Import/export Mermaid

Open mattorp opened this issue 2 years ago • 3 comments

Given that markdown supports Mermaid, importing and exporting to this format would be great for documentation.

mattorp avatar Mar 23 '22 16:03 mattorp

Hi @mattorp !

We're pretty interested in defining a clear extension point for import/export formats. Mermaid makes sense as a candidate format once that is in place.

Exporting should be straightforward. Importing may be less useful until we have another extension point defined, for alignment and layout. Mermaid assumes autolayout. Arrows assumes user defined layout. We can reconcile this on the Arrows side by supporting the classic drawing-program behavior of selecting some elements, then applying one of various layout/aligment strategies.

Cheers, ABK

akollegger avatar Jun 05 '23 08:06 akollegger

Hi @akollegger, awesome!

mattorp avatar Jun 05 '23 11:06 mattorp

For anyone interested, here's a quick and dirty python script to produce mermaid output from the Arrows JSON export.

import json

def generate_mermaid_diagram(arrows_app_output):
    diagram = "graph TD;\n"

    for node in arrows_app_output["nodes"]:
        node_id = node["id"]
        caption = node.get("caption", "")
        labels = ",".join(node["labels"])
        diagram += f'  {node_id}["{caption}\\n({labels})"];\n'

    for relationship in arrows_app_output["relationships"]:
        from_id = relationship["fromId"]
        to_id = relationship["toId"]
        relationship_type = relationship.get("type", "")
        diagram += f'  {from_id} -->'
        if relationship_type:
            diagram += f'|{relationship_type}|'
        diagram += f'{to_id};\n'

    return diagram

# Load Arrows.app output from JSON
arrows_app_output_json = '''
PASTE YOUR ARROWS APP JSON HERE
'''

arrows_app_output = json.loads(arrows_app_output_json)

# Generate Mermaid diagram
mermaid_diagram = generate_mermaid_diagram(arrows_app_output)

print(mermaid_diagram)

djanjanin avatar Nov 12 '23 16:11 djanjanin