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

Add WIP map view #536

Open
wants to merge 15 commits into
base: add-map-view
Choose a base branch
from

Conversation

simonbukin
Copy link

This is a PR to add the WIP map view to Taxonium.

Next steps:

  • Add scaled pie charts to map view (ChatGPT)
  • Create a new backend route from the local and server backends that gets the total counts for an attribute for each country

@vercel
Copy link

vercel bot commented Oct 9, 2023

Someone is attempting to deploy a commit to a Personal Account owned by @theosanderson on Vercel.

@theosanderson first needs to authorize it.

@simonbukin simonbukin changed the title Add leaflet and wrap Treenome in own component Add WIP map view Oct 9, 2023
@vercel
Copy link

vercel bot commented Oct 9, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
cov2tree ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 26, 2024 8:22pm

Copy link
Owner

Choose a reason for hiding this comment

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

This file didn't previously exist - looks like a merge issue and any changes should go to taxonium_component?

Copy link
Author

Choose a reason for hiding this comment

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

Looks like it, I'll go ahead and remove the taxonium_web_client folder from this PR.

@theosanderson
Copy link
Owner

Thank you for opening this! Adding comments piecemeal

Copy link
Owner

Choose a reason for hiding this comment

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

We use yarn for taxonium - I think that means we can lose this file but let me know if there's a reason it's useful, I'm no expert

Copy link
Author

Choose a reason for hiding this comment

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

Will remove! I'm used to NPM based projects, so this was just a force of habit.

<View id="map">
<div
id="map-div"
key={crypto.randomUUID()}
Copy link
Owner

Choose a reason for hiding this comment

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

Is this unique key each time important? (I assume so but just checking)

Copy link
Author

Choose a reason for hiding this comment

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

Usually I err on the side of including an id so that React can more efficiently calculate rerenders. I believe this specific case was added because a warning in the console, so it seems like React was struggling to update Views.

Copy link
Owner

@theosanderson theosanderson Oct 10, 2023

Choose a reason for hiding this comment

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

Ah, the re-render thing was my concern here. My model for what will happen for the code here is that every render the key will be different and so React will not be able to see that there is a (potentially) unchanging element here. I would be happy with key="map-div-key" or similar. Again, I don't claim to be an expert and may be misunderstanding.

Copy link
Author

Choose a reason for hiding this comment

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

I think you're totally right here, so I just swapped out the crypto.uuid with the "map-div-key" string. Thanks!

Copy link
Owner

Choose a reason for hiding this comment

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

We seem to have ended up with the zoom controls repeated 2x, once on the map and once on the tree. (I'd say they are better just on the tree).

Copy link
Author

Choose a reason for hiding this comment

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

Is there a usecase where zooming into the map would be helpful? I was assuming that users may want to zoom into part of the map to view pie charts in only certain regions (eventually), but maybe you had a different idea here. Would the map view be fully zoomed out by default if we remove the zoom functionality?

Copy link
Owner

Choose a reason for hiding this comment

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

Yes, there might be use cases where zooming would be useful - but atm the buttons on the map affect the tree so this is not achieved. I don't see a strong need for zoom buttons for the map -- as opposed to panning and scrolling -- we need them for the tree due to separate X and Y zooms.

Copy link
Owner

Choose a reason for hiding this comment

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

When I click and drag on the minimap a the top right of the tree (regardless of geo-map enabled or not) the preview crashes with Cannot read properties of undefined (reading 'zoom')

Copy link
Author

Choose a reason for hiding this comment

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

I think I have an idea of a fix here, but may take a few days. Will update!

@@ -540,6 +545,49 @@ const useLayers = ({
layers.push(minimap_line_horiz, minimap_line_vert, minimap_scatter);
layers.push(minimap_bound_polygon);

let countryCounts = {};
Copy link
Owner

Choose a reason for hiding this comment

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

It's not clear to me that we will end up using much of this logic other than the layers.push bit. E.g. the max and min aren't used at present. I would probably suggest removing the color piece as it may never be used and leaving all countries coloured the same for now.

Copy link
Author

Choose a reason for hiding this comment

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

Removed the color code for now.

@@ -566,6 +615,7 @@ const useLayers = ({
return new ScatterplotLayer(layer);
}
if (layer.layerType === "LineLayer") {
console.log('processed ', layer);
Copy link
Owner

Choose a reason for hiding this comment

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

to remove in due course

Copy link
Author

Choose a reason for hiding this comment

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

Removed

@simonbukin
Copy link
Author

@theosanderson Sorry for the delay here! Been a busy few months :)

I've looked more deeply into the minimap issues and I believe it has to do with the refactor I did for getting different views to update using setViewState based on their respective viewIds. The code was initially doing an empty return instead of returning the currentViewState, which was causing the viewState on the next render to be undefined.

The above seems to have fixed the crash when dragging on the minimap. However, I believe the dragging behavior is still a little buggy, and I wanted to know if you had any input on the changes I made to fix the crash. I think we might be pretty close to a working minimap again, but I'm getting stumped by the current zoom code (mostly the role of mouseDownIsMinimap, specialMinimap and the old/new scaleX/Y values). Could you take a look at the refactor and see if you can spot a potential issue?

Again, really appreciate your help here!

@theosanderson
Copy link
Owner

theosanderson commented Dec 14, 2023

Thanks for all your efforts @simonbukin. It's great that the crashing is fixed, but you're right that the behaviour is still buggy as compared to the intended behaviour.

The intended behaviour, as currently on Cov2Tree is:

  • clicking on the minimap triggers the main display to shift to the clicked on location
  • dragging the minimap causes the main display to shift to the dragged to region
  • clicking the mouse down on the main display and then dragging the mouse over to the minimap does not trigger the main display to shift - normal pan behaviour continues

I acknowledge that the view code is hard work to understand (for me). There has been a lot of trial and error to get it to behave in the intended way.

mouseDownIsMinimap is intended to record that the user initially pressed down the mouse button within the minimap and so we should treat this action as a minimap drag, not as a pan. (And conversely, when this is false we should treat the action as a pan).

When mouseDownIsMinimap is true, we in general stop the onViewStateChange command from doing anything, in order to avoid the standard pan behaviour from happening:

But we want to manually call onViewStateChange in order to shift the zoom to the place that was clicked on in the minimap

. But if we have stopped onViewState doing anything when mouseDownIsMinimap is true, that won't work. So we define specialMinimap which basically overrides the disabling in the case of mouseDownIsMinimap and manually call it with specialMinimap. The scale stuff is fundamentally about the fact that DeckGL doesn't support zooming in a single axis in a good way, and has been adjusted by trial and error to compensate for that.

@theosanderson
Copy link
Owner

theosanderson commented Dec 14, 2023

(while we're on the minimap - I think it needs to either be overlaid over the tree rather than the map when the map is open, or just disabled in that case)

@theosanderson
Copy link
Owner

Also, if I enable treenome browser mode (not map) and zoom in on the tree, the preview crashes with https://legacy.reactjs.org/docs/error-decoder.html/?invariant=185

@theosanderson
Copy link
Owner

(closing/opening was just a hit-wrong-button thing!)

@simonbukin
Copy link
Author

Thanks for the detail here! I'll take a crack at making it work to spec. I think emulating the empty return using a setViewState is going to solve most of the issues currently occurring with the buggy minimap, but I'll have to see how it goes.

I'll take a look at the Treenome crashing issue; I have a feeling I know what's breaking it.

I'm going to go ahead and disable the minimap when the map is open as a fix for now, but I believe it can be added back later and overlaid on the tree.

Thanks again!

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.

2 participants