Skip to content

Commit c9df28d

Browse files
committed
Add a nice error message when people animate before plotting
1 parent fed224c commit c9df28d

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/plot_api/plot_api.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -2156,7 +2156,11 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
21562156
gd = helpers.getGraphDiv(gd);
21572157

21582158
if(!Lib.isPlotDiv(gd)) {
2159-
throw new Error('This element is not a Plotly plot: ' + gd);
2159+
throw new Error(
2160+
'This element is not a Plotly plot: ' + gd + '. It\'s likely that you\'ve failed ' +
2161+
'to create a plot before animating it. For more details, see ' +
2162+
'https://plot.ly/javascript/animations/'
2163+
);
21602164
}
21612165

21622166
var trans = gd._transitionData;
@@ -2469,7 +2473,11 @@ Plotly.addFrames = function(gd, frameList, indices) {
24692473
}
24702474

24712475
if(!Lib.isPlotDiv(gd)) {
2472-
throw new Error('This element is not a Plotly plot: ' + gd);
2476+
throw new Error(
2477+
'This element is not a Plotly plot: ' + gd + '. It\'s likely that you\'ve failed ' +
2478+
'to create a plot before adding frames. For more details, see ' +
2479+
'https://plot.ly/javascript/animations/'
2480+
);
24732481
}
24742482

24752483
var i, frame, j, idx;

test/jasmine/tests/animate_test.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,26 @@ describe('Test animate API', function() {
9494
destroyGraphDiv();
9595
});
9696

97-
it('throws an error if gd is not a graph', function() {
97+
it('throws an error on addFrames if gd is not a graph', function() {
9898
var gd2 = document.createElement('div');
9999
gd2.id = 'invalidgd';
100100
document.body.appendChild(gd2);
101101

102102
expect(function() {
103103
Plotly.addFrames(gd2, [{}]);
104-
}).toThrow(new Error('This element is not a Plotly plot: [object HTMLDivElement]'));
104+
}).toThrow(new Error('This element is not a Plotly plot: [object HTMLDivElement]. It\'s likely that you\'ve failed to create a plot before adding frames. For more details, see https://plot.ly/javascript/animations/'));
105+
106+
document.body.removeChild(gd);
107+
});
108+
109+
it('throws an error on animate if gd is not a graph', function() {
110+
var gd2 = document.createElement('div');
111+
gd2.id = 'invalidgd';
112+
document.body.appendChild(gd2);
113+
114+
expect(function() {
115+
Plotly.animate(gd2, {data: [{}]});
116+
}).toThrow(new Error('This element is not a Plotly plot: [object HTMLDivElement]. It\'s likely that you\'ve failed to create a plot before animating it. For more details, see https://plot.ly/javascript/animations/'));
105117

106118
document.body.removeChild(gd);
107119
});

0 commit comments

Comments
 (0)