forked from jacomyal/sigma.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunit.animation.js
117 lines (110 loc) · 2.69 KB
/
unit.animation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
module('sigma.misc.animation');
asyncTest('Camera animation', function() {
function approx(v) {
return Math.round(v * 10000) / 10000;
}
var hasTestedFrame,
graph = new sigma.classes.graph(),
camera = new sigma.classes.camera('myCam', graph, sigma.classes.configurable(sigma.settings));
// Fill the graph:
graph.addNode({
id: '0',
x: 1,
y: 2,
size: 1
}).addNode({
id: '1',
x: 2,
y: 1,
size: 1
}).addNode({
id: '2',
x: 1,
y: 0,
size: 1
});
graph.addEdge({
id: '0',
source: '0',
target: '1',
size: 1
});
camera.applyView('', 'display:');
sigma.misc.animation.camera(camera, {
x: 2,
y: 1,
ratio: 2,
angle: Math.PI / 2
}, {
duration: 50,
easing: function(k) {
return (k === 1) ? k : 0.5;
},
onNewFrame: function() {
camera.applyView('', 'display:');
if (!hasTestedFrame) {
start();
deepEqual(
graph.nodes().map(function(n) {
return {
x: approx(n['display:x']),
y: approx(n['display:y']),
size: approx(n['display:size'])
};
}),
[
{
size: approx(Math.pow(2 / 3, camera.settings('nodesPowRatio'))),
x: approx(Math.SQRT1_2),
y: approx(Math.SQRT1_2)
},
{
size: approx(Math.pow(2 / 3, camera.settings('nodesPowRatio'))),
x: approx(Math.SQRT1_2),
y: -approx(Math.SQRT1_2) / 3
},
{
size: approx(Math.pow(2 / 3, camera.settings('nodesPowRatio'))),
x: -approx(Math.SQRT1_2) / 3,
y: -approx(Math.SQRT1_2) / 3
}
],
'Animation\'s middle gives the good values.'
);
stop();
hasTestedFrame = true;
}
},
onComplete: function() {
camera.applyView('', 'display:');
start();
deepEqual(
graph.nodes().map(function(n) {
return {
x: approx(n['display:x']),
y: approx(n['display:y']),
size: approx(n['display:size'])
};
}),
[
{
x: 0.5,
y: 0.5,
size: approx(Math.pow(0.5, camera.settings('nodesPowRatio')))
},
{
x: 0,
y: 0,
size: approx(Math.pow(0.5, camera.settings('nodesPowRatio')))
},
{
x: -0.5,
y: 0.5,
size: approx(Math.pow(0.5, camera.settings('nodesPowRatio')))
}
],
'Animation\'s end gives the good values and custom easings work well.'
);
}
});
});