Determine the default height when the projection domain is set#2102
Merged
Determine the default height when the projection domain is set#2102
Conversation
mbostock
reviewed
Jul 11, 2024
src/projection.js
Outdated
| if (typeof clip === "number") projection.clipAngle?.(clip); | ||
| projection.scale(Math.min(width / kx, height / ky)); | ||
| projection.translate([width / 2, height / 2]); | ||
| if (width && height) { |
Member
There was a problem hiding this comment.
Should this check for nullish instead of zero?
Contributor
Author
There was a problem hiding this comment.
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.
71bdbe7 to
17328e4
Compare
mbostock
approved these changes
Jul 28, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(I don't think this feature is much documented, it "just works".)
closes #2063