Skip to content

Commit

Permalink
Merge pull request #11 from deadmeu/master
Browse files Browse the repository at this point in the history
feat: allow custom dot attributes in Diagram constructor
  • Loading branch information
mingrammer authored Feb 13, 2020
2 parents 27f6e3a + 3f83670 commit 90c5243
Showing 1 changed file with 11 additions and 1 deletion.
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

0 comments on commit 90c5243

Please sign in to comment.