Skip to content

Commit 2514e07

Browse files
rebelinuxCopilot
andauthored
Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 3e63b46 commit 2514e07

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

Sources/BarChart.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,24 @@ public object Chart(double[] values, string[] labels, string filename = "output"
200200
// Set axis limits if values are empty or contain only one value to prevent auto-scaling issues
201201
if (values.Length == 1)
202202
{
203+
double singleValue = values[0];
204+
double padding = Math.Abs(singleValue) * 0.1;
205+
if (padding == 0)
206+
padding = 1;
207+
203208
if (AreaOrientation == Orientations.Horizontal)
204209
{
205-
myPlot.Axes.SetLimits(0, 0, -2, 2);
210+
// Value is on the X-axis for horizontal orientation
211+
double xMin = Math.Min(0, singleValue) - padding;
212+
double xMax = Math.Max(0, singleValue) + padding;
213+
myPlot.Axes.SetLimits(xMin, xMax, -2, 2);
206214
}
207215
else
208216
{
209-
myPlot.Axes.SetLimits(-2, 2, 0, 0);
217+
// Value is on the Y-axis for vertical orientation
218+
double yMin = Math.Min(0, singleValue) - padding;
219+
double yMax = Math.Max(0, singleValue) + padding;
220+
myPlot.Axes.SetLimits(-2, 2, yMin, yMax);
210221
}
211222
}
212223

0 commit comments

Comments
 (0)