Skip to content

Commit e4363a2

Browse files
committed
Add .animate tests
1 parent c7be054 commit e4363a2

File tree

3 files changed

+105
-1
lines changed

3 files changed

+105
-1
lines changed

src/plot_api/plot_api.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2493,9 +2493,11 @@ Plotly.relayout = function relayout(gd, astr, val) {
24932493
* @param {string id or DOM element} gd
24942494
* the id or DOM element of the graph container div
24952495
*/
2496-
Plotly.transition = function(gd /*, data, layout, traces, transitionConfig*/) {
2496+
Plotly.transition = function(gd, data, layout, traces, transitionConfig) {
24972497
gd = getGraphDiv(gd);
24982498

2499+
return Promise.resolve();
2500+
24992501
/*var fullLayout = gd._fullLayout;
25002502
25012503
transitionConfig = Lib.extendFlat({

test/image/mocks/animation.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"data": [
3+
{
4+
"x": [0, 1, 2],
5+
"y": [0, 2, 8],
6+
"type": "scatter"
7+
},
8+
{
9+
"x": [0, 1, 2],
10+
"y": [4, 2, 3],
11+
"type": "scatter"
12+
}
13+
],
14+
"layout": {
15+
"title": "Animation test",
16+
"showlegend": true,
17+
"autosize": false,
18+
"width": 800,
19+
"height": 440,
20+
"xaxis": {
21+
"range": [0, 2],
22+
"domain": [0, 1],
23+
},
24+
"yaxis": {
25+
"range": [0, 10],
26+
"domain": [0, 1],
27+
}
28+
},
29+
"frames": [{
30+
"name": 'frame0',
31+
"data": [
32+
{"y": [0, 2, 8]},
33+
{"y": [4, 2, 3]}
34+
],
35+
"traceIndices": [0, 1],
36+
"layout": { }
37+
}, {
38+
"name": 'frame1',
39+
"data": [
40+
{"y": [1, 3, 9]},
41+
{"y": [5, 3, 4]}
42+
],
43+
"traceIndices": [0, 1],
44+
"layout": { }
45+
}]
46+
}

test/jasmine/tests/animate_test.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
var Plotly = require('@lib/index');
2+
var PlotlyInternal = require('@src/plotly');
3+
var Lib = require('@src/lib');
4+
5+
var createGraphDiv = require('../assets/create_graph_div');
6+
var destroyGraphDiv = require('../assets/destroy_graph_div');
7+
var fail = require('../assets/fail_test');
8+
9+
describe('Test animate API', function() {
10+
'use strict';
11+
12+
var gd;
13+
14+
beforeEach(function(done) {
15+
gd = createGraphDiv();
16+
17+
var mock = require('@mocks/animation');
18+
var mockCopy = Lib.extendDeep({}, mock);
19+
20+
spyOn(PlotlyInternal, 'transition').and.callFake(function() {
21+
return Promise.resolve();
22+
});
23+
24+
Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(function() {
25+
Plotly.addFrames(gd, mockCopy.frames);
26+
}).then(done);
27+
});
28+
29+
afterEach(function() {
30+
destroyGraphDiv();
31+
});
32+
33+
it('rejects if the frame is not found', function(done) {
34+
Plotly.animate(gd, 'foobar').then(fail).then(done, done);
35+
});
36+
37+
it('animates to a frame', function(done) {
38+
Plotly.animate(gd, 'frame0').then(function() {
39+
expect(PlotlyInternal.transition).toHaveBeenCalled();
40+
41+
var args = PlotlyInternal.transition.calls.mostRecent().args;
42+
43+
// was called with gd, data, layout, traceIndices, transitionConfig:
44+
expect(args.length).toEqual(5);
45+
46+
// data has two traces:
47+
expect(args[1].length).toEqual(2);
48+
49+
// layout
50+
expect(args[2]).toEqual({});
51+
52+
// traces are [0, 1]:
53+
expect(args[3]).toEqual([0, 1]);
54+
}).catch(fail).then(done);
55+
});
56+
});

0 commit comments

Comments
 (0)