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 6 years ago committed by GitHub
parent ae7b424aa0
commit 70addf3a64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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)

@ -169,3 +169,34 @@ with Diagram("Stateful Architecture", show=False):
``` ```
![stateful architecture diagram](/img/stateful_architecture_diagram.png) ![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)

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Loading…
Cancel
Save