Skip to content

Commit

Permalink
Merge pull request #31 from NathanBaulch/extra-start-tick
Browse files Browse the repository at this point in the history
Fix incorrect y-axis start value tick
  • Loading branch information
guptarohit authored Feb 16, 2022
2 parents 1f17c2d + 89edd58 commit 201d648
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
6 changes: 1 addition & 5 deletions asciigraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,7 @@ func Plot(series []float64, options ...Option) string {
h := int(math.Max(float64(config.Offset)-float64(len(label)), 0))

plot[w][h] = label
if y == 0 {
plot[w][config.Offset-1] = "┼"
} else {
plot[w][config.Offset-1] = "┤"
}
plot[w][config.Offset-1] = "┤"
}

var y0, y1 int
Expand Down
18 changes: 9 additions & 9 deletions asciigraph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestPlot(t *testing.T) {
nil,
` 11.00 ┤ ╭╮
10.00 ┤ ││
9.00 ││
9.00 ││
8.00 ┤ ││
7.00 ┤ ╭╯│╭╮
6.00 ┤ │ │││
Expand All @@ -42,7 +42,7 @@ func TestPlot(t *testing.T) {
[]Option{Caption("Plot using asciigraph.")},
` 11.00 ┤ ╭╮
10.00 ┤ ││
9.00 ││ ╭╮
9.00 ││ ╭╮
8.00 ┤ ││ ││
7.00 ┤ ╭╯│╭╮ ││
6.00 ┤ │ │││ ╭╯│ ╭╮ ╭╮
Expand All @@ -66,7 +66,7 @@ func TestPlot(t *testing.T) {
[]float64{2, 1, 1, 2, -2, 5, 7, 11, 3, 7, 1},
[]Option{Height(4), Offset(3)},
` 11.00 ┤ ╭╮
7.75 ╭─╯│╭╮
7.75 ╭─╯│╭╮
4.50 ┼╮ ╭╮│ ╰╯│
1.25 ┤╰─╯││ ╰
-2.00 ┤ ╰╯`},
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestPlot(t *testing.T) {
[]float64{192, 431, 112, 449, -122, 375, 782, 123, 911, 1711, 172},
[]Option{Height(10)},
` 1711 ┤ ╭╮
1528 ││
1528 ││
1344 ┤ ││
1161 ┤ ││
978 ┤ ╭╯│
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestPlot(t *testing.T) {
[]Option{Offset(10), Height(10), Caption("I'm a doctor, not an engineer.")},
` 10.00 ┤ ╭╮
8.70 ┤ ╭╮ ││
7.40 ││ ╭╮ ││
7.40 ││ ╭╮ ││
6.10 ┤ ││ ││ ││
4.80 ┤ ││ ││ ││
3.50 ┤ ││ ││ ││
Expand All @@ -150,7 +150,7 @@ func TestPlot(t *testing.T) {
-6.00 ┤ ╰╮ │││ ││
-7.00 ┤ ╰╮│││ ││
-8.00 ┤ ╰╯││ ││
-9.00 ╰╯ ╰╯`},
-9.00 ╰╯ ╰╯`},
{
[]float64{-0.000018527, -0.021, -.00123, .00000021312, -.0434321234, -.032413241234, .0000234234},
[]Option{Height(5), Width(45)},
Expand All @@ -159,7 +159,7 @@ func TestPlot(t *testing.T) {
-0.017 ┤ ╰─────╯ ╰╮ ╭─╯
-0.025 ┤ ╰─╮ ╭─╯
-0.034 ┤ ╰╮ ╭────╯
-0.042 ╰───╯`},
-0.042 ╰───╯`},
{
[]float64{57.76, 54.04, 56.31, 57.02, 59.5, 52.63, 52.97, 56.44, 56.75, 52.96, 55.54, 55.09, 58.22, 56.85, 60.61, 59.62, 59.73, 59.93, 56.3, 54.69, 55.32, 54.03, 50.98, 50.48, 54.55, 47.49, 55.3, 46.74, 46, 45.8, 49.6, 48.83, 47.64, 46.61, 54.72, 42.77, 50.3, 42.79, 41.84, 44.19, 43.36, 45.62, 45.09, 44.95, 50.36, 47.21, 47.77, 52.04, 47.46, 44.19, 47.22, 45.55, 40.65, 39.64, 37.26, 40.71, 42.15, 36.45, 39.14, 36.62},
[]Option{Width(-10), Height(-10), Offset(-1)},
Expand Down Expand Up @@ -199,7 +199,7 @@ func TestPlot(t *testing.T) {
{
[]float64{0, 0, 1, 1, math.NaN(), math.NaN(), 3, 3, 4},
nil,
` 4.00
` 4.00
3.00 ┤ ╶─╯
2.00 ┤
1.00 ┤ ╭─╴
Expand All @@ -225,7 +225,7 @@ func TestPlot(t *testing.T) {
-0.016958 ┤ ╰─────╯ ╰╮ ╭─╯
-0.025449 ┤ ╰─╮ ╭─╯
-0.033940 ┤ ╰╮ ╭────╯
-0.042430 ╰───╯`},
-0.042430 ╰───╯`},
}

for i := range cases {
Expand Down

0 comments on commit 201d648

Please sign in to comment.