Skip to content

Commit

Permalink
Merge pull request #57 from samkhal/fixes
Browse files Browse the repository at this point in the history
Fix shapes not being correctly propagated from SVG
  • Loading branch information
hbmartin authored Jul 2, 2024
2 parents c50ef77 + 630fd7c commit 565e065
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions graphviz2drawio/mx/Node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down
4 changes: 4 additions & 0 deletions graphviz2drawio/mx/NodeFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from graphviz2drawio.models.Rect import Rect
from .Node import Node
from .Text import Text
from . import Shape


class NodeFactory:
Expand Down Expand Up @@ -56,8 +57,10 @@ def from_svg(self, g) -> Node:
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"):
Expand All @@ -78,4 +81,5 @@ def from_svg(self, g) -> Node:
texts=texts,
fill=fill,
stroke=stroke,
shape=shape
)
4 changes: 4 additions & 0 deletions test/directed/hello_rect.gv.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
digraph G {
node [shape=rect]
Hello->World
}
16 changes: 16 additions & 0 deletions test/test_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_port():
file = "test/directed/port.gv.txt"
Expand Down

0 comments on commit 565e065

Please sign in to comment.