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

interactively sorted data table is no longer sorted in line chart #3873

Open
doc0815 opened this issue Feb 7, 2024 · 1 comment
Open

interactively sorted data table is no longer sorted in line chart #3873

doc0815 opened this issue Feb 7, 2024 · 1 comment
Labels
bug For bugs or other software errors

Comments

@doc0815
Copy link

doc0815 commented Feb 7, 2024

I modified the line chart example and included an interactive filter. After filtering, the data gets aggregated and sorted by x values (that will be displayed on the x-axis). Although the data table is sorted as shown in the data viewer, the line chart is messy. Do I miss something in my chart specification?

Screenshots taken from Vega Editor 5.25.0

image image
{
  "$schema": "https://vega.github.io/schema/vega/v5.json",
  "description": "A basic line chart example.",
  "width": 500,
  "height": 200,
  "padding": 5,

  "signals": [
    {
      "name": "objectSelect",
      "value": "ALL",
      "bind": {
        "input": "select",
        "options": [
          "ALL",
          "A",
          "B"
        ]
      }
    }
  ],

  "data": [
    {
      "name": "table",
      "values": [
        {"x": 0, "y": 28, "obj": "A"}, {"x": 0, "y": 20, "obj": "B"},
        {"x": 11, "y": 43, "obj": "A"}, {"x": 1, "y": 35, "obj": "B"},
        {"x": 2, "y": 81, "obj": "A"}, {"x": 2, "y": 10, "obj": "B"},
        {"x": 3, "y": 19, "obj": "A"}, {"x": 3, "y": 15, "obj": "B"},
        {"x": 4, "y": 52, "obj": "A"}, {"x": 4, "y": 48, "obj": "B"},
        {"x": 15, "y": 24, "obj": "A"}, {"x": 5, "y": 28, "obj": "B"},
        {"x": 6, "y": 87, "obj": "A"}, {"x": 6, "y": 66, "obj": "B"},
        {"x": 7, "y": 17, "obj": "A"}, {"x": 7, "y": 27, "obj": "B"},
        {"x": 8, "y": 68, "obj": "A"}, {"x": 8, "y": 16, "obj": "B"},
        {"x": 9, "y": 49, "obj": "A"}, {"x": 9, "y": 25, "obj": "B"}
      ]
    },
    {
      "name": "tableFinal",
      "source": "table",
      "transform": [
        {
          "type": "filter",
          "expr": "objectSelect!='ALL' ? datum.obj==objectSelect : true"
        },
        {
          "type": "aggregate",
          "groupby": ["x"],
          "fields": ["y"],
          "ops": ["sum"],
          "as": ["y"]
        },
        {
          "type": "collect",
          "sort": {"field": "x"}
        }
      ]
    }
  ],

  "scales": [
    {
      "name": "x",
      "type": "point",
      "range": "width",
      "domain": {"data": "tableFinal", "field": "x"}
    },
    {
      "name": "y",
      "type": "linear",
      "range": "height",
      "domain": {"data": "tableFinal", "field": "y"}
    }
  ],

  "axes": [
    {"orient": "bottom", "scale": "x"},
    {"orient": "left", "scale": "y"}
  ],

  "marks": [
    {
      "type": "line",
      "from": {"data": "tableFinal"},
      "encode": {
        "update": {
          "x": {"scale": "x", "field": "x"},
          "y": {"scale": "y", "field": "y"},
          "strokeWidth": {"value": 2}
        }
      }
    }
  ]
}
@doc0815 doc0815 added the bug For bugs or other software errors label Feb 7, 2024
@doc0815
Copy link
Author

doc0815 commented Feb 29, 2024

Imputing missing value to create a regular data set before filtering and aggregation shadows this problem.

        {
          "type": "impute",
          "groupby": ["obj"],
          "key": "x",
          "field": "y"
        },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug For bugs or other software errors
Projects
None yet
Development

No branches or pull requests

1 participant