Browse Source

feat: allow `node.id` to be specified and not automatically generated (#422)

* allow node.id to be specified and not generated

* typing suport for context functions

Co-authored-by: Ivan Melnychuk <ivan.melnychuk@pg3.ch>
pull/435/merge
vanife 2 years ago
committed by GitHub
parent
commit
3c72e76be0
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 7 deletions
  1. +7
    -7
      diagrams/__init__.py

+ 7
- 7
diagrams/__init__.py View File

@@ -15,25 +15,25 @@ __diagram = contextvars.ContextVar("diagrams")
__cluster = contextvars.ContextVar("cluster") __cluster = contextvars.ContextVar("cluster")




def getdiagram():
def getdiagram() -> "Diagram":
try: try:
return __diagram.get() return __diagram.get()
except LookupError: except LookupError:
return None return None




def setdiagram(diagram):
def setdiagram(diagram: "Diagram"):
__diagram.set(diagram) __diagram.set(diagram)




def getcluster():
def getcluster() -> "Cluster":
try: try:
return __cluster.get() return __cluster.get()
except LookupError: except LookupError:
return None return None




def setcluster(cluster):
def setcluster(cluster: "Cluster"):
__cluster.set(cluster) __cluster.set(cluster)




@@ -283,13 +283,13 @@ class Node:


_height = 1.9 _height = 1.9


def __init__(self, label: str = "", **attrs: Dict):
def __init__(self, label: str = "", *, nodeid: str = None, **attrs: Dict):
"""Node represents a system component. """Node represents a system component.


:param label: Node label. :param label: Node label.
""" """
# Generates an ID for identifying a node.
self._id = self._rand_id()
# Generates an ID for identifying a node, unless specified
self._id = nodeid or self._rand_id()
self.label = label self.label = label


# fmt: off # fmt: off


Loading…
Cancel
Save