Skip to content
This repository has been archived by the owner on Aug 29, 2020. It is now read-only.

Commit

Permalink
Closes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
cjbassi committed Mar 9, 2018
1 parent 02b7a07 commit 18ea218
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions termui/sparkline.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,31 @@ func (sl *Sparklines) Buffer() *Buffer {
max = line.Data[i]
}
}
maxHeight := sparkY - title2Y
gap := 100 / float64(maxHeight)
// prints sparkline
for x := sl.X; x >= 1; x-- {
char := SPARKS[0]
var char rune
if (sl.X - x) < len(line.Data) {
char = SPARKS[int((float64(line.Data[(len(line.Data)-1)-(sl.X-x)])/float64(max))*7)]
cur := line.Data[(len(line.Data)-1)-(sl.X-x)]
percent := (float64(cur) / float64(max)) * 100
for i := 0; i < maxHeight; i++ {
min := float64(i) * gap
y := sparkY - i
buf.SetCell(x, y, Cell{char, line.LineColor, sl.Bg})
if percent < min {
char = ' '
} else if percent > min+gap {
char = SPARKS[7]
} else {
char = SPARKS[int(((percent-min)/gap)*7)]
}
buf.SetCell(x, y, Cell{char, line.LineColor, sl.Bg})
}
} else {
char = SPARKS[0]
buf.SetCell(x, sparkY, Cell{char, line.LineColor, sl.Bg})
}
buf.SetCell(x, sparkY, Cell{char, line.LineColor, sl.Bg})
}
}

Expand Down

0 comments on commit 18ea218

Please sign in to comment.