cheatah
Module

scale

cheatah-plot v0.1.0-alpha — Biome Standard 0.6.3-alpha

Classes

Functions

fn std::ostream & operator<<(std::ostream &os_, const Range &v_) #
fn Range data_range(::cheatah::ndarray::basic_ndarray< double > &values) #

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]).

Parameters
values

the data series.

Returns

the data Range (always hi > lo).

Complexity

O(n).

Allocation

the Range.

System testsystests/test_scale.purr
Example
import 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()
fn double nice_step(builtins::Value auto &&span, builtins::Value auto &&target) #

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.

Parameters
span

the axis span (hi - lo); must be > 0.

target

the desired tick count (approximate; must be >= 1).

Returns

the nice step size (> 0).

Complexity

O(1).

Allocation

none.

System testsystests/test_scale.purr
Example
import 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 numbers
fn inline ::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.

Parameters
r

the axis data range.

target

the desired tick count (approximate; must be >= 1).

Returns

the ascending tick positions within [r.lo, r.hi] (at least one).

Complexity

O(ticks).

Allocation

the returned tick array.

System testsystests/test_scale.purr
Example
import 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]
fn 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).

Parameters
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 ticks).

target

the desired tick count (approximate; must be >= 1).

Returns

the ascending tick positions within [r.lo, r.hi] (at least one).

Complexity

O(ticks).

Allocation

the returned tick array.

System testsystests/test_scale.purr
Example
import 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 marks
fn double 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.)

Parameters
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.

Returns

the pixel coordinate of value (not clamped to the span).

Complexity

O(1).

Allocation

none.

System testsystests/test_scale.purr
Example
import 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 Y
fn double 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.

Parameters
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.

Returns

the pixel coordinate of value (not clamped to the span).

Complexity

O(1).

Allocation

none.

System testsystests/test_scale.purr
Example
import 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 three
fn const char * module_abi() noexcept #

ABI/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.

Returns

the module name ("scale").