Skip to content

Commit

Permalink
indented XML formatting, fix port test
Browse files Browse the repository at this point in the history
  • Loading branch information
hbmartin committed Jul 2, 2024
1 parent 125a94e commit c1746f9
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 39 deletions.
20 changes: 0 additions & 20 deletions Pipfile

This file was deleted.

5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[![twitter](https://img.shields.io/badge/@hmartin-00aced.svg?logo=twitter&logoColor=black)](https://twitter.com/hmartin)


Convert graphviz (dot) files into draw.io (mxGraph) format
Convert graphviz (dot) files into draw.io (mxGraph) format.

## Roadmap for 0.3 release (as of July 2, 2024)

Expand Down Expand Up @@ -102,6 +102,9 @@ python -m graphviz2drawio test/directed/hello.gv.txt
## Roadmap to 1.0 release
- [ ] Complete test suite for official graphviz examples
- [ ] Migrate to uv/hatch for packaging and dep mgmt
- [ ] Bezier curve support
- [ ] Port layout
- [ ] Implementation for other outstanding TODOs

## License

Expand Down
5 changes: 1 addition & 4 deletions graphviz2drawio/graphviz2drawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ def convert(graph_to_convert, layout_prog="dot"):
[n.enrich_from_graph(graph_nodes[n.gid]) for n in nodes.values()]

# Put clusters first, so that nodes are drawn in front
nodes_and_clusters = clusters
nodes_and_clusters.update(nodes)

mx_graph = MxGraph(nodes_and_clusters, edges)
mx_graph = MxGraph(nodes | clusters, edges)
return mx_graph.value()


Expand Down
8 changes: 4 additions & 4 deletions graphviz2drawio/models/SvgParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@

def parse_nodes_edges_clusters(
svg_data: bytes,
) -> tuple[dict[str, Node], list[Edge], dict[str, Node]]:
) -> tuple[OrderedDict[str, Node], list[Edge], OrderedDict[str, Node]]:
root = ElementTree.fromstring(svg_data)[0]

coords: CoordsTranslate = CoordsTranslate.from_svg_transform(root.attrib["transform"])
coords = CoordsTranslate.from_svg_transform(root.attrib["transform"])
node_factory = NodeFactory(coords)
edge_factory = EdgeFactory(coords)

nodes: dict[str, Node] = OrderedDict()
nodes: OrderedDict[str, Node] = OrderedDict()
edges: list[Edge] = []
clusters: dict[str, Node] = OrderedDict()
clusters: OrderedDict[str, Node] = OrderedDict()

for g in root:
if SVG.is_tag(g, "g"):
Expand Down
2 changes: 0 additions & 2 deletions graphviz2drawio/mx/MxConst.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
DECLARATION = '<?xml version="1.0"?>'

BLOCK = "block"
DIAMOND = "diamond"

Expand Down
5 changes: 3 additions & 2 deletions graphviz2drawio/mx/MxGraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,6 @@ def add_mx_geo_with_points(element, curve):
def x_y_strs(point):
return str(int(point.real)), str(int(point.imag))

def value(self):
return MxConst.DECLARATION + ET.tostring(self.graph, encoding="unicode")
def value(self) -> str:
ET.indent(self.graph)
return ET.tostring(self.graph, encoding="unicode", xml_declaration=True)
12 changes: 6 additions & 6 deletions test/test_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ def check_value(e, check):
assert match, "no match found for %s" % value


def check_edge(e, source, target):
assert e.attrib.get("edge")
assert e.attrib["source"] == source.attrib["id"]
assert e.attrib["target"] == target.attrib["id"]
def check_edge(edge, source, target):
assert edge.attrib.get("edge")
assert edge.attrib["source"] == source.attrib["id"]
assert edge.attrib["target"] == target.attrib["id"]


def check_edge_dir(e, dx, dy):
Expand Down Expand Up @@ -63,11 +63,11 @@ def test_hello():


def test_port():
file = "./directed/port.gv.txt"
file = "test/directed/port.gv.txt"
xml = graphviz2drawio.convert(file)
root = ET.fromstring(xml)
elements = check_xml_top(root)
check_edge(elements[2], elements[4], elements[5])
check_edge(elements[6], elements[2], elements[3])


def test_polylines():
Expand Down

0 comments on commit c1746f9

Please sign in to comment.