- var firstIndexInSet = 0;
- var afterLastIndexInSet = 0;
- var setLength = 0;
- for (var i = 0; i < setCount; i += 1) {
- setLength = this.layout.setPointsLengths[i];
- afterLastIndexInSet += setLength;
- var setName = setNames[i];
- var color = this.colors[setName];
- var strokeWidth = this.dygraph_.attr_("strokeWidth", setName);
-
- // setup graphics context
- context.save();
- var pointSize = this.dygraph_.attr_("pointSize", setName);
- var prevX = null, prevY = null;
- var drawPoints = this.dygraph_.attr_("drawPoints", setName);
- for (var j = firstIndexInSet; j < afterLastIndexInSet; j++) {
- var point = points[j];
- if (isNullOrNaN(point.canvasy)) {
- if (stepPlot && prevX != null) {
- // Draw a horizontal line to the start of the missing data
- ctx.beginPath();
- ctx.strokeStyle = color;
- ctx.lineWidth = this.attr_('strokeWidth');
- ctx.moveTo(prevX, prevY);
- ctx.lineTo(point.canvasx, prevY);
- ctx.stroke();
- }
- // this will make us move to the next point, not draw a line to it.
- prevX = prevY = null;
- } else {
- // A point is "isolated" if it is non-null but both the previous
- // and next points are null.
- var isIsolated = (!prevX && (j == points.length - 1 ||
- isNullOrNaN(points[j+1].canvasy)));
- if (prevX === null) {
- prevX = point.canvasx;
- prevY = point.canvasy;
- } else {
- // Skip over points that will be drawn in the same pixel.
- if (Math.round(prevX) == Math.round(point.canvasx) &&
- Math.round(prevY) == Math.round(point.canvasy)) {
- continue;
- }
- // TODO(antrob): skip over points that lie on a line that is already
- // going to be drawn. There is no need to have more than 2
- // consecutive points that are collinear.
- if (strokeWidth) {
- ctx.beginPath();
- ctx.strokeStyle = color;
- ctx.lineWidth = strokeWidth;
- ctx.moveTo(prevX, prevY);
- if (stepPlot) {
- ctx.lineTo(point.canvasx, prevY);
- }
- prevX = point.canvasx;
- prevY = point.canvasy;
- ctx.lineTo(prevX, prevY);
- ctx.stroke();
- }
- }