WIP components (as built)
This commit is contained in:
110 files changed
+3975
-273
No files matched your search
@@ -0,0 +1,69 @@
|
||||
package mujica
|
||||
|
||||
import (
|
||||
"github.com/egoist/mygo/ui"
|
||||
"math"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPerformanceChartBenchmarkDrawdownAndKeys(t *testing.T) {
|
||||
values := []float64{100, 110, 88, 120}
|
||||
times := mktTimes(4)
|
||||
var last ChartResult
|
||||
tt := chatTester(760, 420, func(c *ui.Context) {
|
||||
last = PerformanceChart(c, values, PerformanceChartOptions{Frame: ChartFrame{Label: "Performance"}, Times: times, Benchmark: []float64{100, 105, 108, 112}})
|
||||
})
|
||||
if dd := MaxDrawdown(values); dd.Peak != 1 || dd.Trough != 2 || math.Abs(dd.Percent+20) > 1e-9 {
|
||||
t.Fatalf("drawdown %+v", dd)
|
||||
}
|
||||
tt.Key(0, ui.KeyTab)
|
||||
tt.Key(0, ui.KeyTab)
|
||||
tt.Key(0, ui.KeyTab)
|
||||
tt.Key(0, ui.KeyEnd)
|
||||
if last.Point != 3 || !tt.HasText("2026-01-04 · Portfolio +20.00% · Benchmark +12.00%") {
|
||||
t.Fatalf("point %d text %q", last.Point, tt.Texts())
|
||||
}
|
||||
_ = tt.Click("Benchmark")
|
||||
tt.Key(0, ui.KeyTab)
|
||||
tt.Key(0, ui.KeyEnd)
|
||||
if !tt.HasText("2026-01-04 · Portfolio +20.00%") {
|
||||
t.Fatalf("legend %q", tt.Texts())
|
||||
}
|
||||
marketsPanic(t, func(c *ui.Context) {
|
||||
PerformanceChart(c, []float64{-1}, PerformanceChartOptions{Frame: ChartFrame{Label: "x"}})
|
||||
})
|
||||
}
|
||||
func TestPerformanceChartSnapshot(t *testing.T) {
|
||||
|
||||
snapshot(t, "performance_chart", 720, 380, func(c *ui.Context) {
|
||||
ui.Column(c).Padding(16).Gap(12).Fill().Children(func() {
|
||||
PerformanceChart(c, mktSeries(120, 0), PerformanceChartOptions{Frame: ChartFrame{Label: "Performance"}, Times: mktTimes(120), Benchmark: mktSeries(120, 1)})
|
||||
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestPerformanceChartRequiresTimes(t *testing.T) {
|
||||
marketsPanic(t, func(c *ui.Context) {
|
||||
PerformanceChart(c, []float64{100, 110}, PerformanceChartOptions{Frame: ChartFrame{Label: "x"}})
|
||||
})
|
||||
}
|
||||
|
||||
func TestPerformanceChartDateVersion(t *testing.T) {
|
||||
values := []float64{100, 105, 110}
|
||||
times := mktTimes(3)
|
||||
version := 0
|
||||
var axis chartX
|
||||
tt := chatTester(760, 420, func(c *ui.Context) {
|
||||
r := PerformanceChart(c, values, PerformanceChartOptions{Frame: ChartFrame{Label: "Performance"}, Times: times, Version: version})
|
||||
memo := ui.Local(r.Element, "mujica.memo.x", func() chartMemoEntry { return chartMemoEntry{} })
|
||||
axis = memo.val.(chartX)
|
||||
})
|
||||
times[2] = times[0].AddDate(0, 0, 9)
|
||||
values[2] = 120
|
||||
version++
|
||||
tt.Frame()
|
||||
if got := axis.vals[2]; got != float64(times[2].UnixNano())/1e9 {
|
||||
t.Fatalf("axis time %v", got)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user