有没有一种方法可以缩放,然后在不使用vega lite进一步缩放的情况下进行选择间隔



有一个散点图,我知道你在缩放比例上使用绑定来平移和使用轮子来缩放,这很好。然而,一旦缩放,就需要一种方法来进行选择间隔,而不需要进一步的缩放效果。例如,需要一种通过shift键暂停或退出的方式。

实现这一点的一种方法是在选择定义中使用事件修饰符。例如,这里有一个图表,当没有按住shift键时会触发缩放操作,而当按住shift键(在编辑器中打开(时会触发选择操作:
{
"data": {"url": "https://vega.github.io/vega-datasets/data/cars.json"},
"mark": "point",
"encoding": {
"color": {"type": "nominal", "field": "Origin"},
"x": {"type": "quantitative", "field": "Horsepower"},
"y": {"type": "quantitative", "field": "Miles_per_Gallon"}
},
"selection": {
"zoom": {
"type": "interval",
"bind": "scales",
"on": "[mousedown[!event.shiftKey], mouseup] > mousemove",
"translate": "[mousedown[!event.shiftKey], mouseup] > mousemove!"
},
"select": {
"type": "interval",
"on": "[mousedown[event.shiftKey], mouseup] > mousemove",
"translate": "[mousedown[event.shiftKey], mouseup] > mousemove!"
}
}
}

这里的语法遵循vega-eventStream选择器。

最新更新