linechart.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
  2. // Use of this source code is governed by a MIT license that can
  3. // be found in the LICENSE file.
  4. // +build ignore
  5. package main
  6. import (
  7. "math"
  8. "notabug.org/themusicgod1/termui"
  9. )
  10. func main() {
  11. err := termui.Init()
  12. if err != nil {
  13. panic(err)
  14. }
  15. defer termui.Close()
  16. //termui.UseTheme("helloworld")
  17. sinps := (func() []float64 {
  18. n := 220
  19. ps := make([]float64, n)
  20. for i := range ps {
  21. ps[i] = 1 + math.Sin(float64(i)/5)
  22. }
  23. return ps
  24. })()
  25. lc0 := termui.NewLineChart()
  26. lc0.BorderLabel = "braille-mode Line Chart"
  27. lc0.Data = sinps
  28. lc0.Width = 50
  29. lc0.Height = 12
  30. lc0.X = 0
  31. lc0.Y = 0
  32. lc0.AxesColor = termui.ColorWhite
  33. lc0.LineColor = termui.ColorGreen | termui.AttrBold
  34. lc1 := termui.NewLineChart()
  35. lc1.BorderLabel = "dot-mode Line Chart"
  36. lc1.Mode = "dot"
  37. lc1.Data = sinps
  38. lc1.Width = 26
  39. lc1.Height = 12
  40. lc1.X = 51
  41. lc1.DotStyle = '+'
  42. lc1.AxesColor = termui.ColorWhite
  43. lc1.LineColor = termui.ColorYellow | termui.AttrBold
  44. lc2 := termui.NewLineChart()
  45. lc2.BorderLabel = "dot-mode Line Chart"
  46. lc2.Mode = "dot"
  47. lc2.Data = sinps[4:]
  48. lc2.Width = 77
  49. lc2.Height = 16
  50. lc2.X = 0
  51. lc2.Y = 12
  52. lc2.AxesColor = termui.ColorWhite
  53. lc2.LineColor = termui.ColorCyan | termui.AttrBold
  54. termui.Render(lc0, lc1, lc2)
  55. termui.Handle("/sys/kbd/q", func(termui.Event) {
  56. termui.StopLoop()
  57. })
  58. termui.Loop()
  59. }