Commit 04cf0060 authored by Wolfgang Fellger's avatar Wolfgang Fellger

Add moving average stripe to weight graph

parent 1eeb9442
......@@ -66,6 +66,29 @@ WeightGraph = function (canvas, data) {
}
}
ctx.restore();
// Draw moving average from six points as background
var a = data[0][1];
var b = data[1][1];
var smoothValues = [a, a, a, b, b, b];
var smoothSum = a * 3 + b * 3;
ctx.save();
ctx.beginPath();
ctx.strokeStyle = 'rgba(140, 180, 180, 0.5)';
ctx.lineWidth = 20;
ctx.lineJoin = 'round';
for (var x = 1; x < data.length; x++) {
var yVal = data[x][1];
smoothSum -= smoothValues.shift();
smoothValues.push(yVal);
smoothSum += yVal;
translated = translate(data[x][0], smoothSum / smoothValues.length);
ctx[x ? 'lineTo' : 'moveTo'](translated.x, translated.y);
}
ctx.stroke();
ctx.restore();
// Draw actual diagram
ctx.beginPath();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment