Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Check that there is data to chart

Roland Geider28f8b1030834
diff --git a/wger/exercises/static/js/exercises.js b/wger/exercises/static/js/exercises.js
index 36e598b21..b1ebb249a 100644
--- a/wger/exercises/static/js/exercises.js
+++ b/wger/exercises/static/js/exercises.js
@@ -58,34 +58,36 @@ function highlight_muscle(element) {
function draw_weight_log_chart(data, div_id) {
- var legend = [];
- var min_values = [];
- var chart_data = [];
- for (var i = 0; i < data.length; i++) {
- chart_data[i] = MG.convert.date(data[i], 'date');
-
- // Read the possible repetitions for the chart legend
- legend[i] = data[i][0].reps;
-
- // Read the minimum values for each repetition
- min_values[i] = d3.min(data[i], function (data) {
- return data.weight;
+ if (data.length) {
+ var legend = [];
+ var min_values = [];
+ var chart_data = [];
+ for (var i = 0; i < data.length; i++) {
+ chart_data[i] = MG.convert.date(data[i], 'date');
+
+ // Read the possible repetitions for the chart legend
+ legend[i] = data[i][0].reps;
+
+ // Read the minimum values for each repetition
+ min_values[i] = d3.min(data[i], function (data) {
+ return data.weight;
+ });
+ }
+
+ MG.data_graphic({
+ data: chart_data,
+ y_accessor: 'weight',
+ min_y: d3.min(min_values),
+ aggregate_rollover: true,
+ full_width: true,
+ top: 10,
+ left: 30,
+ right: 10,
+ height: 200,
+ legend: legend,
+ target: '#svg-' + div_id,
+ colors: ['#204a87', '#4e9a06', '#ce5c00', '#5c3566', '#2e3436', '8f5902', '#a40000']
});
}
-
- MG.data_graphic({
- data: chart_data,
- y_accessor: 'weight',
- min_y: d3.min(min_values),
- aggregate_rollover: true,
- full_width: true,
- top: 10,
- left: 30,
- right: 10,
- height: 200,
- legend: legend,
- target: '#svg-' + div_id,
- colors: ['#204a87', '#4e9a06', '#ce5c00', '#5c3566', '#2e3436', '8f5902', '#a40000']
- });
}
diff --git a/wger/weight/static/js/weight.js b/wger/weight/static/js/weight.js
index 9dc580a44..e0c3398f6 100644
--- a/wger/weight/static/js/weight.js
+++ b/wger/weight/static/js/weight.js
@@ -41,12 +41,14 @@ $(document).ready(function () {
d3.json(url, function (json) {
- var data = MG.convert.date(json, 'date');
- weight_chart.data = data;
+ if (json.length) {
+ var data = MG.convert.date(json, 'date');
+ weight_chart.data = data;
- // Plot the data
- chart_params.data = data;
- MG.data_graphic(chart_params);
+ // Plot the data
+ chart_params.data = data;
+ MG.data_graphic(chart_params);
+ }
});
$('.modify-time-period-controls button').click(function () {
@@ -63,8 +65,10 @@ $(document).ready(function () {
function modify_time_period(data, past_n_days) {
- if (past_n_days !== 'all' || past_n_days !== '') {
- return MG.clone(data).slice(past_n_days * -1);
+ if (data.length) {
+ if (past_n_days !== 'all' || past_n_days !== '') {
+ return MG.clone(data).slice(past_n_days * -1);
+ }
}
return data;