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.
35 lines
979 B
Go
35 lines
979 B
Go
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)
|
||
})
|
||
}
|