Skip to content

Commit

Permalink
save 1.0.20
Browse files Browse the repository at this point in the history
  • Loading branch information
roffe committed Dec 7, 2024
1 parent 36ba675 commit f68940b
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 76 deletions.
4 changes: 4 additions & 0 deletions WHATSNEW.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.0.20

- Reworked legend to have fixed a more "fixed size" and value to the left

# 1.0.19

- Added E85.X_EthAct_Tech2 to Trionic 7 calibration shortcuts
Expand Down
80 changes: 37 additions & 43 deletions pkg/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"github.com/roffe/txlogger/pkg/assets"
Expand All @@ -23,8 +22,6 @@ type Dashboard struct {

metricRouter map[string]func(float64)

container *fyne.Container

text Texts
gauges Gauges

Expand Down Expand Up @@ -251,48 +248,10 @@ func NewDashboard(cfg *Config) *Dashboard {
db.limpMode.FillMode = canvas.ImageFillContain
db.limpMode.SetMinSize(fyne.NewSize(110, 85))
db.limpMode.Resize(fyne.NewSize(110, 85))
db.render()

return db
}

func (db *Dashboard) render() {
db.container = container.NewWithoutLayout(
db.limpMode,
//db.dbgBar,

db.gauges.rpm,
db.gauges.speed,
db.gauges.airmass,
db.gauges.pressure,
db.gauges.iat,
db.gauges.engineTemp,

db.text.ign,
db.text.ioff,
db.text.idc,
db.text.amul,

db.text.activeAirDem,

db.gauges.nblambda,
db.gauges.wblambda,
db.gauges.throttle,
db.gauges.pwm,
db.checkEngine,
db.text.cruise,
db.knockIcon,
)

if !db.logplayer {
db.container.Add(db.fullscreenBtn)
db.container.Add(db.closeBtn)
db.container.Add(db.logBtn)
} else {
db.container.Add(db.text.time)
}
}

func (db *Dashboard) GetMetricNames() []string {
names := make([]string, 0, len(db.metricRouter))
for k := range db.metricRouter {
Expand Down Expand Up @@ -734,7 +693,6 @@ func (dr *DashboardRenderer) Layout(space fyne.Size) {
return
}
dr.size = space
dr.db.container.Resize(space)

// Calculate common dimensions
dims := &dims{
Expand Down Expand Up @@ -784,5 +742,41 @@ func (dr *DashboardRenderer) Destroy() {
}

func (dr *DashboardRenderer) Objects() []fyne.CanvasObject {
return []fyne.CanvasObject{dr.db.container}

cont := []fyne.CanvasObject{
dr.db.limpMode,
//db.dbgBar,

dr.db.gauges.rpm,
dr.db.gauges.speed,
dr.db.gauges.airmass,
dr.db.gauges.pressure,
dr.db.gauges.iat,
dr.db.gauges.engineTemp,

dr.db.text.ign,
dr.db.text.ioff,
dr.db.text.idc,
dr.db.text.amul,

dr.db.text.activeAirDem,

dr.db.gauges.nblambda,
dr.db.gauges.wblambda,
dr.db.gauges.throttle,
dr.db.gauges.pwm,
dr.db.checkEngine,
dr.db.text.cruise,
dr.db.knockIcon,
}

if !dr.db.logplayer {
cont = append(cont, dr.db.fullscreenBtn)
cont = append(cont, dr.db.closeBtn)
cont = append(cont, dr.db.logBtn)
} else {
cont = append(cont, dr.db.text.time)
}

return cont
}
48 changes: 23 additions & 25 deletions pkg/plotter/plotter.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package plotter

import (
"fmt"
"image"
"image/color"
"log"
"sort"
"strconv"
"sync"

"fyne.io/fyne/v2"
Expand All @@ -29,9 +28,9 @@ type Plotter struct {
canvas fyne.CanvasObject
//canvasImageContainer *fyne.Container

texts []*TappableText
legend *fyne.Container
zoom *widget.Slider
legendTexts []*TappableText
legend *fyne.Container
zoom *widget.Slider

ts []*TimeSeries
plotStartPos int
Expand All @@ -47,7 +46,7 @@ type Plotter struct {
plotResolution fyne.Size
plotResolutionFactor float32

textBuffer []byte
// textBuffer []byte

size fyne.Size

Expand Down Expand Up @@ -98,7 +97,7 @@ func NewPlotter(values map[string][]float64, opts ...PlotterOpt) *Plotter {
for k := range values {
p.valueOrder = append(p.valueOrder, k)
}
sort.Strings(p.valueOrder)
//sort.Strings(p.valueOrder)
}

for n, k := range p.valueOrder {
Expand Down Expand Up @@ -132,27 +131,26 @@ func NewPlotter(values map[string][]float64, opts ...PlotterOpt) *Plotter {
p.overlayText.Text = k
p.overlayText.Color = p.ts[n].Color
p.hilightLine = n
p.texts[n].text.TextStyle.Bold = true
p.legendTexts[n].text.TextStyle.Bold = true
p.RefreshImage()
} else {
//p.ts[n].Color = oldColor
p.texts[n].text.TextStyle.Bold = false
p.legendTexts[n].text.TextStyle.Bold = false
p.overlayText.Text = ""
p.hilightLine = -1
p.RefreshImage()
}
}

legendLabel := NewTappableText(k, p.ts[n].Color, onTapped, onColorUpdate, onHover)
legendLabel.SetTextSize(14)
p.texts = append(p.texts, legendLabel)
p.legend.Add(legendLabel)
labelText := NewTappableText(k, p.ts[n].Color, onTapped, onColorUpdate, onHover)
p.legendTexts = append(p.legendTexts, labelText)
p.legend.Add(labelText)

}

p.dataPointsToShow = min(p.dataLength, 250.0)

canvasImage := container.New(&testL{p: p}, p.canvasImage)
canvasImage := container.New(&plotLayout{p: p}, p.canvasImage)

leading := container.NewBorder(
nil,
Expand All @@ -162,10 +160,10 @@ func NewPlotter(values map[string][]float64, opts ...PlotterOpt) *Plotter {
canvasImage,
)
p.container = container.NewHSplit(leading, container.NewVScroll(p.legend))
p.container.Offset = 0.83
p.container.Offset = 0.90

p.overlayText = canvas.NewText("", color.White)
p.overlayText.TextSize = 20
p.overlayText.TextSize = 25

p.canvas = container.NewWithoutLayout(
p.container,
Expand All @@ -175,12 +173,12 @@ func NewPlotter(values map[string][]float64, opts ...PlotterOpt) *Plotter {
return p
}

type testL struct {
type plotLayout struct {
p *Plotter
oldSize fyne.Size
}

func (t *testL) Layout(_ []fyne.CanvasObject, plotSize fyne.Size) {
func (t *plotLayout) Layout(_ []fyne.CanvasObject, plotSize fyne.Size) {
if t.oldSize == plotSize {
return
}
Expand All @@ -197,7 +195,7 @@ func (t *testL) Layout(_ []fyne.CanvasObject, plotSize fyne.Size) {
t.p.updateCursor()
}

func (t *testL) MinSize([]fyne.CanvasObject) fyne.Size {
func (t *plotLayout) MinSize([]fyne.CanvasObject) fyne.Size {
return fyne.NewSize(400, 100)
}

Expand All @@ -224,13 +222,13 @@ func (p *Plotter) Seek(pos int) {
func (p *Plotter) updateLegend() {
for i, v := range p.valueOrder {
valueIndex := min(p.dataLength, p.cursorPos)
obj := p.texts[i]
p.textBuffer = p.textBuffer[:0]
p.textBuffer = append(p.textBuffer, v+" "...)
p.textBuffer = strconv.AppendFloat(p.textBuffer, p.values[v][valueIndex], 'f', 2, 64)
obj.text.Text = string(p.textBuffer)
obj := p.legendTexts[i]
//p.textBuffer = p.textBuffer[:0]
//p.textBuffer = append(p.textBuffer, v+" "...)
//obj.Text = string(p.textBuffer)
obj.value.Text = fmt.Sprintf("%g", p.values[v][valueIndex])
//obj.text.Text = v + ": " + strconv.FormatFloat(p.values[v][valueIndex], 'f', 2, 64)
p.texts[i].Refresh()
p.legendTexts[i].value.Refresh()
}

}
Expand Down
54 changes: 50 additions & 4 deletions pkg/plotter/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,23 @@ import (

type TappableText struct {
widget.BaseWidget
container *fyne.Container
text *canvas.Text
value *canvas.Text
enabled bool
onTapped func(bool)
onColorUpdate func(col color.Color)
onHover func(bool)
color color.Color

oldSize fyne.Size
}

func NewTappableText(text string, col color.Color, onTapped func(enabled bool), onColorUpdate func(col color.Color), onHover func(bool)) *TappableText {
tt := &TappableText{
container: container.NewWithoutLayout(),
text: canvas.NewText(text, col),
value: canvas.NewText("0", col),
enabled: true,
onTapped: onTapped,
onColorUpdate: onColorUpdate,
Expand All @@ -50,7 +56,15 @@ func NewTappableText(text string, col color.Color, onTapped func(enabled bool),
}
}

tt.text.TextSize = 14
tt.text.TextStyle = fyne.TextStyle{Bold: false, Italic: false}

tt.value.TextSize = 14
tt.value.TextStyle = fyne.TextStyle{Bold: false, Italic: false}

tt.container.Add(tt.value)
tt.container.Add(tt.text)

tt.ExtendBaseWidget(tt)
return tt
}
Expand All @@ -70,14 +84,18 @@ func (tt *TappableText) MouseOut() {
func (tt *TappableText) Enable() {
tt.enabled = true
tt.text.Color = tt.color
tt.value.Color = tt.color
tt.text.TextStyle = fyne.TextStyle{Bold: false, Italic: false}
tt.value.TextStyle = fyne.TextStyle{Bold: false, Italic: false}
tt.text.Refresh()
}

func (tt *TappableText) Disable() {
tt.enabled = false
tt.text.TextStyle = fyne.TextStyle{Bold: false, Italic: true}
tt.value.TextStyle = fyne.TextStyle{Bold: false, Italic: true}
tt.text.Color = color.RGBA{128, 128, 128, 255}
tt.value.Color = color.RGBA{128, 128, 128, 255}
tt.text.Refresh()
}

Expand Down Expand Up @@ -113,10 +131,38 @@ func (tt *TappableText) TappedSecondary(*fyne.PointEvent) {
modal.Show()
}

func (tt *TappableText) SetTextSize(size int) {
tt.text.TextSize = float32(size)
func (tt *TappableText) CreateRenderer() fyne.WidgetRenderer {
return &TappableTextRenderer{
t: tt,
}
}

type TappableTextRenderer struct {
t *TappableText
}

func (tt *TappableText) CreateRenderer() fyne.WidgetRenderer {
return widget.NewSimpleRenderer(tt.text)
func (tr *TappableTextRenderer) Layout(size fyne.Size) {
if tr.t.oldSize == size {
return
}
tr.t.oldSize = size

tr.t.value.Move(fyne.NewPos(0, 0))
tr.t.text.Move(fyne.NewPos(60, 0))
}

func (tr *TappableTextRenderer) MinSize() fyne.Size {
return fyne.NewSize(200, 18)
}

func (tr *TappableTextRenderer) Refresh() {
tr.t.value.Refresh()

}

func (tr *TappableTextRenderer) Objects() []fyne.CanvasObject {
return []fyne.CanvasObject{tr.t.value, tr.t.text}
}

func (tr *TappableTextRenderer) Destroy() {
}
Loading

0 comments on commit f68940b

Please sign in to comment.