diff --git a/CHANGELOG.md b/CHANGELOG.md index ddc3341..dc64ce7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add pester test to validate the functionality of the New-DonutChart cmdlet - Add example 12/13 to document on how to use the New-DonutChart cmdlet - Add radar chart support: implement New-RadarChart cmdlet and associated classes + - Add pester test to validate the functionality of the New-RadarChart cmdlet + - Add example 14/15 to document on how to use the New-RadarChart cmdlet ### Changed diff --git a/Examples/Example12.ps1 b/Examples/Example12.ps1 index 25b5a1f..8da6115 100644 --- a/Examples/Example12.ps1 +++ b/Examples/Example12.ps1 @@ -1,6 +1,6 @@ <# .SYNOPSIS - Example 01 - Basic Donut Chart + Example 12 - Basic Donut Chart .DESCRIPTION This example demonstrates how to create a basic Donut Chart using the AsBuiltReport.Chart module. diff --git a/Examples/Example13.ps1 b/Examples/Example13.ps1 index 908cc57..3bf3186 100644 --- a/Examples/Example13.ps1 +++ b/Examples/Example13.ps1 @@ -1,6 +1,6 @@ <# .SYNOPSIS - Example 02 - Donut Chart with Legend, Custom Colors and Border + Example 13 - Donut Chart with Legend, Custom Colors and Border .DESCRIPTION This example demonstrates how to create a Donut Chart with additional visual options, including: diff --git a/Examples/Example14.ps1 b/Examples/Example14.ps1 new file mode 100644 index 0000000..37845ab --- /dev/null +++ b/Examples/Example14.ps1 @@ -0,0 +1,62 @@ +<# + .SYNOPSIS + Example 14 - Basic Radar Chart + + .DESCRIPTION + This example demonstrates how to create a basic Radar Chart using the AsBuiltReport.Chart module. + The chart displays a simple security posture assessment for two data centers across multiple categories. +#> + +[CmdletBinding()] +param ( + [System.IO.DirectoryInfo] $Path = (Get-Location).Path, + [string] $Format = 'png' +) + +<# + Starting with PowerShell v3, modules are auto-imported when needed. Importing the module here + ensures clarity and avoids ambiguity. +#> + +# Import-Module AsBuiltReport.Chart -Force -Verbose:$false + +<# + Since the chart output is a file, specify the output folder path using $OutputFolderPath. +#> + +$OutputFolderPath = Resolve-Path $Path + +<# + Define the data to be displayed in the chart. + In a real-world scenario these values would come from your infrastructure query. +#> + +$ChartTitle = 'Security Posture Assessment' +$Values = @(@(3,5,4,2)) +$Labels = @('USA DataCenter') + +<# + The New-RadarChart cmdlet generates the Radar Chart image. + + -Title : Sets the chart title displayed at the top of the image. + -Values : Array of numeric values, one per axis. + -LegendLabels : Array of label strings corresponding to each value. + -Format : Output file format (e.g. png, jpg, svg). + -OutputFolderPath : Directory where the generated chart file will be saved. + -Width : Width of the chart image in pixels. + -Height : Height of the chart image in pixels. + -ColorPalette : Predefined color palette (e.g. Category20, Pastel). + -Filename : Name of the output file (without extension). +#> + +New-RadarChart ` + -Title $ChartTitle ` + -Values $Values ` + -LegendLabels $Labels ` + -Format $Format ` + -EnableLegend ` + -OutputFolderPath $OutputFolderPath ` + -Width 600 ` + -Height 400 ` + -ColorPalette Category20 ` + -Filename 'Example14-RadarChart' \ No newline at end of file diff --git a/Examples/Example15.ps1 b/Examples/Example15.ps1 new file mode 100644 index 0000000..d1ad568 --- /dev/null +++ b/Examples/Example15.ps1 @@ -0,0 +1,67 @@ +<# + .SYNOPSIS + Example 15 - Advanced Radar Chart + + .DESCRIPTION + This example demonstrates how to create a Advanced Radar Chart using the AsBuiltReport.Chart module. + The chart displays a security posture assessment for two data centers across multiple categories. +#> + +[CmdletBinding()] +param ( + [System.IO.DirectoryInfo] $Path = (Get-Location).Path, + [string] $Format = 'png' +) + +<# + Starting with PowerShell v3, modules are auto-imported when needed. Importing the module here + ensures clarity and avoids ambiguity. +#> + +# Import-Module AsBuiltReport.Chart -Force -Verbose:$false + +<# + Since the chart output is a file, specify the output folder path using $OutputFolderPath. +#> + +$OutputFolderPath = Resolve-Path $Path + +<# + Define the data to be displayed in the chart. + In a real-world scenario these values would come from your infrastructure query. +#> + +$ChartTitle = 'Security Posture Assessment' +$Values = @(@(1, 2, 5, 8), @(3, 5, 4, 2)) +$Labels = @('USA DataCenter', 'UK DataCenter') +$Spokes = @('Network Security', 'Endpoint Security', 'Identity Management', 'Data Protection') + +<# + The New-RadarChart cmdlet generates the Radar Chart image. + + -Title : Sets the chart title displayed at the top of the image. + -Values : Array of numeric values, one per axis. + -LegendLabels : Array of label strings corresponding to each value. + -SpokeLabels : Array of label strings for each spoke on the radar chart. + -SpokesLength : Length of the spokes (axes) in the radar chart. + -Format : Output file format (e.g. png, jpg, svg). + -OutputFolderPath : Directory where the generated chart file will be saved. + -Width : Width of the chart image in pixels. + -Height : Height of the chart image in pixels. + -ColorPalette : Predefined color palette (e.g. Category20, Pastel). + -Filename : Name of the output file (without extension). +#> + +New-RadarChart ` + -Title $ChartTitle ` + -Values $Values ` + -LegendLabels $Labels ` + -SpokeLabels $Spokes ` + -SpokesLength 9 ` + -Format $Format ` + -EnableLegend ` + -OutputFolderPath $OutputFolderPath ` + -Width 600 ` + -Height 400 ` + -ColorPalette Aurora ` + -Filename 'Example15-RadarChart' \ No newline at end of file diff --git a/Sources/DonutChart.cs b/Sources/DonutChart.cs index a6464ac..ae880ff 100644 --- a/Sources/DonutChart.cs +++ b/Sources/DonutChart.cs @@ -112,6 +112,16 @@ public object Chart(double[] values, string[] labels, string filename = "output" // Set label distance from the center of the donut slices pie.SliceLabelDistance = _labelDistance; + if (DonutCenterText != null) + { + var annotation = myPlot.Add.Annotation(DonutCenterText); + annotation.Alignment = Alignment.MiddleCenter; + annotation.LabelStyle.FontSize = 12; + annotation.LabelStyle.BackgroundColor = Colors.White; + annotation.LabelStyle.BorderColor = Colors.White; + annotation.LabelShadowColor = Colors.Transparent; + } + // Apply watermark if enabled ApplyWatermark(myPlot); @@ -127,6 +137,4 @@ public object Chart(double[] values, string[] labels, string filename = "output" } } } -} - - +} \ No newline at end of file diff --git a/Sources/PowerShell/RadarChartPwsh.cs b/Sources/PowerShell/RadarChartPwsh.cs index a9a362e..ca03bdd 100644 --- a/Sources/PowerShell/RadarChartPwsh.cs +++ b/Sources/PowerShell/RadarChartPwsh.cs @@ -97,6 +97,11 @@ public class NewRadarChartCommand : Cmdlet [Parameter(Mandatory = false, HelpMessage = "Switch to make label font bold.")] public SwitchParameter LabelBold { get; set; } + // this set the distance of the labels from the chart center (Radar Chart) + [Parameter(Mandatory = false, HelpMessage = "Distance of labels from the chart center (0.5 to 0.9). Defaults to 0.6.")] + [ValidateSet("0.5", "0.6", "0.7", "0.8", "0.9")] + public double LabelDistance { get; set; } = 0.8; + // this set the distance of the labels from the chart center (Radar Chart) [Parameter(Mandatory = false, HelpMessage = "Distance of labels from the chart center (10 to 50). Defaults to 10.")] public double SpokesLength { get; set; } = 10; @@ -221,9 +226,12 @@ protected override void ProcessRecord() Chart.TitleFontColor = TitleFontColor; } - // This set the distance of the labels from the chart center (Radar Chart) + // This set the distance of the spokes from the chart center (Radar Chart) Chart.SpokesLength = SpokesLength; + // This set the distance of the labels from the chart center (Radar Chart) + Chart.LabelDistance = LabelDistance; + // Font Settings Chart.FontName = FontName; Chart.LabelFontSize = LabelFontSize; diff --git a/Sources/RadarChart.cs b/Sources/RadarChart.cs index 86c6af1..8a41326 100644 --- a/Sources/RadarChart.cs +++ b/Sources/RadarChart.cs @@ -165,6 +165,7 @@ public object Chart(List values, string[] labels, string[] categoryNam radar.PolarAxis.Spokes[i].LabelStyle.ForeColor = GetDrawingColor(LabelFontColor); radar.PolarAxis.Spokes[i].LabelStyle.Bold = LabelBold; radar.PolarAxis.Spokes[i].LabelStyle.FontName = FontName; + radar.PolarAxis.Spokes[i].LabelPaddingFraction = LabelDistance; } } else