pub struct Bar<'a> {
pub at: &'a str,
pub value: usize,
pub reading: Option<&'a str>,
pub note: Option<&'a str>,
}Expand description
One magnitude in a Chart, at its place on the axis.
Carries no axis of its own on purpose: a bar read against a maximum it states itself is a meter, and a run of those is not a chart.
Fields§
§at: &'a strWhere on the axis this sits: “Mar 3”, “Week 12”.
The position’s own name rather than an index, for the reason a pager’s jump carries its page number: what a chart shows is a window over a series, and an index into that window is not the point it names.
value: usizeThe magnitude, in the chart’s units, read against Chart::most.
reading: Option<&'a str>The magnitude as the app words it: “$42.10”.
Worded rather than derived because the units are the app’s. A renderer handed 4210 cannot know it is money, let alone which money.
note: Option<&'a str>A second fact about this bar, already worded: “3 sales”.
Worded for the reason reading is, plus one of its own:
a count’s noun inflects with the count, and that is language rather than
drawing.
Implementations§
Source§impl<'a> Bar<'a>
impl<'a> Bar<'a>
Sourcepub const fn at(at: &'a str) -> Self
pub const fn at(at: &'a str) -> Self
A place on the axis, with no magnitude on it yet.
The magnitude arrives through of rather than as a second
argument, and that is not stylistic: quasi-declare stages a
constructor’s plain arguments all one way or all the other, so a
constructor taking a place AND a magnitude would have the place standing
in as a number. Split, the place is a value and of is a count, which is
the same split a pager’s of makes and the reason it is spelled the
same.
Sourcepub fn fraction(&self, chart: &Chart<'_>) -> f32
pub fn fraction(&self, chart: &Chart<'_>) -> f32
How far up the axis this bar reaches, 0.0 to 1.0, clamped.
For drawing, which is what a clamped number is good for, and for the two renderers that draw in cells and pixels rather than in CSS. An empty axis reads as 0.0 rather than dividing by zero.
A bar over Chart::most clamps, and unlike Meter that is not a
fact being lost: most is the maximum of the bars, so a bar above it is
an axis the app got wrong rather than an over-run worth drawing.