Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Sources/StackedBarChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public object Chart(List<double[]> values, string[] labels, string[] categoryNam

// create bars
var bars = new List<ScottPlot.Bar>();
// Set a moderate bar width when there is only one element to prevent it from filling the entire chart area
double barSize = values.Count == 1 ? 0.5 : 0.8;
// assign values and colors to each bar
for (int x = 0; x < values.Count; x++)
{
Expand All @@ -101,6 +103,7 @@ public object Chart(List<double[]> values, string[] labels, string[] categoryNam
FillColor = colorPalette.GetColor(i),
Label = $"{values[x][i]}",
CenterLabel = true,
Size = barSize,
});
nextBarBase += values[x][i];
}
Expand Down
8 changes: 8 additions & 0 deletions Tests/AsBuiltReport.Chart.Functions.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,13 @@ Describe 'AsBuiltReport.Chart Exported Functions' {
It 'Should throw error for mismatched Values and LegendCategories' {
{ New-StackedBarChart -Title 'Test' -Values @(@(1, 2), @(3, 4)) -Labels @('A', 'B') -LegendCategories @('X') -Format 'png' -OutputFolderPath $TestDrive } | Should -Throw -ExpectedMessage "Error: Values and category names must be equal."
}
It 'Should run without error with a single element (single-bar chart)' {
{ New-StackedBarChart -Title 'Test' -Values @(,[double[]]@(1, 2)) -Labels @('A') -LegendCategories @('X', 'Y') -Format 'png' -OutputFolderPath $TestDrive } | Should -Not -Throw
}
It 'Should return a file path as output for a single element' {
$result = New-StackedBarChart -Title 'Test' -Values @(,[double[]]@(1, 2)) -Labels @('A') -LegendCategories @('X', 'Y') -Format 'png' -OutputFolderPath $TestDrive
$result | Should -BeOfType 'System.IO.FileSystemInfo'
Test-Path $result | Should -BeTrue
}
}
}