Using the interval
selection type, we can actually make a plot zoomable and pannable by binding to the scales.
A simple example:
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"data": {
"url": "https://raw.githubusercontent.com/vega/vega/master/docs/data/cars.json"
},
"selection": {
"grid": {
"type": "interval", "bind": "scales"
}
},
"mark": "point",
"encoding": {
"x": {"field": "Horsepower", "type": "quantitative"},
"y": {"field": "Miles_per_Gallon", "type": "quantitative"},
"color": { "value": "lightgrey" }
}
}
The grid
in this specification is - just like in the previous section - nothing more than a name that we give to the selection. It could have been abcde
as well…