From 65b51469f40ce9729ea0d5ab79c0b7ef3e8b98ce Mon Sep 17 00:00:00 2001 From: Joshua Haase Date: Sun, 8 Jan 2023 02:14:30 -0600 Subject: [PATCH] feat(c4) Allow adding attributes. (#796) This allows in example adding hyperlinks to C4 diagrams, as requested on #604. This also allows further customization for those elements. --- diagrams/c4/__init__.py | 56 ++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/diagrams/c4/__init__.py b/diagrams/c4/__init__.py index 40577c8c..90ce7a92 100644 --- a/diagrams/c4/__init__.py +++ b/diagrams/c4/__init__.py @@ -58,24 +58,50 @@ def C4Node(name, technology="", description="", type="Container", **kwargs): def Container(name, technology="", description="", **kwargs): - return C4Node(name, technology=technology, description=description, type="Container") + container_attributes = { + "name": name, + "technology": technology, + "description": description, + "type": "Container", + } + container_attributes.update(kwargs) + return C4Node(**container_attributes) def Database(name, technology="", description="", **kwargs): - return C4Node(name, technology=technology, description=description, type="Database", shape="cylinder", labelloc="b") + database_attributes = { + "name": name, + "technology": technology, + "description": description, + "type": "Database", + "shape": "cylinder", + "labelloc": "b", + } + database_attributes.update(kwargs) + return C4Node(**database_attributes) def System(name, description="", external=False, **kwargs): - type = "External System" if external else "System" - fillcolor = "gray60" if external else "dodgerblue4" - return C4Node(name, description=description, type=type, fillcolor=fillcolor) + system_attributes = { + "name": name, + "description": description, + "type": "External System" if external else "System", + "fillcolor": "gray60" if external else "dodgerblue4", + } + system_attributes.update(kwargs) + return C4Node(**system_attributes) def Person(name, description="", external=False, **kwargs): - type = "External Person" if external else "Person" - fillcolor = "gray60" if external else "dodgerblue4" - style = "rounded,filled" - return C4Node(name, description=description, type=type, fillcolor=fillcolor, style=style) + person_attributes = { + "name": name, + "description": description, + "type": "External Person" if external else "Person", + "fillcolor": "gray60" if external else "dodgerblue4", + "style": "rounded,filled", + } + person_attributes.update(kwargs) + return C4Node(**person_attributes) def SystemBoundary(name, **kwargs): @@ -90,8 +116,10 @@ def SystemBoundary(name, **kwargs): def Relationship(label="", **kwargs): - edge_attribtues = {"style": "dashed", "color": "gray60"} - if label: - edge_attribtues.update({"label": _format_edge_label(label)}) - edge_attribtues.update(kwargs) - return Edge(**edge_attribtues) + edge_attributes = { + "style": "dashed", + "color": "gray60", + "label": _format_edge_label(label) if label else "", + } + edge_attributes.update(kwargs) + return Edge(**edge_attributes)