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

Support for touch and pinch in interactions #4208

Closed
mattijn opened this issue Oct 7, 2018 · 11 comments
Closed

Support for touch and pinch in interactions #4208

mattijn opened this issue Oct 7, 2018 · 11 comments

Comments

@mattijn
Copy link
Contributor

mattijn commented Oct 7, 2018

Currently there is only support for mouse click, mouse move and scroll for vega-lite declared interactions.

It would be great if this was extended with touch touchmove and pinch.

@domoritz
Copy link
Member

domoritz commented Oct 7, 2018

How difficult is this and do we need anything else in Vega @arvind?

@kanitw
Copy link
Member

kanitw commented Mar 7, 2019

I think this is already possible. Perhaps, someone should provide an example and we can close this.

@mattijn
Copy link
Contributor Author

mattijn commented Mar 9, 2019

This is surely working in Vega, https://vega.github.io/vega/examples/zoomable-scatter-plot/.
It is just not implemented in Vega-lite.

@domoritz
Copy link
Member

domoritz commented Mar 9, 2019

https://github.com/uwdata/falcon also works on mobile.

@domoritz
Copy link
Member

domoritz commented Mar 9, 2019

This issue is about seeing whether it's possible to manually customize the events in VL to capture touch as well. #4661 is about supporting this by default.

@mattijn
Copy link
Contributor Author

mattijn commented Mar 9, 2019

At this falcon website it seems the anchorpoint is snapping to the left or right edge handlers of the interval.

@domoritz
Copy link
Member

domoritz commented Mar 9, 2019

At this falcon website it seems the anchorpoint is snapping to the left or right edge handlers of the interval.

Can you elaborate?

@mattijn
Copy link
Contributor Author

mattijn commented Mar 9, 2019

681CE082-22F6-4ADD-B587-45284DE3B3DC

@mattijn
Copy link
Contributor Author

mattijn commented Mar 11, 2019

Touch works indeed, I can't get the pinch to work.

Example for creating interval selection box (rectangle will be orange if using touch events):
Click on mobile

{
  "$schema": "https://vega.github.io/schema/vega-lite/v3.json",
  "data": {"url": "data/cars.json"},
  "selection": {
    "MOUSE": {
      "type": "interval",
      "on": "[mousedown, mouseup] > mousemove",
      "translate": "[mousedown, mouseup] > mousemove"
    },
    "TOUCH": {
      "type": "interval",
      "on": "[touchstart, touchend] > touchmove",
      "translate": "[touchstart, touchend] > touchmove",
      "mark": {"fill": "#fdbb84", "fillOpacity": 0.5, "stroke": "#e34a33"}
    }
  },
  "mark": "rect",
  "encoding": {
    "y": {"field": "Origin", "type": "ordinal"},
    "x": {"field": "Cylinders", "type": "ordinal"},
    "color": {
      "condition": {
        "selection": {"or": ["MOUSE", "TOUCH"]},
        "aggregate": "count",
        "type": "quantitative"
      },
      "value": "grey"
    }
  }
}

And an example where one can pan when two touch events are captured. So the panning is only captured when you touch with one finger somewhere outside the chart and pan the chart with another finger:
Click on mobile

{
  "$schema": "https://vega.github.io/schema/vega-lite/v3.json",
  "data": {"url": "data/cars.json"},
  "selection": {
    "MOUSE": {
      "type": "interval", "bind": "scales",    
      "translate": "[mousedown, window:mouseup] > window:mousemove!"
    },
    "TOUCH": {
      "type": "interval", "bind": "scales",
      "translate": "[touchstart[event.touches.length===2], touchend] > touchmove"
    }    
  },
  "mark": "circle",
  "encoding": {
    "x": {
      "field": "Horsepower", "type": "quantitative",
      "scale": {"domain": [75, 150]}
    },
    "y": {
      "field": "Miles_per_Gallon", "type": "quantitative",
      "scale": {"domain": [20, 40]}
    },
    "size": {"field": "Cylinders", "type": "quantitative"}
  }
}

For the last only the TOUCH selection is captured, not in combination with a MOUSE selection.

I can't get the pinching to work within zoom since I can't find a method to access the pinchDistance expression

Also when looking to the underlying created Vega, it doesn't combine the mouse and touch events within a single on directive, but it rather creates two different code blocks.

@domoritz
Copy link
Member

Thanks for the video! I filed vega/falcon#123.

I guess we can close this issue here then and discuss how we can support this natively in #4661.

@corradio
Copy link

corradio commented Feb 3, 2023

Any idea of how to make this work with {"type": "point"} instead of {"type": "interval"}?
Use case is to highlight a point using touchmove, the same way a point is highlighted using mouseover on desktop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants