@@ -404,6 +404,9 @@ def generate_diagram(
404404 with open (output_filename , "w" ) as diagram_file :
405405 diagram_file .write (diagram )
406406
407+ message_handler ("\n \n Diagrams.net diagram generated" , "HEADER" )
408+ message_handler ("Check your diagram: " + output_filename , "OKBLUE" )
409+
407410 @staticmethod
408411 def decode_inflate (value : str ):
409412 decoded = base64 .b64decode (value )
@@ -442,20 +445,22 @@ def build_diagram(
442445
443446 added_resources : List [ResourceDigest ] = []
444447
448+ vpc_box_height = 56565656
449+ subnet_box_height = 424242
445450 vpc_cell = (
446451 '<mxCell id="zB3y0Dp3mfEUP9Fxs3Er-{0}" value="{1}" style="points=[[0,0],[0.25,0],[0.5,0],'
447452 "[0.75,0],[1,0],[1,0.25],[1,0.5],[1,0.75],[1,1],[0.75,1],[0.5,1],[0.25,1],[0,1],[0,0.75],"
448453 "[0,0.5],[0,0.25]];outlineConnect=0;gradientColor=none;html=1;whiteSpace=wrap;fontSize=12;"
449454 "fontStyle=0;shape=mxgraph.aws4.group;grIcon=mxgraph.aws4.group_vpc;strokeColor=#248814;"
450455 'fillColor=none;verticalAlign=top;align=left;spacingLeft=30;fontColor=#AAB7B8;dashed=0;" '
451- 'parent="1" vertex="1"><mxGeometry x="0" y="0" width="1040 " height="1000 " as="geometry" />'
452- "</mxCell>" .format (cell_id , vpc_resource .name )
456+ 'parent="1" vertex="1"><mxGeometry x="0" y="0" width="960 " height="{2} " as="geometry" />'
457+ "</mxCell>" .format (cell_id , vpc_resource .name , vpc_box_height )
453458 )
454459 cell_id += 1
455460 mx_graph_model += vpc_cell
456461
457- public_subnet_x = 80
458- public_subnet_y = 80
462+ public_subnet_x = 40
463+ public_subnet_y = 40
459464 cell_id += 1
460465 # pylint: disable=line-too-long
461466 public_subnet = (
@@ -465,13 +470,17 @@ def build_diagram(
465470 "fontStyle=0;shape=mxgraph.aws4.group;grIcon=mxgraph.aws4.group_security_group;grStroke=0;"
466471 "strokeColor=#248814;fillColor=#E9F3E6;verticalAlign=top;align=left;spacingLeft=30;"
467472 'fontColor=#248814;dashed=0;" vertex="1" parent="1"><mxGeometry x="{X}" y="{Y}" width="420" '
468- 'height="500" as="geometry" /></mxCell>' .format_map (
469- {"X" : str (public_subnet_x ), "Y" : str (public_subnet_y )}
473+ 'height="{H}" as="geometry" /></mxCell>' .format_map (
474+ {
475+ "X" : str (public_subnet_x ),
476+ "Y" : str (public_subnet_y ),
477+ "H" : subnet_box_height ,
478+ }
470479 )
471480 )
472481 mx_graph_model += public_subnet
473482
474- mx_graph_model = self .render_subnet_items (
483+ ( mx_graph_model , public_rows ) = self .render_subnet_items (
475484 added_resources ,
476485 mx_graph_model ,
477486 "{public subnet}" ,
@@ -481,8 +490,8 @@ def build_diagram(
481490 resources ,
482491 )
483492
484- private_subnet_x = 580
485- private_subnet_y = 80
493+ private_subnet_x = 480
494+ private_subnet_y = 40
486495 cell_id += 1
487496 private_subnet = (
488497 '<mxCell id="private_area_id" value="Private subnet" style="points=[[0,0],[0.25,0],'
@@ -491,13 +500,17 @@ def build_diagram(
491500 "fontSize=12;fontStyle=0;shape=mxgraph.aws4.group;grIcon=mxgraph.aws4.group_security_group;"
492501 "grStroke=0;strokeColor=#147EBA;fillColor=#E6F2F8;verticalAlign=top;align=left;"
493502 'spacingLeft=30;fontColor=#147EBA;dashed=0;" vertex="1" parent="1"><mxGeometry '
494- 'x="{X}" y="{Y}" width="420" height="500" as="geometry" /></mxCell>' .format_map (
495- {"X" : str (private_subnet_x ), "Y" : str (private_subnet_y )}
503+ 'x="{X}" y="{Y}" width="420" height="{H}" as="geometry" /></mxCell>' .format_map (
504+ {
505+ "X" : str (private_subnet_x ),
506+ "Y" : str (private_subnet_y ),
507+ "H" : subnet_box_height ,
508+ }
496509 )
497510 )
498511 mx_graph_model += private_subnet
499512
500- mx_graph_model = self .render_subnet_items (
513+ ( mx_graph_model , private_rows ) = self .render_subnet_items (
501514 added_resources ,
502515 mx_graph_model ,
503516 "{private subnet}" ,
@@ -506,6 +519,12 @@ def build_diagram(
506519 resource_relations ,
507520 resources ,
508521 )
522+ subnet_rows = max (public_rows , private_rows )
523+ new_subnet_box_height = subnet_rows * 100 + 80
524+
525+ mx_graph_model = mx_graph_model .replace (
526+ str (subnet_box_height ), str (new_subnet_box_height )
527+ )
509528
510529 count = 0
511530 row = 0
@@ -524,7 +543,7 @@ def build_diagram(
524543 {
525544 "CELL_IDX" : resource .digest .to_string (),
526545 "X" : str (count * 140 + public_subnet_x + 40 ),
527- "Y" : str (580 + row * 100 + 40 ),
546+ "Y" : str (new_subnet_box_height + row * 100 + 60 ),
528547 "STYLE" : style .replace ("fontSize=12" , "fontSize=8" ),
529548 "TITLE" : resource .name ,
530549 }
@@ -535,6 +554,11 @@ def build_diagram(
535554 row += 1
536555 count = 0
537556
557+ new_vpc_box_height = new_subnet_box_height + 100 * row + 180
558+ mx_graph_model = mx_graph_model .replace (
559+ str (vpc_box_height ), str (new_vpc_box_height )
560+ )
561+
538562 mx_graph_model += DIAGRAM_SUFFIX
539563 return MX_FILE .replace ("<MX_GRAPH>" , self .deflate_encode (mx_graph_model ))
540564
@@ -548,7 +572,7 @@ def render_subnet_items(
548572 subnet_y ,
549573 resource_relations ,
550574 resources ,
551- ):
575+ ) -> ( str , int ) :
552576 count = 0
553577 row = 0
554578 # pylint: disable=too-many-nested-blocks
@@ -581,4 +605,4 @@ def render_subnet_items(
581605 if count % 3 == 0 :
582606 row += 1
583607 count = 0
584- return mx_graph_model
608+ return mx_graph_model , row
0 commit comments