A chart, in the program's own units
import hive.ui
// Twelve across and a hundred down, so a month of 68 kilos is drawn 68
// long and nothing has to be turned into pixels first.
func chart(harvest: Int[]): ui.View {
mut ui.Mark[dyn] marks = []
for i := 0; i < len(harvest); i++ {
if harvest bounds i {
tall := hive.conv.itf(harvest[i])
// A bar is placed from its middle, which is why the floor is
// 100 and the middle of one standing on it is half a bar up.
append(marks, ui.bar([ui.paint(ui.Tone.Good())],
hive.conv.itf(i) + 0.5, 100.0 - tall / 2.0, 0.7, tall))
}
}
append(marks, ui.words([ui.paint(ui.Tone.Muted())], 6.0, 8.0, 7.0, "kg per month"))
return ui.canvas([
ui.width(480),
ui.height(200),
ui.region(0.0, 0.0, 12.0, 100.0),
], marks)
}
proc main(): void {
// The same tree a window would swap in is what a page writes out.
echo len(ui.page("Harvest", chart([31, 44, 58, 72, 68, 51])))
}
A line, a ring and a word
import hive.ui
proc main(): void {
// A line through five places — x, y, x, y — and a ring on the last of
// them, which is a dot and so needed no name of its own.
trace := ui.path([ui.thick(0.15), ui.paint(ui.Tone.Good())],
[0.0, 2.0, 1.0, 5.0, 2.0, 4.0, 3.0, 8.0, 4.0, 7.0])
tip := ui.dot([ui.paint(ui.Tone.Good())], 4.0, 7.0, 0.2)
// Words are centred on the place, and their height is in region units
// too — so this one is a twelfth as tall as the plane it sits on.
label := ui.words([ui.paint(ui.Tone.Muted())], 4.0, 8.4, 0.8, "now")
view := ui.canvas([
ui.width(360),
ui.height(200),
ui.region(-0.5, 0.0, 5.5, 10.0),
], [trace, tip, label])
echo ui.html(view)
}