-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathscatterpolargl_test.js
172 lines (151 loc) · 5.01 KB
/
scatterpolargl_test.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
var Plotly = require('@lib');
var Lib = require('@src/lib');
var d3 = require('d3');
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var failTest = require('../assets/fail_test');
var mouseEvent = require('../assets/mouse_event');
var readPixel = require('../assets/read_pixel');
var customAssertions = require('../assets/custom_assertions');
var assertHoverLabelContent = customAssertions.assertHoverLabelContent;
describe('Test scatterpolargl hover:', function() {
var gd;
afterEach(function() {
Plotly.purge(gd);
destroyGraphDiv();
});
function run(specs) {
gd = createGraphDiv();
var fig = Lib.extendDeep(
{width: 700, height: 500},
specs.mock || require('@mocks/glpolar_scatter.json')
);
if(specs.patch) {
fig = specs.patch(fig);
}
var pos = specs.pos || [200, 200];
return Plotly.newPlot(gd, fig).then(function() {
mouseEvent('mousemove', pos[0], pos[1]);
assertHoverLabelContent(specs);
});
}
[{
desc: 'base',
nums: 'r: 3.886013\nθ: 125.2822°',
name: 'Trial 3'
}, {
desc: '(no labels - out of sector)',
patch: function(fig) {
fig.layout.polar.sector = [15, 75];
return fig;
},
pos: [144, 350],
nums: '',
name: ''
}, {
desc: 'on a `thetaunit: radians` polar subplot',
patch: function(fig) {
fig.layout.polar.angularaxis.thetaunit = 'radians';
return fig;
},
nums: 'r: 3.886013\nθ: 2.186586',
name: 'Trial 3'
}, {
desc: 'on log radial axis',
patch: function(fig) {
fig.layout.polar.radialaxis.type = 'log';
return fig;
},
nums: 'r: 1.108937\nθ: 115.4969°',
name: 'Trial 3'
}, {
desc: 'on category axes',
mock: require('@mocks/polar_categories.json'),
patch: function(fig) {
fig.data.forEach(function(t) {
t.type = 'scatterpolargl';
t.fill = 'none';
});
return fig;
},
pos: [470, 80],
nums: 'r: 4\nθ: d',
name: 'angular cate...'
}, {
desc: 'with custom text scalar',
patch: function(fig) {
fig.data.forEach(function(t) { t.text = 'a'; });
return fig;
},
nums: 'r: 3.886013\nθ: 125.2822°\na',
name: 'Trial 3'
}, {
desc: 'with custom text array',
patch: function(fig) {
fig.data.forEach(function(t) { t.text = t.r.map(String); });
return fig;
},
nums: 'r: 3.886013\nθ: 125.2822°\n3.88601339194',
name: 'Trial 3'
}]
.forEach(function(specs) {
it('should generate correct hover labels ' + specs.desc, function(done) {
run(specs).catch(failTest).then(done);
});
});
});
describe('Test scatterpolargl interactions:', function() {
var gd;
afterEach(function() {
Plotly.purge(gd);
destroyGraphDiv();
});
function countCanvases() {
return d3.selectAll('canvas').size();
}
function totalPixels() {
return readPixel(gd.querySelector('.gl-canvas-context'), 0, 0, 400, 400)
.reduce(function(acc, v) { return acc + v; }, 0);
}
it('@gl should be able to toggle from svg to gl', function(done) {
gd = createGraphDiv();
var scene;
Plotly.plot(gd, [{
type: 'scatterpolar',
r: [1, 2, 1],
}], {
width: 400,
height: 400
})
.then(function() {
expect(countCanvases()).toBe(0);
expect(d3.selectAll('.scatterlayer > .trace').size()).toBe(1);
return Plotly.restyle(gd, 'type', 'scatterpolargl');
})
.then(function() {
expect(countCanvases()).toBe(3);
expect(totalPixels()).not.toBe(0);
expect(d3.selectAll('.scatterlayer > .trace').size()).toBe(0);
scene = gd._fullLayout.polar._subplot._scene;
spyOn(scene, 'destroy').and.callThrough();
return Plotly.restyle(gd, 'type', 'scatterpolar');
})
.then(function() {
expect(countCanvases()).toBe(0);
expect(scene.destroy).toHaveBeenCalledTimes(1);
expect(gd._fullLayout.polar._subplot._scene).toBe(null);
expect(d3.selectAll('.scatterlayer > .trace').size()).toBe(1);
return Plotly.restyle(gd, 'type', 'scatterpolargl');
})
.then(function() {
expect(countCanvases()).toBe(3);
// this here was failing before
// https://github.com/plotly/plotly.js/issues/3094
// got fixed
expect(totalPixels()).not.toBe(0);
expect(d3.selectAll('.scatterlayer > .trace').size()).toBe(0);
})
.catch(failTest)
.then(done);
});
});