scale
cheatah-plot v0.1.0-alpha — Biome Standard 0.6.3-alpha
Classes
Range— A closed data interval [lo, hi] on one axis.
Functions
The [min, max] span of a data series, widened to a non-degenerate interval so a flat series still gets a sane axis (all-equal values -> a unit interval centered on the value; empty -> [0, 1]).
values | the data series. |
the data Range (always hi > lo).
O(n).
the Range.
systests/test_scale.purrimport plot.scale as scale
import ndarray
let values = ndarray.array([3.2, 7.9, 5.1, 4.4])
let r = scale.data_range(values) # -> Range 3.2 .. 7.9, ready for ticks()A "nice" tick step — 1, 2, or 5 times a power of ten — for about target ticks across span, so gridlines land on round numbers.
The classic axis-labelling choice.
span | the axis span (hi - lo); must be > 0. |
target | the desired tick count (approximate; must be >= 1). |
the nice step size (> 0).
O(1).
none.
systests/test_scale.purrimport plot.scale as scale
let r = scale.Range({.lo = 0.0, .hi = 7.3})
let step = scale.nice_step(r.hi - r.lo, 6) # -> 1.0: gridlines land on whole numbersinline ::cheatah::ndarray::basic_ndarray< double > ticks(builtins::Value auto &&r, builtins::Value auto &&target)
#
The ascending tick positions across r on a nice step — the round values gridlines and labels sit on.
r | the axis data range. |
target | the desired tick count (approximate; must be >= 1). |
the ascending tick positions within [r.lo, r.hi] (at least one).
O(ticks).
the returned tick array.
systests/test_scale.purrimport plot.scale as scale
let r = scale.Range({.lo = 0.0, .hi = 7.3})
let t = scale.ticks(r, 6) # -> [0, 1, 2, 3, 4, 5, 6, 7]inline ::cheatah::ndarray::basic_ndarray< double > log_ticks(builtins::Value auto &&r, builtins::Value auto &&target)
#
The ascending tick positions for a LOG axis across r — decade marks (powers of ten), strided when the range spans more decades than target, and subdivided with the 1-2-5 mantissas when it spans fewer than two so short log axes still read well.
Sub-decade ranges that trap no 1-2-5 mantissa fall back to linear ticks (the honest choice — log labelling adds nothing there).
r | the axis data range; a log axis holds positive data, so r.lo must be > 0 (a non-positive or degenerate range falls back exactly like |
target | the desired tick count (approximate; must be >= 1). |
the ascending tick positions within [r.lo, r.hi] (at least one).
O(ticks).
the returned tick array.
systests/test_scale.purrimport plot.scale as scale
let r = scale.Range({.lo = 1.0, .hi = 10000.0})
let t = scale.log_ticks(r, 5) # -> [1, 10, 100, 1000, 10000]: decade marksdouble to_pixel(builtins::Value auto &&value, builtins::Value auto &&r, builtins::Value auto &&px_lo, builtins::Value auto &&px_hi)
#
Map a data value to a pixel coordinate: linearly from the data range r onto the pixel span [px_lo, px_hi].
(For a screen Y axis, pass px_lo/px_hi flipped so larger data is higher up.)
value | the data value to place. |
r | the axis data range. |
px_lo | the pixel coordinate of r.lo. |
px_hi | the pixel coordinate of r.hi. |
the pixel coordinate of value (not clamped to the span).
O(1).
none.
systests/test_scale.purrimport plot.scale as scale
let r = scale.Range({.lo = 0.0, .hi = 10.0})
let px = scale.to_pixel(2.5, r, 0.0, 800.0) # -> 200.0
let py = scale.to_pixel(2.5, r, 600.0, 0.0) # -> 450.0: flipped span for screen Ydouble to_pixel_log(builtins::Value auto &&value, builtins::Value auto &&r, builtins::Value auto &&px_lo, builtins::Value auto &&px_hi)
#
Map a data value to a pixel coordinate on a LOG axis: linear in log10 space across r, onto the pixel span [px_lo, px_hi].
Non-positive ranges or values fall back to the linear map — a log axis holds positive data, and the figure layer keeps it that way; the fallback just refuses to NaN.
value | the data value to place (> 0 on a real log axis). |
r | the axis data range (both ends > 0 on a real log axis). |
px_lo | the pixel coordinate of r.lo. |
px_hi | the pixel coordinate of r.hi. |
the pixel coordinate of value (not clamped to the span).
O(1).
none.
systests/test_scale.purrimport plot.scale as scale
let r = scale.Range({.lo = 1.0, .hi = 1000.0})
let px = scale.to_pixel_log(10.0, r, 0.0, 900.0) # -> 300.0: one decade of threeABI/identity marker for the scale cheatah module: returns the module name.
Auto-emitted by purrc's library emitter. It is the concrete symbol that anchors the module's signed static archive in opaque (source-hidden) builds.
the module name ("scale").
