From bc79224cee4c4ed73af649be470b6cbd81915247 Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Sat, 9 Dec 2023 13:27:19 +1100 Subject: [PATCH] Add ability to toggle plot lines by clicking on corresponding label in legend --- db.py | 9 ++++----- templates/partials/sparkline.html | 17 ++++++++++------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/db.py b/db.py index ebce1ed..8f096bf 100644 --- a/db.py +++ b/db.py @@ -508,12 +508,11 @@ class DataBase(): vb_height *= 75 / vb_height # Scale to 75px height # Scale estimated_1rm values for SVG plotting - precision = 3 - estimated_1rm_scaled = [round(((value - min_e1rm) / e1rm_range) * vb_height, precision) for value in estimated_1rm] - repetitions_scaled = [round(((value - min_reps) / reps_range) * vb_height, precision) for value in repetitions] - weight_scaled = [round(((value - min_weight) / weight_range) * vb_height, precision) for value in weight] + estimated_1rm_scaled = [((value - min_e1rm) / e1rm_range) * vb_height for value in estimated_1rm] + repetitions_scaled = [((value - min_reps) / reps_range) * vb_height for value in repetitions] + weight_scaled = [((value - min_weight) / weight_range) * vb_height for value in weight] total_span = date_range.days or 1 - relative_positions = [round((date - min_date).days / total_span, precision) for date in start_dates] + relative_positions = [(date - min_date).days / total_span for date in start_dates] # Convert relative positions and scaled estimated 1RM values to numpy arrays x = np.array(relative_positions) diff --git a/templates/partials/sparkline.html b/templates/partials/sparkline.html index b843d84..bd2e8c2 100644 --- a/templates/partials/sparkline.html +++ b/templates/partials/sparkline.html @@ -1,13 +1,12 @@ -{% set fill = "#2ca02c" %} -{% set stroke = "#2ca02c" %} {% set stroke_width = 4 %} {% set margin = 2 %} +{% set precision = 1 %} {% macro path(data_points, vb_height) %} {% for value, position, message in data_points %} {% set x = (position * vb_width)+margin %} {% set y = (vb_height - value)+margin %} - {% if loop.first %}M{{ x | round(3) }} {{ y | round(3) }}{% else %} L{{ x | round(3) }} {{ y | round(3) }}{% endif %} + {% if loop.first %}M{{ x | round(precision) }} {{ y | round(precision) }}{% else %} L{{ x | round(precision) }} {{ y | round(precision) }}{% endif %} {% endfor %} {% endmacro %} @@ -15,7 +14,7 @@ {% for value, position in best_fit_points %} {% set x = (position * vb_width)+margin %} {% set y = (vb_height - value)+margin %} - {% if loop.first %}M{{ x | round(3) }} {{ y | round(3) }}{% else %} L{{ x | round(3) }} {{ y | round(3) }}{% endif %} + {% if loop.first %}M{{ x | round(precision) }} {{ y | round(precision) }}{% else %} L{{ x | round(precision) }} {{ y | round(precision) }}{% endif %} {% endfor %} {% endmacro %} @@ -23,8 +22,8 @@ {% for value, position, message in data_points %} {% set x = (position * vb_width)+margin %} {% set y = (vb_height - value)+margin %} - - + + {% endfor %} {% endmacro %} @@ -53,12 +52,16 @@ {% for plot in plots %} + {{ plot_line(plot.points, plot.color) }} + {% endfor %}
{% for plot in plots %} -
+
{{ plot.label }}