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

Determine the default height when the projection domain is set #2102

Merged
merged 4 commits into from
Jul 28, 2024

Conversation

Fil
Copy link
Contributor

@Fil Fil commented Jul 11, 2024

(I don't think this feature is much documented, it "just works".)

closes #2063

@Fil Fil requested a review from mbostock July 11, 2024 11:54
@@ -167,8 +167,10 @@ function scaleProjection(createProjection, kx, ky) {
if (precision != null) projection.precision?.(precision);
if (rotate != null) projection.rotate?.(rotate);
if (typeof clip === "number") projection.clipAngle?.(clip);
projection.scale(Math.min(width / kx, height / ky));
projection.translate([width / 2, height / 2]);
if (width && height) {
Copy link
Member

Choose a reason for hiding this comment

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

Should this check for nullish instead of zero?

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! I was thinking aspectRatio, but this part returns the actual projection, so it should respect a collapsed (degenerate) projection.

I fixed it and added a test case (without the fix, the test case displays a map in the default scale, instead of a 0-height map…).

Note that the degenerate case is still slightly problematic, as its path’s d property is an invalid string "M NaN,NaN…" instead of being null. (A projection with a strictly negative scale returns null, so the "issue" is only for scale 0.)

…there's no need to check both)

the case where width and height are undefined is when we are testing the projection's aspect ratio with a given domain

Note that the path in the SVG is broken (full of NaN) when projection.scale() === 0. This seems to be a secondary issue.
@Fil Fil force-pushed the fil/projection-domain-ratio branch from 71bdbe7 to 17328e4 Compare July 11, 2024 14:43
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.

Determine the default height when the projection domain is set
2 participants