diff --git a/frontend/src/ui/common.rs b/frontend/src/ui/common.rs index c089c5d..fd165ef 100644 --- a/frontend/src/ui/common.rs +++ b/frontend/src/ui/common.rs @@ -649,8 +649,7 @@ pub fn view_chart( pub fn plot_line_chart( data: &[(Vec<(NaiveDate, f32)>, usize)], - x_min: NaiveDate, - x_max: NaiveDate, + interval: &Interval, y_min_opt: Option, y_max_opt: Option, theme: &data::Theme, @@ -682,7 +681,7 @@ pub fn plot_line_chart( .y_label_area_size(40f32); let mut chart = chart_builder.build_cartesian_2d( - x_min..x_max, + interval.first..interval.last, f32::max(0., y_min - y_margin)..y_max + y_margin, )?; @@ -724,8 +723,7 @@ pub fn plot_line_chart( pub fn plot_dual_line_chart( data: &[(Vec<(NaiveDate, f32)>, usize)], secondary_data: &[(Vec<(NaiveDate, f32)>, usize)], - x_min: NaiveDate, - x_max: NaiveDate, + interval: &Interval, theme: &data::Theme, ) -> Result, Box> { if all_zeros(data) && all_zeros(secondary_data) { @@ -761,8 +759,14 @@ pub fn plot_dual_line_chart( .x_label_area_size(30f32) .y_label_area_size(40f32) .right_y_label_area_size(40f32) - .build_cartesian_2d(x_min..x_max, y1_min - y1_margin..y1_max + y1_margin)? - .set_secondary_coord(x_min..x_max, y2_min - y2_margin..y2_max + y2_margin); + .build_cartesian_2d( + interval.first..interval.last, + y1_min - y1_margin..y1_max + y1_margin, + )? + .set_secondary_coord( + interval.first..interval.last, + y2_min - y2_margin..y2_max + y2_margin, + ); chart .configure_mesh() @@ -826,8 +830,7 @@ pub fn plot_dual_line_chart( pub fn plot_bar_chart( data: &[(Vec<(NaiveDate, f32)>, usize)], secondary_data: &[(Vec<(NaiveDate, f32)>, usize)], - x_min: NaiveDate, - x_max: NaiveDate, + interval: &Interval, y_min_opt: Option, y_max_opt: Option, single_y_domain: bool, @@ -874,10 +877,13 @@ pub fn plot_bar_chart( .y_label_area_size(40f32) .right_y_label_area_size(30f32) .build_cartesian_2d( - (x_min..x_max).into_segmented(), + (interval.first..interval.last).into_segmented(), y1_min - y1_margin..y1_max + y1_margin, )? - .set_secondary_coord(x_min..x_max, y2_min - y2_margin..y2_max + y2_margin); + .set_secondary_coord( + interval.first..interval.last, + y2_min - y2_margin..y2_max + y2_margin, + ); chart .configure_mesh() diff --git a/frontend/src/ui/page/body_fat.rs b/frontend/src/ui/page/body_fat.rs index 5df8bdb..a71f8f8 100644 --- a/frontend/src/ui/page/body_fat.rs +++ b/frontend/src/ui/page/body_fat.rs @@ -766,8 +766,7 @@ fn view_chart(model: &Model, data_model: &data::Model) -> Node { .collect::>(), common::COLOR_BODY_WEIGHT, )], - model.interval.first, - model.interval.last, + &model.interval, data_model.theme(), ), true, diff --git a/frontend/src/ui/page/body_weight.rs b/frontend/src/ui/page/body_weight.rs index a043f73..44c9d65 100644 --- a/frontend/src/ui/page/body_weight.rs +++ b/frontend/src/ui/page/body_weight.rs @@ -386,8 +386,7 @@ fn view_chart(model: &Model, data_model: &data::Model) -> Node { common::COLOR_AVG_BODY_WEIGHT, ), ], - model.interval.first, - model.interval.last, + &model.interval, None, None, data_model.theme(), diff --git a/frontend/src/ui/page/exercise.rs b/frontend/src/ui/page/exercise.rs index 930d6a5..037a57f 100644 --- a/frontend/src/ui/page/exercise.rs +++ b/frontend/src/ui/page/exercise.rs @@ -572,8 +572,7 @@ pub fn view_charts( &[("Time under tension (s)", common::COLOR_TUT)], common::plot_line_chart( &[(tut.into_iter().collect::>(), common::COLOR_TUT,)], - interval.first, - interval.last, + interval, Some(0.), Some(10.), theme, @@ -585,8 +584,7 @@ pub fn view_charts( &labels, common::plot_line_chart( &data, - interval.first, - interval.last, + interval, Some(0.), Some(10.), theme, @@ -606,8 +604,7 @@ pub fn view_charts( .collect::>(), common::COLOR_WEIGHT, )], - interval.first, - interval.last, + interval, Some(0.), Some(10.), theme, @@ -627,8 +624,7 @@ pub fn view_charts( .collect::>(), common::COLOR_TIME, )], - interval.first, - interval.last, + interval, Some(0.), Some(10.), theme, diff --git a/frontend/src/ui/page/menstrual_cycle.rs b/frontend/src/ui/page/menstrual_cycle.rs index f6bd8bb..87af870 100644 --- a/frontend/src/ui/page/menstrual_cycle.rs +++ b/frontend/src/ui/page/menstrual_cycle.rs @@ -354,8 +354,7 @@ fn view_chart(model: &Model, data_model: &data::Model) -> Node { common::COLOR_PERIOD_INTENSITY, )], &[], - model.interval.first, - model.interval.last, + &model.interval, Some(0.), Some(4.), false, diff --git a/frontend/src/ui/page/routine.rs b/frontend/src/ui/page/routine.rs index c9b17a9..6be52e6 100644 --- a/frontend/src/ui/page/routine.rs +++ b/frontend/src/ui/page/routine.rs @@ -1340,8 +1340,7 @@ pub fn view_charts( &[("Load", common::COLOR_LOAD)], common::plot_line_chart( &[(load.into_iter().collect::>(), common::COLOR_LOAD)], - interval.first, - interval.last, + interval, Some(0.), Some(10.), theme, diff --git a/frontend/src/ui/page/training.rs b/frontend/src/ui/page/training.rs index 0e1c131..a4e9627 100644 --- a/frontend/src/ui/page/training.rs +++ b/frontend/src/ui/page/training.rs @@ -535,8 +535,7 @@ pub fn view_charts( (long_term_load, common::COLOR_LONG_TERM_LOAD), (short_term_load, common::COLOR_LOAD) ], - interval.first, - interval.last, + interval, Some(0.), Some(10.), theme,