Skip to content

Mesh3d cell data checks #3369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jan 7, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/traces/mesh3d/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var triangulate = require('delaunay-triangulate');
var alphaShape = require('alpha-shape');
var convexHull = require('convex-hull');

var isIndex = require('../../lib').isIndex;
var parseColorScale = require('../../lib/gl_format_color').parseColorScale;
var str2RgbaArray = require('../../lib/str2rgbarray');
var zip3 = require('../../plots/gl3d/zip3');
Expand Down Expand Up @@ -91,12 +92,40 @@ function delaunayCells(delaunayaxis, positions) {
return triangulate(b);
}

// validate indices
function hasValidIndices(list, numVertices) {
var len = list.length;
for(var i = 0; i < len; i++) {
if(!isIndex(list[i], numVertices)) {
return false;
}
}
return true;
}

// avoid pointing to an identical vertex twice
function isTriangle(lists) {
var len = lists[0].length;
for(var i = 0; i < len; i++) {
if(
lists[0][i] === lists[1][i] ||
lists[1][i] === lists[2][i] ||
lists[2][i] === lists[0][i]
) {
return false;
}
}
return true;
}

proto.update = function(data) {
var scene = this.scene;
var layout = scene.fullSceneLayout;

this.data = data;

var numVertices = data.x.length;

var positions = zip3(
toDataCoords(layout.xaxis, data.x, scene.dataScale[0], data.xcalendar),
toDataCoords(layout.yaxis, data.y, scene.dataScale[1], data.ycalendar),
Expand All @@ -105,6 +134,18 @@ proto.update = function(data) {

var cells;
if(data.i && data.j && data.k) {

if(
data.i.length !== data.j.length ||
data.j.length !== data.k.length ||
!hasValidIndices(data.i, numVertices) ||
!hasValidIndices(data.j, numVertices) ||
!hasValidIndices(data.k, numVertices) ||
!isTriangle([data.i, data.j, data.k])
) {
data.visible = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't set visible: false here. fullData keys can't be mutated after the defaults step (unless they are _ properties) for our Plotly.react diffing to work correctly.

Just removing this line here will suffice (i.e. and keeping the early return below) should suffice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the info on this. Simply removed the line. And changed jasmine tests for the trace to be visible in all those cases.

return;
}
cells = zip3(
toIndex(data.i),
toIndex(data.j),
Expand Down
40 changes: 1 addition & 39 deletions src/traces/mesh3d/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,45 +48,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
traceOut.visible = false;
return;
}

// test for size of indices
if(
traceIn.i && Lib.isArrayOrTypedArray(traceIn.i) &&
traceIn.j && Lib.isArrayOrTypedArray(traceIn.j) &&
traceIn.k && Lib.isArrayOrTypedArray(traceIn.k)
) {
if(traceIn.k.length !== 0 && (
traceIn.i.length !== traceIn.j.length ||
traceIn.j.length !== traceIn.k.length)) {
traceOut.visible = false;
return;
}
}

var allIndices = readComponents(['i', 'j', 'k']);
if(allIndices) {
var numVertices = coords[0].length;
allIndices.forEach(function(indices) {
indices.forEach(function(index) {
if(!Lib.isIndex(index, numVertices)) {
traceOut.visible = false;
return;
}
});
});

var numFaces = allIndices[0].length;
for(var q = 0; q < numFaces; q++) {
if(
allIndices[0][q] === allIndices[1][q] ||
allIndices[0][q] === allIndices[2][q] ||
allIndices[1][q] === allIndices[2][q]
) {
traceOut.visible = false;
return;
}
}
}
readComponents(['i', 'j', 'k']);

var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');
handleCalendarDefaults(traceIn, traceOut, ['x', 'y', 'z'], layout);
Expand Down
2 changes: 1 addition & 1 deletion test/jasmine/tests/mesh3d_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('Test mesh3d', function() {
expect(gd._fullData[0].visible).toBe(exp, msg);
}

it('@gl mesh3d should be invisible when the indices are not integer', function(done) {
it('@gl mesh3d should be visible when the indices are not integer', function(done) {
Plotly.plot(gd, [{
x: [0, 1, 0.5, 0.5],
y: [0, 0.5, 1, 0.5],
Expand Down