Files
ZacharyZhang-NYandClaude Opus 5.5 03e1f91706 Upgrade MyGo to v0.5.5
Elements are now pass-scoped value handles: tests that read bounds
after a frame bind a ui.Handle. pixel tells frames apart by the build
pass's root, since the Tester clock no longer moves on its own.

Fix the regressions the upgrade brought:
- Clipboard reads in input handlers go through c.Services().
- MyGo notes an overlay's opener after building it, so AutoFocus
  inside lost it; pixel.AutoFocus focuses through a Handle, and
  archtest bans the raw call. Dialogs hand the focus back again.
- Elements around a press stay hovered: Tooltip tells a press-given
  focus by focus arriving under the pointer.
- The web host moves the Tester clock with real time, at most 500 ms
  a call, and gives components the real clock.

The gallery's source index also accepts CRLF checkouts.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-17 01:31:08 -04:00

47 lines
1.3 KiB
Go

package chart
import (
"fmt"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
type WaterfallOptions struct {
// Width and Height are dots; zeros mean 160 by 80.
Width, Height int
}
// Waterfall walks a running total: Good up, Bad down.
func Waterfall(c *ui.Context, text string, labels []string, deltas []float64, o WaterfallOptions) ui.Element {
k := pixel.K(c)
if len(labels) != len(deltas) || len(deltas) == 0 {
panic(fmt.Sprintf("chart: Waterfall has %d labels for %d steps", len(labels), len(deltas)))
}
w, h := size("Waterfall", o.Width, o.Height, 160, 80)
totals := make([]float64, len(deltas)+1)
for i, d := range deltas {
totals[i+1] = totals[i] + d
}
lo, hi := span(totals)
p := fit(lo, hi, w, h, labels)
return ui.Box(c).Size(k.D(w), k.D(h)).Role(ui.RoleImage).Label(text).Description(read(labels, deltas)).Draw(func(pt *ui.Painter, r ui.Rect) {
g := k.Canvas(pt, r)
p.grid(g, labels)
bw := max(1, p.w/len(deltas)*2/3)
for i, d := range deltas {
a, b := p.at(totals[i]), p.at(totals[i+1])
ink := pixel.Good
if d < 0 {
ink = pixel.Bad
}
x := p.slot(i, len(deltas)) - bw/2
g.Rect(x, min(a, b), bw, max(1, abs(a-b)), ink)
if i+1 < len(deltas) {
g.Checker(x+bw, b, p.slot(i+1, len(deltas))-bw/2-x-bw, 1, pixel.Edge)
}
}
})
}