diff --git a/nutils/_graph.py b/nutils/_graph.py index 9a3b4fcb4..705e81da3 100644 --- a/nutils/_graph.py +++ b/nutils/_graph.py @@ -58,7 +58,7 @@ def generate_graphviz_source(self, *, fill_color: Optional[GraphvizColorCallback subgraph_children = _collect_subgraphs(self) id_gen = map(str, itertools.count()) self._collect_graphviz_nodes_edges({}, id_gen, nodes, edges, None, fill_color) - return ''.join(itertools.chain(['digraph {bgcolor="darkgray";'], _generate_graphviz_subgraphs(subgraph_children, nodes, None, id_gen), edges, ['}'])) + return ''.join(itertools.chain(['digraph {bgcolor="darkgray";'], _generate_graphviz_subgraphs(subgraph_children, nodes, None, id_gen, 0), edges, ['}'])) def export_graphviz(self, *, fill_color: Optional[GraphvizColorCallback] = None, dot_path: str = 'dot', image_type: str = 'svg') -> None: src = self.generate_graphviz_source(fill_color=fill_color) @@ -250,9 +250,9 @@ def _generate_asciitree_subgraphs(children: Mapping[Optional[Subgraph], Sequence yield from _generate_asciitree_subgraphs(children, id_gen_map, child, bridge+('├ ' if i else '└ '), bridge+('│ ' if i else ' ')) -def _generate_graphviz_subgraphs(children: Mapping[Optional[Subgraph], Sequence[Subgraph]], nodes: Mapping[Optional[Subgraph], Sequence[str]], subgraph: Optional[Subgraph], id_gen: Iterator[str]) -> Iterator[str]: +def _generate_graphviz_subgraphs(children: Mapping[Optional[Subgraph], Sequence[Subgraph]], nodes: Mapping[Optional[Subgraph], Sequence[str]], subgraph: Optional[Subgraph], id_gen: Iterator[str], depth: int) -> Iterator[str]: for child in children[subgraph]: - yield 'subgraph cluster{} {{bgcolor="lightgray";color="none";'.format(next(id_gen)) - yield from _generate_graphviz_subgraphs(children, nodes, child, id_gen) + yield 'subgraph cluster{} {{bgcolor="{}";color="none";'.format(next(id_gen), 'darkgray' if depth % 2 else 'lightgray') + yield from _generate_graphviz_subgraphs(children, nodes, child, id_gen, depth + 1) yield '}' yield from nodes.get(subgraph, ()) diff --git a/tests/test_graph.py b/tests/test_graph.py index 64b0aed7f..89131a511 100644 --- a/tests/test_graph.py +++ b/tests/test_graph.py @@ -288,7 +288,7 @@ def test_multiple_graphviz_source(self): 'bgcolor="lightgray";' 'color="none";' 'subgraph cluster8 {' - 'bgcolor="lightgray";' + 'bgcolor="darkgray";' 'color="none";' 'subgraph cluster9 {' 'bgcolor="lightgray";' @@ -299,7 +299,7 @@ def test_multiple_graphviz_source(self): '4 [shape=box,label="f"];' '}' 'subgraph cluster10 {' - 'bgcolor="lightgray";' + 'bgcolor="darkgray";' 'color="none";' '6 [shape=box,label="g"];' '}'