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

Add 'touch' handlers for panning on mobile devices #480

Closed
etpinard opened this issue Apr 27, 2016 · 18 comments
Closed

Add 'touch' handlers for panning on mobile devices #480

etpinard opened this issue Apr 27, 2016 · 18 comments

Comments

@etpinard
Copy link
Contributor

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

why not?

@kusan-thana
Copy link

kusan-thana commented Jul 20, 2016

Is there a way to add the compatibility to our scripts? Or how can I help to include this feature into the library?

@rreusser
Copy link
Contributor

rreusser commented Jul 20, 2016

Pulled this off successfully once (requires mobile device for full effect, obv). Here's the code. Unfortunately it's not very isolated into something reusable.

Useful utilities:

  • touch-pinch: Excellent, just didn't give all the info necessary so not an immediate slam dunk
  • mouse-event-offset: if something isn't already in place for cross-browser events.

I won't list them all but long story short, there are good isolated utilities that can hopefully handle as much as possible and straighten out browser kinks, hopefully leaving the rest pretty short.

Bonus features:

  • pan
  • pinch
  • transition from two fingers to one = zoom, then pan
  • transition from one finger to two: pan, then zoom
  • ability to enable/disable zoom or pan independently

@rreusser
Copy link
Contributor

Although, that said, camera, pan, and zoom (and a couple other trivial variables) look like the only external references, so maybe it's not inconceivable to think about just lifting that code and swapping out some logic.

@kusan-thana
Copy link

kusan-thana commented Jul 25, 2016

I tried this:
http://stackoverflow.com/questions/1517924/javascript-mapping-touch-events-to-mouse-events

I thought it would have been nice to have the touch work as the mouse (before implementing new features like pinch, etc.).

But it doesn't seem to work.

Another thing, I can't have relayout work for camera changes.

    var update = {
        title: 'Surface Plot 2',
        scene: {
          camera: {
            eye:{
              x:1,
              y:1,
              z:1
            }
          }
        }
    }
    Plotly.relayout('myDiv', update);

I get the title updated but not the camera, any idea why?

Edit :
got to modify camera position manually like in this exemple: http://codepen.io/etpinard/pen/WxrRoG
calling this code with: document.addEventListener("touchstart", touchHandler, true);

@jdugge
Copy link
Contributor

jdugge commented Aug 3, 2016

The Bokeh plotting library supports this, all the tools (pan, zoom, box zoom, box select, lasso select) work really well using touch gestures. If I understand correctly, Bokeh uses the hammer.js library for handling touch events.

@sriver
Copy link

sriver commented Sep 29, 2016

Any news/plans on this front? Would really love to manipulate plotly.js graphs in a touch-based cordova app.

@dy
Copy link
Contributor

dy commented Dec 2, 2016

Used touch-position and touch-pinch in pan-zoom, should say these two cover both mouse and touch interactions neatly.

@martin-braun
Copy link

Any updates on this? The touch functionality is not working at me, is someone working on it? We need touch support in our project.

@hy9be
Copy link
Contributor

hy9be commented Feb 21, 2017

@etpinard Is this still a part of the roadmap for Plotly 1.x?

@dy
Copy link
Contributor

dy commented Feb 21, 2017

There are actually ready patches for that mikolalysenko/3d-view-controls#1 and gl-vis/gl-plot3d#6

@dy
Copy link
Contributor

dy commented Feb 22, 2017

Merged.

@jackparmer
Copy link
Contributor

3d chart touch is working now thanks to @dfcreative 🙇
Any companies out there that want to fund this one for 2d chart touch?
http://plot.ly/products/consulting-and-oem/

@sriver
Copy link

sriver commented Mar 23, 2017

This example seems to work also for 2d scattergl plots by adding those modifications to plots->gl2d->camera.js. However, to be useful for more complex cases (mine has a mixture of bars and scatter in the same graph), similar modifications would be needed elsewhere, but there is no camera.js equalent for generic 2d cases. In ideas how to implement this more generally (e.g. without Webgl)?

@drorasaf
Copy link

drorasaf commented Apr 2, 2017

@jackparmer , 2d support is for cartesian as well as webgl? I wonder what's the scope of work.

@g34g34
Copy link

g34g34 commented Aug 8, 2017

Any plan to support pinch-to-zoom in the future?

@malina-kirn
Copy link

PR #1804 correctly changed some of plotly's behavior when the device does not have hover capabilities. When the device does not have hover, many interactions normally triggered by mouseover are now triggered by click. As linked earlier in this thread, it's relatively straightforward to intercept touch events and re-emit them as mouse events, here's a working CodePen example (interact with it in your mobile device). This should get you most of the way towards using touch in plotly, though pinch-to-zoom and two-finger scroll don't work.

Note that the has-hover package being used by plotly.js returns true for the Android emulator (and false for an Android device). Consequently, plotly will still listen for mouseover events on the Android emulator. Use a physical Android device to test plotly touch interactions instead of an emulator. This is likely a bug with either the has-hover package or the Android emulator, but I haven't dug in deeply enough to figure out the source of the issue.

@swiperii
Copy link

@malina-kirn The CodePen example you provided seems not to work anymore. Maybe related to #1967?

@etpinard
Copy link
Contributor Author

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 a pull request may close this issue.