Select Git revision
screenplot.go
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
screenplot.go 1.69 KiB
// For fun.. Plot to the screen
package main
import (
"fmt"
"math"
ui "github.com/gizak/termui/v3"
"github.com/gizak/termui/v3/widgets"
)
func breaker(x interface{}) {}
func copyToData (y []float32) ([][]float64){
data := make([]float64, len(y))
for i := range y {
data[i] = float64(y[i])
}
data[0] = data[1]
return [][]float64{data}
}
func scrnPlt(pi, stdErr []float32) error {
fmt.Println()
marker := widgets.MarkerDot
dotMarkerRune := '.'
p1 := widgets.NewPlot()
p1.Title = "π"
p1.Data = copyToData (pi)
p1.Marker = marker
p1.DotMarkerRune = dotMarkerRune
p1.PlotType = widgets.ScatterPlot
p1.Border = true
p2 := widgets.NewPlot()
p2.Title = "standard error"
p2.Data = copyToData (stdErr)
p2.DotMarkerRune = dotMarkerRune
p2.Marker = marker
p3 := widgets.NewPlot()
p3.Title = "abs error"
{
d := make ([]float64, len(pi))
for i, piV := range pi {
d[i] = math.Pi - float64(piV)
}
p3.Data = [][]float64{d}
}
if err := ui.Init(); err != nil {
return err
}
defer ui.Close()
grid := ui.NewGrid()
termWidth, termHeight := ui.TerminalDimensions()
grid.SetRect(0, 0, termWidth, termHeight)
grid.Set (ui.NewRow(1./3, p1), ui.NewRow(1./3, p2), ui.NewRow(1./3, p3))
render(grid)
for e := range ui.PollEvents() {
if e.Type == ui.KeyboardEvent {
break
}
}
return nil
}
// This was how I wanted to do it, but the library does
// not seem to respect background colours.
// ui.Theme = thm
// nrmlStyle := ui.NewStyle (ui.ColorWhite, ui.ColorBlack)
// thm := ui.Theme
// thm.Block.Title = nrmlStyle
// thm.Plot.Axes = ui.ColorWhite
// thm.Plot.Lines = []ui.Color{ui.ColorWhite}
// thm.Default = ui.NewStyle(ui.ColorWhite, ui.ColorBlack)
// thm.Block.Border = nrmlStyle