diff --git a/README.md b/README.md index 1a52af4..e6b8d9d 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,7 @@ python -m graphviz2drawio test/directed/hello.gv.txt - [ ] Implementation for outstanding TODOs in code - [ ] Image / tooltip support #49 - [ ] Text on edge alignment #59 +- [ ] Support for node with `path` shape #47 ## Roadmap to 1.0 - [ ] Complete test suite for official graphviz examples diff --git a/doc/source/conf.py b/doc/source/conf.py index 034d60d..a5cc71f 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Configuration file for the Sphinx documentation builder. # @@ -142,7 +141,7 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, "graphviz2drawio", "Graphviz2drawio Documentation", [author], 1) + (master_doc, "graphviz2drawio", "Graphviz2drawio Documentation", [author], 1), ] diff --git a/graphviz2drawio/__main__.py b/graphviz2drawio/__main__.py index 4001c5b..3b6d3bc 100644 --- a/graphviz2drawio/__main__.py +++ b/graphviz2drawio/__main__.py @@ -1,4 +1,5 @@ from sys import stderr + from .graphviz2drawio import convert from .models import Arguments from .version import __version__ @@ -17,7 +18,7 @@ def main(): except BaseException: stderr.write("Something went wrong, please report\n") stderr.write( - "An automatic crash report can be sent to the developer (no personal or graph information)\n" + "An automatic crash report can be sent to the developer (no personal or graph information)\n", ) permission = input("Type 'no' to cancel report, press enter to send: ") if permission != "no": diff --git a/graphviz2drawio/graphviz2drawio.py b/graphviz2drawio/graphviz2drawio.py index eee2b54..b3d0061 100755 --- a/graphviz2drawio/graphviz2drawio.py +++ b/graphviz2drawio/graphviz2drawio.py @@ -14,7 +14,7 @@ def convert(graph_to_convert, layout_prog="dot"): graph = AGraph(graph_to_convert) except BaseException as e: raise ValueError( - "graph_to_convert must be one of a string, file, or AGraph object" + "graph_to_convert must be one of a string, file, or AGraph object", ) from e graph_edges = { diff --git a/graphviz2drawio/models/Arguments.py b/graphviz2drawio/models/Arguments.py index 3501d0d..8c8347c 100644 --- a/graphviz2drawio/models/Arguments.py +++ b/graphviz2drawio/models/Arguments.py @@ -11,7 +11,7 @@ def __init__(self, version): self.add_argument( "--version", action="version", - version="%(prog)s {version}".format(version=version), + version=f"%(prog)s {version}", ) self.add_argument( "-p", diff --git a/graphviz2drawio/models/SvgParser.py b/graphviz2drawio/models/SvgParser.py index 9def2e5..2b03b9e 100644 --- a/graphviz2drawio/models/SvgParser.py +++ b/graphviz2drawio/models/SvgParser.py @@ -1,11 +1,13 @@ from collections import OrderedDict from xml.etree import ElementTree + from graphviz2drawio.mx.EdgeFactory import EdgeFactory from graphviz2drawio.mx.NodeFactory import NodeFactory -from . import SVG -from .CoordsTranslate import CoordsTranslate + from ..mx.Edge import Edge from ..mx.Node import Node +from . import SVG +from .CoordsTranslate import CoordsTranslate def parse_nodes_edges_clusters( diff --git a/graphviz2drawio/mx/Curve.py b/graphviz2drawio/mx/Curve.py index e70728d..d8b3352 100644 --- a/graphviz2drawio/mx/Curve.py +++ b/graphviz2drawio/mx/Curve.py @@ -18,8 +18,7 @@ def __str__(self): @staticmethod def is_linear(points, threshold=linear_min_r2): - """ - Returns a boolean indicating whether a list of complex points is linear. + """Returns a boolean indicating whether a list of complex points is linear. Takes a list of complex points and optional minimum R**2 threshold for linear regression. """ @@ -27,8 +26,7 @@ def is_linear(points, threshold=linear_min_r2): return r2 > threshold def cubic_bezier_coordinates(self, t): - """ - Returns a complex number representing the point along the cubic bezier curve. + """Returns a complex number representing the point along the cubic bezier curve. Takes parametric parameter t where 0 <= t <= 1 """ @@ -41,8 +39,7 @@ def _cb(self, prop): @staticmethod def _cubic_bezier(p, t): - """ - Returns a float representing the point along the cubic bezier curve in the given dimension. + """Returns a float representing the point along the cubic bezier curve in the given dimension. Takes ordered list of 4 control points [P0, P1, P2, P3] and parametric parameter t where 0 <= t <= 1 diff --git a/graphviz2drawio/mx/CurveFactory.py b/graphviz2drawio/mx/CurveFactory.py index 2afbcdf..0b2c49b 100644 --- a/graphviz2drawio/mx/CurveFactory.py +++ b/graphviz2drawio/mx/CurveFactory.py @@ -1,5 +1,5 @@ -from svg.path import CubicBezier, Move -from svg.path import parse_path +from svg.path import CubicBezier, Move, parse_path + from .Curve import Curve @@ -23,13 +23,14 @@ def from_svg(self, svg_path) -> Curve: cb = [self.coords.complex_translate(p) for p in points] if len(path) > 1: # set of curves/points - for r in range(0, len(path)): + for r in range(len(path)): cbset.append( ( self.coords.translate( - path[r].start.real, path[r].start.imag + path[r].start.real, + path[r].start.imag, ), self.coords.translate(path[r].end.real, path[r].end.imag), - ) + ), ) return Curve(start=start, end=end, cb=cb, cbset=cbset) diff --git a/graphviz2drawio/mx/Edge.py b/graphviz2drawio/mx/Edge.py index 27a7877..addeb85 100644 --- a/graphviz2drawio/mx/Edge.py +++ b/graphviz2drawio/mx/Edge.py @@ -1,4 +1,5 @@ from graphviz2drawio.models import DotAttr + from .Curve import Curve from .GraphObj import GraphObj diff --git a/graphviz2drawio/mx/EdgeFactory.py b/graphviz2drawio/mx/EdgeFactory.py index 94412c7..00ee260 100644 --- a/graphviz2drawio/mx/EdgeFactory.py +++ b/graphviz2drawio/mx/EdgeFactory.py @@ -1,4 +1,5 @@ from graphviz2drawio.models import SVG + from .CurveFactory import CurveFactory from .Edge import Edge diff --git a/graphviz2drawio/mx/MxGraph.py b/graphviz2drawio/mx/MxGraph.py index c30f850..392ae02 100644 --- a/graphviz2drawio/mx/MxGraph.py +++ b/graphviz2drawio/mx/MxGraph.py @@ -1,9 +1,9 @@ +import uuid from xml.etree import ElementTree as ET from graphviz2drawio.models import DotAttr from graphviz2drawio.mx import MxConst from graphviz2drawio.mx.Styles import Styles -import uuid class MxGraph: @@ -133,7 +133,10 @@ def add_mx_geo_with_points(element, curve): ET.SubElement(array, MxConst.POINT, x=str(cb[0][0]), y=str(cb[0][1])) if cb: ET.SubElement( - array, MxConst.POINT, x=str(cb[1][0]), y=str(cb[1][1]) + array, + MxConst.POINT, + x=str(cb[1][0]), + y=str(cb[1][1]), ) # TODO: needs to account for multiple bezier in path diff --git a/graphviz2drawio/mx/NodeFactory.py b/graphviz2drawio/mx/NodeFactory.py index 2c9eb0b..089bab5 100644 --- a/graphviz2drawio/mx/NodeFactory.py +++ b/graphviz2drawio/mx/NodeFactory.py @@ -1,8 +1,9 @@ from graphviz2drawio.models import SVG from graphviz2drawio.models.Rect import Rect + +from . import Shape from .Node import Node from .Text import Text -from . import Shape class NodeFactory: @@ -55,7 +56,7 @@ def from_svg(self, g) -> Node: if SVG.has(g, "polygon"): rect = self.rect_from_svg_points( - SVG.get_first(g, "polygon").attrib["points"] + SVG.get_first(g, "polygon").attrib["points"], ) shape = Shape.RECT else: diff --git a/graphviz2drawio/mx/Styles.py b/graphviz2drawio/mx/Styles.py index 1b3d95f..3d96f7c 100644 --- a/graphviz2drawio/mx/Styles.py +++ b/graphviz2drawio/mx/Styles.py @@ -1,4 +1,5 @@ from enum import Enum + from . import Shape diff --git a/graphviz2drawio/mx/Text.py b/graphviz2drawio/mx/Text.py index 07d1a44..8bfb893 100644 --- a/graphviz2drawio/mx/Text.py +++ b/graphviz2drawio/mx/Text.py @@ -1,5 +1,6 @@ from graphviz2drawio.models import DotAttr from graphviz2drawio.mx import MxConst + from .Styles import Styles diff --git a/test/test_graphs.py b/test/test_graphs.py index 2c80eef..483b846 100644 --- a/test/test_graphs.py +++ b/test/test_graphs.py @@ -1,7 +1,8 @@ -from graphviz2drawio import graphviz2drawio -import xml.etree.ElementTree as ET -import re import html +import re +import xml.etree.ElementTree as ET + +from graphviz2drawio import graphviz2drawio num_cells_offset = 2 @@ -145,16 +146,6 @@ def test_datastruct(): assert elements[-1].attrib["target"] == "node2" -# TODO: https://github.com/hbmartin/graphviz2drawio/issues/33 -# def test_subgraph(): -# file = "test/directed/subgraph.gv.txt" -# xml = graphviz2drawio.convert(file) -# print(xml) -# -# root = ET.fromstring(xml) -# elements = check_xml_top(root) - - def test_compound(): file = "test/directed/compound.gv.txt" xml = graphviz2drawio.convert(file) @@ -162,7 +153,18 @@ def test_compound(): root = ET.fromstring(xml) elements = check_xml_top(root) - assert elements[-1].attrib["target"] == "node7" + assert elements[2].attrib["id"] == "clust1" + assert elements[3].attrib["id"] == "clust2" + + +# TODO: https://github.com/hbmartin/graphviz2drawio/issues/33 +# def test_subgraph(): +# file = "test/directed/subgraph.gv.txt" +# xml = graphviz2drawio.convert(file) +# print(xml) +# +# root = ET.fromstring(xml) +# elements = check_xml_top(root # def test_runAll():