sparklines.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 "notabug.org/themusicgod1/termui"
  7. func main() {
  8. err := termui.Init()
  9. if err != nil {
  10. panic(err)
  11. }
  12. defer termui.Close()
  13. //termui.UseTheme("helloworld")
  14. 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}
  15. spl0 := termui.NewSparkline()
  16. spl0.Data = data[3:]
  17. spl0.Title = "Sparkline 0"
  18. spl0.LineColor = termui.ColorGreen
  19. // single
  20. spls0 := termui.NewSparklines(spl0)
  21. spls0.Height = 2
  22. spls0.Width = 20
  23. spls0.Border = false
  24. spl1 := termui.NewSparkline()
  25. spl1.Data = data
  26. spl1.Title = "Sparkline 1"
  27. spl1.LineColor = termui.ColorRed
  28. spl2 := termui.NewSparkline()
  29. spl2.Data = data[5:]
  30. spl2.Title = "Sparkline 2"
  31. spl2.LineColor = termui.ColorMagenta
  32. // group
  33. spls1 := termui.NewSparklines(spl0, spl1, spl2)
  34. spls1.Height = 8
  35. spls1.Width = 20
  36. spls1.Y = 3
  37. spls1.BorderLabel = "Group Sparklines"
  38. spl3 := termui.NewSparkline()
  39. spl3.Data = data
  40. spl3.Title = "Enlarged Sparkline"
  41. spl3.Height = 8
  42. spl3.LineColor = termui.ColorYellow
  43. spls2 := termui.NewSparklines(spl3)
  44. spls2.Height = 11
  45. spls2.Width = 30
  46. spls2.BorderFg = termui.ColorCyan
  47. spls2.X = 21
  48. spls2.BorderLabel = "Tweeked Sparkline"
  49. termui.Render(spls0, spls1, spls2)
  50. termui.Handle("/sys/kbd/q", func(termui.Event) {
  51. termui.StopLoop()
  52. })
  53. termui.Loop()
  54. }