Browse Source

feat: add custom node class (#25)

* feat: add custom node class

* docs: add example about custom node

* docs: improve example about custom node usage

* docs: fix variable name
pull/31/head
Daniel Ferrari 4 years ago
committed by GitHub
parent
commit
70addf3a64
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 0 deletions
  1. +20
    -0
      diagrams/custom/__init__.py
  2. +31
    -0
      docs/getting-started/examples.md
  3. BIN
      website/static/img/rabbitmq_consumers_diagram.png

+ 20
- 0
diagrams/custom/__init__.py View File

@@ -0,0 +1,20 @@
"""
Custom provides the possibility of load an image to be presented as a node.
"""

from diagrams import Node


class Custom(Node):
_provider = "custom"
_type = "custom"
_icon_dir = None

fontcolor = "#ffffff"

def _load_icon(self):
return self._icon

def __init__(self, label, icon_path):
self._icon = icon_path
super().__init__(label)

+ 31
- 0
docs/getting-started/examples.md View File

@@ -169,3 +169,34 @@ with Diagram("Stateful Architecture", show=False):
```

![stateful architecture diagram](/img/stateful_architecture_diagram.png)

## RabbitMQ Consumers with custom nodes

```python
from urllib.request import urlretrieve

from diagrams import Cluster, Diagram
from diagrams.custom import Custom
from diagrams.aws.database import Aurora
from diagrams.k8s.compute import Pod

# Download an image to be used into a Custom Node class
rabbitmq_url = "https://jpadilla.github.io/rabbitmqapp/assets/img/icon.png"
rabbitmq_icon = "rabbitmq.png"
urlretrieve(rabbitmq_url, rabbitmq_icon)


with Diagram("Broker Consumers", show=False):
with Cluster("Consumers"):
consumers = [
Pod("worker"),
Pod("worker"),
Pod("worker")
]

queue = Custom("Message queue", rabbitmq_icon)

queue >> consumers >> Aurora("Database")
````

![rabbitmq consumers diagram](/img/rabbitmq_consumers_diagram.png)

BIN
website/static/img/rabbitmq_consumers_diagram.png View File

Before After
Width: 580  |  Height: 820  |  Size: 77 KiB

Loading…
Cancel
Save