Skip to content

Commit 35bbb86

Browse files
authored
Merge pull request #1088 from plotly/animation-nice-message
Add a nice error message when people animate before plotting
2 parents cbd6b87 + c9df28d commit 35bbb86

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;
@@ -2496,7 +2500,11 @@ Plotly.addFrames = function(gd, frameList, indices) {
24962500
}
24972501

24982502
if(!Lib.isPlotDiv(gd)) {
2499-
throw new Error('This element is not a Plotly plot: ' + gd);
2503+
throw new Error(
2504+
'This element is not a Plotly plot: ' + gd + '. It\'s likely that you\'ve failed ' +
2505+
'to create a plot before adding frames. For more details, see ' +
2506+
'https://plot.ly/javascript/animations/'
2507+
);
25002508
}
25012509

25022510
var i, frame, j, idx;

test/jasmine/tests/animate_test.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,26 @@ describe('Test animate API', function() {
105105
destroyGraphDiv();
106106
});
107107

108-
it('throws an error if gd is not a graph', function() {
108+
it('throws an error on addFrames if gd is not a graph', function() {
109109
var gd2 = document.createElement('div');
110110
gd2.id = 'invalidgd';
111111
document.body.appendChild(gd2);
112112

113113
expect(function() {
114114
Plotly.addFrames(gd2, [{}]);
115-
}).toThrow(new Error('This element is not a Plotly plot: [object HTMLDivElement]'));
115+
}).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/'));
116+
117+
document.body.removeChild(gd);
118+
});
119+
120+
it('throws an error on animate if gd is not a graph', function() {
121+
var gd2 = document.createElement('div');
122+
gd2.id = 'invalidgd';
123+
document.body.appendChild(gd2);
124+
125+
expect(function() {
126+
Plotly.animate(gd2, {data: [{}]});
127+
}).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/'));
116128

117129
document.body.removeChild(gd);
118130
});

0 commit comments

Comments
 (0)