Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ae007a8

Browse files
authored
Merge pull request plotly#1255 from plotly/send-frames-to-cloud
make Plots.graphJson serialize frames too
2 parents 7e9fc1d + 2455303 commit ae007a8

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-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: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,4 +494,59 @@ 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+
}, null, {
518+
data: [{
519+
y: [1, 2, 3],
520+
}],
521+
layout: {
522+
title: 'frame B'
523+
},
524+
name: 'B'
525+
}, {
526+
data: [null, false, undefined],
527+
layout: 'garbage',
528+
name: 'garbage'
529+
}]
530+
};
531+
532+
Plotly.plot(createGraphDiv(), mock).then(function(gd) {
533+
var str = Plots.graphJson(gd, false, 'keepdata');
534+
var obj = JSON.parse(str);
535+
536+
expect(obj.data).toEqual(mock.data);
537+
expect(obj.layout).toEqual(mock.layout);
538+
expect(obj.frames[0]).toEqual(mock.frames[0]);
539+
expect(obj.frames[1]).toEqual(mock.frames[2]);
540+
expect(obj.frames[2]).toEqual({
541+
data: [null, false, null],
542+
layout: 'garbage',
543+
name: 'garbage'
544+
});
545+
})
546+
.then(function() {
547+
destroyGraphDiv();
548+
done();
549+
});
550+
});
551+
});
497552
});

0 commit comments

Comments
 (0)