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

Hide labels based off distance from camera #187

Merged
merged 5 commits into from
Feb 23, 2024
Merged

Conversation

ghsteff
Copy link
Contributor

@ghsteff ghsteff commented Feb 23, 2024

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

Labels show on every node even when there so small they're unreadable. This can have a big impact on performance

What is the new behavior?

Labels don't render when they're so small they can't be read. This is based off zoom and distance from camera

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

BEFORE

Untitled.mov

AFTER

Screen.Recording.2024-02-22.at.6.50.37.PM.mov
Screen.Recording.2024-02-22.at.6.49.59.PM.mov

This hides labels when they're so far away from the camera you can't read them anyway

labels have a big impact on performance when there's enough of them
Comment on lines +433 to +439
isCentered && (
<Fragment>
{nodeComponents}
{edgeComponents}
{clusterComponents}
</Fragment>
)
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 could make more sense named mounted, but that's also not exactly what it is

isCentered is true when the camera re-orients from it's initial z position of 1000, which happens on big graphs

Without this the label visibility calculation is usually off on the initial render

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 also gets rid of that laggy zoom out/jump on initial big graph renders which I think was previously being handled here with a mounted && ...

@ghsteff
Copy link
Contributor Author

ghsteff commented Feb 23, 2024

This doesn't hide edge labels. Edges don't have a position so we'd prob grab either the source or target node to decide whether to show the label

I can add hiding edge labels to this PR or a follow up

@ghsteff ghsteff requested a review from amcdnl February 23, 2024 01:04
src/utils/visibility.ts Outdated Show resolved Hide resolved
src/utils/visibility.ts Outdated Show resolved Hide resolved
@@ -41,6 +41,8 @@ export const useCenterGraph = ({
disabled
}: CenterGraphInput): CenterGraphOutput => {
const nodes = useStore(state => state.nodes);
const isCentered = useStore(state => state.isCentered);
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to put this in the store based on the current useage, u could just return in state.

@amcdnl amcdnl merged commit 30704ed into master Feb 23, 2024
1 check passed
@amcdnl amcdnl deleted the Hide-small-labels branch February 23, 2024 12:18
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