Skip to main content

Figure

Struct Figure 

Source
pub struct Figure<'a> {
    pub value: &'a str,
    pub caption: &'a str,
    pub change: Option<&'a str>,
    pub tone: Tone,
}
Expand description

One figure with a caption: a number and what it counts.

The dashboard shape. A large value over a small caption, several of them in a strip: a current streak, a completion rate, a total. Added 0.11.0, 93c6a174, after goingson turned out to have five of them across five screens with five class vocabularies for the one shape — task-overview-stat, stat-box, month-stat-item, contact-summary-stat, sync-stat. Four put the value above the caption and one inverts it, which is drift inside the shape rather than a second shape.

§Why the value is text

“17”, “84%”, “12/30”, “3d”. A figure is whatever the app computed, already formatted, and the formatting is the app’s because only it knows whether the number is a percentage, a duration or a ratio. This carries none of the arithmetic Meter carries, and that is the difference between them: a meter is a proportion a renderer draws, and a figure is a fact a renderer sets in type.

§Tone is carried, for Meter’s reason

Three of the five sites tone the figure by their own means — red/blue on the weekly review, a ${type} class on the monthly one, sync-stat-warn on sync. So tone is carried at every site that needs it and derived at none, and no renderer can work out that a streak of zero is worth colouring.

§What is not here

Whether the figure answers a click. One of the five is a control — sync’s “Not Applied: 3” opens the list — and an action is not something this crate can name: nothing here knows what a route is. That belongs beside the figure in whatever layer holds the actions, the same way a row’s activation sits beside its parts rather than inside them.

The arrangement is not here either. Several figures in a strip is a set, and a renderer given them one at a time cannot tell it is looking at one; the layer that holds the tree is where the set gets said.

Fields§

§value: &'a str

The number, formatted the way the app means it to read.

§caption: &'a str

What it counts. The caption under the value.

§change: Option<&'a str>

How the value has moved, if the app is tracking that.

Added 0.13.0. Text, for value’s reason: only the app knows whether a move reads as +12.5%, +3 or 2x, and a renderer handed a number would have to guess.

This is what tone was for and had no consumer of. The MNW server has four screens whose stat card is a label, a value and a delta, and the delta is the toned part: the figure itself is an ordinary fact and it is the movement that reads as good or bad. Without this the delta has to be folded into the caption, which loses the tone and reads as a longer caption rather than as a second, smaller line.

§tone: Tone

What the figure means right now. Tone::Neutral is an ordinary fact.

Applies to change where there is one, since that is the part that carries the judgement, and to the value where there is not.

Implementations§

Source§

impl<'a> Figure<'a>

Source

pub const fn new(value: &'a str, caption: &'a str) -> Self

A figure that is an ordinary fact.

Source

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

How the value has moved.

Source

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

What the figure means.

Trait Implementations§

Source§

impl<'a> Clone for Figure<'a>

Source§

fn clone(&self) -> Figure<'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 Figure<'a>

Source§

impl<'a> Debug for Figure<'a>

Source§

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

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

impl<'a> Eq for Figure<'a>

Source§

impl<'a> Hash for Figure<'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 Figure<'a>

Source§

fn eq(&self, other: &Figure<'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 Figure<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Figure<'a>

§

impl<'a> RefUnwindSafe for Figure<'a>

§

impl<'a> Send for Figure<'a>

§

impl<'a> Sync for Figure<'a>

§

impl<'a> Unpin for Figure<'a>

§

impl<'a> UnsafeUnpin for Figure<'a>

§

impl<'a> UnwindSafe for Figure<'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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.