- // process sets in reverse order (needed for stacked graphs)
- for (var i = setCount - 1; i >= 0; i--) {
- var setName = setNames[i];
- var color = this.colors[setName];
- var axis = this.layout.options.yAxes[
- this.layout.options.seriesToAxisMap[setName]];
- var axisY = 1.0 + axis.minyval * axis.yscale;
- if (axisY < 0.0) axisY = 0.0;
- else if (axisY > 1.0) axisY = 1.0;
- axisY = this.area.h * axisY + this.area.y;
-
- // setup graphics context
- ctx.save();
- var prevX = NaN;
- var prevYs = [-1, -1];
- var yscale = axis.yscale;
- // should be same color as the lines but only 15% opaque.
- var rgb = new RGBColor(color);
- var err_color = 'rgba(' + rgb.r + ',' + rgb.g + ',' + rgb.b + ',' +
- fillAlpha + ')';
- ctx.fillStyle = err_color;
- ctx.beginPath();
- for (var j = 0; j < this.layout.points.length; j++) {
- var point = this.layout.points[j];
- if (point.name == setName) {
- if (!Dygraph.isOK(point.y)) {
- prevX = NaN;
- continue;
- }
- var newYs;
- if (stackedGraph) {
- lastY = baseline[point.canvasx];
- if (lastY === undefined) lastY = axisY;
- baseline[point.canvasx] = point.canvasy;
- newYs = [ point.canvasy, lastY ];
- } else {
- newYs = [ point.canvasy, axisY ];
- }
- if (!isNaN(prevX)) {
- ctx.moveTo(prevX, prevYs[0]);
- if (stepPlot) {
- ctx.lineTo(point.canvasx, prevYs[0]);
- } else {
- ctx.lineTo(point.canvasx, newYs[0]);
- }
- ctx.lineTo(point.canvasx, newYs[1]);
- ctx.lineTo(prevX, prevYs[1]);
- ctx.closePath();
- }
- prevYs = newYs;
- prevX = point.canvasx;
+ // TODO(danvk): there are a lot of options at play in this loop.
+ // The logic would be much clearer if some (e.g. stackGraph and
+ // stepPlot) were split off into separate sub-plotters.
+ while (iter.hasNext) {
+ var point = iter.next();
+ if (!Dygraph.isOK(point.y) && !stepPlot) {
+ traceBackPath(prevX, prevYs[1]);
+ prevX = NaN;
+ if (point.y_stacked !== null && !isNaN(point.y_stacked)) {
+ baseline[point.canvasx] = area.h * point.y_stacked + area.y;