Skip to content

Commit

Permalink
Add attribute customization option for Nodes (#127) (#151)
Browse files Browse the repository at this point in the history
Co-authored-by: Szymon Ulewicz <[email protected]>
  • Loading branch information
sulewicz and Szymon Ulewicz authored May 20, 2020
1 parent aa6d1d2 commit af85c15
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions diagrams/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ class Node:

_height = 1.9

def __init__(self, label: str = ""):
def __init__(self, label: str = "", **attrs: Dict):
"""Node represents a system component.
:param label: Node label.
Expand All @@ -281,12 +281,14 @@ def __init__(self, label: str = ""):
# that label being spanned between icon image and white space.
# Increase the height by the number of new lines included in the label.
padding = 0.4 * (label.count('\n'))
self.attrs = {
self._attrs = {
"shape": "none",
"height": str(self._height + padding),
"image": self._load_icon(),
} if self._icon else {}

# fmt: on
self._attrs.update(attrs)

# Node must be belong to a diagrams.
self._diagram = getdiagram()
Expand All @@ -296,9 +298,9 @@ def __init__(self, label: str = ""):

# If a node is in the cluster context, add it to cluster.
if self._cluster:
self._cluster.node(self._id, self.label, **self.attrs)
self._cluster.node(self._id, self.label, **self._attrs)
else:
self._diagram.node(self._id, self.label, **self.attrs)
self._diagram.node(self._id, self.label, **self._attrs)

def __repr__(self):
_name = self.__class__.__name__
Expand Down

0 comments on commit af85c15

Please sign in to comment.