-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
plot_interact_test.js
163 lines (122 loc) · 4.95 KB
/
plot_interact_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
var d3 = require('d3');
var Plotly = require('@lib/index');
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
describe('Test plot structure', function() {
'use strict';
function assertNamespaces(node) {
expect(node.getAttribute('xmlns'))
.toEqual('http://www.w3.org/2000/svg');
expect(node.getAttribute('xmlns:xlink'))
.toEqual('http://www.w3.org/1999/xlink');
}
afterEach(destroyGraphDiv);
describe('cartesian plots', function() {
describe('scatter traces', function() {
var mock = require('@mocks/14.json');
beforeEach(function(done) {
Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(done);
});
it('has one *subplot xy* node', function() {
var nodes = d3.selectAll('g.subplot.xy');
expect(nodes.size()).toEqual(1);
});
it('has one *scatterlayer* node', function() {
var nodes = d3.selectAll('g.scatterlayer');
expect(nodes.size()).toEqual(1);
});
it('has as many *trace scatter* nodes as there are traces', function() {
var nodes = d3.selectAll('g.trace.scatter');
expect(nodes.size()).toEqual(mock.data.length);
});
it('has as many *point* nodes as there are traces', function() {
var nodes = d3.selectAll('path.point');
var Npts = 0;
mock.data.forEach(function(trace) {
Npts += trace.x.length;
});
expect(nodes.size()).toEqual(Npts);
});
it('has the correct name spaces', function() {
var mainSVGs = d3.selectAll('.main-svg');
mainSVGs.each(function() {
var node = this;
assertNamespaces(node);
});
});
});
describe('pie traces', function() {
var mock = require('@mocks/pie_simple.json');
beforeEach(function(done) {
Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(done);
});
it('has as many *slice* nodes as there are pie items', function() {
var nodes = d3.selectAll('g.slice');
var Npts = 0;
mock.data.forEach(function(trace) {
Npts += trace.values.length;
});
expect(nodes.size()).toEqual(Npts);
});
it('has the correct name spaces', function() {
var mainSVGs = d3.selectAll('.main-svg');
mainSVGs.each(function() {
var node = this;
assertNamespaces(node);
});
var testerSVG = d3.selectAll('#js-plotly-tester');
assertNamespaces(testerSVG.node());
});
});
});
describe('geo plots', function() {
var mock = require('@mocks/geo_first.json');
beforeEach(function(done) {
Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(done);
});
it('has as many *choroplethlocation* nodes as there are choropleth locations', function() {
var nodes = d3.selectAll('path.choroplethlocation');
var Npts = 0;
mock.data.forEach(function(trace) {
var items = trace.locations;
if(items) Npts += items.length;
});
expect(nodes.size()).toEqual(Npts);
});
it('has as many *point* nodes as there are marker points', function() {
var nodes = d3.selectAll('path.point');
var Npts = 0;
mock.data.forEach(function(trace) {
var items = trace.lat;
if(items) Npts += items.length;
});
expect(nodes.size()).toEqual(Npts);
});
it('has the correct name spaces', function() {
var mainSVGs = d3.selectAll('.main-svg');
mainSVGs.each(function() {
var node = this;
assertNamespaces(node);
});
var geoSVGs = d3.select('#geo').selectAll('svg');
geoSVGs.each(function() {
var node = this;
assertNamespaces(node);
});
});
});
describe('polar plots', function() {
var mock = require('@mocks/polar_scatter.json');
beforeEach(function(done) {
Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(done);
});
it('has as many *mark dot* nodes as there are points', function() {
var nodes = d3.selectAll('path.mark.dot');
var Npts = 0;
mock.data.forEach(function(trace) {
Npts += trace.r.length;
});
expect(nodes.size()).toEqual(Npts);
});
});
});