Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Area and band plots #67

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ chrono = { version = "0.4.20", default-features = false, features = ["serde", "w
gloo-console = "0.3.0"
gloo-net = { version = "0.6.0", default-features = false, features = ["http", "json"] }
gloo-storage = "0.3.0"
plotters = { version = "0.3.2", default-features = false, features = ["svg_backend", "datetime", "line_series", "histogram", "point_series"] }
plotters = { version = "0.3.2", default-features = false, features = ["svg_backend", "datetime", "line_series", "histogram", "point_series", "area_series"] }
seed = "0.8"
serde = "1.0"
serde_json = "1.0"
Expand Down
311 changes: 249 additions & 62 deletions frontend/src/ui/common.rs

Large diffs are not rendered by default.

24 changes: 13 additions & 11 deletions frontend/src/ui/page/body_fat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,40 +740,42 @@ fn view_chart(model: &Model, data_model: &data::Model) -> Node<Msg> {

common::view_chart(
vec![
("JP3 (%)", common::COLOR_BODY_FAT_JP3),
("JP7 (%)", common::COLOR_BODY_FAT_JP7),
("Weight (kg)", common::COLOR_BODY_WEIGHT),
("JP3 (%)", common::COLOR_BODY_FAT_JP3, 0.9),
("JP7 (%)", common::COLOR_BODY_FAT_JP7, 0.9),
("Weight (kg)", common::COLOR_BODY_WEIGHT, 0.9),
]
.as_slice(),
common::plot_chart(
&[
common::PlotData {
values: body_weight
values_high: body_weight
.iter()
.map(|bw| (bw.date, bw.weight))
.collect::<Vec<_>>(),
plots: common::plot_line_with_dots(common::COLOR_BODY_WEIGHT),
values_low: None,
plots: common::plot_line(common::COLOR_BODY_WEIGHT, 0.9),
params: common::PlotParams::SECONDARY,
},
common::PlotData {
values: body_fat
values_high: body_fat
.iter()
.filter_map(|bf| bf.jp3(sex).map(|jp3| (bf.date, jp3)))
.collect::<Vec<_>>(),
plots: common::plot_line_with_dots(common::COLOR_BODY_FAT_JP3),
values_low: None,
plots: common::plot_line(common::COLOR_BODY_FAT_JP3, 0.9),
params: common::PlotParams::default(),
},
common::PlotData {
values: body_fat
values_high: body_fat
.iter()
.filter_map(|bf| bf.jp7(sex).map(|jp7| (bf.date, jp7)))
.collect::<Vec<_>>(),
plots: common::plot_line_with_dots(common::COLOR_BODY_FAT_JP7),
values_low: None,
plots: common::plot_line(common::COLOR_BODY_FAT_JP7, 0.9),
params: common::PlotParams::default(),
},
],
model.interval.first,
model.interval.last,
&model.interval,
data_model.theme(),
),
true,
Expand Down
31 changes: 16 additions & 15 deletions frontend/src/ui/page/body_weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,41 +357,42 @@ fn view_body_weight_dialog(dialog: &Dialog, loading: bool) -> Node<Msg> {
}

fn view_chart(model: &Model, data_model: &data::Model) -> Node<Msg> {
let avg_body_weight = data_model
.avg_body_weight
.values()
.filter(|bw| bw.date >= model.interval.first && bw.date <= model.interval.last)
.map(|bw| (bw.date, bw.weight))
.collect::<Vec<_>>();

common::view_chart(
vec![
("Weight (kg)", common::COLOR_BODY_WEIGHT),
("Avg. weight (kg)", common::COLOR_AVG_BODY_WEIGHT),
("Weight (kg)", common::COLOR_BODY_WEIGHT, 0.3),
("Avg. weight (kg)", common::COLOR_AVG_BODY_WEIGHT, 0.9),
]
.as_slice(),
common::plot_chart(
&[
common::PlotData {
values: data_model
values_high: data_model
.body_weight
.values()
.filter(|bw| {
bw.date >= model.interval.first && bw.date <= model.interval.last
})
.map(|bw| (bw.date, bw.weight))
.collect::<Vec<_>>(),
plots: common::plot_line_with_dots(common::COLOR_BODY_WEIGHT),
values_low: Some(avg_body_weight.clone()),
plots: common::plot_area(common::COLOR_BODY_WEIGHT, 0.3),
params: common::PlotParams::default(),
},
common::PlotData {
values: data_model
.avg_body_weight
.values()
.filter(|bw| {
bw.date >= model.interval.first && bw.date <= model.interval.last
})
.map(|bw| (bw.date, bw.weight))
.collect::<Vec<_>>(),
plots: common::plot_line_with_dots(common::COLOR_AVG_BODY_WEIGHT),
values_high: avg_body_weight,
values_low: None,
plots: common::plot_line(common::COLOR_AVG_BODY_WEIGHT, 0.9),
params: common::PlotParams::default(),
},
],
model.interval.first,
model.interval.last,
&model.interval,
data_model.theme(),
),
true,
Expand Down
164 changes: 92 additions & 72 deletions frontend/src/ui/page/exercise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,129 +490,149 @@ pub fn view_charts<Ms>(
}
}

let mut labels = vec![("Repetitions", common::COLOR_REPS)];
let mut labels = vec![("Repetitions", common::COLOR_REPS, 0.9)];
let reps_rpe_values = reps_rpe
.iter()
.map(|(date, (avg_reps, _))| {
#[allow(clippy::cast_precision_loss)]
(*date, avg_reps.iter().sum::<f32>() / avg_reps.len() as f32)
})
.collect::<Vec<_>>();

let mut data = vec![common::PlotData {
values: reps_rpe
.iter()
.map(|(date, (avg_reps, _))| {
#[allow(clippy::cast_precision_loss)]
(*date, avg_reps.iter().sum::<f32>() / avg_reps.len() as f32)
})
.collect::<Vec<_>>(),
plots: common::plot_line_with_dots(common::COLOR_REPS),
params: common::PlotParams::primary_range(0., 10.),
}];
let mut data = vec![];

if show_rpe {
labels.push(("+ Repetitions in reserve", common::COLOR_REPS_RIR));
data.push(common::PlotData {
values: reps_rpe
.into_iter()
.filter_map(|(date, (avg_reps_values, avg_rpe_values))| {
#[allow(clippy::cast_precision_loss)]
let avg_reps =
avg_reps_values.iter().sum::<f32>() / avg_reps_values.len() as f32;
#[allow(clippy::cast_precision_loss)]
let avg_rpe = avg_rpe_values.iter().sum::<f32>() / avg_rpe_values.len() as f32;
if avg_rpe_values.is_empty() {
None
} else {
Some((date, avg_reps + 10.0 - avg_rpe))
}
})
.collect::<Vec<_>>(),
plots: common::plot_line_with_dots(common::COLOR_REPS_RIR),
params: common::PlotParams::primary_range(0., 10.),
});
let rir_values = reps_rpe
.into_iter()
.filter_map(|(date, (avg_reps_values, avg_rpe_values))| {
#[allow(clippy::cast_precision_loss)]
let avg_reps = avg_reps_values.iter().sum::<f32>() / avg_reps_values.len() as f32;
#[allow(clippy::cast_precision_loss)]
let avg_rpe = avg_rpe_values.iter().sum::<f32>() / avg_rpe_values.len() as f32;
if avg_rpe_values.is_empty() {
None
} else {
Some((date, avg_reps + 10.0 - avg_rpe))
}
})
.collect::<Vec<_>>();
if !rir_values.is_empty() {
labels.push(("+ Repetitions in reserve", common::COLOR_REPS_RIR, 0.3));
data.push(common::PlotData {
values_high: rir_values,
values_low: Some(reps_rpe_values.clone()),
plots: common::plot_area_with_border(
common::COLOR_REPS_RIR,
common::COLOR_REPS_RIR,
0.3,
0,
),
params: common::PlotParams::primary_range(0., 10.),
});
}
}

data.push(common::PlotData {
values_high: reps_rpe_values,
values_low: None,
plots: common::plot_line(common::COLOR_REPS, 0.9),
params: common::PlotParams::primary_range(0., 10.),
});

nodes![
common::view_chart(
&[("Set volume", common::COLOR_SET_VOLUME)],
&[("Set volume", common::COLOR_SET_VOLUME, 0.9)],
common::plot_chart(
&[common::PlotData {
values: set_volume.into_iter().collect::<Vec<_>>(),
plots: common::plot_line_with_dots(common::COLOR_SET_VOLUME),
values_high: set_volume.into_iter().collect::<Vec<_>>(),
values_low: None,
plots: common::plot_area_with_border(
common::COLOR_SET_VOLUME,
common::COLOR_SET_VOLUME,
0.3,
2
),
params: common::PlotParams::primary_range(0., 10.),
}],
interval.first,
interval.last,
interval,
theme,
),
false,
),
common::view_chart(
&[("Volume load", common::COLOR_VOLUME_LOAD)],
&[("Volume load", common::COLOR_VOLUME_LOAD, 0.9)],
common::plot_chart(
&[common::PlotData {
values: volume_load.into_iter().collect::<Vec<_>>(),
plots: common::plot_line_with_dots(common::COLOR_VOLUME_LOAD),
values_high: volume_load.into_iter().collect::<Vec<_>>(),
values_low: None,
plots: common::plot_area_with_border(
common::COLOR_VOLUME_LOAD,
common::COLOR_VOLUME_LOAD,
0.3,
2
),
params: common::PlotParams::primary_range(0., 10.),
}],
interval.first,
interval.last,
interval,
theme,
),
false,
),
IF![show_tut =>
common::view_chart(
&[("Time under tension (s)", common::COLOR_TUT)],
&[("Time under tension (s)", common::COLOR_TUT, 0.9)],
common::plot_chart(
&[common::PlotData {
values: tut.into_iter().collect::<Vec<_>>(),
plots: common::plot_line_with_dots(common::COLOR_TUT),
values_high: tut.into_iter().collect::<Vec<_>>(),
values_low: None,
plots: common::plot_line(common::COLOR_TUT, 0.9),
params: common::PlotParams::primary_range(0., 10.),
}],
interval.first,
interval.last,
interval,
theme,
),
false,
)
],
common::view_chart(&labels, common::plot_chart(&data, interval, theme), false,),
common::view_chart(
&labels,
common::plot_chart(&data, interval.first, interval.last, theme),
false,
),
common::view_chart(
&[("Weight (kg)", common::COLOR_WEIGHT)],
common::plot_chart(
&[common::PlotData {
values: weight
.into_iter()
.map(|(date, values)| {
#[allow(clippy::cast_precision_loss)]
(date, values.iter().sum::<f32>() / values.len() as f32)
})
.collect::<Vec<_>>(),
plots: common::plot_line_with_dots(common::COLOR_WEIGHT),
params: common::PlotParams::primary_range(0., 10.),
}],
interval.first,
interval.last,
&[
("Weight (kg)", common::COLOR_WEIGHT, 0.3),
("Avg. weight (kg)", common::COLOR_WEIGHT, 0.9)
],
common::plot_series_with_average(
&weight
.into_iter()
.map(|(date, values)| {
#[allow(clippy::cast_precision_loss)]
(date, values.iter().sum::<f32>() / values.len() as f32)
})
.collect::<Vec<_>>(),
7,
(common::COLOR_WEIGHT, 0.3),
theme,
interval,
Some(0.),
Some(10.),
),
false,
),
IF![show_tut =>
common::view_chart(
&[("Time (s)", common::COLOR_TIME)],
&[("Time (s)", common::COLOR_TIME, 0.9)],
common::plot_chart(
&[common::PlotData{
values: time.into_iter()
values_high: time.into_iter()
.map(|(date, values)| {
#[allow(clippy::cast_precision_loss)]
(date, values.iter().sum::<f32>() / values.len() as f32)
})
.collect::<Vec<_>>(),
plots: common::plot_line_with_dots(common::COLOR_TIME),
values_low: None,
plots: common::plot_line(common::COLOR_TIME, 0.9),
params: common::PlotParams::primary_range(0., 10.)
}],
interval.first,
interval.last,
interval,
theme,
),
false,
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/ui/page/menstrual_cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,18 +347,18 @@ fn view_chart(model: &Model, data_model: &data::Model) -> Node<Msg> {
.collect::<Vec<_>>();

common::view_chart(
vec![("Intensity", common::COLOR_PERIOD_INTENSITY)].as_slice(),
vec![("Intensity", common::COLOR_PERIOD_INTENSITY, 0.9)].as_slice(),
common::plot_chart(
&[common::PlotData {
values: period
values_high: period
.iter()
.map(|p| (p.date, f32::from(p.intensity)))
.collect::<Vec<_>>(),
plots: [common::PlotType::Histogram(common::COLOR_PERIOD_INTENSITY)].to_vec(),
values_low: None,
plots: vec![common::PlotType::Histogram(common::COLOR_PERIOD_INTENSITY, 0.9)],
params: common::PlotParams::primary_range(0., 4.),
}],
model.interval.first,
model.interval.last,
&model.interval,
data_model.theme(),
),
true,
Expand Down
15 changes: 10 additions & 5 deletions frontend/src/ui/page/muscles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,20 @@ pub fn view(model: &Model, data_model: &data::Model) -> Node<Msg> {
m.description()
],
common::view_chart(
&[("Set volume (7 day total)", common::COLOR_SET_VOLUME)],
&[("Set volume (7 day total)", common::COLOR_SET_VOLUME, 0.9)],
common::plot_chart(
&[common::PlotData {
values: total_7day_set_volume,
plots: common::plot_line(common::COLOR_SET_VOLUME),
values_high: total_7day_set_volume,
values_low: None,
plots: common::plot_area_with_border(
common::COLOR_SET_VOLUME,
common::COLOR_SET_VOLUME,
0.3,
2
),
params: common::PlotParams::primary_range(0., 10.),
}],
model.interval.first,
model.interval.last,
&model.interval,
data_model.theme()
),
true,
Expand Down
Loading