Example 5
This time we will add icons and additional information to Node objects.
The Add-DiaNodeIcon (part of Diagrammer.Core module) function enhances the visual representation of nodes by incorporating icons and detailed information. In this example, each server node (Web, Application, and Database) is depicted with a server icon and a table listing its operating system, version, build, and edition. The nodes are organized within a dashed rounded rectangle labeled "3 Tier Concept," visually encapsulating the three-tier architecture. 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. **
This section creates custom objects to hold server information, which are used to set node labels in the diagram.
$WebServerInfo = [PSCustomObject][ordered]@{
'OS' = 'Redhat Linux'
'Version' = '10'
'Build' = "10.1"
'Edition' = "Enterprise"
}
$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 enhance the diagram by adding images to the Node objects and embedding information to describe server properties. Graphviz supports HTML-Like tables to extend object labels, allowing images, text, and tables within Node, Edge, and Subgraph @{Label=} script blocks attributes.
Add-DiaNodeIcon extends PSGraph to improve the appearance of the generated Node objects (Add-DiaNodeIcon is part of Diagrammer.Core).
The $Images object and IconType "Server" must be defined earlier in the script
Finally, call the New-Diagrammer cmdlet with the specified parameters.
New-Diagrammer -InputObject $example5 -OutputFolderPath $OutputFolderPath -Format $Format -MainDiagramLabel $MainGraphLabel -Filename Example5 -LogoName "Main_Logo" -DraftMode:$DraftMode
When you run the script, it generates a PNG file named Example5.png in the specified output folder.
Resulting diagram: