Skip to content

Commit

Permalink
Merge pull request #36 from antback/master
Browse files Browse the repository at this point in the history
Adds edge labels
  • Loading branch information
hbmartin authored Jul 2, 2024
2 parents c1746f9 + 368dd03 commit 052bba2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions graphviz2drawio/models/SVG.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ def get_first(g, tag):
def get_title(g):
return get_first(g, "title").text

def get_text(g):
return get_first(g, "text").text

def is_tag(g, tag):
return g.tag == "{http://www.w3.org/2000/svg}" + tag
Expand Down
3 changes: 2 additions & 1 deletion graphviz2drawio/mx/Edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@


class Edge(GraphObj):
def __init__(self, sid, gid, fr, to, curve):
def __init__(self, sid, gid, fr, to, curve, label):
super(Edge, self).__init__(sid, gid)
self.fr = fr
self.to = to
self.curve = curve
self.style = None
self.dir = None
self.arrowtail = None
self.label = label

def curve_start_end(self):
if self.dir == DotAttr.BACK:
Expand Down
3 changes: 2 additions & 1 deletion graphviz2drawio/mx/EdgeFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ def from_svg(self, g) -> Edge:
to = sp_to[0]
gid = gid_template.format(fr, to)
curve = None
label = SVG.get_text(g)
if SVG.has(g, "path"):
path = SVG.get_first(g, "path")
if "d" in path.attrib:
curve = self.curve_factory.from_svg(path.attrib["d"])
return Edge(sid=g.attrib["id"], gid=gid, fr=fr, to=to, curve=curve)
return Edge(sid=g.attrib["id"], gid=gid, fr=fr, to=to, curve=curve, label=label)
15 changes: 15 additions & 0 deletions graphviz2drawio/mx/MxGraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from graphviz2drawio.models import DotAttr
from graphviz2drawio.mx import MxConst
from graphviz2drawio.mx.Styles import Styles
import uuid


class MxGraph:
Expand Down Expand Up @@ -35,6 +36,20 @@ def add_edge(self, edge):
"target": target.sid,
},
)

if edge.label:
edge_label_element = ET.SubElement(
self.root,
MxConst.CELL,
id=uuid.uuid4().hex,
style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];",
parent=edge.sid,
value=edge.label,
vertex="1",
connectable="0",
)
self.add_mx_geo(edge_label_element)

if edge.curve.cb is None and len(edge.curve.cbset) == 0:
self.add_mx_geo(edge_element)
else:
Expand Down

0 comments on commit 052bba2

Please sign in to comment.