X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;ds=sidebyside;f=dygraph.js;h=045c394ebbe3b379061ba61f5368c5ab28827f89;hb=966ac3fa0de18a7b5ddefe4aba6938d8358ea0cf;hp=01b10a3675453e28ccb8d03e770dd3d169e43396;hpb=90e92cf5ac0af418a771722b81bd7fbce942e5a1;p=dygraphs.git diff --git a/dygraph.js b/dygraph.js index 01b10a3..045c394 100644 --- a/dygraph.js +++ b/dygraph.js @@ -1515,7 +1515,7 @@ Dygraph.prototype.findClosestRow = function(domX) { var l = points.length; for (var i = 0; i < l; i++) { var point = points[i]; - if (!Dygraph.isValidPoint(point)) continue; + if (!Dygraph.isValidPoint(point, true)) continue; var dist = Math.abs(point.canvasx - domX); if (dist < minDistX) { minDistX = dist; @@ -1842,6 +1842,8 @@ Dygraph.prototype.generateLegendHTML_ = function(x, sel_points, oneEmWidth) { */ Dygraph.prototype.setLegendHTML_ = function(x, sel_points) { var labelsDiv = this.attr_("labelsDiv"); + if (!labelsDiv) return; + var sizeSpan = document.createElement('span'); // Calculates the width of 1em in pixels for the legend. sizeSpan.setAttribute('style', 'margin: 0; padding: 0 0 0 1em; border: 0;'); @@ -1999,7 +2001,7 @@ Dygraph.prototype.setSelection = function(row, opt_seriesName) { point = this.layout_.unstackPointAtIndex(pos+row); } - this.selPoints_.push(point); + if (!(point.yval === null)) this.selPoints_.push(point); } pos += set.length; } @@ -2197,9 +2199,8 @@ Dygraph.prototype.predraw_ = function() { // rolling averages. this.rolledSeries_ = [null]; // x-axis is the first series and it's special for (var i = 1; i < this.numColumns(); i++) { - var connectSeparatedPoints = this.attr_('connectSeparatedPoints', i); - var logScale = this.attr_('logscale', i); - var series = this.extractSeries_(this.rawData_, i, logScale, connectSeparatedPoints); + var logScale = this.attr_('logscale', i); // TODO(klausw): this looks wrong + var series = this.extractSeries_(this.rawData_, i, logScale); series = this.rollingAverage(series, this.rollPeriod_); this.rolledSeries_.push(series); } @@ -2296,6 +2297,11 @@ Dygraph.prototype.gatherDatasets_ = function(rolledSeries, dateWindow) { } actual_y = series[j][1]; + if (actual_y === null) { + series[j] = [x, null]; + continue; + } + cumulative_y[x] += actual_y; series[j] = [x, cumulative_y[x]]; @@ -2314,6 +2320,26 @@ Dygraph.prototype.gatherDatasets_ = function(rolledSeries, dateWindow) { datasets[i] = series; } + // For stacked graphs, a NaN value for any point in the sum should create a + // clean gap in the graph. Back-propagate NaNs to all points at this X value. + if (this.attr_("stackedGraph")) { + for (k = datasets.length - 1; k >= 0; --k) { + // Use the first nonempty dataset to get X values. + if (!datasets[k]) continue; + for (j = 0; j < datasets[k].length; j++) { + var x = datasets[k][j][0]; + if (isNaN(cumulative_y[x])) { + // Set all Y values to NaN at that X value. + for (i = datasets.length - 1; i >= 0; i--) { + if (!datasets[i]) continue; + datasets[i][j][1] = NaN; + } + } + } + break; + } + } + return [ datasets, extremes, boundaryIds ]; }; @@ -2682,24 +2708,19 @@ Dygraph.prototype.computeYAxisRanges_ = function(extremes) { * * @private */ -Dygraph.prototype.extractSeries_ = function(rawData, i, logScale, connectSeparatedPoints) { +Dygraph.prototype.extractSeries_ = function(rawData, i, logScale) { var series = []; for (var j = 0; j < rawData.length; j++) { var x = rawData[j][0]; var point = rawData[j][i]; if (logScale) { // On the log scale, points less than zero do not exist. - // This will create a gap in the chart. Note that this ignores - // connectSeparatedPoints. + // This will create a gap in the chart. if (point <= 0) { point = null; } - series.push([x, point]); - } else { - if (point !== null || !connectSeparatedPoints) { - series.push([x, point]); - } } + series.push([x, point]); } return series; }; @@ -2874,7 +2895,7 @@ Dygraph.prototype.detectTypeFromString_ = function(str) { // TODO(danvk): use Dygraph.numberValueFormatter here? /** @private (shut up, jsdoc!) */ this.attrs_.axes.x.valueFormatter = function(x) { return x; }; - this.attrs_.axes.x.ticker = Dygraph.numericTicks; + this.attrs_.axes.x.ticker = Dygraph.numericLinearTicks; this.attrs_.axes.x.axisLabelFormatter = this.attrs_.axes.x.valueFormatter; } }; @@ -3113,7 +3134,7 @@ Dygraph.prototype.parseArray_ = function(data) { /** @private (shut up, jsdoc!) */ this.attrs_.axes.x.valueFormatter = function(x) { return x; }; this.attrs_.axes.x.axisLabelFormatter = Dygraph.numberAxisLabelFormatter; - this.attrs_.axes.x.ticker = Dygraph.numericTicks; + this.attrs_.axes.x.ticker = Dygraph.numericLinearTicks; return data; } }; @@ -3153,7 +3174,7 @@ Dygraph.prototype.parseDataTable_ = function(data) { } else if (indepType == 'number') { this.attrs_.xValueParser = function(x) { return parseFloat(x); }; this.attrs_.axes.x.valueFormatter = function(x) { return x; }; - this.attrs_.axes.x.ticker = Dygraph.numericTicks; + this.attrs_.axes.x.ticker = Dygraph.numericLinearTicks; this.attrs_.axes.x.axisLabelFormatter = this.attrs_.axes.x.valueFormatter; } else { this.error("only 'date', 'datetime' and 'number' types are supported for " +