use std::borrow::Cow;
use tui::{layout::Constraint, symbols::Marker};
use crate::{
app::AppConfigFields,
canvas::components::time_graph::{
AxisBound, ChartScaling, LegendPosition, TimeGraph, variants::get_border_style,
},
options::config::style::Styles,
};
pub(crate) struct PercentTimeGraph<'a> {
pub(crate) display_range: u64,
pub(crate) hide_x_labels: bool,
pub(crate) app_config_fields: &'a AppConfigFields,
pub(crate) current_widget: u64,
pub(crate) is_expanded: bool,
pub(crate) title: Cow<'a, str>,
pub(crate) styles: &'a Styles,
pub(crate) widget_id: u64,
pub(crate) legend_position: Option<LegendPosition>,
pub(crate) legend_constraints: Option<(Constraint, Constraint)>,
}
impl<'a> PercentTimeGraph<'a> {
pub fn build(self) -> TimeGraph<'a> {
const Y_BOUNDS: AxisBound = AxisBound::Max(100.5);
const Y_LABELS: [Cow<'static, str>; 2] = [Cow::Borrowed(" 0%"), Cow::Borrowed("100%")];
let x_min = -(self.display_range as f64);
let marker = if self.app_config_fields.use_dot {
Marker::Dot
} else {
Marker::Braille
};
let graph_style = self.styles.graph_style;
let border_style = get_border_style(self.styles, self.widget_id, self.current_widget);
let title_style = self.styles.widget_title_style;
let border_type = self.styles.border_type;
TimeGraph {
x_min,
hide_x_labels: self.hide_x_labels,
y_bounds: Y_BOUNDS,
y_labels: &Y_LABELS,
graph_style,
border_style,
border_type,
title: self.title,
is_selected: self.current_widget == self.widget_id,
is_expanded: self.is_expanded,
title_style,
legend_position: self.legend_position,
legend_constraints: self.legend_constraints,
marker,
scaling: ChartScaling::Linear,
}
}
}