Skip to content

Commit 90ed6e7

Browse files
committed
Fix when all values are the same
1 parent 2e95454 commit 90ed6e7

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

AsciiChart.Sharp.Tests/Tests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public void TestPlot(double[] series, Options opts, string expected)
2020

2121
private static object[][] Cases =
2222
{
23+
new object[] { new double[] { 1, 1, 1, 1, 1 }, null, " 1.00 ┼──── " },
24+
new object[] { new double[] { 0, 0, 0, 0, 0 }, null, " 0.00 ┼──── " },
2325
new object[]
2426
{
2527
new double[] { 2, 1, 1, 2, -2, 5, 7, 11, 3, 7, 1 }, null, @"

AsciiChart.Sharp/AsciiChart.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static string Plot(IEnumerable<double> series, Options options = null)
2323
var max = seriesList.Max();
2424

2525
var range = Math.Abs(max - min);
26-
var ratio = ((options.Height) ?? range) / range;
26+
var ratio = range == 0 ? 0 : (options.Height ?? range) / range;
2727
var min2 = Math.Round(min * ratio, MidpointRounding.AwayFromZero);
2828
var max2 = Math.Round(max * ratio, MidpointRounding.AwayFromZero);
2929
var rows = Math.Abs(max2 - min2);
@@ -101,7 +101,7 @@ static IReadOnlyList<double> GetYAxisTicks(double max, double range, double rows
101101
var yTicks = new List<double>();
102102
for (var i = 0; i < numberOfTicks; i++)
103103
{
104-
yTicks.Add(max - i * range/rows);
104+
yTicks.Add(max - i * (range == rows ? 1 : range/rows));
105105
}
106106

107107
return yTicks;

0 commit comments

Comments
 (0)