Skip to content

Commit

Permalink
Use interval instead of explicit min/max in plot functions
Browse files Browse the repository at this point in the history
  • Loading branch information
senier committed Nov 6, 2024
1 parent e1fb657 commit 1dd6a98
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 29 deletions.
28 changes: 17 additions & 11 deletions frontend/src/ui/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,7 @@ pub fn view_chart<Ms>(

pub fn plot_line_chart(
data: &[(Vec<(NaiveDate, f32)>, usize)],
x_min: NaiveDate,
x_max: NaiveDate,
interval: &Interval,
y_min_opt: Option<f32>,
y_max_opt: Option<f32>,
theme: &data::Theme,
Expand Down Expand Up @@ -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,
)?;

Expand Down Expand Up @@ -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<Option<String>, Box<dyn std::error::Error>> {
if all_zeros(data) && all_zeros(secondary_data) {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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<f32>,
y_max_opt: Option<f32>,
single_y_domain: bool,
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/ui/page/body_fat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,8 +766,7 @@ fn view_chart(model: &Model, data_model: &data::Model) -> Node<Msg> {
.collect::<Vec<_>>(),
common::COLOR_BODY_WEIGHT,
)],
model.interval.first,
model.interval.last,
&model.interval,
data_model.theme(),
),
true,
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/ui/page/body_weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,7 @@ fn view_chart(model: &Model, data_model: &data::Model) -> Node<Msg> {
common::COLOR_AVG_BODY_WEIGHT,
),
],
model.interval.first,
model.interval.last,
&model.interval,
None,
None,
data_model.theme(),
Expand Down
12 changes: 4 additions & 8 deletions frontend/src/ui/page/exercise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,7 @@ pub fn view_charts<Ms>(
&[("Time under tension (s)", common::COLOR_TUT)],
common::plot_line_chart(
&[(tut.into_iter().collect::<Vec<_>>(), common::COLOR_TUT,)],
interval.first,
interval.last,
interval,
Some(0.),
Some(10.),
theme,
Expand All @@ -585,8 +584,7 @@ pub fn view_charts<Ms>(
&labels,
common::plot_line_chart(
&data,
interval.first,
interval.last,
interval,
Some(0.),
Some(10.),
theme,
Expand All @@ -606,8 +604,7 @@ pub fn view_charts<Ms>(
.collect::<Vec<_>>(),
common::COLOR_WEIGHT,
)],
interval.first,
interval.last,
interval,
Some(0.),
Some(10.),
theme,
Expand All @@ -627,8 +624,7 @@ pub fn view_charts<Ms>(
.collect::<Vec<_>>(),
common::COLOR_TIME,
)],
interval.first,
interval.last,
interval,
Some(0.),
Some(10.),
theme,
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/ui/page/menstrual_cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,7 @@ fn view_chart(model: &Model, data_model: &data::Model) -> Node<Msg> {
common::COLOR_PERIOD_INTENSITY,
)],
&[],
model.interval.first,
model.interval.last,
&model.interval,
Some(0.),
Some(4.),
false,
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/ui/page/routine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1340,8 +1340,7 @@ pub fn view_charts<Ms>(
&[("Load", common::COLOR_LOAD)],
common::plot_line_chart(
&[(load.into_iter().collect::<Vec<_>>(), common::COLOR_LOAD)],
interval.first,
interval.last,
interval,
Some(0.),
Some(10.),
theme,
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/ui/page/training.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,7 @@ pub fn view_charts<Ms>(
(long_term_load, common::COLOR_LONG_TERM_LOAD),
(short_term_load, common::COLOR_LOAD)
],
interval.first,
interval.last,
interval,
Some(0.),
Some(10.),
theme,
Expand Down

0 comments on commit 1dd6a98

Please sign in to comment.