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

Shorthand for GeoJSON properties #1172

Closed
mbostock opened this issue Dec 7, 2022 · 3 comments · Fixed by #2092
Closed

Shorthand for GeoJSON properties #1172

mbostock opened this issue Dec 7, 2022 · 3 comments · Fixed by #2092
Assignees
Labels
enhancement New feature or request geo Maps and projections question Further information is needed

Comments

@mbostock
Copy link
Member

mbostock commented Dec 7, 2022

It’d be nice if Plot.geo supported shorthand for GeoJSON properties, e.g.,

Plot.geo(counties, {fill: "rate"})

would be shorthand for

Plot.geo(counties, {fill: d => d.properties.rate})

I’m not sure how to do it, though, because in theory the properties could be on the features directly, and we’d still want it to work in that case.

@mbostock mbostock added enhancement New feature or request question Further information is needed geo Maps and projections labels Dec 7, 2022
@Fil
Copy link
Contributor

Fil commented Dec 7, 2022

My understanding is that for Plot geo we could change the "string accessor" convention to be:
field === "id" ? (d => d.id) : (d => d.properties[field])

After checking for color names etc. To get a field that is not accessible through that convention, you'd have to create your own function accessor.

@mbostock
Copy link
Member Author

mbostock commented Dec 8, 2022

That wouldn’t be backwards-compatible with the current behavior. But maybe it’s a small enough breakage that it’s okay. Or we could do something like this:

d => (d[field] === undefined ? d.properties : d)[field]

@mbostock
Copy link
Member Author

mbostock commented Dec 8, 2022

I’m not sure where we’d make this change, though. Like, would you expect it to work with a bin transform’s call to valueof too? In which case we’d need to change the behavior of valueof globally for GeoJSON rather than just changing the channels of the geo mark.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request geo Maps and projections question Further information is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants