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:
43 files changed
+3336
-1
No files matched your search
@@ -0,0 +1,46 @@
|
||||
package chart
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/egoist/mygo/ui"
|
||||
|
||||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
||||
)
|
||||
|
||||
type WinLossOptions struct{}
|
||||
|
||||
// WinLoss rows blocks: wins up, losses down, draws dashed.
|
||||
func WinLoss(c *ui.Context, text string, results []int, o WinLossOptions) *ui.Element {
|
||||
k := pixel.K(c)
|
||||
return ui.Box(c).Size(k.D(len(results)*5), k.D(pixel.LineHeight)).Role(ui.RoleImage).Label(text).
|
||||
Description(record(results)).Draw(func(p *ui.Painter, r ui.Rect) {
|
||||
g := k.Canvas(p, r)
|
||||
mid := pixel.LineHeight / 2
|
||||
for i, res := range results {
|
||||
x := i * 5
|
||||
switch res {
|
||||
case 1:
|
||||
g.Rect(x, mid-6, 4, 5, pixel.Good)
|
||||
case -1:
|
||||
g.Rect(x, mid+1, 4, 5, pixel.Bad)
|
||||
default:
|
||||
g.Rect(x, mid-1, 4, 2, pixel.Faint)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// record is "wins-losses-draws: " then each result, checked.
|
||||
func record(results []int) string {
|
||||
var n [3]int
|
||||
all := make([]float64, len(results))
|
||||
for i, r := range results {
|
||||
if r < -1 || r > 1 {
|
||||
panic(fmt.Sprintf("chart: WinLoss result %d is not -1, 0 or 1", r))
|
||||
}
|
||||
n[1-r]++
|
||||
all[i] = float64(r)
|
||||
}
|
||||
return fmt.Sprintf("%d-%d-%d: %s", n[0], n[2], n[1], nums(all))
|
||||
}
|
||||
Reference in new issue
Block a user