Vega-lite: Support for touch and pinch in interactions

Created on 7 Oct 2018  路  10Comments  路  Source: vega/vega-lite

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.

Enhancement

Most helpful comment

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.

All 10 comments

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

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

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

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

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.

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

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

Can you elaborate?

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

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.

Thanks for the video! I filed https://github.com/uwdata/falcon/issues/123.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

learnwithratnesh picture learnwithratnesh  路  4Comments

kanitw picture kanitw  路  3Comments

domoritz picture domoritz  路  4Comments

infai-feineis picture infai-feineis  路  3Comments

mcnuttandrew picture mcnuttandrew  路  3Comments