plot::format
Tick label formatters. Labels may hold $..$ math markup (powers of
ten as $10^{3}$), which the text layout sets as superscripts. A
minus sign is U+2212, as in typeset mathematics.
Enums
FormatSource
pub enum FormatHow tick values become labels.
use plot::Format;
use plot::format::label;
assert(label(1500.0, Format::Si) == "1.5k");
assert(label(0.25, Format::Percent) == "25%");
assert(label(-2.5, Format::Fixed(2)) == "\u{2212}2.50");
As many decimals as the tick step needs; a shared
x10^kat the end of the axis for values from a million up or below 1e-3; powers of the base on log axes; calendar labels on date axes.This many decimals.
Each label as
m x 10^k.SI prefixes:
1.5k,20M,500µ.The value times 100 with
%.Your own function of the value.
Trait implementations 2
impl Debug for Formatimpl Clone for Format
Functions
labelSource
pub fn label(v: f64, fmt: Format) -> str One label for v with fmt, without the context of the other ticks
(Auto uses the shortest exact form).
assert(plot::format::label(0.5, plot::Format::Auto) == "0.5");
labelsSource
pub fn labels(ticks: List<f64>, scale: Scale, fmt: Format) -> (List<str>, str) Labels for a run of ticks on scale, and the offset text shown at
the end of the axis ("" for none).
use plot::{Format, Scale};
use plot::format::labels;
let (l, off) = labels([0.0, 0.5, 1.0], Scale::Linear, Format::Auto);
assert(l == ["0.0", "0.5", "1.0"] && off == "");
let (l, off) = labels([0.0, 2e6, 4e6], Scale::Linear, Format::Auto);
assert(l == ["0", "2", "4"] && off == "$\\times10^{6}$");
let (l, _) = labels([1.0, 10.0, 100.0], Scale::Log(10.0), Format::Auto);
assert(l[2] == "$10^{2}$");
fixedSource
pub fn fixed(v: f64, d: usize) -> str v with d decimals, rounded half away from zero; plain ASCII
minus.
assert(plot::format::fixed(2.345, 2) == "2.35");
assert(plot::format::fixed(-0.004, 2) == "0.00");
assert(plot::format::fixed(1e20, 0) == "100000000000000000000");