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

refactor: Moved hover tooltip rendering logic into component #491

Merged
merged 6 commits into from
Dec 17, 2024

Conversation

ShrimpCryptid
Copy link
Contributor

@ShrimpCryptid ShrimpCryptid commented Dec 6, 2024

Problem

Refactors the rendering logic for hover tooltips into a separate component. As part of this change, I also changed some variable names for clarity and moved component styling.

This will eventually let me add a tag tooltip that follows the mouse as part of #484!

Estimated size: small, 10-20 minutes (faster if you compare deleted changes!!!)

Solution

  • Moves the rendering of tooltip contents out of Viewer.tsx and into a new component, CanvasHoverTooltip.tsx.
  • Moves some styling of the tooltip out of HoverTooltip.tsx and into CanvasHoverTooltip.tsx.
  • Renames some state variables in Viewer.tsx for clarity.

Steps to Verify:

  1. Open PR preview, load a dataset, and hover over cells. https://allen-cell-animated.github.io/timelapse-colorizer/pr-preview/pr-491/
  2. Compare behavior with our public build here: https://timelapse.allencell.org

@ShrimpCryptid ShrimpCryptid added the internals Tech debt, refactoring, dependencies, etc. label Dec 6, 2024
@ShrimpCryptid ShrimpCryptid self-assigned this Dec 6, 2024
Copy link

github-actions bot commented Dec 6, 2024

PR Preview Action v1.4.8
Preview removed because the pull request was closed.
2024-12-17 00:13 UTC

Copy link

github-actions bot commented Dec 6, 2024

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 75.34% 5313 / 7052
🔵 Statements 75.34% 5313 / 7052
🔵 Functions 58.67% 142 / 242
🔵 Branches 81.19% 449 / 553
File CoverageNo changed files found.
Generated in workflow #1278

Comment on lines +203 to +204
const [lastValidHoveredId, setLastValidHoveredId] = useState<number>(-1);
const [showObjectHoverInfo, setShowObjectHoverInfo] = useState(false);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

-1 is okay here as a placeholder value, because showObjectHoverInfo is only set to true when lastValidHoveredId can be set to a valid ID number.

Copy link
Contributor

Choose a reason for hiding this comment

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

since you called this out, it's definitely odd to call it a "valid" hovered id when -1 is allowed!

}
};

// TODO: Move to a separate component?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

:)

Comment on lines +9 to +16
type CanvasHoverTooltipProps = {
dataset: Dataset | null;
featureKey: string;
lastValidHoveredId: number;
showObjectHoverInfo: boolean;
motionDeltas: Float32Array | null;
config: ViewerConfig;
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could really use redux or a state management framework here...

Comment on lines 19 to 29
const TooltipCard = styled.div`
font-family: var(--default-font);

border-radius: var(--radius-control-small);
border: 1px solid var(--color-dividers);
background-color: var(--color-background);
padding: 6px 8px;
overflow-wrap: break-word;

transition: opacity 300ms;
`;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved from HoverTooltip.tsx

@ShrimpCryptid ShrimpCryptid marked this pull request as ready for review December 6, 2024 04:06
@ShrimpCryptid ShrimpCryptid requested a review from a team as a code owner December 6, 2024 04:06
@ShrimpCryptid ShrimpCryptid requested review from toloudis and rugeli and removed request for a team December 6, 2024 04:06
Comment on lines +203 to +204
const [lastValidHoveredId, setLastValidHoveredId] = useState<number>(-1);
const [showObjectHoverInfo, setShowObjectHoverInfo] = useState(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

since you called this out, it's definitely odd to call it a "valid" hovered id when -1 is allowed!

@ShrimpCryptid ShrimpCryptid merged commit ddd8ac0 into main Dec 17, 2024
3 checks passed
@ShrimpCryptid ShrimpCryptid deleted the refactor/move-hover-tooltip-logic branch December 17, 2024 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internals Tech debt, refactoring, dependencies, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants