From 45a5b002448932b19ac3946b0636b8464a20ce3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Wed, 14 Dec 2016 16:29:28 -0500 Subject: [PATCH 1/4] make Plots.graphJson serialize frames too --- src/plots/plots.js | 5 +++- test/jasmine/tests/plots_test.js | 42 ++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/plots/plots.js b/src/plots/plots.js index 3f9e06fb1ae..ad838cd39b2 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -1338,7 +1338,8 @@ plots.graphJson = function(gd, dataonly, mode, output, useDefaults) { } var data = (useDefaults) ? gd._fullData : gd.data, - layout = (useDefaults) ? gd._fullLayout : gd.layout; + layout = (useDefaults) ? gd._fullLayout : gd.layout, + frames = (gd._transitionData || {})._frames; function stripObj(d) { if(typeof d === 'function') { @@ -1411,6 +1412,8 @@ plots.graphJson = function(gd, dataonly, mode, output, useDefaults) { if(gd.framework && gd.framework.isPolar) obj = gd.framework.getConfig(); + if(frames) obj.frames = stripObj(frames); + return (output === 'object') ? obj : JSON.stringify(obj); }; diff --git a/test/jasmine/tests/plots_test.js b/test/jasmine/tests/plots_test.js index 364e348b3a5..ac5b40ad32f 100644 --- a/test/jasmine/tests/plots_test.js +++ b/test/jasmine/tests/plots_test.js @@ -494,4 +494,46 @@ describe('Test Plots', function() { assert(dest, src, expected); }); }); + + describe('Plots.graphJson', function() { + + it('should serialize data, layout and frames', function(done) { + var mock = { + data: [{ + x: [1, 2, 3], + y: [2, 1, 2] + }], + layout: { + title: 'base' + }, + frames: [{ + data: [{ + y: [1, 2, 1], + }], + layout: { + title: 'frame A' + }, + name: 'A' + }, { + data: [{ + y: [1, 2, 3], + }], + layout: { + title: 'frame B' + }, + name: 'B' + }] + }; + + Plotly.plot(createGraphDiv(), mock).then(function(gd) { + var str = Plots.graphJson(gd, false, 'keepdata'); + var obj = JSON.parse(str); + + expect(obj.data).toEqual(mock.data); + expect(obj.layout).toEqual(mock.layout); + expect(obj.frames).toEqual(mock.frames); + }) + .then(done); + }); + }); }); From d97a28c5fcae8c904c15a4092c932ef469811e82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Wed, 14 Dec 2016 16:49:55 -0500 Subject: [PATCH 2/4] fixup: forgot to clear graph div --- test/jasmine/tests/plots_test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/jasmine/tests/plots_test.js b/test/jasmine/tests/plots_test.js index ac5b40ad32f..2516e5524ec 100644 --- a/test/jasmine/tests/plots_test.js +++ b/test/jasmine/tests/plots_test.js @@ -533,7 +533,10 @@ describe('Test Plots', function() { expect(obj.layout).toEqual(mock.layout); expect(obj.frames).toEqual(mock.frames); }) - .then(done); + .then(function() { + destroyGraphDiv(); + done(); + }); }); }); }); From 20233def7180963c865d3337c882433bd1bf3aa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Wed, 14 Dec 2016 18:05:59 -0500 Subject: [PATCH 3/4] improve Plots.graphJson test --- test/jasmine/tests/plots_test.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/jasmine/tests/plots_test.js b/test/jasmine/tests/plots_test.js index 2516e5524ec..f0f839a33c8 100644 --- a/test/jasmine/tests/plots_test.js +++ b/test/jasmine/tests/plots_test.js @@ -514,7 +514,9 @@ describe('Test Plots', function() { title: 'frame A' }, name: 'A' - }, { + }, + null, + { data: [{ y: [1, 2, 3], }], @@ -531,7 +533,8 @@ describe('Test Plots', function() { expect(obj.data).toEqual(mock.data); expect(obj.layout).toEqual(mock.layout); - expect(obj.frames).toEqual(mock.frames); + expect(obj.frames[0]).toEqual(mock.frames[0]); + expect(obj.frames[1]).toEqual(mock.frames[2]); }) .then(function() { destroyGraphDiv(); From 245530304e244592c798bdda86ce0b0389b948dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Wed, 14 Dec 2016 18:10:00 -0500 Subject: [PATCH 4/4] improve Plots.graphJson test (2) --- test/jasmine/tests/plots_test.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/test/jasmine/tests/plots_test.js b/test/jasmine/tests/plots_test.js index f0f839a33c8..60afb54d805 100644 --- a/test/jasmine/tests/plots_test.js +++ b/test/jasmine/tests/plots_test.js @@ -514,9 +514,7 @@ describe('Test Plots', function() { title: 'frame A' }, name: 'A' - }, - null, - { + }, null, { data: [{ y: [1, 2, 3], }], @@ -524,6 +522,10 @@ describe('Test Plots', function() { title: 'frame B' }, name: 'B' + }, { + data: [null, false, undefined], + layout: 'garbage', + name: 'garbage' }] }; @@ -535,6 +537,11 @@ describe('Test Plots', function() { expect(obj.layout).toEqual(mock.layout); expect(obj.frames[0]).toEqual(mock.frames[0]); expect(obj.frames[1]).toEqual(mock.frames[2]); + expect(obj.frames[2]).toEqual({ + data: [null, false, null], + layout: 'garbage', + name: 'garbage' + }); }) .then(function() { destroyGraphDiv();