Skip to content

Commit 45a5b00

Browse files
committed
make Plots.graphJson serialize frames too
1 parent 5bce249 commit 45a5b00

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/plots/plots.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,8 @@ plots.graphJson = function(gd, dataonly, mode, output, useDefaults) {
13381338
}
13391339

13401340
var data = (useDefaults) ? gd._fullData : gd.data,
1341-
layout = (useDefaults) ? gd._fullLayout : gd.layout;
1341+
layout = (useDefaults) ? gd._fullLayout : gd.layout,
1342+
frames = (gd._transitionData || {})._frames;
13421343

13431344
function stripObj(d) {
13441345
if(typeof d === 'function') {
@@ -1411,6 +1412,8 @@ plots.graphJson = function(gd, dataonly, mode, output, useDefaults) {
14111412

14121413
if(gd.framework && gd.framework.isPolar) obj = gd.framework.getConfig();
14131414

1415+
if(frames) obj.frames = stripObj(frames);
1416+
14141417
return (output === 'object') ? obj : JSON.stringify(obj);
14151418
};
14161419

test/jasmine/tests/plots_test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,4 +494,46 @@ describe('Test Plots', function() {
494494
assert(dest, src, expected);
495495
});
496496
});
497+
498+
describe('Plots.graphJson', function() {
499+
500+
it('should serialize data, layout and frames', function(done) {
501+
var mock = {
502+
data: [{
503+
x: [1, 2, 3],
504+
y: [2, 1, 2]
505+
}],
506+
layout: {
507+
title: 'base'
508+
},
509+
frames: [{
510+
data: [{
511+
y: [1, 2, 1],
512+
}],
513+
layout: {
514+
title: 'frame A'
515+
},
516+
name: 'A'
517+
}, {
518+
data: [{
519+
y: [1, 2, 3],
520+
}],
521+
layout: {
522+
title: 'frame B'
523+
},
524+
name: 'B'
525+
}]
526+
};
527+
528+
Plotly.plot(createGraphDiv(), mock).then(function(gd) {
529+
var str = Plots.graphJson(gd, false, 'keepdata');
530+
var obj = JSON.parse(str);
531+
532+
expect(obj.data).toEqual(mock.data);
533+
expect(obj.layout).toEqual(mock.layout);
534+
expect(obj.frames).toEqual(mock.frames);
535+
})
536+
.then(done);
537+
});
538+
});
497539
});

0 commit comments

Comments
 (0)