-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to save the resulting diagram in DOT format? #441
Comments
Thank you for the issue. What about using outformat, something like: According to the documentation outformat support this values with png as default, we can add dot.
according to Go-Diagrams readme it generate both.
Which one is better, generate a folder with dot file and the image(s) or only one file depend on the outformat option? Depends on the choice and If it's ok I can work on it. I prefer the outformat option because it will remain consistent with the current behavior. |
Just to add another data point, I do also prefer the outformat option. But a question, would it be possible to have multiple outformats? Otherwise, Id have to do a run to generate the image (JPG, PNG,etc.) and then another one to generate the dot file...that may be why the Go-Diagrams approach does both. Alternatively I would execute and generate the dot file but then I'd have to be able to read in the dot file with diagrams and render it. Is that possible? |
A Graphviz dot file is created each time you generate an output. This library then deletes the dot file leaving only the image. I have tried to change the code that removes the dot file, but could not find the dot file after I ran my script. See #436 (comment) |
@cldeluna using grouped workers example from the website with outformat=["png", "dot"] from diagrams import Diagram
from diagrams.aws.compute import EC2
from diagrams.aws.database import RDS
from diagrams.aws.network import ELB
with Diagram("Grouped Workers", show=False, direction="TB", outformat=["png", "dot"]):
ELB("lb") >> [EC2("worker1"),
EC2("worker2"),
EC2("worker3"),
EC2("worker4"),
EC2("worker5")] >> RDS("events") Generating this png file: and a dot file with this content:
|
Actually, you don't need to change any of the code at all, just call the Using @gabriel-tessier 's example: from diagrams import Diagram
from diagrams.aws.compute import EC2
from diagrams.aws.database import RDS
from diagrams.aws.network import ELB
with Diagram("Grouped Workers", show=False, direction="TB", ) as diag:
ELB("lb") >> [EC2("worker1"),
EC2("worker2"),
EC2("worker3"),
EC2("worker4"),
EC2("worker5")] >> RDS("events")
diag.dot.save(filename="aws.gv") Contents of "aws.gv"
|
@gabriel-tessier - thank you for the update to allow saving the dot file. it looks like an additional update is needed to deal with the list: Traceback (most recent call last): I then tried @clayms suggestion which actually does generate the dot file but does error out:
Error: Traceback (most recent call last): The dot file is generated but in trying to remove the file path I set in drawing_fp it errors out as there is no such file. Before the updates, where drawing_fp = 'Current_Topology" and where outformat="jpg", i get a file "Current_Topology.jpg" in the desired directory. It looks like the code is trying to remove the file "Current_Topology.jpg" (which I need to keep) but since my variable drawing_fp == 'Current_Topology' it is not found. A bit more testing. if I pass diag.dot.save(filename=drawing_fp) ...essentially the filepath attribute from the Drawing class, it does not error out but I don't get the .dot file either. with this I get two files I get a Current_Topology.dot.jpg drawing and a Current_Topology.dot file which looks to be a valid dot file but it errors out on the os.remove(self.filename) Let me know what other information I can provide! |
Thank you @gabriel-tessier, I had not realized that. FWIW I like the option of passing outformat a list. Apart from saving the dot file it could have broader uses...if I wanted to generate a PNG and JPG for the same diagram or JPG and SVG. It all works the same and the specifics of generating the requested format are done "behind the scenes". I'll keep an eye out on #446 and use @clayms workaround in the meantime. |
* mhmdio/master: bump: up to version 0.21.1 feat(output): Generate dot file and support multi outformat.(mingrammer#441) Re (mingrammer#592) feat: add digitalocean provider (mingrammer#646) docs(website): update docs bump: up to version 0.21.0 docs(readme): update badges docs(readme): update docs(readme): add digital ocean badge feat(provider): added DigitalOcean provider (mingrammer#621) feat(node): Dremio Service in OnPrem.Analytics (mingrammer#451) chore(deps): bump shelljs from 0.8.4 to 0.8.5 in /website (mingrammer#641) feat(node): add Nagios in OnPrem monitoring (mingrammer#638) feat(node): adding GCP API gateway image (mingrammer#636) feat(node): add chatbot icon (mingrammer#633) chore(deps): bump graphviz from 0.17 to 0.19.1 (mingrammer#635) feat(node): added Dapr programming runtime (mingrammer#591) docs: add mac dev guide (mingrammer#576) docs(readme): add Python 3.9 to badges (mingrammer#584) 👌 IMPROVE: HashiCorp Icons 📦 NEW: Add remaining HashiCorp Icons
is it possible to save the resulting diagram in dot notation?
Basically the pyGraphviz equivalent of this:
G.write("file.dot")
It would be nice to be able to keep the dot files under revision control and even "snapshot" drawings in text.
The text was updated successfully, but these errors were encountered: