Fork me on GitHub
#datavis
<
2021-09-21
>
Ben Sless16:09:14

This is probably trivial I can't figure out the right way to do it in vega(lite) How do I add a selection of a set of values and filter the [:data :values] such that they are equal to the selection i.e. datum.field == param.field @metasoarous

metasoarous17:09:29

Hey @ben.sless. Are you trying to do this using a dropdown selection, or a brush selection?

metasoarous17:09:57

This is kind of a nice example cause it combines both (click the bars below to select by single value, and draw a region above for brush select)

metasoarous17:09:35

In short, you add a filter transform with param set to whatever the selection name is.

Ben Sless17:09:47

I think that's what I did, but it's not filtering it. Wanted to start with something super simple, just filter the dataset by one parameter https://gist.github.com/bsless/505af2f15a1bf4ccf58983a9576105a9

Ben Sless17:09:24

Specifically

"encoding": {
  "x": {
    "field": "*percentile",
    "type": "quantitative",
    "axis": {
      "values": [
        -0.47712125471966244,
        0,
        0.954242509439325,
        1.9956351945975495,
        2.999565488225982,
        3.9999565683802403,
        4.999995657035442,
        5.9999995656928125
      ]
    }
  },
  "y": {"field": "latency", "type": "quantitative"},
  "transform": [
    {
      "filter": "datum.rate == selection_rate"
      }
    ],
  "color": {
    "field": "rate", 
    "type": "nominal",
    "condition": {
      "param": "selection",
      "field": "rate", 
      "type": "nominal"
      }
    }
  },
  "mark": "line",
  "params": [
  {
    "name": "selection",
    "value": 30,
    "select": {
      "type": "point", 
      "fields": ["rate"]
      },
    "bind": {
      "rate": {
        "input": "select",
        "field": "rate",
        "value": 30,
        "options": [30, 50, 60]
        }
      }
    }
  ]

metasoarous17:09:27

Try something like {:filter {:param :selection}}