Skip to content

Commit 6db2451

Browse files
committed
Modify Plotly.plot to accept frames #1014
1 parent 95c56e8 commit 6db2451

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/plot_api/plot_api.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,21 @@ var subroutines = require('./subroutines');
4747
*
4848
*/
4949
Plotly.plot = function(gd, data, layout, config) {
50+
var frames;
51+
5052
gd = helpers.getGraphDiv(gd);
5153

5254
// Events.init is idempotent and bails early if gd has already been init'd
5355
Events.init(gd);
5456

57+
if(Lib.isPlainObject(data)) {
58+
var obj = data;
59+
data = obj.data;
60+
layout = obj.layout;
61+
config = obj.config;
62+
frames = obj.frames;
63+
}
64+
5565
var okToPlot = Events.triggerHandler(gd, 'plotly_beforeplot', [data, layout, config]);
5666
if(okToPlot === false) return Promise.reject();
5767

@@ -62,6 +72,12 @@ Plotly.plot = function(gd, data, layout, config) {
6272
'but this container doesn\'t yet have a plot.', gd);
6373
}
6474

75+
function addFrames() {
76+
if(frames) {
77+
return Plotly.addFrames(gd, frames);
78+
}
79+
}
80+
6581
// transfer configuration options to gd until we move over to
6682
// a more OO like model
6783
setPlotContext(gd, config);
@@ -330,6 +346,7 @@ Plotly.plot = function(gd, data, layout, config) {
330346
Lib.syncOrAsync([
331347
Plots.previousPromises,
332348
drawFramework,
349+
addFrames,
333350
marginPushers,
334351
marginPushersAgain,
335352
positionAndAutorange,

test/jasmine/tests/plot_api_test.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var subroutines = require('@src/plot_api/subroutines');
1111
var d3 = require('d3');
1212
var createGraphDiv = require('../assets/create_graph_div');
1313
var destroyGraphDiv = require('../assets/destroy_graph_div');
14+
var fail = require('../assets/fail_test');
1415

1516

1617
describe('Test plot api', function() {
@@ -22,6 +23,44 @@ describe('Test plot api', function() {
2223
});
2324
});
2425

26+
describe('Plotly.plot', function() {
27+
var gd;
28+
29+
beforeEach(function() {
30+
gd = createGraphDiv();
31+
});
32+
33+
afterEach(destroyGraphDiv);
34+
35+
it('accepts gd, data, layout, and config as args', function(done) {
36+
Plotly.plot(gd,
37+
[{x: [1, 2, 3], y: [1, 2, 3]}],
38+
{width: 500, height: 500},
39+
{editable: true}
40+
).then(function() {
41+
expect(gd.layout.width).toEqual(500);
42+
expect(gd.layout.height).toEqual(500);
43+
expect(gd.data.length).toEqual(1);
44+
expect(gd._context.editable).toBe(true);
45+
}).catch(fail).then(done);
46+
});
47+
48+
it('accepts gd and an object as args', function(done) {
49+
Plotly.plot(gd, {
50+
data: [{x: [1, 2, 3], y: [1, 2, 3]}],
51+
layout: {width: 500, height: 500},
52+
config: {editable: true},
53+
frames: [{y: [2, 1, 0], name: 'frame1'}]
54+
}).then(function() {
55+
expect(gd.layout.width).toEqual(500);
56+
expect(gd.layout.height).toEqual(500);
57+
expect(gd.data.length).toEqual(1);
58+
expect(gd._transitionData._frames.length).toEqual(1);
59+
expect(gd._context.editable).toBe(true);
60+
}).catch(fail).then(done);
61+
});
62+
});
63+
2564
describe('Plotly.relayout', function() {
2665
var gd;
2766

0 commit comments

Comments
 (0)