Merge Markets; port to public ChartSpec
This commit is contained in:
3 files changed
+15
-15
No files matched your search
+5
-5
@@ -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)))
|
return k.Surface.Mix(trendColor(c, trendSign(ch)), float32(0.15+0.85*min(math.Abs(ch)/scale, 1)))
|
||||||
}
|
}
|
||||||
ch := newChart(c, opts.Frame)
|
ch := newChart(c, opts.Frame)
|
||||||
spec := chartSpec{n: len(tiles)}
|
spec := ChartSpec{Marks: len(tiles)}
|
||||||
spec.readout = func(i int) string {
|
spec.Readout = func(i int) string {
|
||||||
t := tiles[i]
|
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))
|
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 {
|
if t.branch {
|
||||||
@@ -74,7 +74,7 @@ func MarketHeatmap(c *ui.Context, path *[]string, root HeatNode, opts MarketHeat
|
|||||||
}
|
}
|
||||||
return s
|
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) {
|
for i, t := range squarify(caps, r) {
|
||||||
if t.Contains(x, y) {
|
if t.Contains(x, y) {
|
||||||
return i
|
return i
|
||||||
@@ -82,14 +82,14 @@ func MarketHeatmap(c *ui.Context, path *[]string, root HeatNode, opts MarketHeat
|
|||||||
}
|
}
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
spec.activate = func(i int) {
|
spec.Activate = func(i int) {
|
||||||
if tiles[i].branch {
|
if tiles[i].branch {
|
||||||
*path = append(slices.Clone(*path), tiles[i].name)
|
*path = append(slices.Clone(*path), tiles[i].name)
|
||||||
res.value = true
|
res.value = true
|
||||||
slog.Debug("mujica: market_heatmap drill", "path", strings.Join(*path, "/"))
|
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) {
|
for i, t := range squarify(caps, r) {
|
||||||
bg := color(tiles[i].change)
|
bg := color(tiles[i].change)
|
||||||
p.Fill(t, bg, 2)
|
p.Fill(t, bg, 2)
|
||||||
|
|||||||
+4
-4
@@ -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)}
|
internal.Linear{D0: ylo, D1: yhi, R0: float64(plot.Y + plot.H), R1: float64(plot.Y)}
|
||||||
}
|
}
|
||||||
up, down := trendColor(c, 1), trendColor(c, -1)
|
up, down := trendColor(c, 1), trendColor(c, -1)
|
||||||
spec := chartSpec{n: n}
|
spec := ChartSpec{Marks: n}
|
||||||
spec.readout = func(i int) string {
|
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]))
|
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)
|
plot, xs, _ := geom(r)
|
||||||
if !plot.Contains(x, y) {
|
if !plot.Contains(x, y) {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
return max(0, min(n-1, int(math.Round((xs.Invert(x)-lo)/(hi-lo)*float64(n-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)
|
plot, xs, ys := geom(r)
|
||||||
internal.AxisY(p, plot, ys, ticks, func(v float64) string { return internal.FormatTick(v, step) }, size, k)
|
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)))
|
lx, ll, lstep := internal.Nice(lo, hi, max(2, int(plot.W/90)))
|
||||||
|
|||||||
@@ -81,9 +81,9 @@ func PerformanceChart(c *ui.Context, values []float64, opts PerformanceChartOpti
|
|||||||
if !ok {
|
if !ok {
|
||||||
n = 0
|
n = 0
|
||||||
}
|
}
|
||||||
keys := make([]chartKey, len(series))
|
keys := make([]ChartLegendItem, len(series))
|
||||||
for i, s := range 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 ticks []float64
|
||||||
var step float64
|
var step float64
|
||||||
@@ -96,15 +96,15 @@ func PerformanceChart(c *ui.Context, values []float64, opts PerformanceChartOpti
|
|||||||
plot := chartInset(r, 56, 26)
|
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)}
|
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 := ChartSpec{Marks: n, Legend: keys, Hidden: ch.toggles(true)}
|
||||||
spec.pick = func(r ui.Rect, x, y float32) int {
|
spec.Pick = func(r ui.Rect, x, y float32) int {
|
||||||
plot, xs, _ := geom(r)
|
plot, xs, _ := geom(r)
|
||||||
if !plot.Contains(x, y) {
|
if !plot.Contains(x, y) {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
return ax.nearest(xs.Invert(x))
|
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")}
|
parts := []string{opts.Times[i].Format("2006-01-02")}
|
||||||
for _, s := range series {
|
for _, s := range series {
|
||||||
if !ch.hidden(s.Name) {
|
if !ch.hidden(s.Name) {
|
||||||
@@ -113,7 +113,7 @@ func PerformanceChart(c *ui.Context, values []float64, opts PerformanceChartOpti
|
|||||||
}
|
}
|
||||||
return strings.Join(parts, " · ")
|
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)
|
plot, xs, ys := geom(r)
|
||||||
x := func(i int) float32 { return internal.Snap(p, xs.Map(ax.vals[i])) }
|
x := func(i int) float32 { return internal.Snap(p, xs.Map(ax.vals[i])) }
|
||||||
if dd.Percent < 0 && !ch.hidden(name) {
|
if dd.Percent < 0 && !ch.hidden(name) {
|
||||||
|
|||||||
Reference in new issue
Block a user