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

feat(c4) Allow adding attributes. #796

Merged
merged 1 commit into from
Jan 8, 2023
Merged
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
56 changes: 42 additions & 14 deletions diagrams/c4/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)