Add attribute customization option for Nodes (#127) (#151)

Co-authored-by: Szymon Ulewicz <ulewicz@amazon.com>
pull/154/head
sulewicz 5 years ago committed by GitHub
parent aa6d1d21f6
commit af85c15aac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -267,7 +267,7 @@ class Node:
_height = 1.9 _height = 1.9
def __init__(self, label: str = ""): def __init__(self, label: str = "", **attrs: Dict):
"""Node represents a system component. """Node represents a system component.
:param label: Node label. :param label: Node label.
@ -281,12 +281,14 @@ class Node:
# that label being spanned between icon image and white space. # that label being spanned between icon image and white space.
# Increase the height by the number of new lines included in the label. # Increase the height by the number of new lines included in the label.
padding = 0.4 * (label.count('\n')) padding = 0.4 * (label.count('\n'))
self.attrs = { self._attrs = {
"shape": "none", "shape": "none",
"height": str(self._height + padding), "height": str(self._height + padding),
"image": self._load_icon(), "image": self._load_icon(),
} if self._icon else {} } if self._icon else {}
# fmt: on # fmt: on
self._attrs.update(attrs)
# Node must be belong to a diagrams. # Node must be belong to a diagrams.
self._diagram = getdiagram() self._diagram = getdiagram()
@ -296,9 +298,9 @@ class Node:
# If a node is in the cluster context, add it to cluster. # If a node is in the cluster context, add it to cluster.
if self._cluster: if self._cluster:
self._cluster.node(self._id, self.label, **self.attrs) self._cluster.node(self._id, self.label, **self._attrs)
else: else:
self._diagram.node(self._id, self.label, **self.attrs) self._diagram.node(self._id, self.label, **self._attrs)
def __repr__(self): def __repr__(self):
_name = self.__class__.__name__ _name = self.__class__.__name__

Loading…
Cancel
Save