packages

plot::ticks

Tick locators. Linear axes use the extended Wilkinson algorithm (Talbot, Lin and Hanrahan, "An Extension of Wilkinson's Algorithm for Positioning Tick Labels on Axes", InfoVis 2010), as R's labeling::extended; log axes put majors on powers of the base; date axes pick a calendar unit (calendar.nabi).

Functions

extendedSource

pub fn extended(dmin: f64, dmax: f64, m: usize, only_loose: bool = false) -> List<f64>

Nice tick values covering [dmin, dmax] with about m ticks, by the extended Wilkinson search: the best weighted sum of simplicity (steps 1, 5, 2, 2.5, 4, 3 times a power of ten, zero included), coverage of the data range, density near m and legibility. The result can reach past the range; only_loose makes it cover the range. O(m) candidates a step size; the search stops by the paper's bounds.

nabi
use plot::ticks::extended;

assert(extended(0.0, 100.0, 5) == [0.0, 25.0, 50.0, 75.0, 100.0]);
assert(extended(1.0, 10.0, 5) == [0.0, 2.5, 5.0, 7.5, 10.0]);
assert(extended(-3.7, 12.2, 7)[0] == -2.5);

locateSource

pub fn locate(scale: Scale, lo: f64, hi: f64, m: usize) -> (List<f64>, List<f64>)

Major and minor ticks for a view [lo, hi] on scale, about m majors. Every tick returned lies in the view.

nabi
use plot::Scale;
use plot::ticks::locate;

let (major, minor) = locate(Scale::Log(10.0), 1.0, 1000.0, 5);
assert(major == [1.0, 10.0, 100.0, 1000.0]);
assert(minor.len() == 24);