|
@@ -66,27 +66,36 @@ def generate_diagram(page: Page) -> ET.Element:
|
|
|
# Create the actual <mxCell>
|
|
# Create the actual <mxCell>
|
|
|
c = ET.SubElement(par, "mxCell", attrs, **cell.attributes)
|
|
c = ET.SubElement(par, "mxCell", attrs, **cell.attributes)
|
|
|
|
|
|
|
|
|
|
+ def optional_attributes(dict):
|
|
|
|
|
+ attrs = {}
|
|
|
|
|
+ for key, val in dict.items():
|
|
|
|
|
+ if val != None:
|
|
|
|
|
+ attrs[key] = str(val)
|
|
|
|
|
+ return attrs
|
|
|
|
|
+
|
|
|
def write_point(parent_xml, point: Point, as_str: Optional[str] = None):
|
|
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
|
|
|
|
|
|
|
+ attrs = optional_attributes({
|
|
|
|
|
+ "x": point.x,
|
|
|
|
|
+ "y": point.y,
|
|
|
|
|
+ "as": as_str,
|
|
|
|
|
+ })
|
|
|
return ET.SubElement(parent_xml, "mxPoint", attrs)
|
|
return ET.SubElement(parent_xml, "mxPoint", attrs)
|
|
|
|
|
|
|
|
# Geometry
|
|
# Geometry
|
|
|
if isinstance(cell, Vertex):
|
|
if isinstance(cell, Vertex):
|
|
|
- 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"
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ g = ET.SubElement(c, "mxGeometry", optional_attributes({
|
|
|
|
|
+ "x": cell.geometry.x,
|
|
|
|
|
+ "y": cell.geometry.y,
|
|
|
|
|
+ "width": cell.geometry.width,
|
|
|
|
|
+ "height": cell.geometry.height,
|
|
|
|
|
+ "as": "geometry",
|
|
|
|
|
+ }))
|
|
|
if cell.geometry.offset != None:
|
|
if cell.geometry.offset != None:
|
|
|
write_point(g, cell.geometry.offset, "offset")
|
|
write_point(g, cell.geometry.offset, "offset")
|
|
|
elif isinstance(cell, Edge):
|
|
elif isinstance(cell, Edge):
|
|
|
g = ET.SubElement(c, "mxGeometry", {
|
|
g = ET.SubElement(c, "mxGeometry", {
|
|
|
"relative": "1",
|
|
"relative": "1",
|
|
|
- "as": "geometry"
|
|
|
|
|
|
|
+ "as": "geometry",
|
|
|
})
|
|
})
|
|
|
if len(cell.geometry.points) > 0:
|
|
if len(cell.geometry.points) > 0:
|
|
|
a = ET.SubElement(g, "Array", {"as": "points"})
|
|
a = ET.SubElement(g, "Array", {"as": "points"})
|