Skip to content
Snippets Groups Projects
Commit b39ba4c8 authored by Andrew E. Torda's avatar Andrew E. Torda
Browse files

Almost working version with vicious had to over-ride the default render function.

parent 58009410
Branches
No related tags found
No related merge requests found
...@@ -4,79 +4,64 @@ package main ...@@ -4,79 +4,64 @@ package main
import ( import (
"fmt" "fmt"
"image" "math"
"image/color"
"image/draw"
ui "github.com/gizak/termui/v3" ui "github.com/gizak/termui/v3"
"github.com/gizak/termui/v3/widgets" "github.com/gizak/termui/v3/widgets"
) )
func breaker(x interface{}) {} func breaker(x interface{}) {}
func scrnPlt(pi, stdErr []float32) error { func copyToData (y []float32) ([][]float64){
nrmlStyle := ui.NewStyle (ui.ColorBlack, ui.ColorClear) data := make([]float64, len(y))
// invisStyle := ui.NewStyle (ui.ColorClear, ui.ColorClear) for i := range y {
thm := ui.Theme data[i] = float64(y[i])
thm.Block.Title = nrmlStyle }
thm.Plot.Axes = ui.ColorBlack data[0] = data[1]
return [][]float64{data}
}
thm.Default = ui.NewStyle(ui.ColorBlack, ui.ColorClear)
thm.Block.Border = nrmlStyle
ui.Theme = thm func scrnPlt(pi, stdErr []float32) error {
fmt.Println()
marker := widgets.MarkerDot
dotMarkerRune := '.'
ptxt := widgets.NewParagraph()
for i := 0; i < 24; i++ {
for j := 0; j < 800; j++ {
ptxt.Text += "."
}
ptxt.Text += " \n"
}
ptxt.SetRect(0, 0, 80, 24)
ptxt.TextStyle = ui.NewStyle(ui.ColorWhite, ui.ColorWhite)
p1 := widgets.NewPlot() p1 := widgets.NewPlot()
p1.Title = "π" p1.Title = "π"
{ p1.Data = copyToData (pi)
data := make([][]float64, 2) p1.Marker = marker
data[0] = make([]float64, len(pi)) p1.DotMarkerRune = dotMarkerRune
data[1] = make([]float64, len(pi))
for i := range pi {
data[0][i] = float64(i + 1)
data[1][i] = float64(pi[i])
}
p1.Data = data
}
p1.SetRect(2, 2, 80, 24)
p1.Block.TitleStyle = nrmlStyle
p1.AxesColor = ui.ColorBlack
// p1.LineColors = []ui.Color{ui.ColorBlack, ui.ColorBlack}
p1.SetRect (0, 0, 80, 24)
p1.Marker = widgets.MarkerBraille
p1.PlotType = widgets.ScatterPlot p1.PlotType = widgets.ScatterPlot
p1.Border = false p1.Border = true
breaker(thm) p2 := widgets.NewPlot()
p2.Title = "standard error"
p2.Data = copyToData (stdErr)
p2.DotMarkerRune = dotMarkerRune
p2.Marker = marker
m := image.NewRGBA(image.Rect(0, 0, 80, 24)) 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}
}
// draw.Draw(m, m.Bounds(), &image.Uniform{color.White}, image.ZP, draw.Src)
draw.Draw(m, m.Bounds(), &image.Uniform{color.White}, image.ZP, draw.Src)
img := widgets.NewImage(m)
img.SetRect(0, 0, 100, 50)
defer fmt.Println ("m bounds", m.Bounds())
if err := ui.Init(); err != nil { if err := ui.Init(); err != nil {
return err return err
} }
defer ui.Close() 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))
ui.Render(img, ptxt, p1) render(grid)
for e := range ui.PollEvents() { for e := range ui.PollEvents() {
if e.Type == ui.KeyboardEvent { if e.Type == ui.KeyboardEvent {
break break
...@@ -84,3 +69,14 @@ func scrnPlt(pi, stdErr []float32) error { ...@@ -84,3 +69,14 @@ func scrnPlt(pi, stdErr []float32) error {
} }
return nil 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment