Skip to content

Commit 02dcf5d

Browse files
committed
Verify gd is a plot div for animate, addFrames, deleteFrames
1 parent fc39f57 commit 02dcf5d

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

src/plot_api/plot_api.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2485,6 +2485,12 @@ Plotly.relayout = function relayout(gd, astr, val) {
24852485
*/
24862486
Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
24872487
gd = getGraphDiv(gd);
2488+
2489+
if(!Lib.isPlotDiv(gd)) {
2490+
Lib.warn('This element is not a Plotly plot.', gd);
2491+
return Promise.reject();
2492+
}
2493+
24882494
var trans = gd._transitionData;
24892495

24902496
// This is the queue of frames that will be animated as soon as possible. They
@@ -2764,6 +2770,11 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
27642770
Plotly.addFrames = function(gd, frameList, indices) {
27652771
gd = getGraphDiv(gd);
27662772

2773+
if(!Lib.isPlotDiv(gd)) {
2774+
Lib.warn('This element is not a Plotly plot.', gd);
2775+
return Promise.reject();
2776+
}
2777+
27672778
var i, frame, j, idx;
27682779
var _frames = gd._transitionData._frames;
27692780
var _hash = gd._transitionData._frameHash;
@@ -2848,6 +2859,11 @@ Plotly.addFrames = function(gd, frameList, indices) {
28482859
Plotly.deleteFrames = function(gd, frameList) {
28492860
gd = getGraphDiv(gd);
28502861

2862+
if(!Lib.isPlotDiv(gd)) {
2863+
Lib.warn('This element is not a Plotly plot.', gd);
2864+
return Promise.reject();
2865+
}
2866+
28512867
var i, idx;
28522868
var _frames = gd._transitionData._frames;
28532869
var ops = [];

src/plots/plots.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,8 +1342,18 @@ plots.computeFrame = function(gd, frameName) {
13421342
/**
13431343
* Transition to a set of new data and layout properties
13441344
*
1345-
* @param {string id or DOM element} gd
1346-
* the id or DOM element of the graph container div
1345+
* @param {DOM element} gd
1346+
* the DOM element of the graph container div
1347+
* @param {Object[]} data
1348+
* an array of data objects following the normal Plotly data definition format
1349+
* @param {Object} layout
1350+
* a layout object, following normal Plotly layout format
1351+
* @param {Number[]} traceIndices
1352+
* indices of the corresponding traces specified in `data`
1353+
* @param {Object} frameOpts
1354+
* options for the frame (i.e. whether to redraw post-transition)
1355+
* @param {Object} transitionOpts
1356+
* options for the transition
13471357
*/
13481358
plots.transition = function(gd, data, layout, traceIndices, frameOpts, transitionOpts) {
13491359
var i, traceIdx;

test/jasmine/tests/animate_test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ describe('Test animate API', function() {
9494
destroyGraphDiv();
9595
});
9696

97+
it('throws an error if the div is not a plot', function(done) {
98+
var gd2 = createGraphDiv(gd);
99+
100+
// Then = fail, rejection = success
101+
Plotly.animate(gd2).then(fail).catch(done);
102+
});
103+
97104
runTests(0);
98105
runTests(30);
99106

0 commit comments

Comments
 (0)