|
|
@@ -66,15 +66,23 @@ def generate_diagram(page: Page) -> ET.Element:
|
|
|
# Create the actual <mxCell>
|
|
|
c = ET.SubElement(par, "mxCell", attrs, **cell.attributes)
|
|
|
|
|
|
+ def write_point(parent_xml, point: Point, as_str: Optional[str] = None):
|
|
|
+ attrs = {"x": str(point.x), "y": str(point.y)}
|
|
|
+ if as_str != None:
|
|
|
+ attrs['as'] = as_str
|
|
|
+ return ET.SubElement(parent_xml, "mxPoint", attrs)
|
|
|
+
|
|
|
# Geometry
|
|
|
if isinstance(cell, Vertex):
|
|
|
- ET.SubElement(c, "mxGeometry", {
|
|
|
+ g = ET.SubElement(c, "mxGeometry", {
|
|
|
"x": str(cell.geometry.x),
|
|
|
"y": str(cell.geometry.y),
|
|
|
"width": str(cell.geometry.width),
|
|
|
"height": str(cell.geometry.height),
|
|
|
"as": "geometry"
|
|
|
})
|
|
|
+ if cell.geometry.offset != None:
|
|
|
+ write_point(g, cell.geometry.offset, "offset")
|
|
|
elif isinstance(cell, Edge):
|
|
|
g = ET.SubElement(c, "mxGeometry", {
|
|
|
"relative": "1",
|
|
|
@@ -83,13 +91,11 @@ def generate_diagram(page: Page) -> ET.Element:
|
|
|
if len(cell.geometry.points) > 0:
|
|
|
a = ET.SubElement(g, "Array", {"as": "points"})
|
|
|
for p in cell.geometry.points:
|
|
|
- ET.SubElement(a, "mxPoint", {"x": str(p.x), "y": str(p.y)})
|
|
|
+ write_point(a, p)
|
|
|
if cell.geometry.source_point is not None:
|
|
|
- sp = cell.geometry.source_point
|
|
|
- ET.SubElement(g, "mxPoint", {"x": str(sp.x), "y": str(sp.y), "as": "sourcePoint"})
|
|
|
+ write_point(g, cell.geometry.source_point, "sourcePoint")
|
|
|
if cell.geometry.target_point is not None:
|
|
|
- tp = cell.geometry.target_point
|
|
|
- ET.SubElement(g, "mxPoint", {"x": str(tp.x), "y": str(tp.y), "as": "targetPoint"})
|
|
|
+ write_point(g, cell.geometry.target_point, "targetPoint")
|
|
|
|
|
|
for child in cell.children:
|
|
|
write_cell(child)
|