有没有一种方法可以缩放然后进行选择间隔而不用 vega-lite 进一步缩放

Is there a way to zoom and then do a selection interval without further zooming with vega-lite

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

实现此目的的一种方法是在选择定义中使用事件修饰符。例如,这是一张图表,当不按住 shift 键时触发缩放动作,当按住 shift 键时触发选择动作(open in editor):

{
  "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 selectors.