2017-02-17 09:41:56 -07:00
|
|
|
// +build ignore
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math"
|
|
|
|
"math/rand"
|
|
|
|
"time"
|
2018-08-16 21:22:32 -06:00
|
|
|
|
2018-09-06 15:48:09 -06:00
|
|
|
ui "github.com/gizak/termui"
|
2017-02-17 09:41:56 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2018-09-06 19:22:04 -06:00
|
|
|
err := ui.Init()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2018-09-06 15:48:09 -06:00
|
|
|
defer ui.Close()
|
|
|
|
|
2017-02-17 09:41:56 -07:00
|
|
|
rand.Seed(time.Now().UTC().UnixNano())
|
|
|
|
randomDataAndOffset := func() (data []float64, offset float64) {
|
|
|
|
noSlices := 1 + rand.Intn(5)
|
|
|
|
data = make([]float64, noSlices)
|
|
|
|
for i := range data {
|
|
|
|
data[i] = rand.Float64()
|
|
|
|
}
|
|
|
|
offset = 2.0 * math.Pi * rand.Float64()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
run := true
|
|
|
|
|
2018-09-06 15:48:09 -06:00
|
|
|
pc := ui.NewPieChart()
|
2017-02-17 09:41:56 -07:00
|
|
|
pc.BorderLabel = "Pie Chart"
|
|
|
|
pc.Width = 70
|
|
|
|
pc.Height = 36
|
|
|
|
pc.Data = []float64{.25, .25, .25, .25}
|
|
|
|
pc.Offset = -.5 * math.Pi
|
|
|
|
pc.Label = func(i int, v float64) string {
|
|
|
|
return fmt.Sprintf("%.02f", v)
|
|
|
|
}
|
|
|
|
|
2018-09-06 17:36:14 -06:00
|
|
|
drawTicker := time.NewTicker(time.Second)
|
|
|
|
drawTickerCount := 1
|
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
if run {
|
|
|
|
pc.Data, pc.Offset = randomDataAndOffset()
|
|
|
|
ui.Render(pc)
|
|
|
|
}
|
|
|
|
|
|
|
|
drawTickerCount++
|
|
|
|
<-drawTicker.C
|
2017-02-17 09:41:56 -07:00
|
|
|
}
|
2018-09-06 17:36:14 -06:00
|
|
|
}()
|
2017-02-17 09:41:56 -07:00
|
|
|
|
2018-09-06 17:36:14 -06:00
|
|
|
ui.Handle("s", func(ui.Event) {
|
2017-02-17 09:41:56 -07:00
|
|
|
run = !run
|
|
|
|
if run {
|
|
|
|
pc.BorderLabel = "Pie Chart"
|
|
|
|
} else {
|
|
|
|
pc.BorderLabel = "Pie Chart (Stopped)"
|
|
|
|
}
|
2018-09-06 15:48:09 -06:00
|
|
|
ui.Render(pc)
|
2017-02-17 09:41:56 -07:00
|
|
|
})
|
|
|
|
|
2018-09-06 17:36:14 -06:00
|
|
|
ui.Handle("q", func(ui.Event) {
|
2018-09-06 15:48:09 -06:00
|
|
|
ui.StopLoop()
|
2017-02-17 09:41:56 -07:00
|
|
|
})
|
2018-09-06 15:48:09 -06:00
|
|
|
|
|
|
|
ui.Render(pc)
|
|
|
|
|
|
|
|
ui.Loop()
|
2017-02-17 09:41:56 -07:00
|
|
|
}
|