Skip to content

Commit

Permalink
feat(cluster): support custom graph attributes for the Cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
mingrammer committed May 6, 2020
1 parent 2bd4aa5 commit 6741ed9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion diagrams/__init__.py
Expand Up @@ -193,11 +193,14 @@ class Cluster:
# FIXME:
# Cluster direction does not work now. Graphviz couldn't render
# correctly for a subgraph that has a different rank direction.
def __init__(self, label: str = "cluster", direction: str = "LR"):
def __init__(
self, label: str = "cluster", direction: str = "LR", graph_attr: dict = {},
):
"""Cluster represents a cluster context.
:param label: Cluster label.
:param direction: Data flow direction. Default is 'left to right'.
:param graph_attr: Provide graph_attr dot config attributes.
"""
self.label = label
self.name = "cluster_" + self.label
Expand All @@ -224,6 +227,9 @@ def __init__(self, label: str = "cluster", direction: str = "LR"):
coloridx = self.depth % len(self.__bgcolors)
self.dot.graph_attr["bgcolor"] = self.__bgcolors[coloridx]

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

def __enter__(self):
setcluster(self)
return self
Expand Down

0 comments on commit 6741ed9

Please sign in to comment.