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
|
|
|
|
|
2015-03-13 11:20:17 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-01-23 21:12:10 -07:00
|
|
|
"log"
|
2015-03-13 11:20:17 -06:00
|
|
|
"math"
|
|
|
|
|
2018-09-06 15:48:09 -06:00
|
|
|
ui "github.com/gizak/termui"
|
2019-01-23 21:12:10 -07:00
|
|
|
"github.com/gizak/termui/widgets"
|
2015-03-13 11:20:17 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2019-01-23 21:12:10 -07:00
|
|
|
if err := ui.Init(); err != nil {
|
|
|
|
log.Fatalf("failed to initialize termui: %v", err)
|
2018-09-06 19:22:04 -06:00
|
|
|
}
|
2018-09-06 15:48:09 -06:00
|
|
|
defer ui.Close()
|
2015-03-13 11:20:17 -06:00
|
|
|
|
2019-01-23 21:12:10 -07:00
|
|
|
sinData := func() [][]float64 {
|
2015-03-13 11:20:17 -06:00
|
|
|
n := 220
|
2019-01-23 21:12:10 -07:00
|
|
|
data := make([][]float64, 2)
|
|
|
|
data[0] = make([]float64, n)
|
|
|
|
data[1] = make([]float64, n)
|
2018-08-16 18:40:32 -06:00
|
|
|
for i := 0; i < n; i++ {
|
2019-01-23 21:12:10 -07:00
|
|
|
data[0][i] = 1 + math.Sin(float64(i)/5)
|
|
|
|
data[1][i] = 1 + math.Cos(float64(i)/5)
|
2015-03-13 11:20:17 -06:00
|
|
|
}
|
2019-01-23 21:12:10 -07:00
|
|
|
return data
|
|
|
|
}()
|
2015-03-13 11:20:17 -06:00
|
|
|
|
2019-01-23 21:12:10 -07:00
|
|
|
lc0 := widgets.NewLineChart()
|
|
|
|
lc0.Title = "braille-mode Line Chart"
|
|
|
|
lc0.Data = sinData
|
|
|
|
lc0.SetRect(0, 0, 50, 15)
|
2018-09-06 15:48:09 -06:00
|
|
|
lc0.AxesColor = ui.ColorWhite
|
2019-01-23 21:12:10 -07:00
|
|
|
lc0.LineColors[0] = ui.ColorGreen
|
2015-03-13 11:20:17 -06:00
|
|
|
|
2019-01-23 21:12:10 -07: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-06 15:48:09 -06:00
|
|
|
lc1.AxesColor = ui.ColorWhite
|
2019-01-23 21:12:10 -07:00
|
|
|
lc1.LineColors[0] = ui.ColorYellow
|
|
|
|
lc1.DrawDirection = widgets.DrawLeft
|
2015-03-13 11:20:17 -06:00
|
|
|
|
2019-01-23 21:12:10 -07: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-06 15:48:09 -06:00
|
|
|
lc2.AxesColor = ui.ColorWhite
|
2019-01-23 21:12:10 -07:00
|
|
|
lc2.LineColors[0] = ui.ColorCyan
|
2018-09-06 15:48:09 -06:00
|
|
|
|
|
|
|
ui.Render(lc0, lc1, lc2)
|
2015-03-13 11:20:17 -06:00
|
|
|
|
2018-11-29 16:32:42 -07:00
|
|
|
uiEvents := ui.PollEvents()
|
2018-11-28 19:19:34 -07:00
|
|
|
for {
|
2018-11-29 16:32:42 -07:00
|
|
|
e := <-uiEvents
|
2018-11-28 19:19:34 -07:00
|
|
|
switch e.ID {
|
|
|
|
case "q", "<C-c>":
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2015-03-13 11:20:17 -06:00
|
|
|
}
|