termui/_examples/sparklines.go

65 lines
1.3 KiB
Go
Raw Normal View History

2017-01-13 23:07:43 -07:00
// Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
2015-03-20 14:21:50 -06:00
// Use of this source code is governed by a MIT license that can
// be found in the LICENSE file.
// +build ignore
package main
2018-09-06 15:48:09 -06:00
import ui "github.com/gizak/termui"
func main() {
2018-09-06 15:48:09 -06:00
ui.Init()
defer ui.Close()
data := []int{4, 2, 1, 6, 3, 9, 1, 4, 2, 15, 14, 9, 8, 6, 10, 13, 15, 12, 10, 5, 3, 6, 1, 7, 10, 10, 14, 13, 6}
2018-09-06 15:48:09 -06:00
spl0 := ui.NewSparkline()
spl0.Data = data[3:]
spl0.Title = "Sparkline 0"
2018-09-06 15:48:09 -06:00
spl0.LineColor = ui.ColorGreen
// single
2018-09-06 15:48:09 -06:00
spls0 := ui.NewSparklines(spl0)
spls0.Height = 2
spls0.Width = 20
2015-10-08 20:11:26 -06:00
spls0.Border = false
2018-09-06 15:48:09 -06:00
spl1 := ui.NewSparkline()
spl1.Data = data
spl1.Title = "Sparkline 1"
2018-09-06 15:48:09 -06:00
spl1.LineColor = ui.ColorRed
2018-09-06 15:48:09 -06:00
spl2 := ui.NewSparkline()
spl2.Data = data[5:]
spl2.Title = "Sparkline 2"
2018-09-06 15:48:09 -06:00
spl2.LineColor = ui.ColorMagenta
// group
2018-09-06 15:48:09 -06:00
spls1 := ui.NewSparklines(spl0, spl1, spl2)
spls1.Height = 8
spls1.Width = 20
spls1.Y = 3
2015-10-08 20:11:26 -06:00
spls1.BorderLabel = "Group Sparklines"
2018-09-06 15:48:09 -06:00
spl3 := ui.NewSparkline()
spl3.Data = data
spl3.Title = "Enlarged Sparkline"
spl3.Height = 8
2018-09-06 15:48:09 -06:00
spl3.LineColor = ui.ColorYellow
2018-09-06 15:48:09 -06:00
spls2 := ui.NewSparklines(spl3)
spls2.Height = 11
spls2.Width = 30
2018-09-06 15:48:09 -06:00
spls2.BorderFg = ui.ColorCyan
spls2.X = 21
2015-10-08 20:11:26 -06:00
spls2.BorderLabel = "Tweeked Sparkline"
2018-09-06 15:48:09 -06:00
ui.Render(spls0, spls1, spls2)
ui.Handle("q", func(ui.Event) {
2018-09-06 15:48:09 -06:00
ui.StopLoop()
2015-10-08 20:11:26 -06:00
})
2018-09-06 15:48:09 -06:00
ui.Loop()
}