pub struct Stat { /* private fields */ }Expand description
One figure of a stats row: what it counts, the value, and optionally a line
under it, an icon, a link, a trend and a sparkline.
Stat::new("Revenue", "$12,400")
.detail("8% more than last month")
.trend(Trend::Up)
.color(Color::Success)
.chart([9.1, 10.2, 11.0, 12.4]);Implementations§
Source§impl Stat
impl Stat
Sourcepub async fn records<R: Resource>(cx: &Cx) -> Result<Option<Self>>
pub async fn records<R: Resource>(cx: &Cx) -> Result<Option<Self>>
How many records of R the request may see, under R’s sidebar label and icon, linking to
its list; None when the request may not open that list, so no tile counts records it
cannot see or links to a list that would answer 403.
The count reads scoped_query: the caller’s tenant, R’s
query, and no trashed record.
§Errors
The database’s, when the count fails.
Source§impl Stat
impl Stat
Sourcepub fn new(label: impl Into<Text>, value: impl Into<String>) -> Self
pub fn new(label: impl Into<Text>, value: impl Into<String>) -> Self
A figure labelled label, with value already formatted: "1,204", "98%".
Sourcepub fn detail(self, detail: impl Into<Text>) -> Self
pub fn detail(self, detail: impl Into<Text>) -> Self
The line under the value, such as "12 this week".
Sourcepub fn href(self, href: impl Into<String>) -> Self
pub fn href(self, href: impl Into<String>) -> Self
The URL the whole tile links to, such as the list the figure counts.
Sourcepub fn trend(self, trend: Trend) -> Self
pub fn trend(self, trend: Trend) -> Self
Which way the figure moved, as an arrow before the detail line; a stat with no detail line shows none.
Sourcepub fn color(self, color: Color) -> Self
pub fn color(self, color: Color) -> Self
The color of the detail line and the sparkline; defaults to Color::Gray, muted. A
trend is good or bad only for the figure it moves, so the color is the caller’s to pick.
Sourcepub fn chart(self, values: impl IntoIterator<Item = f64>) -> Self
pub fn chart(self, values: impl IntoIterator<Item = f64>) -> Self
The values the tile draws as a sparkline under the value, oldest first. Fewer than two finite values draw none.