Skip to content

Conversation

@Fil
Copy link
Contributor

@Fil Fil commented Dec 7, 2022

the height for projections (including the null projection when Plot.geo is used) is computed for a target frame with an aspect ratio that defaults to the golden ratio. When using facets, the computation takes into account the number of rows and columns, with similar limits to what total size is acceptable (1260px).

The projection's preferred aspect ratio is adapted for a few named projections. For example "equal-earth" and "equirectangular" are wider than tall, "mercator" and a few azimuthal projections default to a square.

closes #1136
supersedes #1162

the height for projections (including the null projection when Plot.geo is used) is computed for a target frame with an aspect ratio that defaults to the golden ratio. When using facets, the computation takes into account the number of rows and columns, with similar limits to what total size is acceptable (1260px).

The projection's preferred aspect ratio is adapted for a few named projections. For example "equal-earth" and "equirectangular" are wider than tall, "mercator" and a few azimuthal projections default to a square.

closes #1136
supersedes #1162
@Fil Fil requested a review from mbostock December 7, 2022 08:20
@Fil Fil added enhancement New feature or request geo Maps and projections labels Dec 7, 2022
@Fil Fil mentioned this pull request Dec 7, 2022
@Fil Fil changed the title autoHeight simpler projection autoHeight Dec 7, 2022
Fil added 2 commits December 7, 2022 22:20
…er=0.1, paddingOuter=0, instead of relying on the fx scale still being in the intermediate state where its range is [0,1]. There's a 2px discrepancy in the tests, which is probably coming from some rounding.
@Fil Fil requested a review from mbostock December 7, 2022 21:45
140,
Math.min(
1260,
((fy ? 1.1 * fy.scale.domain().length - 0.1 : 1) / (fx ? 1.1 * fx.scale.domain().length - 0.1 : 1)) *
Copy link
Member

Choose a reason for hiding this comment

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

Is this not dependent on the padding? (I wonder if the 0.1 here corresponds to the default padding.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is based on the defaults for paddingInner and paddingOuter, which are 0.1 and 0 in the case of facet scales.

By the same logic as with the other dimension options (width, marginLeft, etc), if the user changes the padding, we don't want the height to change, so computing only based on all defaults.

@mbostock
Copy link
Member

mbostock commented Dec 7, 2022

I would expect that, if we know the desired aspect ratio of the projection, the default height would depend on the user-specified width. E.g., that you’d get a bigger map if you change the width to 960 instead of the default 640. I’m going to experiment.

@Fil
Copy link
Contributor Author

Fil commented Dec 7, 2022

Yes, it works for me if you replace 640 by width.

(This will be different from the usual autoheight which is independent of width, but there's obviously a good reason to do it it, since the two directions are linked.)

Co-authored-by: Philippe Rivière <fil@rezo.net>
const {aspectRatio} = namedProjection(projection);
if (aspectRatio) return aspectRatio;
}
if (geometry) return golden - 1;
Copy link
Member

Choose a reason for hiding this comment

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

I think this isn’t quite right… we also want to use golden - 1 if a projection has been specified even if there is no geometry (as when using a custom projection).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch; should be

Suggested change
if (geometry) return golden - 1;
if (projection !== undefined || geometry) return golden - 1;

(since the null projection is a projection)

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I don’t think we should distinguish between the null and undefined projection.

@mbostock mbostock merged commit 558bcdc into main Dec 8, 2022
@mbostock mbostock deleted the fil/autoheight-simple branch December 8, 2022 00:06
@Fil
Copy link
Contributor Author

Fil commented Dec 8, 2022

🎉 that was the last one!

chaichontat pushed a commit to chaichontat/plot that referenced this pull request Jan 14, 2024
* autoHeight

the height for projections (including the null projection when Plot.geo is used) is computed for a target frame with an aspect ratio that defaults to the golden ratio. When using facets, the computation takes into account the number of rows and columns, with similar limits to what total size is acceptable (1260px).

The projection's preferred aspect ratio is adapted for a few named projections. For example "equal-earth" and "equirectangular" are wider than tall, "mercator" and a few azimuthal projections default to a square.

closes observablehq#1136
supersedes observablehq#1162

* determine the width of a facet from the (default) value of paddingInner=0.1, paddingOuter=0, instead of relying on the fx scale still being in the intermediate state where its range is [0,1]. There's a 2px discrepancy in the tests, which is probably coming from some rounding.

* refactor: use the ratio implied by tx and ty

* aspectRatio

* auto height based on width

* Update src/dimensions.js

Co-authored-by: Philippe Rivière <fil@rezo.net>

* fix auto height when geometry-less projection

* fix default height for custom projections

Co-authored-by: Mike Bostock <mbostock@gmail.com>
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

autoHeight + projections

3 participants