mingrammer / diagrams

:art: Diagram as Code for prototyping cloud system architectures
https://diagrams.mingrammer.com
MIT License
39.11k stars 2.52k forks source link

Is there a way to export the diagram as XML? #869

Open arsoni20 opened 1 year ago

arsoni20 commented 1 year ago

First off, thanks for creating this amazing package, it makes idea to diagram journey so simple, without me fiddling with edges in the initial phases of incubation. I was wondering if there is a way we can export the image as XML so it can be edited in draw.io ?

matzmz commented 3 months ago

Hi @arsoni20,

Currently, I'm doing the following:

  1. Exporting the diagram in DOT format.
  2. Converting the DOT format to XML using graphviz2drawio.
  3. Importing the generated XML into draw.io.

Here's the code I'm using:

from diagrams import Cluster, Diagram
from diagrams.k8s.compute import Pod, StatefulSet
from diagrams.k8s.network import Service
from diagrams.k8s.storage import PV, PVC, StorageClass
from graphviz2drawio import graphviz2drawio

filename = "my_diagram"

with Diagram("Stateful Architecture", show=False, outformat=["dot"], filename=filename):
    with Cluster("Apps"):
        svc = Service("svc")
        sts = StatefulSet("sts")

        apps = []
        for _ in range(3):
            pod = Pod("pod")
            pvc = PVC("pvc")
            pod - sts - pvc
            apps.append(svc >> pod >> pvc)

    apps << PV("pv") << StorageClass("sc")

xml = graphviz2drawio.convert(f"{filename}.dot")

with open(f"{filename}.xml", "w") as xml_file:
    xml_file.write(xml)

If you have any improvements or suggestions, please share!

ravening commented 3 months ago

@matzmz

when I export it to xml and open it in draw.io, I dont see the cluster box. Is there a way to retain the box for the cluster also?

matzmz commented 3 months ago

@ravening Same issue here, the box is not drawn.