Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

render_example_test.gno

1.99 Kb · 63 lines
 1package sparklinedemo
 2
 3// ExampleRender pins the realm's Render output as a testable example.
 4func ExampleRender() {
 5	print(Render(""))
 6	// Output:
 7	// # Sparklines
 8	//
 9	// A numeric series as one line of block characters, demoing the [`p/moul/x/daily/sparkline`](/p/moul/x/daily/sparkline/v0) library.
10	//
11	// ## A series
12	//
13	// `▁▁▂▄▃▅█▆▅▃▂▁`
14	//
15	// `3, 5, 9, 14, 12, 18, 25, 21, 16, 11, 7, 4`
16	//
17	// Scaled between its own bounds, `3` and `25`. The shape is the point; the axis is not.
18	//
19	// ## The ramp
20	//
21	// `▁▂▃▄▅▆▇█` — eight levels, low to high.
22	//
23	// | value | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
24	// |---|---|---|---|---|---|---|---|---|
25	// | level | `▁` | `▂` | `▃` | `▄` | `▅` | `▆` | `▇` | `█` |
26	//
27	// ## A flat series
28	//
29	// `▅▅▅▅` — `1000, 1000, 1000, 1000`
30	//
31	// Mid-ramp, not along the floor. A series that never moves has no shape, but drawing it at the bottom would claim it was *zero*, which is a different thing and a wrong one.
32	//
33	// ## Negatives
34	//
35	// `▁▃▄▅█▅▂` — `-8, -3, 0, 4, 9, 2, -5`
36	//
37	// Nothing special: the window is the minimum and maximum, wherever zero happens to fall.
38	//
39	// ## A fixed window clamps
40	//
41	// `-20, 0, 25, 50, 75, 100, 140` against `0..100`:
42	//
43	// `▁▁▂▄▆██`
44	//
45	// `-20` pins to the floor and `140` to the ceiling. Choosing the window keeps a percentage readable, and one outlier cannot flatten the rest of the picture — or break the realm that drew it.
46	//
47	// ## Rounding is floor
48	//
49	// | value in `0..100` | level |
50	// |---|---|
51	// | 0 | `▁` |
52	// | 14 | `▁` |
53	// | 50 | `▄` |
54	// | 85 | `▆` |
55	// | 99 | `▇` |
56	// | 100 | `█` |
57	//
58	// Only the maximum itself reaches the top of the ramp, so the peak of a series is always visually distinct.
59	//
60	// ## Why integers
61	//
62	// Scaling is integer division throughout. Render output has to be byte-identical on every validating node, and floating point is the usual way that quietly stops being true.
63}