diff --git a/market_heatmap.go b/market_heatmap.go index 8fb2944..94b5f2a 100644 --- a/market_heatmap.go +++ b/market_heatmap.go @@ -65,8 +65,8 @@ func MarketHeatmap(c *ui.Context, path *[]string, root HeatNode, opts MarketHeat return k.Surface.Mix(trendColor(c, trendSign(ch)), float32(0.15+0.85*min(math.Abs(ch)/scale, 1))) } ch := newChart(c, opts.Frame) - spec := chartSpec{n: len(tiles)} - spec.readout = func(i int) string { + spec := ChartSpec{Marks: len(tiles)} + spec.Readout = func(i int) string { t := tiles[i] s := fmt.Sprintf("%s · %s %s%% · %s", t.name, trendWord(c, trendSign(t.change)), statisticSigned(t.change, 2), statisticFormat(t.cap, 0)) if t.branch { @@ -74,7 +74,7 @@ func MarketHeatmap(c *ui.Context, path *[]string, root HeatNode, opts MarketHeat } return s } - spec.pick = func(r ui.Rect, x, y float32) int { + spec.Pick = func(r ui.Rect, x, y float32) int { for i, t := range squarify(caps, r) { if t.Contains(x, y) { return i @@ -82,14 +82,14 @@ func MarketHeatmap(c *ui.Context, path *[]string, root HeatNode, opts MarketHeat } return -1 } - spec.activate = func(i int) { + spec.Activate = func(i int) { if tiles[i].branch { *path = append(slices.Clone(*path), tiles[i].name) res.value = true slog.Debug("mujica: market_heatmap drill", "path", strings.Join(*path, "/")) } } - spec.draw = func(p *ui.Painter, r ui.Rect, active int) { + spec.Draw = func(p *ui.Painter, r ui.Rect, active int) { for i, t := range squarify(caps, r) { bg := color(tiles[i].change) p.Fill(t, bg, 2) diff --git a/payoff_diagram.go b/payoff_diagram.go index 17f59c1..5e4c224 100644 --- a/payoff_diagram.go +++ b/payoff_diagram.go @@ -126,18 +126,18 @@ func PayoffDiagram(c *ui.Context, legs []OptionLeg, opts PayoffDiagramOptions) C internal.Linear{D0: ylo, D1: yhi, R0: float64(plot.Y + plot.H), R1: float64(plot.Y)} } up, down := trendColor(c, 1), trendColor(c, -1) - spec := chartSpec{n: n} - spec.readout = func(i int) string { + spec := ChartSpec{Marks: n} + spec.Readout = func(i int) string { return fmt.Sprintf(msg(c, "payoff_diagram.readout"), format(d.px[i]), trendWord(c, trendSign(d.pl[i])), format(d.pl[i])) } - spec.pick = func(r ui.Rect, x, y float32) int { + spec.Pick = func(r ui.Rect, x, y float32) int { plot, xs, _ := geom(r) if !plot.Contains(x, y) { return -1 } return max(0, min(n-1, int(math.Round((xs.Invert(x)-lo)/(hi-lo)*float64(n-1))))) } - spec.draw = func(p *ui.Painter, r ui.Rect, active int) { + spec.Draw = func(p *ui.Painter, r ui.Rect, active int) { plot, xs, ys := geom(r) internal.AxisY(p, plot, ys, ticks, func(v float64) string { return internal.FormatTick(v, step) }, size, k) lx, ll, lstep := internal.Nice(lo, hi, max(2, int(plot.W/90))) diff --git a/performance_chart.go b/performance_chart.go index 5ba745e..989933f 100644 --- a/performance_chart.go +++ b/performance_chart.go @@ -81,9 +81,9 @@ func PerformanceChart(c *ui.Context, values []float64, opts PerformanceChartOpti if !ok { n = 0 } - keys := make([]chartKey, len(series)) + keys := make([]ChartLegendItem, len(series)) for i, s := range series { - keys[i] = chartKey{Name: s.Name, Color: pal[i], Shape: i} + keys[i] = ChartLegendItem{Name: s.Name, Color: pal[i], Shape: i} } var ticks []float64 var step float64 @@ -96,15 +96,15 @@ func PerformanceChart(c *ui.Context, values []float64, opts PerformanceChartOpti plot := chartInset(r, 56, 26) return plot, ax.scale(plot), internal.Linear{D0: lo, D1: hi, R0: float64(plot.Y + plot.H), R1: float64(plot.Y)} } - spec := chartSpec{n: n, keys: keys, toggle: true} - spec.pick = func(r ui.Rect, x, y float32) int { + spec := ChartSpec{Marks: n, Legend: keys, Hidden: ch.toggles(true)} + spec.Pick = func(r ui.Rect, x, y float32) int { plot, xs, _ := geom(r) if !plot.Contains(x, y) { return -1 } return ax.nearest(xs.Invert(x)) } - spec.readout = func(i int) string { + spec.Readout = func(i int) string { parts := []string{opts.Times[i].Format("2006-01-02")} for _, s := range series { if !ch.hidden(s.Name) { @@ -113,7 +113,7 @@ func PerformanceChart(c *ui.Context, values []float64, opts PerformanceChartOpti } return strings.Join(parts, " · ") } - spec.draw = func(p *ui.Painter, r ui.Rect, active int) { + spec.Draw = func(p *ui.Painter, r ui.Rect, active int) { plot, xs, ys := geom(r) x := func(i int) float32 { return internal.Snap(p, xs.Map(ax.vals[i])) } if dd.Percent < 0 && !ch.hidden(name) {