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

Upgrade d3 geo projections #5112

Merged
merged 19 commits into from Jun 30, 2021
Merged

Upgrade d3 geo projections #5112

merged 19 commits into from Jun 30, 2021

Conversation

archmoj
Copy link
Contributor

@archmoj archmoj commented Sep 1, 2020

Replace old d3.geo functions with upgraded d3-geo modules (that support IE) as part of d3 bump cc: #424.
Some new geo projections e.g. satelite could potentially be added as listed in 8dd4ba0 to address #4781.

This would also result in reducing the size of various partial bundles that do not need geo trace.

@plotly/plotly_js

@alexcjohnson
Copy link
Contributor

This looks like a good idea, but I think we need to be more careful about each projection we add: (1) does it work well in the simple case? In your demo codepen a number of them fall look pretty bad either immediately or easily as you zoom / pan around so should probably not be included without some adjustment. (2) maybe you've already done this, do they support all the same parameters as the existing ones? isConic? lonaxisSpan / lataxisSpan? Any other special cases? (3) each one we add needs to be included in at least one mock, maybe more so we can ensure their parameters work right. geo_fitbounds-locations says it includes "all projection types", let's ensure that stays true.

 - note upgrading to latest versions is not possible atm
 - due to ES2015 syntax and drop of IE support
package.json Outdated
@@ -57,7 +57,7 @@
]
},
"dependencies": {
"@plotly/d3": "^3.5.18",
"@plotly/d3": "git://github.com/plotly/d3.git#e792de9ae52d956d18582cac8a49ea6a03c7e010",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@archmoj
Copy link
Contributor Author

archmoj commented Jan 14, 2021

This looks like a good idea, but I think we need to be more careful about each projection we add: (1) does it work well in the simple case? In your demo codepen a number of them fall look pretty bad either immediately or easily as you zoom / pan around so should probably not be included without some adjustment. (2) maybe you've already done this, do they support all the same parameters as the existing ones? isConic? lonaxisSpan / lataxisSpan? Any other special cases? (3) each one we add needs to be included in at least one mock, maybe more so we can ensure their parameters work right. geo_fitbounds-locations says it includes "all projection types", let's ensure that stays true.

Thanks for the notes @alexcjohnson.
With the updates (reflected in the PR description now) no new projections were added in the API as a result of this PR.

@@ -1353,46 +1353,6 @@ describe('Test geo interactions', function() {
.then(done, done.fail);
});

it('should clear hover label when cursor slips off subplot', function(done) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did these 2 tests get removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I recall (as mentioned in the commit message) there used to be a bug in d3.geo where a function returned NaN positions. And we guarded against it.

Copy link
Contributor

Choose a reason for hiding this comment

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

But these tests are just using the high-level API, not d3 geo itself. If they started failing, that means something changed about the user-facing behavior. What changed? Are we comfortable with that change? I'd much prefer if we can adapt the tests to the new version so we can see the difference.

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 question. Pointing to the fact that rebase somehow forgot to remove geo/projections.
It is now fixed in 557ebde.

Copy link
Contributor

Choose a reason for hiding this comment

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

This test should still be able to pass though. Perhaps the exact pixel positions need to change because there's some small change in how the projection is applied? If I try to manually follow what's going on in the test (I believe it's hovering on the point off the coast of Africa, then slowly mousing off the edge of the globe) the behavior looks identical before/after the change. So we should be able to bring the test back, but if the exact values need to change a little (px = 390, py = 290 and if(px < 402) that's fine.

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 call. Adjusted in 647b0dc.
In fact with previous positions the tests didn't pass locally. But now the test now passes both locally and on the CI.

@nicolaskruchten
Copy link
Member

We don't strictly speaking need to merge this PR for v2, so let's leave it alone for now?

@archmoj
Copy link
Contributor Author

archmoj commented Jan 14, 2021

We don't strictly speaking need to merge this PR for v2, so let's leave it alone for now?

That's what we may end up doing. But it is worth having the conversion going before committing to v2 IMHO.

@archmoj archmoj removed this from the NEXT milestone Jan 14, 2021
src/plots/geo/geo.js Outdated Show resolved Hide resolved
@archmoj archmoj added this to the v2.3.0 milestone Jun 26, 2021
@archmoj
Copy link
Contributor Author

archmoj commented Jun 26, 2021

Conflicts are resolved here and the plotly/d3 PR.
Now adding this to v2.3.0 milestone.

Copy link
Contributor

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for making the new issue.
💃 after publishing the updated @plotly/d3

package.json Outdated Show resolved Hide resolved
@archmoj archmoj merged commit 17c9f0c into master Jun 30, 2021
@archmoj archmoj deleted the new-d3-geo branch June 30, 2021 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants