summaryrefslogtreecommitdiffstats
path: root/termui/linegraph.go
diff options
context:
space:
mode:
authorCaleb Bassi <calebjbassi@gmail.com>2018-03-09 16:29:05 -0800
committerCaleb Bassi <calebjbassi@gmail.com>2018-03-09 16:29:05 -0800
commit75220b3db8e4ed759eec75b75aada8fa63f49283 (patch)
tree0226cc52c129fe35d65b4d76acc28c852a68574d /termui/linegraph.go
parentd3bf834aa398c186fa0ab250c51291fac5cd76ac (diff)
Added graph zooming; closes #3
Diffstat (limited to 'termui/linegraph.go')
-rw-r--r--termui/linegraph.go15
1 files changed, 13 insertions, 2 deletions
diff --git a/termui/linegraph.go b/termui/linegraph.go
index 4b01691..01d8414 100644
--- a/termui/linegraph.go
+++ b/termui/linegraph.go
@@ -12,6 +12,7 @@ type LineGraph struct {
*Block
Data map[string][]float64
LineColor map[string]Color
+ Zoom int
DefaultLineColor Color
}
@@ -22,6 +23,7 @@ func NewLineGraph() *LineGraph {
Block: NewBlock(),
Data: make(map[string][]float64),
LineColor: make(map[string]Color),
+ Zoom: 5,
DefaultLineColor: Theme.LineGraph,
}
@@ -61,9 +63,18 @@ func (lc *LineGraph) Buffer() *Buffer {
lastY, lastX := -1, -1
// assign colors to `colors` and lines/points to the canvas
for i := len(seriesData) - 1; i >= 0; i-- {
- x := ((lc.X + 1) * 2) - 1 - (((len(seriesData) - 1) - i) * 5)
+ x := ((lc.X + 1) * 2) - 1 - (((len(seriesData) - 1) - i) * lc.Zoom)
y := ((lc.Y + 1) * 4) - 1 - int((float64((lc.Y)*4)-1)*(seriesData[i]/100))
- if x < 0 { // stop rendering at the left-most wall
+ if x < 0 {
+ // render the line to the last point up to the wall
+ if x > 0-lc.Zoom {
+ for _, p := range drawille.Line(lastX, lastY, x, y) {
+ if p.X > 0 {
+ c.Set(p.X, p.Y)
+ colors[p.X/2][p.Y/4] = seriesLineColor
+ }
+ }
+ }
break
}
if lastY == -1 { // if this is the first point