feat(cluster): support custom graph attributes for the Cluster

pull/129/head
mingrammer 5 years ago
parent 2bd4aa50a5
commit 6741ed9e2b

@ -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
@ -224,6 +227,9 @@ class Cluster:
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

Loading…
Cancel
Save