Skip to content

Commit 55e5e12

Browse files
committed
added more logic
1 parent e97f5ed commit 55e5e12

File tree

2 files changed

+50
-30
lines changed

2 files changed

+50
-30
lines changed

src/traces/mesh3d/defaults.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,31 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3939
return;
4040
}
4141

42-
var allIndices = readComponents(['i', 'j', 'k']);
43-
if(allIndices === false) {
42+
// three indices should be all provided or not
43+
if(
44+
(traceIn.i && (!traceIn.j || !traceIn.k)) ||
45+
(traceIn.j && (!traceIn.k || !traceIn.i)) ||
46+
(traceIn.k && (!traceIn.i || !traceIn.j))
47+
) {
4448
traceOut.visible = false;
4549
return;
4650
}
51+
52+
// test for size of indices
53+
if(
54+
traceIn.i && Lib.isArrayOrTypedArray(traceIn.i) &&
55+
traceIn.j && Lib.isArrayOrTypedArray(traceIn.j) &&
56+
traceIn.k && Lib.isArrayOrTypedArray(traceIn.k)
57+
) {
58+
if( traceIn.k.length !== 0 && (
59+
traceIn.i.length !== traceIn.j.length ||
60+
traceIn.j.length !== traceIn.k.length)) {
61+
traceOut.visible = false;
62+
return;
63+
}
64+
}
65+
66+
var allIndices = readComponents(['i', 'j', 'k']);
4767
if(allIndices) {
4868
var numVertices = coords[0].length;
4969
allIndices.forEach(function(indices) {

test/jasmine/tests/mesh3d_test.js

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -76,34 +76,6 @@ describe('Test mesh3d', function() {
7676
expect(gd._fullData[0].visible).toBe(exp, msg);
7777
}
7878

79-
it('@gl mesh3d should be visible when the vertex array are empty', function(done) {
80-
Plotly.plot(gd, [{
81-
x: [],
82-
y: [],
83-
z: [],
84-
type: 'mesh3d'
85-
}])
86-
.then(function() {
87-
assertVisibility(false, 'not to be visible');
88-
})
89-
.catch(failTest)
90-
.then(done);
91-
});
92-
93-
it('@gl mesh3d should be visible when the index arrays are not provided', function(done) {
94-
Plotly.plot(gd, [{
95-
x: [0, 1, 0.5, 0.5],
96-
y: [0, 0.5, 1, 0.5],
97-
z: [0, 0.5, 0.5, 1],
98-
type: 'mesh3d'
99-
}])
100-
.then(function() {
101-
assertVisibility(false, 'not to be visible');
102-
})
103-
.catch(failTest)
104-
.then(done);
105-
});
106-
10779
it('@gl mesh3d should be invisible when the indices are not integer', function(done) {
10880
Plotly.plot(gd, [{
10981
x: [0, 1, 0.5, 0.5],
@@ -222,6 +194,34 @@ describe('Test mesh3d', function() {
222194
.catch(failTest)
223195
.then(done);
224196
});
197+
198+
it('@gl mesh3d should be visible when the index arrays are not provided', function(done) {
199+
Plotly.plot(gd, [{
200+
x: [0, 1, 0.5, 0.5],
201+
y: [0, 0.5, 1, 0.5],
202+
z: [0, 0.5, 0.5, 1],
203+
type: 'mesh3d'
204+
}])
205+
.then(function() {
206+
assertVisibility(true, 'to be visible');
207+
})
208+
.catch(failTest)
209+
.then(done);
210+
});
211+
212+
it('@gl mesh3d should be visible when the vertex array are empty', function(done) {
213+
Plotly.plot(gd, [{
214+
x: [],
215+
y: [],
216+
z: [],
217+
type: 'mesh3d'
218+
}])
219+
.then(function() {
220+
assertVisibility(true, 'not to be visible');
221+
})
222+
.catch(failTest)
223+
.then(done);
224+
});
225225
});
226226

227227
});

0 commit comments

Comments
 (0)