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

Allow custom dot attributes in Diagram constructor #11

Merged
merged 1 commit into from
Feb 13, 2020
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
12 changes: 11 additions & 1 deletion diagrams/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,18 @@ class Diagram:

# TODO: Label position option
# TODO: Save directory option (filename + directory?)
def __init__(self, name: str = "", direction: str = "LR", outformat: str = "png", show: bool = True):
def __init__(self, name: str = "", direction: str = "LR",
outformat: str = "png", show: bool = True,
graph_attr: dict = {}, node_attr: dict = {}, edge_attr: dict = {}):
"""Diagram represents a global diagrams context.

:param name: Diagram name. It will be used for output filename.
:param direction: Data flow direction. Default is 'left to right'.
:param outformat: Output file format. Default is 'png'.
:param show: Open generated image after save if true, just only save otherwise.
:param graph_attr: Provide graph_attr dot config attributes.
:param node_attr: Provide node_attr dot config attributes.
:param edge_attr: Provide edge_attr dot config attributes.
"""
self.name = name

Expand All @@ -106,6 +111,11 @@ def __init__(self, name: str = "", direction: str = "LR", outformat: str = "png"
raise ValueError(f'"{outformat}" is not a valid output format')
self.outformat = outformat

# Merge passed in attributes
self.dot.graph_attr.update(graph_attr)
self.dot.node_attr.update(node_attr)
self.dot.edge_attr.update(edge_attr)

self.show = show

def __enter__(self):
Expand Down