Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty selections cannot be composed with "and" in a transform filter #5553

Closed
victornoel opened this issue Nov 15, 2019 · 4 comments
Closed

Comments

@victornoel
Copy link

Here is an example

When you select:

  • null (aka empty selection if I understood well), the whole dataset is kept
  • a value for only one of the select input, the chart gets blank
  • a value for both inputs, the filter is applied

I would expect that selecting a value for only one of the two inputs would filter according to this input.

Note that the same problem happens:

  • without using the null value but only at first (because before the user touch the input, the selection is considered empty in the same way)
  • when using multiple fields and bindings (select) in the same selection, but in that case, instead of getting a blank chart, we get all points.
{
  "$schema": "https://vega.github.io/schema/vega-lite/v3.4.0.json",
  "data": {
    "url": "https://vega.github.io/vega-datasets/data/cars.json"
  },
  "encoding": {
    "color": {
      "field": "Origin",
      "type": "nominal"
    },
    "tooltip": [
      {
        "field": "Name",
        "type": "nominal"
      },
      {
        "field": "Origin",
        "type": "nominal"
      },
      {
        "field": "Horsepower",
        "type": "quantitative"
      },
      {
        "field": "Miles_per_Gallon",
        "type": "quantitative"
      }
    ],
    "x": {
      "field": "Horsepower",
      "type": "quantitative"
    },
    "y": {
      "field": "Miles_per_Gallon",
      "type": "quantitative"
    }
  },
  "mark": {
    "type": "circle"
  },
  "selection": {
    "selector011": {
      "bind": {
        "input": "select",
        "options": [
          null,
          "USA",
          "Europe",
          "Japan"
        ]
      },
      "fields": [
        "Origin"
      ],
      "type": "single"
    },
    "selector012": {
      "bind": {
        "input": "select",
        "options": [
          null,
          8,
          4,
          6,
          3,
          5
        ]
      },
      "fields": [
        "Cylinders"
      ],
      "type": "single"
    }
  },
  "transform": [
    {
      "filter": {
        "selection": {
          "and": [
            "selector011",
            "selector012"
          ]
        }
      }
    }
  ]
}
@victornoel victornoel changed the title Empty selections cannot be composed with and in a transform filter Empty selections cannot be composed with "and" in a transform filter Nov 15, 2019
@petermattia
Copy link

FYI - I have a toy example of this bug in this SO question

@jeremysalwen
Copy link

I am seeing this bug as well. Is there any workaround?

@drgould
Copy link

drgould commented Dec 2, 2020

Moving the "and" outside of the selection is a workaround. Like so:

{
  "filter": {
    "and": [
      {"selection": "selection_1"},
      {"selection": "selection_2"}
    ]
  }
}

@arvind
Copy link
Member

arvind commented Jan 6, 2021

Thank you @victornoel for filing the issue, and @drgould for the workaround. This issue will be fixed with #7155, which standardizes the workaround by dropping support for logical compositions within a single "selection" property.

@arvind arvind closed this as completed Jan 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants