From debf513daa78c2af66932ae4272f100319050d46 Mon Sep 17 00:00:00 2001 From: Phyks Date: Fri, 28 Mar 2014 15:02:55 +0100 Subject: [PATCH] Option to disable rounding --- examples/index.html | 2 +- timeline.js | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/examples/index.html b/examples/index.html index 8aebf39..f2b1389 100644 --- a/examples/index.html +++ b/examples/index.html @@ -7,7 +7,7 @@ } - +
diff --git a/timeline.js b/timeline.js index 1bc6188..caa38b3 100644 --- a/timeline.js +++ b/timeline.js @@ -209,13 +209,16 @@ SVG.getControlPoints = function (data) { return {p1:p1, p2:p2}; } -SVG.draw = function() { +SVG.draw = function(rounded) { var scale = SVG.scale(SVG.raw_points); var x = new Array(); var y = new Array(); var circle = false; var line = false; var point = false; + var px = false; + var py = false; + var path = ''; /* Draw points */ for(point in SVG.raw_points) { @@ -235,11 +238,18 @@ SVG.draw = function() { circle.addEventListener('mouseover', function() { this.setAttribute('r', '6'); }) circle.addEventListener('mouseout', function() { this.setAttribute('r', '4'); }) } - var px = SVG.getControlPoints(x); - var py = SVG.getControlPoints(y); - var path = ''; - for(point = 0; point < SVG.raw_points.length - 1; point++) { - path += 'C '+px.p1[point]+' '+py.p1[point]+' '+px.p2[point]+' '+py.p2[point]+' '+x[point+1]+' '+y[point+1]+' '; + + if(rounded === true) { + px = SVG.getControlPoints(x); + py = SVG.getControlPoints(y); + for(point = 0; point < SVG.raw_points.length - 1; point++) { + path += 'C '+px.p1[point]+' '+py.p1[point]+' '+px.p2[point]+' '+py.p2[point]+' '+x[point+1]+' '+y[point+1]+' '; + } + } + else { + for(point = 1; point < SVG.raw_points.length; point++) { + path += 'L '+x[point]+' '+y[point]+' '; + } } line = document.createElementNS(SVG.ns, 'path'); line.setAttribute('class', 'graph');