Skip to content

Add support for projections to the standalone Plot.scale function#2427

Open
Fil wants to merge 7 commits intomainfrom
fil/scale-projection
Open

Add support for projections to the standalone Plot.scale function#2427
Fil wants to merge 7 commits intomainfrom
fil/scale-projection

Conversation

@Fil
Copy link
Copy Markdown
Contributor

@Fil Fil commented Apr 13, 2026

e.g. Plot.scale({projection: {type: "mercator", width, domain: …}}).

When merged, we must add this to the changelog PR #2426:

The standalone [Plot.scale](https://observablehq.com/plot/features/scales#scale) function now also supports projections.

```js
const projection = Plot.scale({projection: {type: "mercator"}});
projection.apply([-1.55, 47.22]) // [316.7, 224.2]

const plot = Plot.plot({projection, marks: [Plot.sphere()]});
```

Fil added 2 commits April 13, 2026 17:26
_e.g._ Plot.scale({projection: {type: "mercator", width, domain: …}}).
@Fil Fil requested a review from mbostock April 13, 2026 15:46
Comment thread docs/features/scales.md Outdated
Comment thread src/scales.d.ts Outdated
Comment thread src/scales.js Outdated
Comment thread src/scales.js Outdated
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.

As far as testing goes, I’m hoping that we can test this new implementation against the existing (more wasteful) one. This:

Plot.plot({projection: {type: "mercator"}}).scale("projection")

Should be the same as this:

Plot.scale({projection: {type: "mercator"}})

Comment thread src/scales.d.ts Outdated
Fil and others added 5 commits April 13, 2026 23:54
Co-authored-by: Mike Bostock <mbostock@gmail.com>
note that the terse definitions here are for Plot.scale({projection}), and get overridden by more detailed definitions in Plot.plot()
Comment thread src/dimensions.d.ts
@@ -1,3 +1,21 @@
/** Options for specifying the dimensions of a plot or standalone projection. */
Copy link
Copy Markdown
Contributor Author

@Fil Fil Apr 14, 2026

Choose a reason for hiding this comment

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

note that the terse definitions here are in fact only for Plot.scale({projection}), and get overridden by more detailed definitions in Plot.plot(), i.e.

plot/src/plot.d.ts

Lines 11 to 23 in 1c6b239

/**
* The outer width of the plot in pixels, including margins. Defaults to 640.
* On Observable, this can be set to the built-in [width][1] for full-width
* responsive plots. Note: the default style has a max-width of 100%; the plot
* will automatically shrink to fit even when a fixed width is specified.
*
* [1]: https://github.com/observablehq/stdlib/blob/main/README.md#width
*/
width?: number;
/**
* The outer height of the plot in pixels, including margins. The default
* depends on the plot’s scales, and the plot’s width if an aspectRatio is

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.

2 participants