You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. ---
  2. id: diagram
  3. title: Diagrams
  4. ---
  5. Diagram is a primary object representing a diagram.
  6. ## Basic
  7. Diagram represents a global diagram context.
  8. You can create a diagram context with Diagram class. The first parameter of Diagram constructor will be used for output filename.
  9. ```python
  10. from diagrams import Diagram
  11. from diagrams.aws.compute import EC2
  12. with Diagram("Simple Diagram"):
  13. EC2("web")
  14. ```
  15. And if you run the above script with below command,
  16. ```shell
  17. $ python diagram.py
  18. ```
  19. It will generate an image file with single `EC2` node drawn as `simple_diagram.png` on your working directory, and open that created image file immediately.
  20. ## Jupyter Notebooks
  21. Diagrams can be also rendered directly inside the notebook as like this:
  22. ```python
  23. from diagrams import Diagram
  24. from diagrams.aws.compute import EC2
  25. with Diagram("Simple Diagram") as diag:
  26. EC2("web")
  27. diag
  28. ```
  29. ## Options
  30. You can specify the output file format with `outformat` parameter. Default is **png**.
  31. > (png, jpg, svg, and pdf) are allowed.
  32. ```python
  33. from diagrams import Diagram
  34. from diagrams.aws.compute import EC2
  35. with Diagram("Simple Diagram", outformat="jpg"):
  36. EC2("web")
  37. ```
  38. You can specify the output filename with `filename` parameter. The extension shouldn't be included, it's determined by the `outformat` parameter.
  39. ```python
  40. from diagrams import Diagram
  41. from diagrams.aws.compute import EC2
  42. with Diagram("Simple Diagram", filename="my_diagram"):
  43. EC2("web")
  44. ```
  45. You can also disable the automatic file opening by setting the `show` parameter as **false**. Default is **true**.
  46. ```python
  47. from diagrams import Diagram
  48. from diagrams.aws.compute import EC2
  49. with Diagram("Simple Diagram", show=False):
  50. EC2("web")
  51. ```
  52. It allows custom Graphviz dot attributes options.
  53. > `graph_attr`, `node_attr` and `edge_attr` are supported. Here is a [reference link](https://www.graphviz.org/doc/info/attrs.html).
  54. ```python
  55. from diagrams import Diagram
  56. from diagrams.aws.compute import EC2
  57. graph_attr = {
  58. "fontsize": "45",
  59. "bgcolor": "transparent"
  60. }
  61. with Diagram("Simple Diagram", show=False, graph_attr=graph_attr):
  62. EC2("web")
  63. ```