-
Notifications
You must be signed in to change notification settings - Fork 197
simpler projection autoHeight #1166
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
Conversation
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
…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.
src/dimensions.js
Outdated
| 140, | ||
| Math.min( | ||
| 1260, | ||
| ((fy ? 1.1 * fy.scale.domain().length - 0.1 : 1) / (fx ? 1.1 * fx.scale.domain().length - 0.1 : 1)) * |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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.
|
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. |
|
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>
src/projection.js
Outdated
| const {aspectRatio} = namedProjection(projection); | ||
| if (aspectRatio) return aspectRatio; | ||
| } | ||
| if (geometry) return golden - 1; |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch; should be
| if (geometry) return golden - 1; | |
| if (projection !== undefined || geometry) return golden - 1; |
(since the null projection is a projection)
There was a problem hiding this comment.
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.
|
🎉 that was the last one! |
* 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>
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