summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaleb Bassi <calebjbassi@gmail.com>2018-03-09 13:14:37 -0800
committerCaleb Bassi <calebjbassi@gmail.com>2018-03-09 13:14:37 -0800
commit18ea218a08acc3782ebc7f3665a7f414ff26c05e (patch)
tree7d3ff0e4f8ceb10abd721395f4bb1ac96ed7bae3
parent02b7a07f8855206d876e3b469b25799c99b91a10 (diff)
-rw-r--r--termui/sparkline.go24
1 files changed, 21 insertions, 3 deletions
diff --git a/termui/sparkline.go b/termui/sparkline.go
index 6beeb8d..2597b17 100644
--- a/termui/sparkline.go
+++ b/termui/sparkline.go
@@ -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})
}
}