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

Remove panning logic from map boundary calculation #27392

Merged
merged 3 commits into from
Jan 10, 2023

Conversation

iethree
Copy link
Contributor

@iethree iethree commented Dec 22, 2022

Resolves #26213

Story Time

Chapter 1

Once upon a time, some maps in metabase would repeat themselves, to make the left-right panning experience nicer: e.g. it would be easier to center a global map on Japan, even though most global maps center on Europe. This functionality was removed in #22427 because it looked a little funny and users reported it as a bug. In order to make maps appear correctly after repeating was removed, we added this code to center maps:

And all was well. (spoiler: it was not all well).

Chapter 2

Later on, we discovered an issue where users "couldn't load" new maps #23450 (spoiler: in fact, maps would load just fine, their previews just wouldn't appear for some reason)

It appeared that the panning code actually was pushing the maps out of the viewport, and removing the panning code fixed everything! (spoiler: it did not fix everything)

Chapter 3

And it came to pass that again, we have a reported issue that certain maps seem to be squished to the side and cut off 🤔

199487692-6d131fbf-55db-400a-8ccf-aaaa4ed675e0

But some maps are totally fine:
Screen Shot 2022-12-22 at 2 50 01 PM

What if we just stick the panning code back in?
Screen Shot 2022-12-22 at 2 49 28 PM

Hooray! we've saved the world, but it cost us California, the UK and the Pacific Islands. 😢

Alright? what's really going on here?

Well, it turns out that in the code that sets map boundaries, for certain large maps, it sets ridiculously large boundaries (wait for it...) to allow you to pan side to side.

Changes

Deleted the conditional and calculations that set map boundaries wide enough to allow side-to-side map panning.

Screen Shot 2022-12-22 at 2 19 45 PM

And all the maps are happy now.

Testing Steps

I used all of these test maps to make sure they appeared correctly, in the map loader (in admin settings), and in the query builder, and in dashboards.

https://raw.githubusercontent.com/metabase/metabase/master/resources/frontend_client/app/assets/geojson/world.json
https://raw.githubusercontent.com/johan/world.geo.json/master/countries.geo.json
https://raw.githubusercontent.com/datasets/geo-countries/master/data/countries.geojson
https://raw.githubusercontent.com/codeforgermany/click_that_hood/main/public/data/california-counties.geojson
https://pacificdata.org/data/dataset/964dbebf-2f42-414e-bf99-dd7125eedb16/resource/dad3f7b2-a8aa-4584-8bca-a77e16a391fe/download/country_boundary_eez.geojson
https://gist.githubusercontent.com/iethree/ec57ec72e12fb61d74a595a1e88a2826/raw/d02fb28577f76c41d07fb07131f4d0ec8067839c/uk_regions.geojson
https://raw.githubusercontent.com/codeforgermany/click_that_hood/main/public/data/africa.geojson

Gonna poke around a bit and see if there's a way to unit test this. 🕵️‍♀️
It appears that JSDOM doesn't really support svg rendering, so any meaningful unit tests are impossible with our current test setup.
https://stackoverflow.com/questions/54382414/fixing-react-leaflet-testing-error-cannot-read-property-layeradd-of-null/54384719#54384719

@iethree iethree requested a review from a team December 22, 2022 22:02
@iethree iethree self-assigned this Dec 22, 2022
Comment on lines -13 to -24
if (antemeridianGapSize > normalGapSize) {
return L.latLngBounds(
L.latLng(south, west), // SW
L.latLng(north, east), // NE
);
} else {
return L.latLngBounds(
L.latLng(south, -360 + gap[1]), // SW
L.latLng(north, gap[0]), // NE
);
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

as far as i can tell, the only purpose of this conditional, and the computeLargestGap function, was to determine if a map was large enough to warrant panning.

@github-actions
Copy link

github-actions bot commented Dec 22, 2022

Notifying subscribers in CODENOTIFY files for diff 2d8b306...96ff2a2.

Notify File(s)
@alxnddr frontend/src/metabase/visualizations/components/LeafletChoropleth.jsx
frontend/src/metabase/visualizations/lib/mapping.js

);
} else {
return L.latLngBounds(
L.latLng(south, -360 + gap[1]), // SW
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this -360 is the giveaway. longitude only goes to +/- 180, so no matter what the biggest gap is, this is going to give us a left boundary wider than the globe

@codecov
Copy link

codecov bot commented Dec 22, 2022

Codecov Report

Base: 64.98% // Head: 64.97% // Decreases project coverage by -0.00% ⚠️

Coverage data is based on head (96ff2a2) compared to base (eb7645a).
Patch coverage: 0.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #27392      +/-   ##
==========================================
- Coverage   64.98%   64.97%   -0.01%     
==========================================
  Files        3180     3184       +4     
  Lines       92471    92664     +193     
  Branches    11748    11770      +22     
==========================================
+ Hits        60088    60208     +120     
- Misses      27532    27605      +73     
  Partials     4851     4851              
Flag Coverage Δ
back-end 85.41% <ø> (-0.02%) ⬇️
front-end 46.16% <0.00%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...base/admin/settings/components/SettingsSetting.jsx 50.00% <ø> (ø)
...ettings/components/widgets/CustomGeoJSONWidget.jsx 0.00% <0.00%> (ø)
...se/visualizations/components/LeafletChoropleth.jsx 4.76% <ø> (ø)
...rontend/src/metabase/visualizations/lib/mapping.js 13.63% <0.00%> (+7.11%) ⬆️
...s/ExpressionEditorTextfield/helper-text-strings.ts 28.76% <0.00%> (-51.24%) ⬇️
...rontend/src/metabase/containers/CollectionName.jsx 33.33% <0.00%> (-33.34%) ⬇️
...nd/src/metabase/entities/containers/EntityName.jsx 66.66% <0.00%> (-33.34%) ⬇️
...se/visualizations/components/ChartTooltip/utils.ts 66.66% <0.00%> (-33.34%) ⬇️
src/metabase/bootstrap.clj 71.42% <0.00%> (-11.91%) ⬇️
...questions/components/TimelineCard/TimelineCard.tsx 79.31% <0.00%> (-8.69%) ⬇️
... and 144 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@gusaiani gusaiani left a comment

Choose a reason for hiding this comment

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

Code looks good to me and so do manual tests.

Asking @flamber for a look as you may catch outlying cases.

@iethree iethree added the visual Run Percy visual testing label Jan 4, 2023
@iethree
Copy link
Contributor Author

iethree commented Jan 5, 2023

Looks like I need to update the visual tests to account for loading time for maps:

9c3fb2ffec4fe42d9f6f8c30c0217d985cf73af6e232e43bd90f63da836bcc0c

Copy link
Contributor

@flamber flamber left a comment

Choose a reason for hiding this comment

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

This seems to work as expected on all the maps I have.
Is this going into 45? Then remember the backport label.

@iethree iethree added the backport Automatically create PR on current release branch on merge label Jan 6, 2023
@deploysentinel
Copy link

deploysentinel bot commented Jan 6, 2023

No failed tests 🎉

@iethree iethree merged commit f3cb01c into master Jan 10, 2023
@iethree iethree deleted the gh-26213-custom-region-maps branch January 10, 2023 00:04
github-actions bot pushed a commit that referenced this pull request Jan 10, 2023
* remove panning logic from map boundary calculation

* add map viz percy tests

* wait for map load in visual tests
metabase-bot bot added a commit that referenced this pull request Jan 10, 2023
* remove panning logic from map boundary calculation

* add map viz percy tests

* wait for map load in visual tests

Co-authored-by: Ryan Laurie <30528226+iethree@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport Automatically create PR on current release branch on merge visual Run Percy visual testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom region maps only shows partial map visualization
3 participants