pub struct StatItem {
pub label: Text,
pub value: Text,
pub sub: Option<Text>,
pub tone: Option<Tone>,
pub title: Option<String>,
}Expand description
One tile of a stats well.
Fields§
§label: TextWhat is counted.
value: TextThe figure.
sub: Option<Text>A note under the figure.
tone: Option<Tone>Colors the figure.
title: Option<String>The tooltip.
Implementations§
Source§impl StatItem
impl StatItem
Sourcepub fn new(label: impl Into<Text>, value: impl Into<Text>) -> Self
pub fn new(label: impl Into<Text>, value: impl Into<Text>) -> Self
A tile showing value under label.
Examples found in repository?
examples/dashboard.rs (line 746)
727 fn stats(&self) -> ui::Stats<Msg> {
728 let total = self.services.len();
729 let healthy = self
730 .services
731 .iter()
732 .filter(|s| s.health == Health::Healthy)
733 .count();
734 let deploys = |state| self.deploys.iter().filter(|d| d.state == state).count();
735 let open = self
736 .incidents
737 .iter()
738 .filter(|i| i.phase != Phase::Resolved)
739 .count();
740 let unacked = self
741 .incidents
742 .iter()
743 .filter(|i| i.phase == Phase::Open)
744 .count();
745 let rps: f64 = self.services.iter().filter_map(|s| s.rps.last()).sum();
746 let mut services = StatItem::new("Healthy", format!("{healthy}/{total}")).sub("services");
747 if healthy < total {
748 services = services.tone(Tone::Warning);
749 }
750 let mut incidents =
751 StatItem::new("Open incidents", open.to_string()).sub(format!("{unacked} unacknowledged"));
752 if unacked > 0 {
753 incidents = incidents.tone(Tone::Error);
754 }
755 ui::stats([
756 services,
757 StatItem::new("Rolling out", deploys(State::Running).to_string())
758 .sub(format!("{} need approval", deploys(State::Waiting))),
759 incidents,
760 StatItem::new("Traffic", format!("{rps:.0}")).sub("req/s"),
761 ])
762 }Sourcepub fn sub(self, sub: impl Into<Text>) -> Self
pub fn sub(self, sub: impl Into<Text>) -> Self
Sets the note under the figure.
Examples found in repository?
examples/dashboard.rs (line 746)
727 fn stats(&self) -> ui::Stats<Msg> {
728 let total = self.services.len();
729 let healthy = self
730 .services
731 .iter()
732 .filter(|s| s.health == Health::Healthy)
733 .count();
734 let deploys = |state| self.deploys.iter().filter(|d| d.state == state).count();
735 let open = self
736 .incidents
737 .iter()
738 .filter(|i| i.phase != Phase::Resolved)
739 .count();
740 let unacked = self
741 .incidents
742 .iter()
743 .filter(|i| i.phase == Phase::Open)
744 .count();
745 let rps: f64 = self.services.iter().filter_map(|s| s.rps.last()).sum();
746 let mut services = StatItem::new("Healthy", format!("{healthy}/{total}")).sub("services");
747 if healthy < total {
748 services = services.tone(Tone::Warning);
749 }
750 let mut incidents =
751 StatItem::new("Open incidents", open.to_string()).sub(format!("{unacked} unacknowledged"));
752 if unacked > 0 {
753 incidents = incidents.tone(Tone::Error);
754 }
755 ui::stats([
756 services,
757 StatItem::new("Rolling out", deploys(State::Running).to_string())
758 .sub(format!("{} need approval", deploys(State::Waiting))),
759 incidents,
760 StatItem::new("Traffic", format!("{rps:.0}")).sub("req/s"),
761 ])
762 }Sourcepub fn tone(self, tone: impl Into<Tone>) -> Self
pub fn tone(self, tone: impl Into<Tone>) -> Self
Sets the figure’s tone.
Examples found in repository?
examples/dashboard.rs (line 748)
727 fn stats(&self) -> ui::Stats<Msg> {
728 let total = self.services.len();
729 let healthy = self
730 .services
731 .iter()
732 .filter(|s| s.health == Health::Healthy)
733 .count();
734 let deploys = |state| self.deploys.iter().filter(|d| d.state == state).count();
735 let open = self
736 .incidents
737 .iter()
738 .filter(|i| i.phase != Phase::Resolved)
739 .count();
740 let unacked = self
741 .incidents
742 .iter()
743 .filter(|i| i.phase == Phase::Open)
744 .count();
745 let rps: f64 = self.services.iter().filter_map(|s| s.rps.last()).sum();
746 let mut services = StatItem::new("Healthy", format!("{healthy}/{total}")).sub("services");
747 if healthy < total {
748 services = services.tone(Tone::Warning);
749 }
750 let mut incidents =
751 StatItem::new("Open incidents", open.to_string()).sub(format!("{unacked} unacknowledged"));
752 if unacked > 0 {
753 incidents = incidents.tone(Tone::Error);
754 }
755 ui::stats([
756 services,
757 StatItem::new("Rolling out", deploys(State::Running).to_string())
758 .sub(format!("{} need approval", deploys(State::Waiting))),
759 incidents,
760 StatItem::new("Traffic", format!("{rps:.0}")).sub("req/s"),
761 ])
762 }Trait Implementations§
impl Eq for StatItem
impl StructuralPartialEq for StatItem
Auto Trait Implementations§
impl Freeze for StatItem
impl RefUnwindSafe for StatItem
impl Send for StatItem
impl Sync for StatItem
impl Unpin for StatItem
impl UnsafeUnpin for StatItem
impl UnwindSafe for StatItem
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.