Skip to content

Commit

Permalink
test for datastruct.gv and minor cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
hbmartin committed Jul 2, 2024
1 parent 565e065 commit 2dd60d5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Convert graphviz (dot) files into draw.io (mxGraph) format.
- [ ] Migrate from Make to GHA for release
- [ ] Fix "cb" bug
- [x] Add support for clusters
- [x] Add support for edge labels
- [ ] Address or triage all open issues
- [ ] Merge or close all outstanding PRs
- [x] Upgrade to latest pygraphviz
Expand Down
6 changes: 1 addition & 5 deletions graphviz2drawio/mx/MxGraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,7 @@ def get_edge_style(self, edge, source_node, target_node):
end_arrow = MxConst.DIAMOND

start_curve, end_curve = edge.curve_start_end()

if edge.curve.cb is not None:
curved = 1
else:
curved = 0
curved = 1 if edge.curve.cb is not None else 0

style = Styles.EDGE.format(
entry_x=target_node.rect.x_ratio(end_curve.real),
Expand Down
10 changes: 6 additions & 4 deletions graphviz2drawio/mx/NodeFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,13 @@ def from_svg(self, g) -> Node:
if "stroke" in polygon.attrib:
stroke = polygon.attrib["stroke"]

fill = None
if SVG.has(g, "ellipse"):
fill = g.attrib.get("fill", None)
try:
ellipse = SVG.get_first(g, "ellipse")
if "fill" in ellipse.attrib:
fill = ellipse.attrib["fill"]
if ellipse_fill := ellipse.attrib.get("fill"):
fill = ellipse_fill
except IndexError:
pass

return Node(
sid=g.attrib["id"],
Expand Down
12 changes: 12 additions & 0 deletions test/test_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def test_convnet():

assert elements[-1].attrib["value"] == "$$l_t$$"


def test_multilabel():
file = "test/directed/multilabel.gv.txt"
xml = graphviz2drawio.convert(file)
Expand All @@ -131,6 +132,17 @@ def test_multilabel():
assert elements[-1].attrib["value"] == "c<div>b</div><div>a</div>"


def test_datastruct():
file = "test/directed/datastruct.gv.txt"
xml = graphviz2drawio.convert(file)
print(xml)

root = ET.fromstring(xml)
elements = check_xml_top(root)

assert elements[-1].attrib["source"] == "node12"
assert elements[-1].attrib["target"] == "node2"

# def test_runAll():
# for f in os.listdir('undirected'):
# xml = graphviz2drawio.convert(f)
Expand Down

0 comments on commit 2dd60d5

Please sign in to comment.