Skip to content

Commit f43ac01

Browse files
committed
Throw animate API errors whne gd is not a plot
1 parent 02dcf5d commit f43ac01

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/plot_api/plot_api.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -2487,8 +2487,7 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
24872487
gd = getGraphDiv(gd);
24882488

24892489
if(!Lib.isPlotDiv(gd)) {
2490-
Lib.warn('This element is not a Plotly plot.', gd);
2491-
return Promise.reject();
2490+
throw new Error('This element is not a Plotly plot: ' + gd);
24922491
}
24932492

24942493
var trans = gd._transitionData;
@@ -2771,8 +2770,7 @@ Plotly.addFrames = function(gd, frameList, indices) {
27712770
gd = getGraphDiv(gd);
27722771

27732772
if(!Lib.isPlotDiv(gd)) {
2774-
Lib.warn('This element is not a Plotly plot.', gd);
2775-
return Promise.reject();
2773+
throw new Error('This element is not a Plotly plot: ' + gd);
27762774
}
27772775

27782776
var i, frame, j, idx;
@@ -2781,8 +2779,7 @@ Plotly.addFrames = function(gd, frameList, indices) {
27812779

27822780

27832781
if(!Array.isArray(frameList)) {
2784-
Lib.warn('addFrames failure: frameList must be an Array of frame definitions', frameList);
2785-
return Promise.reject();
2782+
throw new Error('addFrames failure: frameList must be an Array of frame definitions' + frameList);
27862783
}
27872784

27882785
// Create a sorted list of insertions since we run into lots of problems if these
@@ -2860,8 +2857,7 @@ Plotly.deleteFrames = function(gd, frameList) {
28602857
gd = getGraphDiv(gd);
28612858

28622859
if(!Lib.isPlotDiv(gd)) {
2863-
Lib.warn('This element is not a Plotly plot.', gd);
2864-
return Promise.reject();
2860+
throw new Error('This element is not a Plotly plot: ' + gd);
28652861
}
28662862

28672863
var i, idx;

test/jasmine/tests/animate_test.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,16 @@ 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);
97+
it('throws an error if gd is not a graph', function() {
98+
var gd2 = document.createElement('div');
99+
gd2.id = 'invalidgd';
100+
document.body.appendChild(gd2);
99101

100-
// Then = fail, rejection = success
101-
Plotly.animate(gd2).then(fail).catch(done);
102+
expect(function() {
103+
Plotly.addFrames(gd2, [{}]);
104+
}).toThrow(new Error('This element is not a Plotly plot: [object HTMLDivElement]'));
105+
106+
document.body.removeChild(gd);
102107
});
103108

104109
runTests(0);

0 commit comments

Comments
 (0)