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

Unable to filter out null objects if referenced by encoding #3441

Closed
LucidObscurity opened this issue Mar 3, 2018 · 11 comments
Closed

Unable to filter out null objects if referenced by encoding #3441

LucidObscurity opened this issue Mar 3, 2018 · 11 comments
Assignees

Comments

@LucidObscurity
Copy link

{
  "$schema": "https://vega.github.io/schema/vega-lite/v2.json",
  "description": "Unable to truly filter data",
  "data": {
    "values":[
      {
        "date": "2000-01-01"
      },
      {
        "date": "2000-02-01",
        "options": {
          "price": 16 
        }
      },
      {
        "date": "2000-03-01",
        "options": {
          "price": 17 
        }
      } 
    ]
  },
  "transform": [{"filter": "datum.options != null"}],
  "mark": "line",
  "encoding": {
    "x": {"field": "date", "type": "temporal", "axis": {"format": "%Y"}},
    "y": {"field": "options.price", "type": "quantitative"}
  }
}

This will throw "ERROR TypeError: Cannot read property 'price' of undefined" in the console.
I'm not sure why "options.price" would ever try to be evaluated for the record which was supposed to be filtered out.

@domoritz
Copy link
Member

domoritz commented Mar 3, 2018

Should be addressed as part of #3369

@nyurik
Copy link
Member

nyurik commented Mar 4, 2018

@LucidObscurity to work around, use compiled Vega panel at the bottom, copy/paste the Vega code into the editor, and move your filtering transform to the top of the list.

@domoritz
Copy link
Member

domoritz commented Mar 4, 2018

Or add a calculate transform and flatten your data.

@nyurik
Copy link
Member

nyurik commented Mar 4, 2018

@domoritz i think the input parsing happens before all of the transforms... Do you have an example?

@domoritz
Copy link
Member

domoritz commented Mar 5, 2018

Vega-Lite will not generate a parse expression if you use a calculate.

@domoritz
Copy link
Member

domoritz commented Apr 28, 2018

This works fine if you have an empty object. I don't know whether it is worth adding a lot of special code to support this case. It's pretty tricky to get right with selections and so on.

{
  "$schema": "https://vega.github.io/schema/vega-lite/v2.json",
  "description": "Unable to truly filter data",
  "data": {
    "values":[
      {
        "date": "2000-01-01",
        "options": {
        }
      },
      {
        "date": "2000-02-01",
        "options": {
          "price": 16 
        }
      },
      {
        "date": "2000-03-01",
        "options": {
          "price": 17 
        }
      } 
    ]
  },
  "transform": [{"filter": "datum.options != null"}],
  "mark": "line",
  "encoding": {
    "x": {"field": "date", "type": "temporal", "axis": {"format": "%Y"}},
    "y": {"field": "options.price", "type": "quantitative"}
  }
}

@domoritz
Copy link
Member

However, maybe it's enough to get it working in format parse so that you can flatten your data afterwards.

@LucidObscurity
Copy link
Author

Thanks for the follow up. I switched to the full Vega schema and the issue was resolved. I also resolved the reason why there were nulls in the first place, by building an API in between Kibana and Elasticsearch to generate my own statistics and add them to the JSON, but that issue exists in another repo. ;)

Thanks again, hopefully your follow up will help others.

domoritz added a commit that referenced this issue Apr 28, 2018
@domoritz
Copy link
Member

I have a fix in #3676

@LucidObscurity
Copy link
Author

Nice. I do love the simplicity of Vega-Lite for most scenarios.

domoritz added a commit that referenced this issue Apr 28, 2018
@domoritz
Copy link
Member

image

kanitw added a commit that referenced this issue May 6, 2018
* master:
  docs: fix "example gallery" link in layering docs
  Update versions
  Bump to 2.4.2
  Allow making line uses original order in the data
  Upgrade deps
  Never automatically set scale `zero` to true when custom domain is provided
  Add oz to list of libs in docs (#3690)
  Update and simplify CO2 example
  Rebuild examples
  Add example with missing subobject. Add more tests to formatparse. Always access flattened fields after transforms.
  leave -> leaf
  Only add parse for non-nested fields. Always flatten nested fields.
  Restructure Gallery (#3679)
  Fix typo
  Update details about value vs mark properties
  Remove mocha scripts from CONTRIBUTING.md and add test:inspect script (#3674)
  Resolve conflict between scale.domain and bin.extent (#3675)
  Add datum to access path. Fixes #3441
  Flatten nested fields. Fixes #3369

# Conflicts:
#	_data/examples.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants