Skip to content

Commit

Permalink
feat: added table fill for drawio; tableID is optional for backward c…
Browse files Browse the repository at this point in the history
…ompatibility
  • Loading branch information
tsypuk committed Jun 15, 2023
1 parent f5d7d86 commit 3bd6351
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
15 changes: 11 additions & 4 deletions multicloud_diagrams/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,22 @@ def stringify_dict(metadata: dict) -> str:
else:
return ''

def add_list(self, table_id: str, table_name='', rows=[], width="300"):
# green fillColor=#d5e8d4
# red fillColor=#f8cecc;"
def add_list(self, table_id='', table_name='', fillColor='', rows=[], width="300"):
if not table_id:
table_id = table_name

style="swimlane;fontStyle=0;childLayout=stackLayout;horizontal=1;startSize=30;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=1;marginBottom=0;whiteSpace=wrap;html=1;"

if fillColor:
style += f"fillColor={fillColor}"

mx_cell = et.SubElement(self.root,
'mxCell',
id=f'vertex:{table_id}:list',
value=f'<b>{table_name}</b>',
style=("swimlane;fontStyle=0;childLayout=stackLayout;horizontal=1;"
"startSize=30;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;"
"collapsible=1;marginBottom=0;whiteSpace=wrap;html=1;"),
style=(style),
parent="1",
vertex="1")

Expand Down
10 changes: 5 additions & 5 deletions samples/samples/aws_dynamo_boto3_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def prepare_data_model(mcd):
rows_keys = []
for attribute in dynamo_table['KeySchema']:
rows_keys.append(attribute['AttributeName'] + ' : ' + attribute['KeyType'])
mcd.add_list(f'Schema:{table_name}', rows=rows_keys)
mcd.add_list(table_name=f'Schema:{table_name}', rows=rows_keys)
mcd.add_link(f'dynamo:{table_arn}', f'Schema:{table_name}:list', action=['Key Schema'])

# Attributes
Expand All @@ -164,7 +164,7 @@ def prepare_data_model(mcd):
attributes = []
for attribute in dynamo_table['LocalSecondaryIndexes']:
attributes.append('IndexName: ' + attribute['IndexName'])
mcd.add_list(f'LSIs:{table_name}', rows=attributes)
mcd.add_list(table_name=f'LSIs:{table_name}', rows=attributes)
mcd.add_link(f'dynamo:{table_arn}', f'LSIs:{table_name}:list', action=['index: LSI'])

for attribute in dynamo_table['LocalSecondaryIndexes']:
Expand All @@ -181,15 +181,15 @@ def prepare_data_model(mcd):
rows_schema = rows_schema.rstrip(rows_schema[-1]) + '}'
attributes.append('Schema: ' + rows_schema)

mcd.add_list(f'LSI:{table_name}-{index_name}', rows=attributes)
mcd.add_list(table_name=f'LSI:{table_name}-{index_name}', rows=attributes)
mcd.add_link(f'LSIs:{table_name}:list', f'LSI:{table_name}-{index_name}:list', action=[f'LSI : {index_name}'])

# Global Secondary Indexes
if 'GlobalSecondaryIndexes' in dynamo_table:
rows = []
for attribute in dynamo_table['GlobalSecondaryIndexes']:
rows.append('IndexName: ' + attribute['IndexName'])
mcd.add_list(f'GSIs:{table_name}', rows=rows)
mcd.add_list(table_name=f'GSIs:{table_name}', rows=rows)
mcd.add_link(f'dynamo:{table_arn}', f'GSIs:{table_name}:list', action=['index: GSI'])

for attribute in dynamo_table['GlobalSecondaryIndexes']:
Expand All @@ -209,7 +209,7 @@ def prepare_data_model(mcd):
rows_schema = rows_schema.rstrip(rows_schema[-1]) + '}'
rows.append('Schema: ' + rows_schema)

mcd.add_list(f'GSI:{table_name}-{index_name}', rows=rows)
mcd.add_list(table_name=f'GSI:{table_name}-{index_name}', rows=rows)
mcd.add_link(f'GSIs:{table_name}:list', f'GSI:{table_name}-{index_name}:list', action=[f'GSI : {index_name}'])


Expand Down

0 comments on commit 3bd6351

Please sign in to comment.