Skip to content

Commit

Permalink
feat: add rendering of additional notes; append additional note to ex…
Browse files Browse the repository at this point in the history
…isting edge label
  • Loading branch information
tsypuk committed Jan 13, 2024
1 parent 5fdb194 commit 79faefb
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 123 deletions.
17 changes: 16 additions & 1 deletion docs/docs/core-components/custom_edge.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,19 @@ that has ``style`` parameter to customize any style.
## Rendering:
{: .no_toc }

![layers](output/jpg/connection_edgeStyle.jpg)
![layers](output/jpg/connection_edgeStyle.jpg)


# Add additional note to existing Label of existing Edge

### Code Snippet:
{: .no_toc }

```python
{% root_include_snippet ../tests/test_adding_note.py note%}
```

## Rendering:
{: .no_toc }

![layers](output/jpg/note.jpg)
24 changes: 24 additions & 0 deletions docs/docs/core-components/output/drawio/note.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<mxfile host="multicloud-diagrams" agent="PIP package multicloud-diagrams. Generate resources in draw.io compatible format for Cloud infrastructure. Copyrights @ Roman Tsypuk 2023. MIT license." type="MultiCloud">
<diagram id="diagram_1" name="AWS components">
<mxGraphModel dx="1015" dy="661" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="1">
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="vertex:lambda_function:arn:aws:lambda:eu-west-1:123456789012:function:consumer_lambda" value="&lt;b&gt;Name&lt;/b&gt;: consumer_lambda&lt;BR&gt;&lt;b&gt;ARN&lt;/b&gt;: arn:aws:lambda:eu-west-1:123456789012:function:consumer_lambda&lt;BR&gt;-----------&lt;BR&gt;&lt;b&gt;CodeSize&lt;/b&gt;: 1234&lt;BR&gt;&lt;b&gt;Memory&lt;/b&gt;: 128" style="verticalLabelPosition=bottom;verticalAlign=top;aspect=fixed;align=left;pointerEvents=1;shape=mxgraph.aws3.lambda_function;prIcon=server;fillColor=#F58534;gradientColor=none;html=1;" parent="1" vertex="1">
<mxGeometry width="69" height="72" as="geometry" x="254.5" y="-470"/>
</mxCell>
<mxCell id="vertex:sqs:arn:aws:sqs:eu-west-1:123456789012:int-eu-live-events.fifo" value="&lt;b&gt;Name&lt;/b&gt;: int-eu-live-events.fifo&lt;BR&gt;&lt;b&gt;ARN&lt;/b&gt;: arn:aws:sqs:eu-west-1:123456789012:int-eu-live-events.fifo&lt;BR&gt;-----------&lt;BR&gt;&lt;b&gt;FifoQueue&lt;/b&gt;: TRUE" style="sketch=0;outlineConnect=0;fontColor=#232F3E;gradientColor=#FF4F8B;gradientDirection=north;fillColor=#BC1356;strokeColor=#ffffff;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=left;html=1;fontSize=12;fontStyle=0;aspect=fixed;shape=mxgraph.aws4.resourceIcon;resIcon=mxgraph.aws4.sqs;" parent="1" vertex="1">
<mxGeometry width="78" height="78" as="geometry" x="250" y="-70"/>
</mxCell>
<mxCell id="edge:lambda_function:arn:aws:lambda:eu-west-1:123456789012:function:consumer_lambda:to:sqs:arn:aws:sqs:eu-west-1:123456789012:int-eu-live-events.fifo" style="jettySize=auto;html=1;startArrow=none;endArrow=none;" parent="1" source="vertex:lambda_function:arn:aws:lambda:eu-west-1:123456789012:function:consumer_lambda" target="vertex:sqs:arn:aws:sqs:eu-west-1:123456789012:int-eu-live-events.fifo" edge="2">
<mxGeometry as="geometry"/>
</mxCell>
<mxCell id="label:lambda_function:arn:aws:lambda:eu-west-1:123456789012:function:consumer_lambda:to:sqs:arn:aws:sqs:eu-west-1:123456789012:int-eu-live-events.fifo" value="Action1, Action2&lt;BR&gt;Additional Note added to existing EDGE&lt;BR&gt;Second Note added to existing EDGE&lt;BR&gt;Third Note added to existing EDGE" style="edgeLabel;html=1;align=left;verticalAlign=middle;resizable=0;points=[];labelBackgroundColor=none;" parent="edge:lambda_function:arn:aws:lambda:eu-west-1:123456789012:function:consumer_lambda:to:sqs:arn:aws:sqs:eu-west-1:123456789012:int-eu-live-events.fifo" vertex="1" connectable="0">
<mxGeometry relative="1" as="geometry">
<mxPoint as="offset"/>
</mxGeometry>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
Binary file added docs/docs/core-components/output/jpg/note.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 33 additions & 19 deletions multicloud_diagrams/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,18 +427,19 @@ def add_connection(self, src_node_id, dst_node_id, edge_style=None, labels=None,
customize(node_template=node_template, style=edge_style)

parent_id = str(self.get_layer_id(layer_name, layer_id))
mx_cell = Et.SubElement(self.root,
'mxCell',
id=edge_id,
style=node_template['style'],
parent=parent_id,
source=f'vertex:{src_node_id}',
target=f'vertex:{dst_node_id}',
edge="2")
mx_cell_edge = Et.SubElement(
self.root,
'mxCell',
id=edge_id,
style=node_template['style'],
parent=parent_id,
source=f'vertex:{src_node_id}',
target=f'vertex:{dst_node_id}',
edge="2")

if self.debug_mode:
mx_cell.insert(0, Et.Comment(f'edge:{src_node_id}:to:{dst_node_id}'))
mx_geometry = Et.SubElement(mx_cell, 'mxGeometry')
mx_cell_edge.insert(0, Et.Comment(f'edge:{src_node_id}:to:{dst_node_id}'))
mx_geometry = Et.SubElement(mx_cell_edge, 'mxGeometry')
mx_geometry.set('as', 'geometry')

# Add label to edge
Expand All @@ -464,7 +465,7 @@ def add_connection(self, src_node_id, dst_node_id, edge_style=None, labels=None,
mx_geometry.set('as', 'offset')

self.update_vertex_coords_from_prev_version(mx_geometry, f'label:{src_node_id}:to:{dst_node_id}')
return edge_id
return mx_cell_edge

# </mxGeometry>
# </mxCell>
Expand All @@ -481,7 +482,7 @@ def add_link(self, src_node_id, dst_node_id, action=None, layer_name=None, layer
'startArrow': 'none',
'endArrow': 'none'
}
self.add_connection(src_node_id=src_node_id, dst_node_id=dst_node_id, labels=action, edge_style=style, layer_name=layer_name, layer_id=layer_id)
return self.add_connection(src_node_id=src_node_id, dst_node_id=dst_node_id, labels=action, edge_style=style, layer_name=layer_name, layer_id=layer_id)

def add_link_uml(self, src_node_id, dst_node_id, action=None, layer_name=None, layer_id=None, edge_style=None, label_style=None):
return self.add_connection(src_node_id=src_node_id, dst_node_id=dst_node_id, labels=action, edge_style=edge_style, label_style=label_style, layer_name=layer_name, layer_id=layer_id,
Expand All @@ -492,21 +493,21 @@ def add_bidirectional_link(self, src_node_id, dst_node_id, action=None):
'startArrow': 'classic',
'endArrow': 'classic'
}
self.add_connection(src_node_id=src_node_id, dst_node_id=dst_node_id, edge_style=style, labels=action)
return self.add_connection(src_node_id=src_node_id, dst_node_id=dst_node_id, edge_style=style, labels=action)

def add_unidirectional_link(self, src_node_id, dst_node_id, action=None):
style = {
'startArrow': 'none',
'endArrow': 'classic'
}
self.add_connection(src_node_id=src_node_id, dst_node_id=dst_node_id, edge_style=style, labels=action)
return self.add_connection(src_node_id=src_node_id, dst_node_id=dst_node_id, edge_style=style, labels=action)

def add_unidirectional_reverse_link(self, src_node_id, dst_node_id, action=None):
style = {
'startArrow': 'classic',
'endArrow': 'none'
}
self.add_connection(src_node_id=src_node_id, dst_node_id=dst_node_id, edge_style=style, labels=action)
return self.add_connection(src_node_id=src_node_id, dst_node_id=dst_node_id, edge_style=style, labels=action)

def add_link_list(self, links):
for link in links:
Expand Down Expand Up @@ -639,8 +640,17 @@ def read_uml_from_file(self, file_name, edge_style=None, label_style=None):
self.add_layer(base_name)
self.extract_messages_from_uml(sequence_diagram, actors=actors, participants=participants, layer_name=base_name, edge_style=edge_style, label_style=label_style)

def add_note_to_existing_edge(self, current_note, prev_edge):
pass
def add_note_to_existing_edge(self, current_note, prev_edge, prefix=None):
if (prefix):
id = prev_edge.attrib['id'].replace(f'edge_{prefix}:', '')
for mxLabel in self.root:
if mxLabel.attrib['id'] == f'label_{prefix}:{id}':
mxLabel.attrib['value'] = mxLabel.attrib['value'] + '<BR>' + current_note
else:
id = prev_edge.attrib['id'].replace('edge:', '')
for mxLabel in self.root:
if mxLabel.attrib['id'] == f'label:{id}':
mxLabel.attrib['value'] = mxLabel.attrib['value'] + '<BR>' + current_note

def extract_messages_from_uml(self, sequence_diagram, actors, participants, layer_name, edge_style, label_style):
lines = sequence_diagram.split('\n')
Expand All @@ -663,6 +673,7 @@ def extract_messages_from_uml(self, sequence_diagram, actors, participants, laye
current_note = note_match.group(2).strip()
print(f'NOTE === {current_note} ===')
# add current_note to last edge (prev_edge)
self.add_note_to_existing_edge(current_note, prev_edge, layer_name)
current_note = ''
continue

Expand All @@ -676,13 +687,16 @@ def extract_messages_from_uml(self, sequence_diagram, actors, participants, laye
if end_note_match:
print(f'NOTE ==={current_note} ===')
# add current_note to last edge (prev_edge)
self.add_note_to_existing_edge(current_note, prev_edge)
self.add_note_to_existing_edge(current_note, prev_edge, layer_name)
current_note = ''
in_note_section = False
continue

if in_note_section:
current_note = current_note + '\n' + strip
if (len(current_note) > 0):
current_note = current_note + '<BR>' + strip
else:
current_note = strip
continue

entity = starts_with_any(strip, actors, participants)
Expand Down
10 changes: 9 additions & 1 deletion samples/output/output.prod.dynamo.drawio

Large diffs are not rendered by default.

0 comments on commit 79faefb

Please sign in to comment.