Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

The x-axis now uses the date, but the graph still doesn't look good

Roland Geider302f17120d05
diff --git a/weight/templates/weight_overview.html b/weight/templates/weight_overview.html
index 6dccc9de5..b7fd5975f 100644
--- a/weight/templates/weight_overview.html
+++ b/weight/templates/weight_overview.html
@@ -56,15 +56,22 @@ $(document).ready(function () {
position: 'top'
});
+function getDate(d) {
+ return new Date(d);
+}
+
+var data = {{chart_data|safe}};
+
-var data = {{chart_data}};
+var minDate = getDate(data[0].x),
+ maxDate = getDate(data[data.length-1].x);
var margin = {top: 10, right: 10, bottom: 20, left: 40},
width = 600 - margin.left - margin.right,
height = 300 - margin.top - margin.bottom;
-var x = d3.scale.linear()
- .domain([0, 35])
+var x = d3.time.scale()
+ .domain([minDate, maxDate])
.range([0, width]);
var y = d3.scale.linear()
@@ -74,13 +81,14 @@ var y = d3.scale.linear()
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");
+ //.ticks(d3.time.days);
var yAxis = d3.svg.axis()
.scale(y)
.orient("left");
var line = d3.svg.line()
- .x(function(d) { return x(d.x); })
+ .x(function(d) { return x(getDate(d.x)); })
.y(function(d) { return y(d.y); });
var area = d3.svg.area()
diff --git a/weight/views.py b/weight/views.py
index f75b9f23c..d9d099988 100644
--- a/weight/views.py
+++ b/weight/views.py
@@ -111,25 +111,18 @@ def overview(request):
chart_data = "[\n"
j = 0
for i in weights:
- chart_data += '{x: %s, y: %s},\n' % (j, i.weight)
+ chart_data += '{x: "%(month)s/%(month)s/%(year)s", y: %(weight)s, id: %(id)s},\n' % {
+ 'year': i.creation_date.year,
+ 'month': i.creation_date.month,
+ 'day': i.creation_date.day,
+ 'weight': i.weight,
+ 'id': i.id}
j += 1
- data_y = ', '.join([str(i.weight) for i in weights])
- data_x = ', '.join(["new Date(%s, %s, %s)" % (i.creation_date.year,
- i.creation_date.month,
- i.creation_date.day) for i in weights])
+
chart_data = chart_data.rstrip(',')
chart_data += "]"
template_data['chart_data'] = chart_data
-
- # Make a mapping between index and ID, this is used to edit the entries
- mapping = {}
- index = 0
- for i in weights:
- mapping[index] = i.id
- index += 1
- template_data['index_mapping'] = json.dumps(mapping)
-
return render_to_response('weight_overview.html',
template_data,
context_instance=RequestContext(request))