From: Dan Vanderkam Date: Mon, 8 Aug 2011 02:00:35 +0000 (-0400) Subject: deep/shallow copy confusion; only two tests fail X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=1f71e2b9385bd5ca2f979470576bbd464a2eb6a5;p=dygraphs.git deep/shallow copy confusion; only two tests fail --- diff --git a/auto_tests/tests/axis_labels.js b/auto_tests/tests/axis_labels.js index 7d6a662..6027c58 100644 --- a/auto_tests/tests/axis_labels.js +++ b/auto_tests/tests/axis_labels.js @@ -47,6 +47,7 @@ AxisLabelsTestCase.prototype.testMinusOneToOne = function() { // TODO(danvk): would ['-1.0','-0.5','0.0','0.5','1.0'] be better? assertEquals(['-1','-0.5','0','0.5','1'], getYLabels()); + assertEquals("X,Y\n" + "0,-1\n" + "1,0\n" + "2,1\n" + "3,0\n", g.file_); // Go up to 2 data += "4,2\n"; @@ -142,10 +143,10 @@ AxisLabelsTestCase.prototype.testXAxisTimeLabelFormatter = function() { }); // This is what the output should be: - // assertEquals(["00:05:00", "00:05:06", "00:05:12", "00:05:18", "00:05:24", "00:05:30", "00:05:36", "00:05:42", "00:05:48", "00:05:54"], getXLabels()); + assertEquals(["00:05:00","00:05:12","00:05:24","00:05:36","00:05:48"], getXLabels()); // This is what it is: - assertEquals(['5','5.1','5.2','5.3','5.4','5.5', '5.6', '5.7', '5.8', '5.9'], getXLabels()); + // assertEquals(['5','5.1','5.2','5.3','5.4','5.5', '5.6', '5.7', '5.8', '5.9'], getXLabels()); }; /* @@ -178,12 +179,7 @@ AxisLabelsTestCase.prototype.testAxisLabelFormatter = function () { var graph = document.getElementById("graph"); var g = new Dygraph(graph, data, opts); - // This is the existing behavior: - assertEquals(['y0','y1','y2','y3','y4','y5','y6','y7','y8'], getXLabels()); - - // This is the correct behavior: - // assertEquals(['x0','x1','x2','x3','x4','x5','x6','x7','x8'], getXLabels()); - + assertEquals(['x0','x2','x4','x6','x8'], getXLabels()); assertEquals(['y0','y2','y4','y6','y8','y10','y12','y14','y16','y18'], getYLabels()); }; @@ -233,10 +229,10 @@ AxisLabelsTestCase.prototype.testValueFormatter = function () { var g = new Dygraph(graph, data, opts); // This is the existing behavior: - assertEquals(['y0','y1','y2','y3','y4','y5','y6','y7','y8'], getXLabels()); + assertEquals(["0","2","4","6","8"], getXLabels()); // This is the correct behavior: - // assertEquals(['x0','x1','x2','x3','x4','x5','x6','x7','x8'], getXLabels()); + // assertEquals(['x0','x2','x4','x6','x8'], getXLabels()); assertEquals(['y0','y2','y4','y6','y8','y10','y12','y14','y16','y18'], getYLabels()); }; @@ -296,10 +292,10 @@ AxisLabelsTestCase.prototype.testAxisLabelFormatterPrecedence = function () { var g = new Dygraph(graph, data, opts); // This is the existing behavior: - assertEquals(['y0','y1','y2','y3','y4','y5','y6','y7','y8'], getXLabels()); + // assertEquals(['y0','y1','y2','y3','y4','y5','y6','y7','y8'], getXLabels()); // This is the correct behavior: - // assertEquals(['x0','x1','x2','x3','x4','x5','x6','x7','x8'], getXLabels()); + assertEquals(['x0','x2','x4','x6','x8'], getXLabels()); assertEquals(['y0','y2','y4','y6','y8','y10','y12','y14','y16','y18'], getYLabels()); }; diff --git a/dygraph-utils.js b/dygraph-utils.js index 2ba6ab5..7d8bf14 100644 --- a/dygraph-utils.js +++ b/dygraph-utils.js @@ -523,6 +523,7 @@ Dygraph.isDateLike = function (o) { }; /** + * Note: this only seems to work for arrays. * @private */ Dygraph.clone = function(o) { diff --git a/dygraph.js b/dygraph.js index ab9a52f..ad7daf9 100644 --- a/dygraph.js +++ b/dygraph.js @@ -2692,7 +2692,11 @@ Dygraph.prototype.updateOptions = function(input_attrs, block_redraw) { * @private */ Dygraph.mapLegacyOptions_ = function(attrs) { - var my_attrs = Dygraph.clone(attrs); + var my_attrs = {}; + for (var k in attrs) { + if (attrs.hasOwnProperty(k)) my_attrs[k] = attrs[k]; + } + var set = function(axis, opt, value) { if (!my_attrs.axes) my_attrs.axes = {}; if (!my_attrs.axes[axis]) my_attrs.axes[axis] = {};