From 6741ed9e2bcca297a1044ca5c8f2cf9eb3f8b5b3 Mon Sep 17 00:00:00 2001 From: mingrammer Date: Wed, 6 May 2020 21:59:07 +0900 Subject: [PATCH] feat(cluster): support custom graph attributes for the Cluster --- diagrams/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/diagrams/__init__.py b/diagrams/__init__.py index 966670f8..272e4c82 100644 --- a/diagrams/__init__.py +++ b/diagrams/__init__.py @@ -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