-DygraphCanvasRenderer.prototype._renderLineChart = function() {
- // TODO(danvk): use this.attr_ for many of these.
- var context = this.elementContext;
- var fillAlpha = this.attr_('fillAlpha');
- var errorBars = this.attr_("errorBars") || this.attr_("customBars");
- var fillGraph = this.attr_("fillGraph");
- var stackedGraph = this.attr_("stackedGraph");
- var stepPlot = this.attr_("stepPlot");
-
- var setNames = [];
- for (var name in this.layout.datasets) {
- if (this.layout.datasets.hasOwnProperty(name)) {
- setNames.push(name);
- }
- }
- var setCount = setNames.length;
+DygraphCanvasRenderer._fillPlotter = function(e) {
+ // Skip if we're drawing a single series for interactive highlight overlay.
+ if (e.singleSeriesName) return;
+
+ // We'll handle all the series at once, not one-by-one.
+ if (e.seriesIndex !== 0) return;
+
+ var g = e.dygraph;
+ var setNames = g.getLabels().slice(1); // remove x-axis
+
+ // getLabels() includes names for invisible series, which are not included in
+ // allSeriesPoints. We remove those to make the two match.
+ // TODO(danvk): provide a simpler way to get this information.
+ for (var i = setNames.length; i >= 0; i--) {
+ if (!g.visibility()[i]) setNames.splice(i, 1);
+ }
+
+ var anySeriesFilled = (function() {
+ for (var i = 0; i < setNames.length; i++) {
+ if (g.getBooleanOption("fillGraph", setNames[i])) return true;
+ }
+ return false;
+ })();
+
+ if (!anySeriesFilled) return;
+
+ var area = e.plotArea;
+ var sets = e.allSeriesPoints;
+ var setCount = sets.length;
+
+ var fillAlpha = g.getNumericOption('fillAlpha');
+ var stackedGraph = g.getBooleanOption("stackedGraph");
+ var colors = g.getColors();
+
+ // For stacked graphs, track the baseline for filling.
+ //
+ // The filled areas below graph lines are trapezoids with two
+ // vertical edges. The top edge is the line segment being drawn, and
+ // the baseline is the bottom edge. Each baseline corresponds to the
+ // top line segment from the previous stacked line. In the case of
+ // step plots, the trapezoids are rectangles.
+ var baseline = {};
+ var currBaseline;
+ var prevStepPlot; // for different line drawing modes (line/step) per series
+
+ // process sets in reverse order (needed for stacked graphs)
+ for (var setIdx = setCount - 1; setIdx >= 0; setIdx--) {
+ var ctx = e.drawingContext;
+ var setName = setNames[setIdx];
+ if (!g.getBooleanOption('fillGraph', setName)) continue;
+
+ var stepPlot = g.getBooleanOption('stepPlot', setName);
+ var color = colors[setIdx];
+ var axis = g.axisPropertiesForSeries(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 = area.h * axisY + area.y;
+
+ var points = sets[setIdx];
+ var iter = Dygraph.createIterator(points, 0, points.length,
+ DygraphCanvasRenderer._getIteratorPredicate(
+ g.getBooleanOption("connectSeparatedPoints", setName)));