-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
While doing some refactoring in the main app, this patch starts implementing the history feature as described in #5. It generates "graphs" using fyne canvas instead of using any other complicated, heavy libs.
- Loading branch information
Cédric Jeanneret
committed
Mar 23, 2021
1 parent
486d403
commit be10d02
Showing
5 changed files
with
234 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package apolloGraph | ||
|
||
import ( | ||
"fyne.io/fyne/v2" | ||
"fyne.io/fyne/v2/canvas" | ||
"fyne.io/fyne/v2/container" | ||
"github.com/cjeanneret/gopolloplus/pkg/apolloMonitor" | ||
"github.com/cjeanneret/gopolloplus/pkg/apolloUtils" | ||
"image/color" | ||
"path" | ||
) | ||
|
||
const ( | ||
pos_shift = 2 | ||
) | ||
|
||
func PlotGraph(session string, ct *fyne.Container, cfg *apolloUtils.ApolloConfig, width, height int) { | ||
fname := path.Join(cfg.HistoryDir, session) | ||
data := apolloMonitor.LoadCSV(fname) | ||
watt := []int64{} | ||
split := []int64{} | ||
for _, d := range data { | ||
watt = append(watt, int64(d.Watt)) | ||
split = append(split, int64(d.TimeTo500m)) | ||
} | ||
|
||
_, w_max := apolloUtils.FindMinMax(watt) | ||
_, s_max := apolloUtils.FindMinMax(split) | ||
|
||
w_scale := float32(1) | ||
s_scale := float32(1) | ||
|
||
if int(w_max) > height { | ||
w_scale = float32(w_max)*100/float32(height) | ||
} | ||
if int(s_max) > height { | ||
s_scale = float32(s_max)*100/float32(height) | ||
} | ||
|
||
w_color := color.RGBA{3, 169, 244, 125} | ||
s_color := color.RGBA{210, 132, 69, 125} | ||
|
||
_ct := container.NewWithoutLayout() | ||
_ct.Resize(fyne.Size{Width: float32(width), Height: float32(2*height)}) | ||
|
||
for i, _ := range watt { | ||
if watt[i] != 0 && split[i] != 0 { | ||
w_size := fyne.Size{Width: pos_shift, Height: w_scale*float32(watt[i])} | ||
s_size := fyne.Size{Width: pos_shift, Height: s_scale*float32(split[i])} | ||
|
||
pos := fyne.Position{float32(i)*pos_shift*0.5, 100} | ||
|
||
w_rect := canvas.NewRectangle(w_color) | ||
w_rect.Resize(w_size) | ||
w_rect.Move(pos) | ||
s_rect := canvas.NewRectangle(s_color) | ||
s_rect.Resize(s_size) | ||
s_rect.Move(pos) | ||
_ct.Add(w_rect) | ||
_ct.Add(s_rect) | ||
} | ||
} | ||
|
||
scroller := container.NewHScroll(_ct) | ||
scroller.Resize(fyne.Size{Height: float32(height-100), Width: float32(width)}) | ||
scroller.Move(fyne.Position{310, 0}) | ||
|
||
// Empty the existing container | ||
if len(ct.Objects) == 3 { | ||
ct.Remove(ct.Objects[2]) | ||
} | ||
ct.Add(scroller) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.