Add chart components 216-245; step-aware ticks, font-aware labels

Bars, lines, areas, pies, donuts, radar, histogram, scatter, bubbles,
heatmaps, gauge, bullet, funnel, waterfall, treemap, candles, box
plots, steps, rings, legend, axis, crosshair, polar area, pyramid,
spectrum bars and win-loss strips, each drawn dot by dot. Ticks follow
1-2-5 steps and print as precisely as their step needs; a label row
uses micro letters or the pixel font as a whole. Descriptions carry the
data in numbers. Bad data panics.
This commit is contained in:
ZacharyZhang-NY committed 2026-10-12 00:58:44 -04:00
1 parent a2f2796455
commit 596c62e026
43 files changed
+3336 -1

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
package chart
import (
"fmt"
"strconv"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
type ProgressRingOptions struct {
// Size is the ring's width in dots; zero means 40.
Size int
Slot pixel.Slot
}
// ProgressRing fills a ring clockwise from twelve, in pixel arcs.
func ProgressRing(c *ui.Context, text string, value float64, o ProgressRingOptions) *ui.Element {
k := pixel.K(c)
if !(value >= 0 && value <= 1) {
panic(fmt.Sprintf("chart: ProgressRing value %v outside 0–1", value))
}
n := pixel.Or("ProgressRing Size", o.Size, 40)
pct := strconv.Itoa(int(value*100)) + "%"
ink := pick(o.Slot, 0)
return ui.Box(c).Size(k.D(n), k.D(n)).Role(ui.RoleProgress).Label(text).Description(pct).Draw(func(p *ui.Painter, r ui.Rect) {
g := k.Canvas(p, r)
c, rad := n/2, n/2-1
sector(g, c, c, rad-4, rad, 0, 1, pixel.Well)
sector(g, c, c, rad-4, rad, 0, value, ink)
tiny(g, c-tinyW(pct)/2+1, c-2, pct, pixel.Ink)
})
}