From 11f4d0cfd36b870bf24da8e5609fb2c546327aa4 Mon Sep 17 00:00:00 2001 From: Gertjan van Zwieten Date: Fri, 16 Feb 2024 15:08:19 +0100 Subject: [PATCH] scale graphviz svg down to 2/3 of original size This patch modifies the width and height parameters of the graphviz generated svg image in order. This avoids having to scale the image via the browser which may affect other tabs as well. Sadly it does not seem possible to instruct the dot executable to generate an image at the desired scale directly. --- nutils/_graph.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nutils/_graph.py b/nutils/_graph.py index f11964fc7..18db64308 100644 --- a/nutils/_graph.py +++ b/nutils/_graph.py @@ -71,6 +71,8 @@ def export_graphviz(self, *, fill_color: Optional[GraphvizColorCallback] = None, treelog.warning('graphviz failed for error code', status.returncode) graph = status.stdout if image_type == 'svg': + graph = re.sub(b'(width|height)="(\d+)pt"', lambda match: + b'%s="%dpt"' % (match.group(1), (int(match.group(2))*2)//3), graph, count=2) i = graph.rindex(b'') graph = graph[:i] + clickHandler + graph[i:] img.write(graph)