user29263305
user29263305

Reputation: 11

min(value) does not update when transform filter is applied in layered chart

Because of this issue, I was trying to make a boxplot with a filter selection manually. The problem is, when I select a boxplot first, it is displayed correct, but when i select another option first the boxplot is wrong My example in the editor

when_selected_first

when_another_option_is_selected_first

I figured out that q1() and q3() are changed everytime I change my selection. But min() and max() stay the same and the problem only occurs in layered charts. Why is that the case?


{
  "config": {"view": {"continuousWidth": 300, "continuousHeight": 300}},
  "layer": [
    {
      "mark": {"type": "rule", "color": "black"},
      "encoding": {
        "y": {"field": "lower_whisker", "type": "quantitative"},
        "y2": {"field": "upper_whisker"}
      },
      "name": "view_1",
      "transform": [
        {"filter": "param_1.task == 'All' || param_1.task == datum.task"},
        {
          "aggregate": [
            {"op": "q1", "field": "value", "as": "q1_value"},
            {"op": "q3", "field": "value", "as": "q3_value"},
            {"op": "min", "field": "value", "as": "min_value"},
            {"op": "max", "field": "value", "as": "max_value"}
          ]
        },
        {"calculate": "warn(datum.min_value)", "as": "debug2"},
        {"calculate": "datum.q3_value - datum.q1_value", "as": "IQR"},
        {
          "calculate": "max(datum.q1_value - 1.5 * datum.IQR, datum.min_value)",
          "as": "lower_whisker"
        },
        {
          "calculate": "min(datum.q3_value + 1.5 * datum.IQR, datum.max_value)",
          "as": "upper_whisker"
        }
      ]
    },
    {
      "mark": {"type": "bar", "size": 20},
      "encoding": {
        "y": {"field": "q1_value", "type": "quantitative"},
        "y2": {"field": "q3_value"}
      },
      "transform": [
        {"filter": "param_1.task == 'All' || param_1.task == datum.task"},
        {
          "aggregate": [
            {"op": "q1", "field": "value", "as": "q1_value"},
            {"op": "q3", "field": "value", "as": "q3_value"},
            {"op": "min", "field": "value", "as": "min_value"},
            {"op": "max", "field": "value", "as": "max_value"}
          ]
        },
        {"calculate": "warn(datum)", "as": "debug"},
        {"calculate": "warn(datum.min_value)", "as": "debug2"},
        {"calculate": "datum.q3_value - datum.q1_value", "as": "IQR"},
        {
          "calculate": "max(datum.q1_value - 1.5 * datum.IQR, datum.min_value)",
          "as": "lower_whisker"
        },
        {
          "calculate": "min(datum.q3_value + 1.5 * datum.IQR, datum.max_value)",
          "as": "upper_whisker"
        }
      ]
    },
    {
      "mark": {"type": "tick", "color": "black", "size": 20},
      "encoding": {"y": {"field": "q2_value", "type": "quantitative"}},
      "transform": [
        {"filter": "param_1.task == 'All' || param_1.task == datum.task"},
        {
          "aggregate": [
            {"op": "q1", "field": "value", "as": "q1_value"},
            {"op": "q3", "field": "value", "as": "q3_value"},
            {"op": "min", "field": "value", "as": "min_value"},
            {"op": "max", "field": "value", "as": "max_value"}
          ]
        },
        {"calculate": "warn(datum)", "as": "debug"},
        {"calculate": "warn(datum.min_value)", "as": "debug2"},
        {"calculate": "datum.q3_value - datum.q1_value", "as": "IQR"},
        {
          "calculate": "max(datum.q1_value - 1.5 * datum.IQR, datum.min_value)",
          "as": "lower_whisker"
        },
        {
          "calculate": "min(datum.q3_value + 1.5 * datum.IQR, datum.max_value)",
          "as": "upper_whisker"
        }
      ]
    },
    {
      "mark": {"type": "tick", "color": "black", "size": 20},
      "encoding": {"y": {"field": "lower_whisker", "type": "quantitative"}},
      "transform": [
        {"filter": "param_1.task == 'All' || param_1.task == datum.task"},
        {
          "aggregate": [
            {"op": "q1", "field": "value", "as": "q1_value"},
            {"op": "q3", "field": "value", "as": "q3_value"},
            {"op": "min", "field": "value", "as": "min_value"},
            {"op": "max", "field": "value", "as": "max_value"}
          ]
        },
        {"calculate": "warn(datum)", "as": "debug"},
        {"calculate": "warn(datum.min_value)", "as": "debug2"},
        {"calculate": "datum.q3_value - datum.q1_value", "as": "IQR"},
        {
          "calculate": "max(datum.q1_value - 1.5 * datum.IQR, datum.min_value)",
          "as": "lower_whisker"
        },
        {
          "calculate": "min(datum.q3_value + 1.5 * datum.IQR, datum.max_value)",
          "as": "upper_whisker"
        }
      ]
    },
    {
      "mark": {"type": "tick", "color": "black", "size": 20},
      "encoding": {"y": {"field": "upper_whisker", "type": "quantitative"}},
      "transform": [
        {"filter": "param_1.task == 'All' || param_1.task == datum.task"},
        {
          "aggregate": [
            {"op": "q1", "field": "value", "as": "q1_value"},
            {"op": "q3", "field": "value", "as": "q3_value"},
            {"op": "min", "field": "value", "as": "min_value"},
            {"op": "max", "field": "value", "as": "max_value"}
          ]
        },
        {"calculate": "warn(datum)", "as": "debug"},
        {"calculate": "warn(datum.min_value)", "as": "debug2"},
        {"calculate": "datum.q3_value - datum.q1_value", "as": "IQR"},
        {
          "calculate": "max(datum.q1_value - 1.5 * datum.IQR, datum.min_value)",
          "as": "lower_whisker"
        },
        {
          "calculate": "min(datum.q3_value + 1.5 * datum.IQR, datum.max_value)",
          "as": "upper_whisker"
        }
      ]
    }
  ],
  "data": {"name": "data-fb1bcd3819f4a40f7f4db85408d553b7"},
  "encoding": {"y": {"scale": {"domain": [0, 10]}, "title": "value"}},
  "params": [
    {
      "name": "param_1",
      "select": {"type": "point", "fields": ["task"]},
      "bind": {
        "input": "select",
        "options": ["All", "A", "B"],
        "name": "Dropdown Menu: "
      },
      "value": "All",
      "views": ["view_1"]
    }
  ],
  "$schema": "https://vega.github.io/schema/vega-lite/v5.20.1.json",
  "datasets": {
    "data-fb1bcd3819f4a40f7f4db85408d553b7": [
      {"task": "A", "value": 0},
      {"task": "A", "value": 1},
      {"task": "A", "value": 2},
      {"task": "A", "value": 3},
      {"task": "A", "value": 4},
      {"task": "B", "value": 5},
      {"task": "B", "value": 6},
      {"task": "B", "value": 7},
      {"task": "B", "value": 8},
      {"task": "B", "value": 9}
    ]
  }
}    

Upvotes: 1

Views: 22

Answers (0)

Related Questions