plotly.js icon indicating copy to clipboard operation
plotly.js copied to clipboard

Add 'touch' handlers for panning on mobile devices

Open etpinard opened this issue 10 years ago • 18 comments

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

why not?

etpinard avatar Apr 27 '16 13:04 etpinard

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

kusan-reveur avatar Jul 20 '16 08:07 kusan-reveur

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 avatar Jul 20 '16 12:07 rreusser

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.

rreusser avatar Jul 20 '16 12:07 rreusser

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);

kusan-reveur avatar Jul 25 '16 09:07 kusan-reveur

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.

jdugge avatar Aug 03 '16 14:08 jdugge

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

sriver avatar Sep 29 '16 17:09 sriver

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

dy avatar Dec 02 '16 22:12 dy

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

martin-braun avatar Jan 21 '17 10:01 martin-braun

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

hy9be avatar Feb 21 '17 15:02 hy9be

There are actually ready patches for that https://github.com/mikolalysenko/3d-view-controls/pull/1 and https://github.com/gl-vis/gl-plot3d/pull/6

dy avatar Feb 21 '17 15:02 dy

Merged.

dy avatar Feb 22 '17 08:02 dy

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/

jackparmer avatar Mar 23 '17 15:03 jackparmer

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)?

sriver avatar Mar 23 '17 16:03 sriver

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

drorasaf avatar Apr 02 '17 17:04 drorasaf

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

g34g34 avatar Aug 08 '17 01:08 g34g34

PR https://github.com/plotly/plotly.js/pull/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.

malina-kirn avatar Aug 17 '17 16:08 malina-kirn

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

swiperii avatar Jan 24 '18 13:01 swiperii

Closing.

Parts of this tickets were either:

  • implemented in https://github.com/plotly/plotly.js/pull/1424 or https://github.com/plotly/plotly.js/pull/1804
  • currently discussed in https://github.com/plotly/plotly.js/issues/1858
  • or reported in https://github.com/plotly/plotly.js/issues/1967

etpinard avatar Sep 14 '18 14:09 etpinard