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

Trigger hover and click events on gl3d graphs #240

Merged
merged 16 commits into from
Feb 25, 2016
Merged

Trigger hover and click events on gl3d graphs #240

merged 16 commits into from
Feb 25, 2016

Conversation

etpinard
Copy link
Contributor

@etpinard etpinard commented Feb 5, 2016

@mdtusz

I didn't add anything to the library all week, so I found this to do as a day project.

Triggering hover events was easy. Click events needed a patch to gl-plot3d. But by far the hardest part was adding tests for this thing.

TODO:

bubbles: true,
clientX: x,
clientY: y
};

// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent
if(opts) {
if(opts.buttons) fullOpts.buttons = opts.buttons;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons

This is what the gl-vis relies on to determine which mouse over is considered a click event.

@etpinard
Copy link
Contributor Author

etpinard commented Feb 5, 2016

So looks like CircleCI + headless Chrome and headless Firefox + WebGL don't get along:

Putting a console.log on this line yields:
image

Maybe we should make the gl_plot_interact suite a pre-build requirement instead?

- add instructions on how to manually test gl interaction specs
var eventType = (selection.buttons) ? 'plotly_click' : 'plotly_hover',
eventData = makeEventData(xVal, yVal, zVal, trace, selection);

scene.graphDiv.emit(eventType, eventData);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

To note, click events are fired within the same distance as hover events. Specifically, click events can be fired in situations where the cursor isn't exactly on top of a given data point.

This behaviour is debatable. We might want to restrict click events to some selection.distance.


sceneIds = Plots.getSubplotIds(fullLayout, 'gl3d');
sceneIds.forEach(function(id) {
fullLayout[id]._scene.destroy();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mdtusz I think I found why running the gl interactions tests was so shaky and machine-dependent:

  • destroying the graph div does not clear the gl context associated with it, meaning that many contexts were piling up on the test page making each tests slowing to run as time progressed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now, each gl context is destroyed after each gl test run, making for more consistent test runs.

@@ -93,8 +111,22 @@ function render(scene) {
container: svgContainer
});
}

var eventData = makeEventData(xVal, yVal, zVal, trace, selection);
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 just inline this? It doesn't seem to get used anywhere else (as far as I see so far) and if it does, we can make it a function later.

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. Thanks!

@mdtusz
Copy link
Contributor

mdtusz commented Feb 25, 2016

Are we going to wait for the gl-plot3d dependency update first? If not, 💃!

scene.graphDiv.emit('plotly_click', eventData);
}
else {
scene.graphDiv.emit('plotly_hover', eventData);
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 added a commit that referenced this pull request Feb 25, 2016
Trigger hover and click events on gl3d graphs
@etpinard etpinard merged commit a7451ff into master Feb 25, 2016
@etpinard etpinard deleted the gl-hover branch February 25, 2016 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants