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

derive x & y scale domains from geometry #1468

Merged
merged 4 commits into from
Jun 2, 2023
Merged

Conversation

mbostock
Copy link
Member

@mbostock mbostock commented Apr 19, 2023

While writing the documentation for the geo mark, I was thinking about how we can use the geo mark independent of a projection. It bothered me that you can use the geo mark in conjunction with predefined scales, or scales derived from other marks, but that the geo mark itself could not assist in the automatic definition of the scales like other marks.

So now it does. The geometry channel now produces derived x and y channels that can be used to initialize the x and y scales, just like normal marks. Which means you can now say

Plot.geo({type: "LineString", coordinates: aapl.map((d) => [d.Date, d.Close])}).plot()

and it behaves almost identical to

Plot.line(aapl.map((d) => [d.Date, d.Close])).plot()

This is still a draft because I think we should skip constructing the derived x and y channels in a couple cases:

  • If there’s a projection (because then there won’t be x and y scales by definition)
  • If the x or y scales have pre-defined domains (because then we don’t care about these derived channels)

This changes the behavior of one of the tests, but I think it makes sense, and you can still get the old behavior by setting the projection to identity if you want it.

Fixes #1507.

@mbostock mbostock requested a review from Fil April 19, 2023 05:02
@mbostock mbostock force-pushed the mbostock/geo-scales branch from 07be0c6 to d71e888 Compare April 19, 2023 05:04
@Fil
Copy link
Contributor

Fil commented Apr 19, 2023

This makes it much easier to just pass in a GeoJSON file. No more quarter-Earth!

@Fil
Copy link
Contributor

Fil commented May 11, 2023

@Fil
Copy link
Contributor

Fil commented Jun 1, 2023

follow-up in #1663

@mbostock mbostock force-pushed the mbostock/geo-scales branch from 0dea987 to a6d4533 Compare June 2, 2023 15:50
* fix pending issues and add tests

* optimize and comment

* move hasProjection

---------

Co-authored-by: Mike Bostock <[email protected]>
@mbostock mbostock marked this pull request as ready for review June 2, 2023 15:55
src/plot.js Outdated Show resolved Hide resolved
@mbostock
Copy link
Member Author

mbostock commented Jun 2, 2023

This looks good to me. What do you think @Fil?

@mbostock mbostock enabled auto-merge (squash) June 2, 2023 16:01
@mbostock mbostock merged commit ce8ccab into main Jun 2, 2023
@mbostock mbostock deleted the mbostock/geo-scales branch June 2, 2023 16:28
@Fil
Copy link
Contributor

Fil commented Jun 2, 2023

🎉 We should now be able to throw any valid GeoJSON file at Plot.geo(…).plot(), and have something show up on the screen—independently of the file’s coordinate reference system (CRS). Plus, the x and y axes will show the extent of the coordinates, which will help evaluate if the file is “unprojected” or “projected”, and even maybe (with a bit of practice) which CRS is more likely.

Fil added a commit that referenced this pull request Aug 21, 2023
* derive x & y scale domains from geometry

* follow-up: derive x & y scale domains from geometry (#1663)

* fix pending issues and add tests

* optimize and comment

* move hasProjection

---------

Co-authored-by: Mike Bostock <[email protected]>

---------

Co-authored-by: Philippe Rivière <[email protected]>
chaichontat pushed a commit to chaichontat/plot that referenced this pull request Jan 14, 2024
* derive x & y scale domains from geometry

* follow-up: derive x & y scale domains from geometry (observablehq#1663)

* fix pending issues and add tests

* optimize and comment

* move hasProjection

---------

Co-authored-by: Mike Bostock <[email protected]>

---------

Co-authored-by: Philippe Rivière <[email protected]>
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

Successfully merging this pull request may close these issues.

aspectRatio fails when there is a geo mark and no projection
2 participants