From 1c3f120e2b282adb09254e9ab02bee9576e68e69 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 5 Jan 2023 04:34:44 +0000 Subject: [PATCH 1/2] Propagate the shape from the SVG by default --- graphviz2drawio/mx/Node.py | 4 ++-- graphviz2drawio/mx/NodeFactory.py | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/graphviz2drawio/mx/Node.py b/graphviz2drawio/mx/Node.py index 9a9b6e6..f3bc5a7 100644 --- a/graphviz2drawio/mx/Node.py +++ b/graphviz2drawio/mx/Node.py @@ -2,14 +2,14 @@ class Node(GraphObj): - def __init__(self, sid, gid, rect, texts, fill, stroke): + def __init__(self, sid, gid, rect, texts, fill, stroke, shape): super(Node, self).__init__(sid, gid) self.rect = rect self.texts = texts self.fill = fill self.stroke = stroke self.label = None - self.shape = None + self.shape = shape def text_to_mx_value(self): value = "" diff --git a/graphviz2drawio/mx/NodeFactory.py b/graphviz2drawio/mx/NodeFactory.py index b07edd1..7e81775 100644 --- a/graphviz2drawio/mx/NodeFactory.py +++ b/graphviz2drawio/mx/NodeFactory.py @@ -2,6 +2,7 @@ from graphviz2drawio.models.Rect import Rect from .Node import Node from .Text import Text +from . import Shape class NodeFactory: @@ -56,8 +57,10 @@ def from_svg(self, g): rect = self.rect_from_svg_points( SVG.get_first(g, "polygon").attrib["points"] ) + shape = Shape.RECT else: rect = self.rect_from_ellipse_svg(SVG.get_first(g, "ellipse").attrib) + shape = Shape.ELLIPSE stroke = None if SVG.has(g, "polygon"): @@ -72,4 +75,5 @@ def from_svg(self, g): texts=texts, fill=g.attrib.get("fill", None), stroke=stroke, + shape=shape ) From 630fd7c257e70b758190e118ad6f9643ac839331 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 5 Jan 2023 05:22:26 +0000 Subject: [PATCH 2/2] add test for correct shape --- test/directed/hello_rect.gv.txt | 4 ++++ test/test_graphs.py | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 test/directed/hello_rect.gv.txt diff --git a/test/directed/hello_rect.gv.txt b/test/directed/hello_rect.gv.txt new file mode 100644 index 0000000..30497e9 --- /dev/null +++ b/test/directed/hello_rect.gv.txt @@ -0,0 +1,4 @@ +digraph G { + node [shape=rect] + Hello->World +} diff --git a/test/test_graphs.py b/test/test_graphs.py index a9ae74e..abeeb8b 100644 --- a/test/test_graphs.py +++ b/test/test_graphs.py @@ -61,6 +61,22 @@ def test_hello(): check_edge(edge, hello, world) check_edge_dir(edge, dx=0, dy=1) +def test_hello_rect(): + file = "./directed/hello_rect.gv.txt" + xml = graphviz2drawio.convert(file) + print(xml) + + root = ET.fromstring(xml) + elements = check_xml_top(root) + + hello = elements[3] + check_value(hello, "Hello") + assert "ellipse" not in hello.attrib["style"] + + world = elements[4] + check_value(world, "World") + assert "ellipse" not in world.attrib["style"] + def test_polylines(): file = "./undirected/polylines.gv.txt"