Skip to content

Commit

Permalink
fix duplicate box-characters issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
guptarohit committed Jun 30, 2018
1 parent 458d747 commit 072ccbd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
9 changes: 5 additions & 4 deletions asciigraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,26 @@ func Plot(series []float64, options ...Option) string {
minNumLength := len(fmt.Sprintf("%0.*f", precision, minimum))
maxWidth := int(math.Max(float64(maxNumLength), float64(minNumLength)))

y0 := int(round(series[0]*ratio) - min2)

// axis and labels
for y := intmin2; y < intmax2+1; y++ {
label := fmt.Sprintf("%*.*f", maxWidth+1, precision, maximum-(float64(y-intmin2)*interval/float64(rows)))
w := y - intmin2
h := int(math.Max(float64(config.Offset)-float64(len(label)), 0))

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

y0 := int(round(series[0]*ratio) - min2)
var y1 int

plot[rows-y0][config.Offset-1] = "┼" // first value

var y1 int

for x := 0; x < len(series)-1; x++ { // plot the line
y0 = int(round(series[x+0]*ratio) - float64(intmin2))
y1 = int(round(series[x+1]*ratio) - float64(intmin2))
Expand Down
10 changes: 5 additions & 5 deletions asciigraph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestPlot(t *testing.T) {
nil,
` 11.00 ┤ ╭╮
10.00 ┤ ││
9.00 ││
9.00 ││
8.00 ┤ ││
7.00 ┤ ╭╯│╭╮
6.00 ┤ │ │││
Expand All @@ -33,7 +33,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 @@ -57,7 +57,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 @@ -90,7 +90,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 @@ -119,7 +119,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 Down

0 comments on commit 072ccbd

Please sign in to comment.