mirror of https://github.com/mingrammer/diagrams
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.
70 lines
1.6 KiB
70 lines
1.6 KiB
5 years ago
|
---
|
||
|
id: diagram
|
||
|
title: Diagrams
|
||
|
---
|
||
|
|
||
|
Diagram is a primary object representing a diagram.
|
||
|
|
||
|
## Basic
|
||
|
|
||
|
Diagram represents a global diagram context.
|
||
|
|
||
|
You can create a diagram context with Diagram class. The first parameter of Diagram constructor will be used for output filename.
|
||
|
|
||
|
```python
|
||
|
from diagrams import Diagram
|
||
|
from diagrams.aws.compute import EC2
|
||
|
|
||
|
with Diagram("Simple Diagram"):
|
||
|
EC2("web")
|
||
|
```
|
||
|
|
||
|
And if you run the above script with below command,
|
||
|
|
||
|
```shell
|
||
|
$ python diagram.py
|
||
5 years ago
|
```
|
||
5 years ago
|
|
||
|
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.
|
||
|
|
||
|
## Options
|
||
|
|
||
|
You can specify the output file format with `outformat` parameter. Default is **png**.
|
||
|
|
||
|
> (png, jpg, svg, and pdf) are allowed.
|
||
|
|
||
|
```python
|
||
|
from diagrams import Diagram
|
||
|
from diagrams.aws.compute import EC2
|
||
|
|
||
|
with Diagram("Simple Diagram", outformat="jpg"):
|
||
|
EC2("web")
|
||
|
```
|
||
|
|
||
|
You can also disable the automatic file opening by setting the `show` parameter as **false**. Default is **true**.
|
||
|
|
||
|
```python
|
||
|
from diagrams import Diagram
|
||
|
from diagrams.aws.compute import EC2
|
||
|
|
||
|
with Diagram("Simple Diagram", show=False):
|
||
|
EC2("web")
|
||
5 years ago
|
```
|
||
|
|
||
5 years ago
|
It allows custom Graphviz dot attributes options.
|
||
5 years ago
|
|
||
5 years ago
|
> `graph_attr`, `node_attr` and `edge_attr` are supported. Here is a [reference link](https://www.graphviz.org/doc/info/attrs.html).
|
||
5 years ago
|
|
||
|
```python
|
||
|
from diagrams import Diagram
|
||
|
from diagrams.aws.compute import EC2
|
||
|
|
||
|
graph_attr = {
|
||
|
"fontsize": 45,
|
||
5 years ago
|
"bgcolor": "transparent"
|
||
5 years ago
|
}
|
||
|
|
||
|
with Diagram("Simple Diagram", show=False, graph_attr=graph_attr):
|
||
|
EC2("web")
|
||
|
```
|