This example demonstrates how to use the Add-DiaNodeSpacer (part of Diagrammer.Core) cmdlet to add spacer nodes that assist with diagram alignment.
The Add-DiaNodeSpacer cmdlet allows you to insert invisible spacer nodes into your diagram. These spacer nodes do not appear in the final output but play a crucial role in controlling the alignment and spacing of visible nodes. By strategically placing spacer nodes, you can resolve layout issues—such as centering or evenly distributing nodes—ensuring your diagram appears balanced and visually organized.
The $Images variable is a hashtable containing the names of image files used in the diagram.The image files must be located in the directory specified by $IconPath.
** Image sizes should be around 100x100, 150x150 pixels for optimal display. **
In this diagram there is a alignment issue with the Web01 node, as it is not centered with the App01 and DB01 nodes below it. To fix this, we create two spacer nodes (FillerRight and FillerLeft) on either side of the Web01 node.
The Add-DiaNodeSpacer cmdlet is used to create invisible spacer nodes that help with diagram alignment (Part of Diagrammer.Core module).
$example15=&{SubGraph3tier-Attributes@{Label='3 Tier Concept';fontsize=18;penwidth=1.5;labelloc='t';style="dashed,rounded";color="gray"}{$Signature=Add-DiaHtmlSignatureTable-ImagesObj$Images-Rows"Author: Bugs Bunny","Company: ACME Inc."-TableBorder2-CellBorder0-Align'left'-Logo"Logo_Footer"-DraftMode:$DraftModeSubGraphSignature-Attributes@{Label=$Signature;fontsize=22;penwidth=1.5;labelloc='b';labeljust='right';style="invis";color="darkgray"}{$WebServerFarm=@(@{Name='Web-Server-01';AdditionalInfo=[PSCustomObject][ordered]@{'OS'='Redhat Linux''Version'='10''Build'="10.1"'Edition'="Enterprise"}IconType="ServerRedhat"},@{Name='Web-Server-02';AdditionalInfo=[PSCustomObject][ordered]@{'OS'='Redhat Linux''Version'='10''Build'="10.1"'Edition'="Enterprise"}IconType="ServerRedhat"},@{Name='Web-Server-03';AdditionalInfo=[PSCustomObject][ordered]@{'OS'='Ubuntu Linux''Version'='24''Build'="11"'Edition'="Enterprise"}IconType="ServerUbuntu"})$Web01Label=Add-DiaHTMLNodeTable-ImagesObj$Images-inputObject$WebServerFarm.Name-iconType$WebServerFarm.IconType-columnSize3-AditionalInfo$WebServerFarm.AdditionalInfo-Subgraph-SubgraphLabel"Web Server Farm"-SubgraphLabelPos"top"-SubgraphTableStyle"dashed,rounded"-TableBorderColor"gray"-TableBorder"1"-SubgraphLabelFontsize20-fontSize18-MultiIcon-DraftMode:$DraftMode$App01Label=Add-DiaNodeIcon-Name'App-Server-01'-AditionalInfo$AppServerInfo-ImagesObj$Images-IconType"Server"-Align"Center"-FontSize18-DraftMode:$DraftMode$DB01Label=Add-DiaNodeIcon-Name'Db-Server-01'-AditionalInfo$DBServerInfo-ImagesObj$Images-IconType"Server"-Align"Center"-FontSize18-DraftMode:$DraftModeNode-NameWeb01-Attributes@{Label=$Web01Label;shape='plain';fillColor='transparent';fontsize=14}Node-NameApp01-Attributes@{Label=$App01Label;shape='plain';fillColor='transparent';fontsize=14}Node-NameDB01-Attributes@{Label=$DB01Label;shape='plain';fillColor='transparent';fontsize=14}Edge-FromWeb01-ToApp01@{label='gRPC';color='black';fontsize=12;fontcolor='black';minlen=3}Edge-FromApp01-ToDB01@{label='SQL';color='black';fontsize=12;fontcolor='black';minlen=3}Rank-NodesApp01,DB01$RouterInfo=[PSCustomObject][ordered]@{'OS'='Cisco IOS''Version'='15.2'}$RouterLabel=Add-DiaNodeIcon-Name'Core-Router'-AdditionalInfo$RouterInfo-ImagesObj$Images-IconType"Router"-Align"Center"-FontSize18-DraftMode:$DraftModeNode-NameRouter01-Attributes@{label=$RouterLabel;shape='plain';fillColor='transparent';fontsize=14}Edge-FromRouter01-ToWeb01@{label='GE0/0';color='black';fontsize=18;fontcolor='black';minlen=2}Add-DiaNodeImage-Name"WAN"-ImagesObj$Images-IconType"Cloud"-IconPath$IconPath-ImageSizePercent30-DraftMode:$DraftModeEdge-FromWAN-ToRouter01@{label='Serial0/0';color='black';fontsize=18;fontcolor='black';minlen=2}$RouterNetworkInfo=@("S0/0:""164.42.203.10/30""G0/0:""192.168.5.10/24")Add-DiaHTMLTable-Name'RouterNetworkInfo'-Rows$RouterNetworkInfo-NodeObject-ColumnSize2-TableBorder1-TableBorderColor"black"-FontSize14-Subgraph-SubgraphLabel"Interfaces Table"-SubgraphLabelPos"top"-SubgraphTableStyle"solid,rounded"-SubgraphLabelFontsize20-GraphvizAttributes@{style='filled,rounded';fillcolor='lightblue'}-DraftMode:$DraftModeEdge-FromRouter01-ToRouterNetworkInfo@{color='black';fontsize=18;fontcolor='black';minlen=1;style='filled';arrowhead='none';arrowtail='none'}RankRouter01,RouterNetworkInfoAdd-DiaNodeShape-Name"Firewall"-Shaperectangle-ShapeStyle'filled'-ShapeFillColor'red:white'-ShapeFontSize14-ShapeFontColor'black'-ShapeFontName'Arial'-ShapeWidth3-ShapeLabelPositioncenter-ShapeLineColor'black'-DraftMode:$DraftMode# An edge is created from WAN to Firewall and from Firewall to Router01Edge-FromWAN-ToFirewall@{labeldistance=5;headlabel='port1';color='black';fontsize=18;fontcolor='black';minlen=2;arrowhead='normal';arrowtail='normal'}Edge-FromFirewall-ToRouter01@{labeldistance=4;headlabel='Serial0/0';taillabel='port2';color='black';fontsize=18;fontcolor='black';minlen=2;arrowhead='normal';arrowtail='normal'}<# In this example, we create two spacer nodes to help align the web server node. -Name parameter sets the name of the spacer node. -ShapeWidth parameter sets the width of the spacer node. -ShapeHeight parameter sets the height of the spacer node. -ShapeOrientation parameter sets the orientation of the spacer node (0 for horizontal, 1 for vertical). -DraftMode parameter specifies whether the node is in draft mode. The rank command is used to align the spacer nodes and the web server node horizontally. The edge commands create invisible edges between the spacer nodes and the web server node to maintain alignment. #>Add-DiaNodeSpacer-Name"SpaceRight"-ShapeWidth2-ShapeHeight1-ShapeOrientation0-DraftMode:$DraftModeAdd-DiaNodeSpacer-Name"SpaceLeft"-ShapeWidth2-ShapeHeight1-ShapeOrientation0-DraftMode:$DraftMode# The Rank command is used to align the spacer nodes and the web server node horizontally.Rank-NodesSpaceLeft,Web01,SpaceRight# An invisible edge is created from SpaceLeft to Web01 and from Web01 to SpaceRight to maintain alignment.$Style=if($DraftMode){'filled'}else{'invis'}$StyleColor=if($DraftMode){'red'}else{'transparent'}# The edge style is set to 'invis' for normal mode and 'filled' for draft mode, with corresponding colors.Edge-FromSpaceLeft-ToWeb01@{minlen=2;style=$Style;color=$StyleColor;}Edge-FromWeb01-ToSpaceRight@{minlen=2;style=$Style;color=$StyleColor;}}}}
Finally, call the New-Diagrammer cmdlet with the specified parameters.