Permalink
Browse files

Interpolation option added to choose between lines and bezier curves

  • Loading branch information...
1 parent 8390f2f commit 389da6c2c04f3ce1b4a16323a1616a679384c6dd Dmitry Vyal committed Aug 1, 2011
Showing with 13 additions and 4 deletions.
  1. +13 −4 smoothie.js
View
@@ -73,6 +73,7 @@ function SmoothieChart(options) {
options.minValue = options.minValue;
options.maxValue = options.maxValue;
options.labels = options.labels || { fillStyle:'#ffffff' };
+ options.interpolation = options.interpolation || "bezier";
this.options = options;
this.seriesSet = [];
}
@@ -231,10 +232,18 @@ SmoothieChart.prototype.render = function(canvas, time) {
// so adjacent curves appear to flow as one.
//
else {
- canvasContext.bezierCurveTo( // startPoint (A) is implicit from last iteration of loop
- Math.round((lastX + x) / 2), lastY, // controlPoint1 (P)
- Math.round((lastX + x)) / 2, y, // controlPoint2 (Q)
- x, y); // endPoint (B)
+ switch (options.interpolation) {
+ case "line":
+ canvasContext.lineTo(x,y);
+ break;
+ case "bezier":
+ default:
+ canvasContext.bezierCurveTo( // startPoint (A) is implicit from last iteration of loop
+ Math.round((lastX + x) / 2), lastY, // controlPoint1 (P)
+ Math.round((lastX + x)) / 2, y, // controlPoint2 (Q)
+ x, y); // endPoint (B)
+ break;
+ }
}
lastX = x, lastY = y;

0 comments on commit 389da6c

Please sign in to comment.