Skip to content
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

Mesh3d cell data checks #3369

Merged
merged 16 commits into from
Jan 7, 2019
Merged

Mesh3d cell data checks #3369

merged 16 commits into from
Jan 7, 2019

Conversation

archmoj
Copy link
Contributor

@archmoj archmoj commented Dec 22, 2018

Fix #2630 by removing the indices clean up from the defaults code.
@plotly/plotly_js

@archmoj archmoj changed the title Mesh3d no longer clean up user cell data if messy Mesh3d would no longer clean up user cell data if messy Dec 22, 2018
@etpinard etpinard added the bug something broken label Dec 24, 2018
if(indices) {
// otherwise, convert all face indices to ints
indices.forEach(function(index) {
for(var i = 0; i < index.length; ++i) index[i] |= 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. So you didn't move this to mesh3d/convert.js? Just 🔪 ing it didn't break any tests?

Can you try plotting a mesh3d trace with non-integer indices and see what happens?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@etpinard Thanks for the review.
That's true! One could get bad errors in case of having non-integer ids.
So, in the revised code I added map functions to round the float values to integers.
However; there is now extra logic to check and handle for such cases. A series of jasmine tests are also added to define the expected behaviour in various scenarios.

@archmoj archmoj changed the title Mesh3d would no longer clean up user cell data if messy Mesh3d cell data checks Jan 3, 2019
!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.

type: 'mesh3d'
}])
.then(function() {
assertVisibility(true, 'to be visible');
Copy link
Contributor

Choose a reason for hiding this comment

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

Right, this is correct: fullData will have visible:false. But this doesn't test any of the new logic in convert.js.

Could you add a check for e.g.

gd._fullLayout.scene._scene.glplot.objects[0].positions

which should be an ok proxy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. Will do so.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, sorry for not catching this sooner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem. Previously we get different visibility values there...

return b;
}

// Unpack position data
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@etpinard wondering where could these functions go if we want to reuse these functions in other places e.g. in iso-surfaces?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd vote for putting helper functions like this one in a new file src/traces/mesh3d/helpers.js.

.catch(failTest)
.then(done);
function assertPositions(exp, msg) {
expect(gd._fullLayout.scene._scene.glplot.objects[0].positions.length !== undefined).toBe(exp, msg);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we test the actual length values, not just whether positions and cells are arrays like you did in your latest commit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. I'll fix that.

});
// three indices should be all provided or not
if(
(traceIn.i && (!traceIn.j || !traceIn.k)) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Ha, you're using traceIn here. So something like

{
  i: 1,
  j: true,
  k: {}
}

would have visible:true.

Could we be more stringent and use traceOut instead, to ensure that i,j,k are all non-empty arrays.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good Call. Now traceOut is applied.
Noting that visible would "only" be false in case of bad 'vertices'.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. I don't understand traceOut.i, traceOut.j and traceOut.k should be defined at this stage. They get filled in during the coerce() calls in readComponents below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right. That is fixed in 29f5a06
Now the traces become invisible in case of bad index arrays.

@etpinard
Copy link
Contributor

etpinard commented Jan 7, 2019

All right, good enough for now 💃

Thanks!

@archmoj archmoj merged commit 9fec03a into master Jan 7, 2019
@archmoj archmoj deleted the 2630-mesh3d-dont-modify-messy-data branch January 7, 2019 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants