Skip to main content

Chart

Struct Chart 

Source
pub struct Chart<'a> {
    pub most: usize,
    pub label: Option<&'a str>,
    pub tone: Tone,
}
Expand description

A run of magnitudes read against one axis.

Meter is one proportion; this is a series of them that share a maximum, and the shared maximum is the whole difference. A run of meters draws each bar against its own total, so a chart said that way states the axis once per bar and nothing holds the copies together. Here the axis is stated once and a bar carries only where it sits on it.

§Why the axis and not a percentage per bar

Meter’s reason, one layer out. The app that drew MNW’s revenue chart computed revenue / most * 100.0 and put the percentage in the markup, and what reached the reader was a width with no numbers behind it: a bar at 100% because it is the largest and a bar at 100% because the axis is wrong are the same width and are not the same fact. Carrying both integers keeps the fact, and Bar::fraction is one call away for a renderer that wants the ratio.

It is also the only shape that survives a compiled template. A residual holds numbers the description HANDS a renderer, never ones a renderer works out from two of them, so a chart drawn from a supplied percentage could be described and could not be compiled. See quasi_router::stage::number_at.

§What is worded here and what is not

Bar::at is where the bar sits on the axis and label is what the magnitudes are, which is Meter::label’s split exactly. What differs is Bar::reading and Bar::note: both arrive already worded, because a magnitude’s own units are the app’s (“$42.10”, not 4210) and a count’s noun inflects (“1 sale”, “3 sales”). A renderer that pluralised would be growing a lexer for one language.

Fields§

§most: usize

The magnitude the axis runs to. Every bar is read against this.

Zero means there is no axis, not that every bar is full. A renderer draws nothing rather than dividing by it; see is_empty.

usize because that is what a description counts in – a pager’s offset and page size are the same – and because it is the only width quasi_router::stage::number_at has a stand-in for, which is what lets a chart reach a compiled template at all.

§label: Option<&'a str>

What the magnitudes are: “revenue”, “plays”.

The noun, not the unit and not the ratio. The unit is already in each Bar::reading, where it belongs, because only the app knows it.

§tone: Tone

What the axis means, where it means anything.

Implementations§

Source§

impl<'a> Chart<'a>

Source

pub const fn new(most: usize) -> Self

An axis running to most, untoned and unlabelled.

Source

pub const fn label(self, label: &'a str) -> Self

What the magnitudes are.

Source

pub const fn tone(self, tone: Tone) -> Self

What the axis means.

Source

pub const fn is_empty(&self) -> bool

Whether there is an axis to read against.

Meter::is_empty’s case: an axis running to zero is what an app with nothing to chart actually has, and saying so beats dividing by it.

Trait Implementations§

Source§

impl<'a> Clone for Chart<'a>

Source§

fn clone(&self) -> Chart<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for Chart<'a>

Source§

impl<'a> Debug for Chart<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Eq for Chart<'a>

Source§

impl<'a> Hash for Chart<'a>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a> PartialEq for Chart<'a>

Source§

fn eq(&self, other: &Chart<'a>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<'a> StructuralPartialEq for Chart<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Chart<'a>

§

impl<'a> RefUnwindSafe for Chart<'a>

§

impl<'a> Send for Chart<'a>

§

impl<'a> Sync for Chart<'a>

§

impl<'a> Unpin for Chart<'a>

§

impl<'a> UnsafeUnpin for Chart<'a>

§

impl<'a> UnwindSafe for Chart<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.