From b21464d8bb8cdf73c4c3e0146587fa97519d1396 Mon Sep 17 00:00:00 2001 From: Ricky Reusser Date: Wed, 14 Dec 2016 15:38:46 -0500 Subject: [PATCH 1/3] Compress away nulls when adding frames --- src/plot_api/plot_api.js | 2 ++ test/jasmine/tests/frame_api_test.js | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 2026234ae8d..2ad681f1fee 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -2566,6 +2566,8 @@ Plotly.addFrames = function(gd, frameList, indices) { var insertions = []; for(i = frameList.length - 1; i >= 0; i--) { + if (!frameList[i]) continue; + var name = (_hash[frameList[i].name] || {}).name; var newName = frameList[i].name; diff --git a/test/jasmine/tests/frame_api_test.js b/test/jasmine/tests/frame_api_test.js index 495acbb6418..dd8af3bd79d 100644 --- a/test/jasmine/tests/frame_api_test.js +++ b/test/jasmine/tests/frame_api_test.js @@ -43,6 +43,13 @@ describe('Test frame api', function() { }).catch(fail).then(done); }); + it('compresses nulls when adding frames', function (done) { + Plotly.addFrames(gd, [null, {name: 'test'}, null]).then(function () { + expect(Object.keys(h)).toEqual(['test']); + expect(f).toEqual([{name: 'test'}]); + }).catch(fail).then(done); + }); + it('treats a null list as a noop', function(done) { Plotly.addFrames(gd, null).then(function() { expect(Object.keys(h)).toEqual([]); From de50fe83b024dc63be3bdf2f579af0af8a42452d Mon Sep 17 00:00:00 2001 From: Ricky Reusser Date: Wed, 14 Dec 2016 15:41:34 -0500 Subject: [PATCH 2/3] Fix lint errors --- src/plot_api/plot_api.js | 2 +- test/jasmine/tests/frame_api_test.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 2ad681f1fee..9b58c7bed0e 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -2566,7 +2566,7 @@ Plotly.addFrames = function(gd, frameList, indices) { var insertions = []; for(i = frameList.length - 1; i >= 0; i--) { - if (!frameList[i]) continue; + if(!frameList[i]) continue; var name = (_hash[frameList[i].name] || {}).name; var newName = frameList[i].name; diff --git a/test/jasmine/tests/frame_api_test.js b/test/jasmine/tests/frame_api_test.js index dd8af3bd79d..a34633ed5fb 100644 --- a/test/jasmine/tests/frame_api_test.js +++ b/test/jasmine/tests/frame_api_test.js @@ -43,8 +43,8 @@ describe('Test frame api', function() { }).catch(fail).then(done); }); - it('compresses nulls when adding frames', function (done) { - Plotly.addFrames(gd, [null, {name: 'test'}, null]).then(function () { + it('compresses nulls when adding frames', function(done) { + Plotly.addFrames(gd, [null, {name: 'test'}, null]).then(function() { expect(Object.keys(h)).toEqual(['test']); expect(f).toEqual([{name: 'test'}]); }).catch(fail).then(done); From 27c274e23c5b15efbfb4bac26eea1402a12be8d4 Mon Sep 17 00:00:00 2001 From: Ricky Reusser Date: Wed, 14 Dec 2016 15:45:45 -0500 Subject: [PATCH 3/3] Further check that *is* plain object instead of simply truthy --- src/plot_api/plot_api.js | 2 +- test/jasmine/tests/frame_api_test.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 9b58c7bed0e..70f15d97dcf 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -2566,7 +2566,7 @@ Plotly.addFrames = function(gd, frameList, indices) { var insertions = []; for(i = frameList.length - 1; i >= 0; i--) { - if(!frameList[i]) continue; + if(!Lib.isPlainObject(frameList[i])) continue; var name = (_hash[frameList[i].name] || {}).name; var newName = frameList[i].name; diff --git a/test/jasmine/tests/frame_api_test.js b/test/jasmine/tests/frame_api_test.js index a34633ed5fb..16c253e06e8 100644 --- a/test/jasmine/tests/frame_api_test.js +++ b/test/jasmine/tests/frame_api_test.js @@ -43,8 +43,8 @@ describe('Test frame api', function() { }).catch(fail).then(done); }); - it('compresses nulls when adding frames', function(done) { - Plotly.addFrames(gd, [null, {name: 'test'}, null]).then(function() { + it('compresses garbage when adding frames', function(done) { + Plotly.addFrames(gd, [null, 'garbage', 14, true, false, {name: 'test'}, null]).then(function() { expect(Object.keys(h)).toEqual(['test']); expect(f).toEqual([{name: 'test'}]); }).catch(fail).then(done);