From d3c5a8990a6c1da5cf0aadb4ad967b18d22441c0 Mon Sep 17 00:00:00 2001 From: Laurier Loiselle Date: Tue, 13 Sep 2022 17:01:24 -0400 Subject: [PATCH] mx: NodeFactory: support creating blank rect from image Image nodes are nice to have in some schematics. Because of the representation in mxGraph, it would be a pain to create them in the xml. Instead, this follows the least-effort methodology and replace the image by an equally sized rectangle. In drawio GUI, the image can then be switched back in place of the rectangle. As a reference on the mxImageShape if someone wants to dive deeper: https://jgraph.github.io/mxgraph/java/docs/com/mxgraph/shape/mxImageShape.html --- graphviz2drawio/mx/NodeFactory.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/graphviz2drawio/mx/NodeFactory.py b/graphviz2drawio/mx/NodeFactory.py index b07edd1..606a197 100644 --- a/graphviz2drawio/mx/NodeFactory.py +++ b/graphviz2drawio/mx/NodeFactory.py @@ -29,6 +29,14 @@ def rect_from_svg_points(self, svg): height = test_height return Rect(x=min_x, y=min_y, width=width, height=height) + @staticmethod + def rect_from_image(attrib): + filtered = dict() + for k, v in attrib.items(): + if k in ['x', 'y', 'width', 'height'] + filtered = { k: float(v.strip('px')) } + return Rect(**filtered) + def rect_from_ellipse_svg(self, attrib): cx = float(attrib["cx"]) cy = float(attrib["cy"]) @@ -56,6 +64,8 @@ def from_svg(self, g): rect = self.rect_from_svg_points( SVG.get_first(g, "polygon").attrib["points"] ) + elif SVG.has(g, "image"): + rect = self.rect_from_image(SVG.get_first(g, "image").attrib) else: rect = self.rect_from_ellipse_svg(SVG.get_first(g, "ellipse").attrib)