Skip to content

Commit

Permalink
feat: added shadow mode for rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
tsypuk committed Jul 29, 2023
1 parent e182863 commit 21cc025
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
10 changes: 8 additions & 2 deletions multicloud_diagrams/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,20 @@ class OnPrem(Enum):


class MultiCloudDiagrams:
def __init__(self, debug_mode=False, layer_name=''):
def __init__(self, debug_mode=False, shadow=True, layer_name=''):
self.mxfile = et.Element('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")

self.diagram = et.SubElement(self.mxfile, 'diagram', id="diagram_1", name="AWS components")
self.mx_graph_model = et.SubElement(self.diagram, '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="0")
pageScale="1", pageWidth="850", pageHeight="1100", math="0")
if shadow:
self.mx_graph_model.attrib['shadow'] = '1'
else:
self.mx_graph_model.attrib['shadow'] = '0'

self.root = et.SubElement(self.mx_graph_model, 'root')
self.layers = {}
self.mx_cell_id_0 = et.SubElement(self.root, 'mxCell', id="0")
Expand Down
31 changes: 31 additions & 0 deletions tests/test_mcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,34 @@ def test_comment(self):
'vertex': '1'
}
self.verify_aws_resource(expected, mcd.mxfile, resource_name, 'fallback_vertex', debug_mode=True)

def test_shadow_drawio(self):
# given
mcd = MultiCloudDiagrams(shadow=True)

# when
tree = et.ElementTree(mcd.mxfile)

# then
self.verify_mx_graph_models(tree.findall("./*/"))

def test_default_shadow_drawio(self):
# given
mcd = MultiCloudDiagrams()

# when
tree = et.ElementTree(mcd.mxfile)

# then
self.verify_mx_graph_models(tree.findall("./*/"))

def test_no_shadow_drawio(self):
# given
shadow_mode = False
mcd = MultiCloudDiagrams(shadow=shadow_mode)

# when
tree = et.ElementTree(mcd.mxfile)

# then
self.verify_mx_graph_models(tree.findall("./*/"), shadow_mode=shadow_mode)
8 changes: 6 additions & 2 deletions utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def verify_mxfile(self, roots):
self.assertEqual('PIP package multicloud-diagrams. Generate resources in draw.io compatible format for Cloud infrastructure. Copyrights @ Roman Tsypuk 2023. MIT license.',
root.attrib['agent'])
self.assertEqual('MultiCloud', root.attrib['type'])
self.assertNotIn('shadow', root.attrib)

def verify_diagrams(self, diagrams):
diagram = diagrams[0]
Expand All @@ -40,14 +41,17 @@ def verify_diagrams(self, diagrams):
self.assertEqual('diagram_1', diagram.attrib['id'])
self.assertEqual('AWS components', diagram.attrib['name'])

def verify_mx_graph_models(self, mx_graph_models):
def verify_mx_graph_models(self, mx_graph_models, shadow_mode=True):
mx_graph_model = mx_graph_models[0]
shadow_value = '0'
if shadow_mode:
shadow_value = '1'

# then
self.assertEqual(1, len(mx_graph_models))
self.assertEqual('mxGraphModel', mx_graph_model.tag)
expected = {'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': '0'}
'pageWidth': '850', 'pageHeight': '1100', 'math': '0', 'shadow': shadow_value}
self.assertEqual(expected, mx_graph_model.attrib)

def verify_roots(self, roots):
Expand Down

0 comments on commit 21cc025

Please sign in to comment.