Skip to content

Commit

Permalink
remove old python compat
Browse files Browse the repository at this point in the history
  • Loading branch information
hbmartin committed Jul 3, 2024
1 parent 9c5304f commit 51e38e5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
18 changes: 2 additions & 16 deletions graphviz2drawio/graphviz2drawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ def convert(graph_to_convert, layout_prog="dot"):
graph = AGraph(graph_to_convert)

graph_edges = {
e[0] + "->" + e[1]: list37(e.attr.iteritems())
for e in list37(graph.edges_iter())
e[0] + "->" + e[1]: list(e.attr.iteritems()) for e in graph.edges_iter()
}
graph_nodes = {n: list37(n.attr.iteritems()) for n in list37(graph.nodes_iter())}
graph_nodes = {n: list(n.attr.iteritems()) for n in graph.nodes_iter()}

svg_graph = graph.draw(prog=layout_prog, format="svg")
nodes, edges, clusters = parse_nodes_edges_clusters(svg_graph)
Expand All @@ -26,16 +25,3 @@ def convert(graph_to_convert, layout_prog="dot"):
# Put clusters first, so that nodes are drawn in front
mx_graph = MxGraph(clusters | nodes, edges)
return mx_graph.value()


# Workaround for change in iterator behavior in Python 3.7
# https://www.python.org/dev/peps/pep-0479/
# TODO: remove this
def list37(iterator):
rv = []
try:
for i in iterator:
rv.append(i)
except RuntimeError:
pass
return rv
8 changes: 4 additions & 4 deletions graphviz2drawio/mx/Curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __init__(self, start, end, cb, cbset=None) -> None:
cbset = []
self.start = start
self.end = end
if cb is not None and len(cb) != 4:
if cb is not None and len(cb) != 4: # noqa: PLR2004
raise InvalidCbError
self.cb = cb
self.cbset = cbset
Expand Down Expand Up @@ -44,13 +44,13 @@ def _cb(self, prop):
return [getattr(x, prop) for x in self.cb]

@staticmethod
def _cubic_bezier(p: list[float], t: float) -> float:
"""Returns a float representing the point along the cubic Bézier.
def _cubic_bezier(p: list, t: float):
"""Calculate the point along the cubic Bézier.
`p` is an ordered list of 4 control points [P0, P1, P2, P3]
`t` is a parametric parameter where 0 <= t <= 1
implements explicit form of https://en.wikipedia.org/wiki/B%C3%A9zier_curve#Cubic_B%C3%A9zier_curves
implements https://en.wikipedia.org/wiki/B%C3%A9zier_curve#Cubic_B%C3%A9zier_curves
B(t) = (1-t)³P₀ + 3(1-t)²tP₁ + 3(1-t)t²P₂ + t³P₃ where 0 ≤ t ≤1
"""
return (
Expand Down

0 comments on commit 51e38e5

Please sign in to comment.