2017-01-14 14:07:43 +08:00
|
|
|
// Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
|
2015-03-21 04:21:50 +08:00
|
|
|
// Use of this source code is governed by a MIT license that can
|
|
|
|
// be found in the LICENSE file.
|
|
|
|
|
|
|
|
// +build ignore
|
|
|
|
|
2015-03-14 01:20:17 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-01-24 12:12:10 +08:00
|
|
|
"log"
|
2015-03-14 01:20:17 +08:00
|
|
|
"math"
|
|
|
|
|
2018-09-07 05:48:09 +08:00
|
|
|
ui "github.com/gizak/termui"
|
2019-01-24 12:12:10 +08:00
|
|
|
"github.com/gizak/termui/widgets"
|
2015-03-14 01:20:17 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2019-01-24 12:12:10 +08:00
|
|
|
if err := ui.Init(); err != nil {
|
|
|
|
log.Fatalf("failed to initialize termui: %v", err)
|
2018-09-07 09:22:04 +08:00
|
|
|
}
|
2018-09-07 05:48:09 +08:00
|
|
|
defer ui.Close()
|
2015-03-14 01:20:17 +08:00
|
|
|
|
2019-01-24 12:12:10 +08:00
|
|
|
sinData := func() [][]float64 {
|
2015-03-14 01:20:17 +08:00
|
|
|
n := 220
|
2019-01-24 12:12:10 +08:00
|
|
|
data := make([][]float64, 2)
|
|
|
|
data[0] = make([]float64, n)
|
|
|
|
data[1] = make([]float64, n)
|
2018-08-17 08:40:32 +08:00
|
|
|
for i := 0; i < n; i++ {
|
2019-01-24 12:12:10 +08:00
|
|
|
data[0][i] = 1 + math.Sin(float64(i)/5)
|
|
|
|
data[1][i] = 1 + math.Cos(float64(i)/5)
|
2015-03-14 01:20:17 +08:00
|
|
|
}
|
2019-01-24 12:12:10 +08:00
|
|
|
return data
|
|
|
|
}()
|
2015-03-14 01:20:17 +08:00
|
|
|
|
2019-01-24 12:12:10 +08:00
|
|
|
lc0 := widgets.NewLineChart()
|
|
|
|
lc0.Title = "braille-mode Line Chart"
|
|
|
|
lc0.Data = sinData
|
|
|
|
lc0.SetRect(0, 0, 50, 15)
|
2018-09-07 05:48:09 +08:00
|
|
|
lc0.AxesColor = ui.ColorWhite
|
2019-01-24 12:12:10 +08:00
|
|
|
lc0.LineColors[0] = ui.ColorGreen
|
2015-03-14 01:20:17 +08:00
|
|
|
|
2019-01-24 12:12:10 +08:00
|
|
|
lc1 := widgets.NewLineChart()
|
|
|
|
lc1.Title = "custom Line Chart"
|
|
|
|
lc1.LineType = widgets.DotLine
|
|
|
|
lc1.Data = [][]float64{[]float64{1, 2, 3, 4, 5}}
|
|
|
|
lc1.SetRect(50, 0, 75, 10)
|
|
|
|
lc1.DotChar = '+'
|
2018-09-07 05:48:09 +08:00
|
|
|
lc1.AxesColor = ui.ColorWhite
|
2019-01-24 12:12:10 +08:00
|
|
|
lc1.LineColors[0] = ui.ColorYellow
|
|
|
|
lc1.DrawDirection = widgets.DrawLeft
|
2015-03-14 01:20:17 +08:00
|
|
|
|
2019-01-24 12:12:10 +08:00
|
|
|
lc2 := widgets.NewLineChart()
|
|
|
|
lc2.Title = "dot-mode Line Chart"
|
|
|
|
lc2.LineType = widgets.DotLine
|
|
|
|
lc2.Data = make([][]float64, 2)
|
|
|
|
lc2.Data[0] = sinData[0][4:]
|
|
|
|
lc2.Data[1] = sinData[1][4:]
|
|
|
|
lc2.SetRect(0, 15, 50, 30)
|
2018-09-07 05:48:09 +08:00
|
|
|
lc2.AxesColor = ui.ColorWhite
|
2019-01-24 12:12:10 +08:00
|
|
|
lc2.LineColors[0] = ui.ColorCyan
|
2018-09-07 05:48:09 +08:00
|
|
|
|
|
|
|
ui.Render(lc0, lc1, lc2)
|
2015-03-14 01:20:17 +08:00
|
|
|
|
2018-11-30 07:32:42 +08:00
|
|
|
uiEvents := ui.PollEvents()
|
2018-11-29 10:19:34 +08:00
|
|
|
for {
|
2018-11-30 07:32:42 +08:00
|
|
|
e := <-uiEvents
|
2018-11-29 10:19:34 +08:00
|
|
|
switch e.ID {
|
|
|
|
case "q", "<C-c>":
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2015-03-14 01:20:17 +08:00
|
|
|
}
|