|
1 | 1 | var Plotly = require('@lib');
|
2 | 2 | // var Lib = require('@src/lib');
|
3 | 3 |
|
| 4 | +var supplyAllDefaults = require('../assets/supply_defaults'); |
4 | 5 | var createGraphDiv = require('../assets/create_graph_div');
|
5 | 6 | var destroyGraphDiv = require('../assets/destroy_graph_div');
|
6 | 7 | var failTest = require('../assets/fail_test');
|
@@ -49,74 +50,111 @@ describe('Test isosurface', function() {
|
49 | 50 |
|
50 | 51 | var gd;
|
51 | 52 |
|
52 |
| - beforeEach(function() { |
53 |
| - gd = createGraphDiv(); |
54 |
| - }); |
55 |
| - |
56 |
| - afterEach(function() { |
57 |
| - Plotly.purge(gd); |
58 |
| - destroyGraphDiv(); |
59 |
| - }); |
| 53 | + describe('defaults', function() { |
60 | 54 |
|
61 |
| - function assertVisibility(exp, msg) { |
62 |
| - expect(gd._fullData[0]).not.toBe(undefined, 'no visibility!'); |
63 |
| - expect(gd._fullData[0].visible).toBe(exp, msg); |
64 |
| - } |
| 55 | + function assertVisibility(exp, msg) { |
| 56 | + expect(gd._fullData[0]).not.toBe(undefined, 'no visibility!'); |
| 57 | + expect(gd._fullData[0].visible).toBe(exp, msg); |
| 58 | + } |
65 | 59 |
|
66 |
| - function assertPositions(exp, msg) { |
67 |
| - expect(gd._fullLayout.scene._scene.glplot.objects[0].positions.length).toBe(exp, msg); |
68 |
| - } |
| 60 | + it('@gl isosurface should not set `visible: false` for traces with x,y,z,value arrays', function() { |
| 61 | + gd = createIsosurfaceFig(); |
69 | 62 |
|
70 |
| - function assertCells(exp, msg) { |
71 |
| - expect(gd._fullLayout.scene._scene.glplot.objects[0].cells.length).toBe(exp, msg); |
72 |
| - } |
| 63 | + supplyAllDefaults(gd); |
| 64 | + assertVisibility(true, 'to be visible'); |
| 65 | + }); |
73 | 66 |
|
| 67 | + it('@gl isosurface should set `visible: false` for traces missing x,y,z,value arrays', function() { |
| 68 | + var keysToChange = ['x', 'y', 'z', 'value']; |
74 | 69 |
|
75 |
| - describe('defaults', function() { |
| 70 | + keysToChange.forEach(function(k) { |
| 71 | + gd = createIsosurfaceFig(); |
| 72 | + delete gd.data[0][k]; |
76 | 73 |
|
77 |
| - it('@gl isosurface should not set `visible: false` for traces with x,y,z,value arrays', function(done) { |
78 |
| - Plotly.plot(gd, createIsosurfaceFig()) |
79 |
| - .then(function() { |
80 |
| - assertVisibility(true, 'to be visible'); |
81 |
| - }) |
82 |
| - .catch(failTest) |
83 |
| - .then(done); |
| 74 | + supplyAllDefaults(gd); |
| 75 | + assertVisibility(false, 'to be invisible after changing key: ' + keysToChange[k]); |
| 76 | + }); |
84 | 77 | });
|
85 | 78 |
|
86 |
| - it('@gl isosurface should set `visible: false` for traces missing x,y,z,value arrays', function(done) { |
| 79 | + it('@gl isosurface should set `visible: false` for traces with empty x,y,z,value arrays', function() { |
87 | 80 | var keysToChange = ['x', 'y', 'z', 'value'];
|
88 | 81 |
|
89 | 82 | keysToChange.forEach(function(k) {
|
90 |
| - var fig = createIsosurfaceFig(); |
91 |
| - delete fig.data[0][k]; |
| 83 | + gd = createIsosurfaceFig(); |
| 84 | + gd.data[0][k] = []; |
92 | 85 |
|
93 |
| - Plotly.plot(gd, fig) |
94 |
| - .then(function() { |
95 |
| - assertVisibility(false, 'to be invisible after changing key: ' + keysToChange[k]); |
96 |
| - }) |
97 |
| - |
98 |
| - .catch(failTest) |
99 |
| - .then(done); |
| 86 | + supplyAllDefaults(gd); |
| 87 | + assertVisibility(false, 'to be invisible after changing key: ' + keysToChange[k]); |
100 | 88 | });
|
101 | 89 | });
|
102 | 90 |
|
103 |
| - it('@gl isosurface should set `visible: false` for traces with empty x,y,z,value arrays', function(done) { |
| 91 | + it('@gl isosurface should be invisible when the vertex arrays are not arrays', function() { |
104 | 92 | var keysToChange = ['x', 'y', 'z', 'value'];
|
| 93 | + var casesToCheck = [0, 1, true, false, NaN, Infinity, -Infinity, null, undefined, [], {}, '', 'text']; |
105 | 94 |
|
106 | 95 | keysToChange.forEach(function(k) {
|
107 |
| - var fig = createIsosurfaceFig(); |
108 |
| - fig.data[0][k] = []; |
109 |
| - |
110 |
| - Plotly.plot(gd, fig) |
111 |
| - .then(function() { |
112 |
| - assertVisibility(false, 'to be invisible after changing key: ' + keysToChange[k]); |
113 |
| - }) |
| 96 | + for(var q = 0; q < casesToCheck.length; q++) { |
| 97 | + gd = createIsosurfaceFig(); |
| 98 | + gd.data[0][k] = casesToCheck[q]; |
114 | 99 |
|
115 |
| - .catch(failTest) |
116 |
| - .then(done); |
| 100 | + supplyAllDefaults(gd); |
| 101 | + assertVisibility(false, 'to be invisible after changing key: ' + keysToChange[k]) + ' to: ' + casesToCheck[q]; |
| 102 | + } |
117 | 103 | });
|
118 | 104 | });
|
119 | 105 |
|
| 106 | + it('@gl isosurface should not set `visible: false` when isomin > isomax', function() { |
| 107 | + gd = createIsosurfaceFig(); |
| 108 | + gd.data[0].isomin = 0.9; |
| 109 | + gd.data[0].isomax = 0.1; |
| 110 | + |
| 111 | + supplyAllDefaults(gd); |
| 112 | + assertVisibility(true, 'to be visible'); |
| 113 | + }); |
| 114 | + |
| 115 | + it('@gl isosurface should set `isomin: null` and `isomax: null` when isomin > isomax', function() { |
| 116 | + gd = createIsosurfaceFig(); |
| 117 | + gd.data[0].isomin = 0.9; |
| 118 | + gd.data[0].isomax = 0.1; |
| 119 | + |
| 120 | + supplyAllDefaults(gd); |
| 121 | + expect(gd._fullData[0].isomin).toBe(null, 'isomin not set to default'); |
| 122 | + expect(gd._fullData[0].isomax).toBe(null, 'isomax not set to default'); |
| 123 | + }); |
| 124 | + |
| 125 | + it('@gl isosurface should accept cases where isomin === isomax', function() { |
| 126 | + gd = createIsosurfaceFig(); |
| 127 | + gd.data[0].isomin = 1e-2; |
| 128 | + gd.data[0].isomax = 0.01; |
| 129 | + |
| 130 | + supplyAllDefaults(gd); |
| 131 | + expect(gd._fullData[0].isomin).not.toBe(null, 'isomin not set'); |
| 132 | + expect(gd._fullData[0].isomax).not.toBe(null, 'isomax not set'); |
| 133 | + }); |
| 134 | + |
| 135 | + }); |
| 136 | + |
| 137 | + describe('mesh_generation', function() { |
| 138 | + |
| 139 | + var gd; |
| 140 | + |
| 141 | + beforeEach(function() { |
| 142 | + gd = createGraphDiv(); |
| 143 | + }); |
| 144 | + |
| 145 | + afterEach(function() { |
| 146 | + Plotly.purge(gd); |
| 147 | + destroyGraphDiv(); |
| 148 | + }); |
| 149 | + |
| 150 | + function assertPositions(exp, msg) { |
| 151 | + expect(gd._fullLayout.scene._scene.glplot.objects[0].positions.length).toBe(exp, msg); |
| 152 | + } |
| 153 | + |
| 154 | + function assertCells(exp, msg) { |
| 155 | + expect(gd._fullLayout.scene._scene.glplot.objects[0].cells.length).toBe(exp, msg); |
| 156 | + } |
| 157 | + |
120 | 158 | it('@gl isosurface should create no iso-surface and set `gl-positions: []` for traces when all the data is between isomin and isomax', function(done) {
|
121 | 159 | var fig = createIsosurfaceFig();
|
122 | 160 | var data = fig.data[0];
|
@@ -159,75 +197,21 @@ describe('Test isosurface', function() {
|
159 | 197 | .then(done);
|
160 | 198 | });
|
161 | 199 |
|
162 |
| - it('@gl isosurface should be invisible when the vertex arrays are not arrays', function(done) { |
163 |
| - |
164 |
| - var keysToChange = ['x', 'y', 'z', 'value']; |
165 |
| - var casesToCheck = [0, 1, true, false, NaN, Infinity, -Infinity, null, undefined, [], {}, '', 'text']; |
166 |
| - |
167 |
| - function _testUsing(k, q) { |
168 |
| - assertVisibility(false, 'to be invisible after changing key: ' + keysToChange[k]) + ' to: ' + casesToCheck[q]; |
169 |
| - } |
170 |
| - |
171 |
| - keysToChange.forEach(function(k) { |
172 |
| - for(var q = 0; q < casesToCheck.length; q++) { |
173 |
| - |
174 |
| - var fig = createIsosurfaceFig(); |
175 |
| - fig.data[0][k] = casesToCheck[q]; |
176 |
| - |
177 |
| - Plotly.plot(gd, fig) |
178 |
| - .then(_testUsing) |
179 |
| - .catch(failTest) |
180 |
| - .then(done); |
181 |
| - } |
182 |
| - }); |
183 |
| - }); |
184 |
| - |
185 |
| - it('@gl isosurface should not set `visible: false` when isomin > isomax', function(done) { |
186 |
| - var fig = createIsosurfaceFig(); |
187 |
| - fig.data[0].isomin = 0.9; |
188 |
| - fig.data[0].isomax = 0.1; |
| 200 | + }); |
189 | 201 |
|
190 |
| - Plotly.plot(gd, createIsosurfaceFig()) |
191 |
| - .then(function() { |
192 |
| - assertVisibility(true, 'to be visible'); |
193 |
| - }) |
194 |
| - .catch(failTest) |
195 |
| - .then(done); |
196 |
| - }); |
| 202 | + describe('restyle', function() { |
197 | 203 |
|
198 |
| - it('@gl isosurface should set `isomin: null` and `isomax: null` when isomin > isomax', function(done) { |
199 |
| - var fig = createIsosurfaceFig(); |
200 |
| - fig.data[0].isomin = 0.9; |
201 |
| - fig.data[0].isomax = 0.1; |
| 204 | + var gd; |
202 | 205 |
|
203 |
| - Plotly.plot(gd, fig) |
204 |
| - .then(function() { |
205 |
| - expect(gd._fullData[0].isomin).toBe(null, 'isomin not set to default'); |
206 |
| - expect(gd._fullData[0].isomax).toBe(null, 'isomax not set to default'); |
207 |
| - }) |
208 |
| - .catch(failTest) |
209 |
| - .then(done); |
| 206 | + beforeEach(function() { |
| 207 | + gd = createGraphDiv(); |
210 | 208 | });
|
211 | 209 |
|
212 |
| - it('@gl isosurface should accept cases where isomin === isomax', function(done) { |
213 |
| - var fig = createIsosurfaceFig(); |
214 |
| - fig.data[0].isomin = 1e-2; |
215 |
| - fig.data[0].isomax = 0.01; |
216 |
| - |
217 |
| - Plotly.plot(gd, fig) |
218 |
| - .then(function() { |
219 |
| - expect(gd._fullData[0].isomin).not.toBe(null, 'isomin not set'); |
220 |
| - expect(gd._fullData[0].isomax).not.toBe(null, 'isomax not set'); |
221 |
| - }) |
222 |
| - .catch(failTest) |
223 |
| - .then(done); |
| 210 | + afterEach(function() { |
| 211 | + Plotly.purge(gd); |
| 212 | + destroyGraphDiv(); |
224 | 213 | });
|
225 | 214 |
|
226 |
| - }); |
227 |
| - |
228 |
| - |
229 |
| - describe('restyle', function() { |
230 |
| - |
231 | 215 | it('should clear *cauto* when restyle *cmin* and/or *cmax*', function(done) {
|
232 | 216 |
|
233 | 217 | function _assert(user, full) {
|
|
0 commit comments