Skip to content

Commit 146dc14

Browse files
committed
Support single series value
1 parent 90ed6e7 commit 146dc14

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

AsciiChart.Sharp.Tests/Tests.cs

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

2121
private static object[][] Cases =
2222
{
23+
new object[] { new double[] { 1 }, null, " 1.00 ┼ " },
2324
new object[] { new double[] { 1, 1, 1, 1, 1 }, null, " 1.00 ┼──── " },
2425
new object[] { new double[] { 0, 0, 0, 0, 0 }, null, " 0.00 ┼──── " },
2526
new object[]

AsciiChart.Sharp/AsciiChart.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,13 @@ public static string Plot(IEnumerable<double> series, Options options = null)
3636
var yAxisLabels = GetYAxisLabels(max, range, rows, options);
3737
ApplyYAxisLabels(resultArray, yAxisLabels, columnIndexOfFirstDataPoint);
3838

39+
var rowIndex0 = Math.Round(seriesList[0] * ratio, MidpointRounding.AwayFromZero) - min2;
40+
resultArray[(int) (rows - rowIndex0)][columnIndexOfFirstDataPoint - 1] = "┼";
41+
3942
for (var x = 0; x < seriesList.Count - 1; x++)
4043
{
41-
var rowIndex0 = Math.Round(seriesList[x] * ratio, MidpointRounding.AwayFromZero) - min2;
4244
var rowIndex1 = Math.Round(seriesList[x + 1] * ratio, MidpointRounding.AwayFromZero) - min2;
4345

44-
if (x == 0)
45-
{
46-
resultArray[(int) (rows - rowIndex0)][columnIndexOfFirstDataPoint - 1] = "┼";
47-
}
48-
4946
if (rowIndex0 == rowIndex1)
5047
{
5148
resultArray[(int) (rows - rowIndex0)][x + columnIndexOfFirstDataPoint] = "─";
@@ -60,6 +57,8 @@ public static string Plot(IEnumerable<double> series, Options options = null)
6057
{
6158
resultArray[(int) (rows - y)][x + columnIndexOfFirstDataPoint] = "│";
6259
}
60+
61+
rowIndex0 = rowIndex1;
6362
}
6463
}
6564

0 commit comments

Comments
 (0)