11function Export-AbrDiagram {
22 <#
33 . SYNOPSIS
4- Used by As Built Report to export diagrams
4+ Used by As Built Report to export diagrams.
55 . DESCRIPTION
6- Exports diagrams using the Diagrammer module based on user options set in the report options.
6+ Renders and embeds a Graphviz diagram into the active PScribo report section using the
7+ AsBuiltReport.Diagram module's New-Diagrammer cmdlet. Optionally, the diagram can also
8+ be saved to disk in one or more formats.
9+
10+ Behaviour is driven by the Options block of the report configuration JSON:
11+
12+ EnableDiagrams - Master switch. When false the function exits immediately.
13+ DiagramTheme - 'Black', 'Neon', or 'White' (default). Controls background
14+ and font colours passed to New-Diagrammer.
15+ DiagramWaterMark - Text watermark overlaid on the diagram image.
16+ ExportDiagrams - When true, saves the diagram to OutputFolderPath on disk.
17+ ExportDiagramsFormat - Array of formats to save (e.g. @('png', 'pdf', 'svg')).
18+ Defaults to 'png' if not set.
19+ EnableDiagramDebug - When true, passes DraftMode to New-Diagrammer so that
20+ Graphviz debug styling (red borders, visible edges) is
21+ rendered, which is useful for troubleshooting layout.
22+ EnableDiagramSignature - When true, adds an author/company signature block.
23+ SignatureAuthorName - Author name shown in the signature block.
24+ SignatureCompanyName - Company name shown in the signature block.
25+ EnableDiagramMainLogo - Controls whether the main logo is shown in the diagram.
26+
27+ The diagram is always rendered as base64 and embedded in the report via the PScribo
28+ Image cmdlet. If ExportDiagrams is also enabled the diagram is additionally written to
29+ disk in the requested format(s) before the base64 pass.
30+ . PARAMETER DiagramObject
31+ The Graphviz graph object produced by the diagram builder function (e.g.
32+ Get-AbrProcessDiagram). This is passed directly to New-Diagrammer as its -InputObject.
33+ . PARAMETER MainDiagramLabel
34+ Human-readable label used as the diagram title and as the PScribo Section heading.
35+ Defaults to 'Change Me' if not specified.
36+ . PARAMETER FileName
37+ Base file name (without extension) used when saving the diagram to disk.
38+ Required when ExportDiagrams is enabled.
39+ . INPUTS
40+ None. This function does not accept pipeline input.
41+ . OUTPUTS
42+ None. Output is written directly to the PScribo document object via Section and Image
43+ cmdlets. If ExportDiagrams is enabled, files are also written to OutputFolderPath.
44+ . EXAMPLE
45+ # Typically called from within a report section function such as Get-AbrProcessInfo:
46+ $diagram = Get-AbrProcessDiagram
47+ Export-AbrDiagram -DiagramObject $diagram -MainDiagramLabel 'Process Hierarchy Diagram' -FileName 'AsBuiltReport.System.Resources.Cluster'
748 . NOTES
849 Version: 0.1.2
950 Author: AsBuiltReport Community
1051 Twitter: @AsBuiltReport
1152 Github: AsBuiltReport
12-
1353 . LINK
14-
54+ https://github.com/AsBuiltReport/AsBuiltReport.System.Resources
1555 #>
1656
1757 [Diagnostics.CodeAnalysis.SuppressMessageAttribute (' PSAvoidUsingCmdletAliases' , ' ' , Scope = ' Function' )]
1858
1959 [CmdletBinding ()]
2060 param (
61+ # The Graphviz graph object to render. No type constraint is applied because the
62+ # PSGraph DSL returns a custom object type from the AsBuiltReport.Diagram module.
2163 $DiagramObject ,
2264 [string ] $MainDiagramLabel = ' Change Me' ,
2365 [Parameter (Mandatory = $true )]
@@ -32,9 +74,12 @@ function Export-AbrDiagram {
3274 if ($Options.EnableDiagrams ) {
3375 Write-PScriboMessage - Message " Collecting $MainDiagramLabel diagram"
3476
77+ # Resolve the icons directory relative to the module root so that icon images can
78+ # be embedded into diagram nodes by New-Diagrammer.
3579 $RootPath = Split-Path (Split-Path $PSScriptRoot - Parent) - Parent
3680 [System.IO.FileInfo ]$IconPath = Join-Path - Path $RootPath - ChildPath ' icons'
3781
82+ # Build the core parameter set shared by all New-Diagrammer invocations.
3883 $DiagramParams = @ {
3984 ' FileName' = $FileName
4085 ' OutputFolderPath' = $OutputFolderPath
@@ -52,6 +97,7 @@ function Export-AbrDiagram {
5297 ' DisableMainDiagramLogo' = $Options.EnableDiagramMainLogo
5398 }
5499
100+ # Apply theme-specific colour overrides on top of the defaults.
55101 if ($Options.DiagramTheme -eq ' Black' ) {
56102 $DiagramParams.add (' MainGraphBGColor' , ' Black' )
57103 $DiagramParams.add (' Edgecolor' , ' White' )
@@ -68,6 +114,7 @@ function Export-AbrDiagram {
68114 $DiagramParams.add (' WaterMarkColor' , ' #333333' )
69115 }
70116
117+ # When ExportDiagrams is enabled, write the diagram to disk in the requested formats.
71118 if ($Options.ExportDiagrams ) {
72119 if (-not $Options.ExportDiagramsFormat ) {
73120 $DiagramFormat = ' png'
@@ -80,9 +127,9 @@ function Export-AbrDiagram {
80127 }
81128
82129 if ($Options.EnableDiagramDebug ) {
83-
130+ # DraftMode enables Graphviz debug output (e.g. red borders on nodes/edges)
131+ # to help identify layout problems during development.
84132 $DiagramParams.Add (' DraftMode' , $True )
85-
86133 }
87134
88135 if ($Options.EnableDiagramSignature ) {
@@ -108,6 +155,8 @@ function Export-AbrDiagram {
108155 Write-PScriboMessage - IsWarning - Message " Unable to export the $MainDiagramLabel Diagram: $ ( $_.Exception.Message ) "
109156 }
110157 }
158+ # Always render the diagram as base64 for embedding in the report, regardless of
159+ # whether ExportDiagrams is enabled. Reuse $DiagramParams but swap the Format.
111160 try {
112161 $DiagramParams.Remove (' Format' )
113162 $DiagramParams.Add (' Format' , ' base64' )
0 commit comments