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

Make a selected node the center of the page #103

Closed
mabreyes opened this issue May 22, 2024 · 9 comments
Closed

Make a selected node the center of the page #103

mabreyes opened this issue May 22, 2024 · 9 comments

Comments

@mabreyes
Copy link

How do I make a selected node the center of the graph? In my code below, the selectedNode holds the value of the node. How do I get its coordinates and refresh the graph with the selectedNode as the center?

orbRef.current.data.setup({ nodes, edges });
            const selectedNode = orbRef.current.data.getNodeById(searchTerm);
            if (selectedNode) {
                selectedNode.state = GraphObjectState.SELECTED;
            }

            orbRef.current.view.setSettings({
                zoomFitTransformMs: 1000,
                render: {
                    shadowIsEnabled: true,
                    shadowOnEventIsEnabled: false,
                    fps: 100,
                    minZoom: 2.5,
                },
                simulation: {
                    centering: {
                        x: 0,
                        y: 0,
                        strength: 1,
                    },
                }
            });

            orbRef.current.view.render(() => {
                orbRef.current.view.recenter();
            });

Thank you!

@matea16
Copy link

matea16 commented May 23, 2024

Hi @mabreyes, thank you for opening this issue. Someone from the team will pick this up and take a look at it

@josiahbryan
Copy link

josiahbryan commented May 24, 2024

Hey @mabreyes , thanks to hints from @tonilastre in #52, I've crafted this function which does just what you're talking about I think - you just have to call it with the selected node:

https://gist.github.com/josiahbryan/354a0357dd52e43b14b3df4022267b9f

I use it like this in my app:

const nodeIdForFocus = 'aidgno_ticss4ego8hzw5tx3ov9sdz9b';

const orbNode = orb.data
	.getNodes()
	.find((x) => x.id === nodeIdForFocus);

if (orbNode) {
	orbFocusOnNode(orb, orbNode);
}

@mabreyes
Copy link
Author

Thanks @josiahbryan is this before the render or after the render?

@josiahbryan
Copy link

josiahbryan commented May 25, 2024 via email

@mabreyes
Copy link
Author

Got it to work and I was also able to make it change based on the search query. Thanks @josiahbryan

@tonilastre
Copy link
Contributor

@josiahbryan thanks for jumping in with a great solution.

We are preparing a 1.0.0 version of the Orb that will have some changes to the API (e.g. render will be called automatically) along with several performance fixes. We added zoom handle functions there, but we are definitely missing the panning of the canvas, so once 1.0.0 is out, we will add this capability to the official API.

Our plan after 1.0.0 was to fix the default layout algo (d3-force) and also expose layout algorithms where you will be able to plug in any other layout (e.g. tree layout), but adding this feature before that makes more sense.

@josiahbryan
Copy link

Thanks @tonilastre - will the 1.0.0 "break" any of the APIs I used in this "hack"? Or will this still work on 1.0.0 (before you add it to the official API)?

@tonilastre
Copy link
Contributor

tonilastre commented May 27, 2024

The main part of the code (90% of it) will work as is, there will be some minor changes, e.g. orb.view doesn't exist anymore, it is now a separate class: OrbDefaultView or OrbMapView which contain a renderer. Canvas is not anymore in the main class, but in the renderer because orb 1.0.0 already has a fix where the renderer listens on Device Pixel Ratio (DPR) to render a graph with a better quality on retina displays (#45).

All in all, it is just a simple find+replace on some of the classes and functions. We will create a guided migration document for it to help out with the transition.

@josiahbryan
Copy link

Ahh nice!! Love to hear there will be a migration doc - thanks for the quick response and appreciate your detailed reply. Looking forward to trying out 1.0.0 - yeah I was noticing some less-than-optimal rendering on a few of my screens (quad-monitor setup) - so looking forward to the DPR enhancements too. Thanks!

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

No branches or pull requests

4 participants