Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Feature: Bmi on graph at weight overview Issue(#462)

Svn-Sp2dbf8f0db3cc
diff --git a/wger/weight/static/js/weight.js b/wger/weight/static/js/weight.js
index 742024d8a..1fbe75446 100644
--- a/wger/weight/static/js/weight.js
+++ b/wger/weight/static/js/weight.js
@@ -78,6 +78,40 @@ $(document).ready(function () {
chartParams.data = data;
MG.data_graphic(chartParams);
}
+ });
+ //show bmi lines
+ $(document.querySelector("#enable_bmi")).click(function(){
+ var height = document.querySelector("#height").value / 100;
+ //kg = bmi * cm²
+ var max = height*height * 25;
+ var min = height*height * 20;
+ var yAxisChildren = document.querySelector("#weight_diagram").querySelector("svg").querySelector(".mg-y-axis").children;
+ //get index of first text element
+ for(let i = 0; i<yAxisChildren.length; i++){
+ if(yAxisChildren[i].tagName=="text"){
+ var firstTextIndex = i;
+ break;
+ }
+ }
+ //calculate the y pos of the two lines
+ var pxDifference = parseFloat(yAxisChildren[firstTextIndex + 1].attributes["y"].value) - parseFloat(yAxisChildren[firstTextIndex].attributes["y"].value);
+ var kgDifference = parseFloat(yAxisChildren[firstTextIndex + 1].textContent) - parseFloat(yAxisChildren[firstTextIndex].textContent);
+ var pxPerKg = pxDifference / kgDifference;
+ var kgLowestToMin = min - parseFloat(yAxisChildren[firstTextIndex].textContent);
+ var minYPos = parseFloat(yAxisChildren[firstTextIndex].attributes["y"].value) + (kgLowestToMin * pxPerKg);
+ var kgLowestToMax = max - parseFloat(yAxisChildren[firstTextIndex].textContent);
+ var maxYPos = parseFloat(yAxisChildren[firstTextIndex].attributes["y"].value) + (kgLowestToMax * pxPerKg);
+ var minMaxYPos = [minYPos, maxYPos];
+ //create & draw lines
+ var ns = 'http://www.w3.org/2000/svg';
+ for(let i of minMaxYPos){
+ var line = document.createElementNS(ns, 'line');
+ line.setAttributeNS(null, "x1", 30);
+ line.setAttributeNS(null, "x2", 720);
+ line.setAttributeNS(null,"y1", i );
+ line.setAttributeNS(null, "y2", i);
+ document.querySelector("#weight_diagram").querySelector("svg").querySelector(".mg-y-axis").appendChild(line);
+ }
});
});
diff --git a/wger/weight/templates/overview.html b/wger/weight/templates/overview.html
index d024529f4..037c9c110 100644
--- a/wger/weight/templates/overview.html
+++ b/wger/weight/templates/overview.html
@@ -30,7 +30,9 @@
{% endif %}
<div id="weight_diagram"></div>
-
+<br>
+<input id="height" type="number">
+<input id="enable_bmi" type="button" value="BMI">
<div class="btn-group modify-time-period-controls float-right" role="group" aria-label="..." style="padding-bottom: 1em;">
<button type="button" class="btn btn-default" data-time_period="90">{% trans "Last 3 months" %}</button>