Skip to content

Commit

Permalink
feat: coordinates of label on edges are persisted; reload label posit…
Browse files Browse the repository at this point in the history
…ion from previous version of diagram
  • Loading branch information
tsypuk committed Jul 24, 2023
1 parent d697f7c commit a630f2c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions multicloud_diagrams/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ def add_connection(self, src_node_id, dest_node_id, start, end, labels=[]):
# <mxPoint as="offset"/>
mx_geometry = et.SubElement(mx_geometry, 'mxPoint')
mx_geometry.set('as', 'offset')
if f'label:{src_node_id}:to:{dest_node_id}' in self.prev_coords:
if 'x' in self.prev_coords[f'label:{src_node_id}:to:{dest_node_id}']:
mx_geometry.set('x', self.prev_coords[f'label:{src_node_id}:to:{dest_node_id}']['x'])
if 'y' in self.prev_coords[f'label:{src_node_id}:to:{dest_node_id}']:
mx_geometry.set('y', self.prev_coords[f'label:{src_node_id}:to:{dest_node_id}']['y'])

# </mxGeometry>
# </mxCell>
else:
Expand Down Expand Up @@ -338,6 +344,16 @@ def read_coords_from_file(self, file_name: str):
cords['width'] = data.get('width')
self.prev_coords[neighbor.get('id')] = cords

elif neighbor.get('id').startswith("label:"):
data = neighbor.find('mxGeometry')
mx_point = data.find('mxPoint')
cords = {}
if mx_point.get('x') is not None:
cords['x'] = mx_point.get('x')
if mx_point.get('y') is not None:
cords['y'] = mx_point.get('y')
self.prev_coords[neighbor.get('id')] = cords

def export_to_file(self, file_path):
with open(file_path, 'wb') as file:
tree = et.ElementTree(self.mxfile)
Expand Down

0 comments on commit a630f2c

Please sign in to comment.