From 10583668cf7f0202eb7a1ccea262b37f6048d057 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 11 Nov 2016 16:43:50 -0500 Subject: [PATCH 1/5] Clone input trace --- src/plot_api/plot_api.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index bd9f22f8fe8..8727a3442a7 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -956,6 +956,12 @@ Plotly.addTraces = function addTraces(gd, traces, newIndices) { if(!Array.isArray(traces)) { traces = [traces]; } + + // make sure traces does not repeat existing ones + traces = traces.map(function(trace) { + return Lib.extendFlat({}, trace); + }); + helpers.cleanData(traces, gd.data); // add the traces to gd.data (no redrawing yet!) From ea8ce866798c7db6757f3494d20a613f9f2ede77 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 11 Nov 2016 16:55:00 -0500 Subject: [PATCH 2/5] Ignore line ending style --- .eslintrc | 1 - 1 file changed, 1 deletion(-) diff --git a/.eslintrc b/.eslintrc index 093ed358b6f..9404630b5bc 100644 --- a/.eslintrc +++ b/.eslintrc @@ -22,7 +22,6 @@ "no-trailing-spaces": [2], "no-multiple-empty-lines": [2, {"max": 2, "maxEOF": 0}], "eol-last": [2], - "linebreak-style": [2, "unix"], "indent": [2, 4, {"SwitchCase": 1}], "max-len": [0, 80], "brace-style": [0, "stroustrup", {"allowSingleLine": true}], From fa18648b20ed97fa7f54744a835beb9a919c0b16 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 11 Nov 2016 16:55:06 -0500 Subject: [PATCH 3/5] Fix typo --- src/plot_api/plot_api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 8727a3442a7..11191a1d275 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -957,7 +957,7 @@ Plotly.addTraces = function addTraces(gd, traces, newIndices) { traces = [traces]; } - // make sure traces does not repeat existing ones + // make sure traces do not repeat existing ones traces = traces.map(function(trace) { return Lib.extendFlat({}, trace); }); From ecd795af59b6422f496a679b017d105fa1d032ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Mon, 21 Nov 2016 11:34:50 -0500 Subject: [PATCH 4/5] test: add case for addTraces with exising data/traces --- test/jasmine/tests/plot_api_test.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/jasmine/tests/plot_api_test.js b/test/jasmine/tests/plot_api_test.js index c4d99ac8846..15bfc910895 100644 --- a/test/jasmine/tests/plot_api_test.js +++ b/test/jasmine/tests/plot_api_test.js @@ -474,7 +474,21 @@ describe('Test plot api', function() { expect(gd.data[2].uid).toBeDefined(); expect(PlotlyInternal.redraw).not.toHaveBeenCalled(); expect(PlotlyInternal.moveTraces).toHaveBeenCalledWith(gd, [-1], [0]); + }); + + it('should work when adding an existing trace', function() { + Plotly.addTraces(gd, gd.data[0]); + + expect(gd.data.length).toEqual(3); + expect(gd.data[0]).not.toBe(gd.data[2]); + }); + + it('should work when duplicating the existing data', function() { + Plotly.addTraces(gd, gd.data); + expect(gd.data.length).toEqual(4) + expect(gd.data[0]).not.toBe(gd.data[2]); + expect(gd.data[1]).not.toBe(gd.data[3]); }); }); From 7e4c5c196f007a769d3ca053ba6ba094991a6dff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Mon, 21 Nov 2016 12:31:01 -0500 Subject: [PATCH 5/5] lint --- src/plot_api/plot_api.js | 5 ++--- test/jasmine/tests/plot_api_test.js | 5 +---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 11191a1d275..1a5bd8d1fc0 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -633,8 +633,7 @@ function checkMoveTracesArgs(gd, currentIndices, newIndices) { * @param newIndices */ function checkAddTracesArgs(gd, traces, newIndices) { - var i, - value; + var i, value; // check that gd has attribute 'data' and 'data' is array if(!Array.isArray(gd.data)) { @@ -965,7 +964,7 @@ Plotly.addTraces = function addTraces(gd, traces, newIndices) { helpers.cleanData(traces, gd.data); // add the traces to gd.data (no redrawing yet!) - for(i = 0; i < traces.length; i += 1) { + for(i = 0; i < traces.length; i++) { gd.data.push(traces[i]); } diff --git a/test/jasmine/tests/plot_api_test.js b/test/jasmine/tests/plot_api_test.js index 15bfc910895..80acfbb1b7e 100644 --- a/test/jasmine/tests/plot_api_test.js +++ b/test/jasmine/tests/plot_api_test.js @@ -414,7 +414,6 @@ describe('Test plot api', function() { // make sure we didn't muck with gd.data if things failed! expect(gd).toEqual(expected); - }); it('should throw an error when traces and newIndices arrays are unequal', function() { @@ -454,7 +453,6 @@ describe('Test plot api', function() { expect(gd.data[3].uid).toBeDefined(); expect(PlotlyInternal.redraw).not.toHaveBeenCalled(); expect(PlotlyInternal.moveTraces).toHaveBeenCalledWith(gd, [-2, -1], [1, 3]); - }); it('should work when newIndices has negative indices', function() { @@ -465,7 +463,6 @@ describe('Test plot api', function() { expect(gd.data[3].uid).toBeDefined(); expect(PlotlyInternal.redraw).not.toHaveBeenCalled(); expect(PlotlyInternal.moveTraces).toHaveBeenCalledWith(gd, [-2, -1], [-3, -1]); - }); it('should work when newIndices is an integer', function() { @@ -486,7 +483,7 @@ describe('Test plot api', function() { it('should work when duplicating the existing data', function() { Plotly.addTraces(gd, gd.data); - expect(gd.data.length).toEqual(4) + expect(gd.data.length).toEqual(4); expect(gd.data[0]).not.toBe(gd.data[2]); expect(gd.data[1]).not.toBe(gd.data[3]); });