Example 9
This time we will demonstrate the use of the Add-DiaHTMLNodeTable MultiIcon feature. The Add-DiaHTMLNodeTable function enhances the visual representation of nodes by creating a table layout that can include multiple icons and detailed information for each node. In this example, we simulate a web server farm with three web servers, each represented with its own icon and properties.
The web servers are organized within a dashed rounded rectangle labeled "Web Server Farm," visually encapsulating the group. Additionally, the Application and Database servers are depicted with their respective icons and properties. Connections between the nodes are clearly labeled with the communication protocols used (gRPC and SQL), providing a comprehensive overview of the web application structure.
[CmdletBinding()]
param (
[System.IO.FileInfo] $Path = '~\Desktop\',
[array] $Format = @('png'),
[bool] $DraftMode = $false
)
Starting with PowerShell v3, modules are auto-imported when needed. Importing the module here ensures clarity and avoids ambiguity.
Since the diagram output is a file, specify the output folder path using $OutputFolderPath.
The $MainGraphLabel variable sets the main title of the diagram.
If the diagram uses custom icons, specify the path to the icons directory. This is a Graphviz requirement.
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. **
$script:Images = @{
"Main_Logo" = "Diagrammer.png"
"Server" = "Server.png"
"ServerRedhat" = "Linux_Server_RedHat.png"
"ServerUbuntu" = "Linux_Server_Ubuntu.png"
"Cloud" = "Cloud.png"
"Router" = "Router.png"
"Logo_Footer" = "Signature_Logo.png"
}
This section creates custom objects to hold server information, which are used to set node labels in the diagram.
$AppServerInfo = [PSCustomObject][ordered]@{
'OS' = 'Windows Server'
'Version' = '2019'
'Build' = "17763.3163"
'Edition' = "Datacenter"
}
$DBServerInfo = [PSCustomObject][ordered]@{
'OS' = 'Oracle Server'
'Version' = '8'
'Build' = "8.2"
'Edition' = "Enterprise"
}
This time, we will simulate a Web Server Farm with multiple web server node. While the Add-DiaNodeIcon cmdlet is typically used to add icons/properties to nodes, it lack the ability to create multiple nodes with distinct properties.
Add-DiaHTMLNodeTable has the capability to create a table layout for the nodes simulting a web server farm. It also allows the addition of icons and properties to each node in the table.
** The $Images object and IconType "Server" must be defined earlier in the script **
In this example, Web-Server-01, Web-Server-02, and Web-Server-03 are part of the web server farm. Each server has its own properties defined in the AdditionalInfo parameter ($WebServerFarm).
The MultiIcon parameter allows multiple icons to be displayed in the table.
Finally, call the New-Diagrammer cmdlet with the specified parameters.
New-Diagrammer -InputObject $example9 -OutputFolderPath $OutputFolderPath -Format $Format -MainDiagramLabel $MainGraphLabel -Filename Example9 -LogoName "Main_Logo" -DraftMode:$DraftMode
When you run the script, it generates a PNG file named Example9.png in the specified output folder.
Resulting diagram: