-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAdvancedExample01.ps1
More file actions
183 lines (156 loc) · 8.29 KB
/
AdvancedExample01.ps1
File metadata and controls
183 lines (156 loc) · 8.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# ** This example demonstrates how to use the Add-HtmlSubGraph cmdlet to simulate Graphviz SubGraphs. (part of AsBuiltReport.Diagram) **
<#
This example demonstrates how to create a 3-tier web application diagram using the AsBuiltReport.Diagram module.
#>
[CmdletBinding()]
param (
[System.IO.FileInfo] $Path = '~\Desktop\',
[array] $Format = @('png'),
[bool] $DraftMode = $false
)
<#
Starting with PowerShell v3, modules do not need to be explicitly imported.
It is included here for clarity.
#>
# Import-Module AsBuiltReport.Diagram -Force -Verbose:$false
<#
The diagram output is a file, so we need to specify the output folder path. In this example, $OutputFolderPath is used.
#>
$OutputFolderPath = Resolve-Path -Path $Path
<#
If the diagram uses custom icons, specify the path to the icons directory. This is a Graphviz requirement.
#>
$RootPath = $PSScriptRoot
[System.IO.FileInfo]$IconPath = Join-Path -Path $RootPath -ChildPath 'Icons'
<#
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' = 'AsBuiltReport.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'
}
<#
The $MainGraphLabel variable sets the main title of the diagram.
#>
$MainGraphLabel = 'Web Application Diagram'
$advancedexample01 = & {
<#
A SubGraph allows you to group objects in a container, creating a graph within a graph.
SubGraph, Node, and Edge have attributes for setting background color, label, border color, style, etc.
(SubGraph is a reserved word in the PSGraph module)
https://psgraph.readthedocs.io/en/latest/Command-SubGraph/
#>
SubGraph 3tier -Attributes @{Label = 'Advanced Diagram Concepts'; fontsize = 22; penwidth = 1.5; labelloc = 't'; style = 'dashed,rounded'; color = 'darkgray' } {
<#
Native Graphviz SubGraph has its issues when it comes to layout and connectivity.
For example, nodes in a SubGraph are not always aligned properly, and edges connecting nodes inside
and outside the SubGraph can be misaligned or not connect as expected. This can lead to diagrams that
are difficult to read and understand. Additionally, Nodes inside SubGraphs cannot be split across multiple
rows or columns, limiting the flexibility of the layout. This can be particularly problematic when trying to create
complex diagrams with many nodes and connections.
#>
SubGraph Traditional -Attributes @{Label = 'Native Graphviz SubGraph'; bgcolor = '#c1cfe5ff'; fontsize = 22; penwidth = 1.5; labelloc = 't'; style = 'dashed,rounded'; color = 'darkgray' } {
$index = 1
while ($index -le 6) {
$AdditionalInfo = [PSCustomObject][ordered]@{
'OS' = 'Redhat Linux'
'Version' = '10'
'Build' = '10.1'
}
Add-NodeIcon -Name "Web-Server-0$index" -AdditionalInfo $AdditionalInfo -ImagesObj $Images -IconType 'ServerRedhat' -Align 'Center' -FontSize 18 -DraftMode:$DraftMode -NodeObject -TableBackgroundColor '#c1cfe5ff' -CellBackgroundColor '#c1cfe5ff'
$index++
}
}
<#
AsBuiltReport.Diagram provides a workaround using HTML-like labels to simulate SubGraphs with enhanced layout
and connectivity options.By using HTML-like labels, we can create more complex and flexible layouts for nodes within
a SubGraph. This allows us to better organize and present information in the diagram.Additionally, HTML-like labels provide
more control over the appearance and formatting of the nodes, allowing for a more polished and professional look. This approach
can help to overcome some of the limitations of traditional Graphviz SubGraphs, making it easier to create clear and effective diagrams.
#>
<#
Here I create a web server farm with 6 web servers using Add-HtmlNodeTable. Each server will have an icon and additional information displayed in a table format.
The servers will be arranged in a table with **3 columns** (This can't be done with Graphviz Native SubGraph).
#>
$WebServerFarm = @(
@{
Name = 'Web-Server-01';
AdditionalInfo = [PSCustomObject][ordered]@{
'OS' = 'Redhat Linux'
'Version' = '10'
'Build' = '10.1'
}
IconType = 'ServerRedhat'
},
@{
Name = 'Web-Server-02';
AdditionalInfo = [PSCustomObject][ordered]@{
'OS' = 'Redhat Linux'
'Version' = '10'
'Build' = '10.1'
}
IconType = 'ServerRedhat'
},
@{
Name = 'Web-Server-03';
AdditionalInfo = [PSCustomObject][ordered]@{
'OS' = 'Redhat Linux'
'Version' = '10'
'Build' = '10.1'
}
IconType = 'ServerRedhat'
},
@{
Name = 'Web-Server-04';
AdditionalInfo = [PSCustomObject][ordered]@{
'OS' = 'Redhat Linux'
'Version' = '10'
'Build' = '10.1'
}
IconType = 'ServerRedhat'
}, @{
Name = 'Web-Server-05';
AdditionalInfo = [PSCustomObject][ordered]@{
'OS' = 'Redhat Linux'
'Version' = '10'
'Build' = '10.1'
}
IconType = 'ServerRedhat'
},
@{
Name = 'Web-Server-06';
AdditionalInfo = [PSCustomObject][ordered]@{
'OS' = 'Redhat Linux'
'Version' = '10'
'Build' = '10.1'
}
IconType = 'ServerRedhat'
}
)
<#
The Add-HtmlNodeTable cmdlet creates a HTML-like table with icons and additional information for each web server.
The -columnSize parameter is set to 3, which arranges the servers in a table with 3 columns.
The -MultiIcon switch allows multiple icons to be displayed in the table.
The resulting HTML-like table is then used as the label for a Node representing the web server farm.
#>
$WebLabel = Add-HtmlNodeTable -Name 'WebLabel' -ImagesObj $Images -inputObject $WebServerFarm.Name -iconType $WebServerFarm.IconType -ColumnSize 3 -AditionalInfo $WebServerFarm.AdditionalInfo -MultiIcon -DraftMode:$DraftMode -FontSize 18 -TableBackgroundColor '#a8c3b8ff' -CellBackgroundColor '#a8c3b8ff'
<#
The Add-HtmlSubGraph cmdlet creates a HTML-like table that simulates a SubGraph with enhanced layout and connectivity options.
The -columnSize parameter is set to 1, which arranges the web servers in a table with 1 column.
The resulting HTML-like table is then used as the label for a Node representing the web server farm.
The -NodeObject switch is used to create a Node with the HTML-like table as its label.
#>
Add-HtmlSubGraph -Name 'USA-WebServers' -ImagesObj $Images -TableArray $WebLabel -Align 'Center' -Label 'AsBuiltReport.Diagram SubGraph' -LabelPos 'top' -TableStyle 'dashed,rounded' -TableBorderColor 'darkgray' -TableBorder '1' -ColumnSize 1 -FontSize 22 -DraftMode:$DraftMode -TableBackgroundColor '#a8c3b8ff' -IconType 'Server' -NodeObject
}
}
<#
This command generates the diagram using the New-AbrDiagram cmdlet (part of AsBuiltReport.Diagram).
#>
New-AbrDiagram -InputObject $advancedexample01 -OutputFolderPath $OutputFolderPath -Format $Format -MainDiagramLabel $MainGraphLabel -Filename AdvancedExample01 -LogoName 'Main_Logo' -Direction top-to-bottom -IconPath $IconPath -ImagesObj $Images -DraftMode:$DraftMode