From 051a854a82738473230fd1c20b6c9cacb036269d Mon Sep 17 00:00:00 2001 From: Steve Jones Date: Fri, 26 Aug 2016 17:48:09 +0200 Subject: [PATCH] Bug fix: indexFromSetName on invisible sets (#771) * indexFromSetName works with trailing invisible sets If the last set(s) have their visibility set to false, their names would not be added to `setIndexByName_`, so `indexFromSetName` would not be able to find them. This fixes that problem. * Corrected test. * Properly clone graph options --- auto_tests/tests/data_api.js | 18 ++++++++++++++++++ src/dygraph.js | 7 +++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/auto_tests/tests/data_api.js b/auto_tests/tests/data_api.js index e692fc6..6319909 100644 --- a/auto_tests/tests/data_api.js +++ b/auto_tests/tests/data_api.js @@ -4,6 +4,7 @@ * @author danvdk@gmail.com (Dan Vanderkam) */ import Dygraph from '../../src/dygraph'; +import * as utils from '../../src/dygraph-utils'; describe("data-api", function() { cleanupAfterEach(); @@ -99,4 +100,21 @@ it('testGetRowForXDuplicates', function() { assert.equal(5, g.getRowForX(9)); }); +// indexFromSeriesName should return a value even if the series is invisible +// In 1.1.1, if you request the last set and it's invisible, the method returns undefined. +it('testIndexFromSetNameOnInvisibleSet', function() { + + var localOpts = utils.clone(opts); + localOpts.visibility = [true, false]; + + var g = new Dygraph(graphDiv, [ + "x,y1,y2", + "1,1,1", + "2,2,2", + "3,3,3" + ].join('\n'), localOpts); + + assert.equal(2, g.indexFromSetName("y2")); +}); + }); diff --git a/src/dygraph.js b/src/dygraph.js index e5053ba..ff3bcb6 100644 --- a/src/dygraph.js +++ b/src/dygraph.js @@ -2304,16 +2304,15 @@ Dygraph.prototype.drawGraph_ = function() { this.setIndexByName_ = {}; var labels = this.attr_("labels"); - if (labels.length > 0) { - this.setIndexByName_[labels[0]] = 0; - } var dataIdx = 0; for (var i = 1; i < points.length; i++) { - this.setIndexByName_[labels[i]] = i; if (!this.visibility()[i - 1]) continue; this.layout_.addDataset(labels[i], points[i]); this.datasetIndex_[i] = dataIdx++; } + for (var i = 0; i < labels.length; i++) { + this.setIndexByName_[labels[i]] = i; + } this.computeYAxisRanges_(extremes); this.layout_.setYAxes(this.axes_); -- 2.7.4