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

Mutation over time grid doesn't show numbers when switching tabs #517

Closed
chaoran-chen opened this issue Nov 15, 2024 · 1 comment · Fixed by #523
Closed

Mutation over time grid doesn't show numbers when switching tabs #517

chaoran-chen opened this issue Nov 15, 2024 · 1 comment · Fixed by #523
Assignees
Labels
bug Something isn't working components Regarding the components

Comments

@chaoran-chen
Copy link
Member

In my PR for the wastewater mutations over time plot (#504), I'm reusing the existing mutations over time grid and am observing a bug where the proportion numbers don't display initially when switching the tab but become visible if we change the size of the window:

https://dashboard-components-git-wastewater-mutations-cov-spectrum.vercel.app/?path=/story/visualization-wastewater-mutations-over-time--default

Screen.Recording.2024-11-15.at.16.52.18.mov
@chaoran-chen chaoran-chen added bug Something isn't working components Regarding the components labels Nov 15, 2024
@fengelniederhammer fengelniederhammer self-assigned this Nov 18, 2024
@fengelniederhammer
Copy link
Collaborator

The problem is the following:

We use this function to compute whether to show the proportion number or not:

function useShowProportion(
gridRef: RefObject<HTMLDivElement>,
girdColumns: number,
setShowProportionText: (value: ((prevState: boolean) => boolean) | boolean) => void,
) {
useEffect(() => {
const checkWidth = () => {
if (gridRef.current) {
const width = gridRef.current.getBoundingClientRect().width;
const widthPerDate = (width - remToPx(MUTATION_CELL_WIDTH_REM)) / girdColumns;
const maxWidthProportionText = 28;
setShowProportionText(widthPerDate > maxWidthProportionText);
}
};
checkWidth();
window.addEventListener('resize', checkWidth);
return () => {
window.removeEventListener('resize', checkWidth);
};
}, [girdColumns, gridRef, setShowProportionText]);
}

When the tab is not visible, then checkWidth will execute gridRef.current.getBoundingClientRect().width, which evaluates to 0 (since that grid is currently not visible). Thus, the proportions are not shown.
The component does not receive an update when switching tabs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working components Regarding the components
Projects
None yet
2 participants