Skip to content
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

Add feature: Custom node #25

Merged
merged 4 commits into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions diagrams/custom/__init__.py
Original file line number Diff line number Diff line change
@@ -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 changes: 31 additions & 0 deletions docs/getting-started/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Binary file added website/static/img/rabbitmq_consumers_diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.