Skip to content

plot.scale("projection")#2397

Merged
mbostock merged 12 commits intomainfrom
fil/expose-projection-2
Apr 1, 2026
Merged

plot.scale("projection")#2397
mbostock merged 12 commits intomainfrom
fil/expose-projection-2

Conversation

@Fil
Copy link
Copy Markdown
Contributor

@Fil Fil commented Mar 27, 2026

plot.scale("projection") exposes the materialized projection from a plot

The returned object exposes the resolved projection options, reflecting the actual values used to construct the projection, making it possible to create a new plot with the same projection. The projection object also exposes an apply method that projects a [longitude, latitude] point to [x, y] pixel coordinates, as well as an invert method.

closes #1191
supersedes #2038

@Fil Fil requested a review from mbostock March 27, 2026 14:38
@Fil Fil mentioned this pull request Mar 27, 2026
4 tasks
Copy link
Copy Markdown
Member

@mbostock mbostock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can work on this…

@mbostock mbostock marked this pull request as draft April 1, 2026 00:38
Copy link
Copy Markdown
Member

@mbostock mbostock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I have pared back this PR by avoiding the introduction of a new “materialized projection” interface (i.e., Projection), instead exposing the existing ProjectionImplementation interface which was already exposed as context.projection.

This avoids the challenge of trying to normalize a provided ProjectionImplementation into a Projection (noted above). More importantly, it ensures when you reuse a projection across a plot, the projections behave identically rather than rescaling the projection to fit the dimensions of the other plot. This mirrors the current behavior of plot.scale (with respect to scales), and I believe is what we want. If you want to share the same projection type (or some other partial specification of a projection), then you should simply splat your projection options into multiple plots; you don’t need plot.scale to help with that.

All that said, I’d still like to expose a projection.apply and projection.invert convenience method, since that seems useful for implementing interaction. And in the case that the provided projection implementation is a function and exposes projection.invert, we can simply use that as-is. I’ll work on that next…

@mbostock mbostock force-pushed the fil/expose-projection-2 branch from d26e559 to 08ef2dd Compare April 1, 2026 02:32
@mbostock mbostock marked this pull request as ready for review April 1, 2026 02:32
@mbostock mbostock merged commit e59b17a into main Apr 1, 2026
1 check passed
@mbostock mbostock deleted the fil/expose-projection-2 branch April 1, 2026 02:36
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.

expose the projection to make it reusable

2 participants