Skip to content

Commit c85c3a2

Browse files
committed
Verify gd is a plot div for animate, addFrames, deleteFrames
1 parent 0f23eef commit c85c3a2

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

src/plot_api/plot_api.js

+16
Original file line numberDiff line numberDiff line change
@@ -2484,6 +2484,12 @@ Plotly.relayout = function relayout(gd, astr, val) {
24842484
*/
24852485
Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
24862486
gd = getGraphDiv(gd);
2487+
2488+
if(!Lib.isPlotDiv(gd)) {
2489+
Lib.warn('This element is not a Plotly plot.', gd);
2490+
return Promise.reject();
2491+
}
2492+
24872493
var trans = gd._transitionData;
24882494

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

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

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

src/plots/plots.js

+12-2
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

+7
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)