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

centerAt #72

Closed
Doni44 opened this issue May 17, 2018 · 2 comments
Closed

centerAt #72

Doni44 opened this issue May 17, 2018 · 2 comments
Assignees

Comments

@Doni44
Copy link

Doni44 commented May 17, 2018

Hello!

I am trying to fix my forceGraph in the center of a div.
However, since it is loaded it goes away all the time.
I have read that the centerAt() function can help me to do what I want but when I used it the console tells me that centerAt is not a function.

Here is my code:

`const Graph = ForceGraph3D()(document.getElementById("infoCarto3D"));

			var nodes = ${jsonNodes};
			var links = ${jsonLinks};
			var width = widthCarto;
			var height = heightCarto;
			
		    const dataSet = function(Graph) 
		    {
		       Graph
		          	.width(width)
		          	.height(height)
		          	//.cameraPosition({ x:50, y:50, z:10})//50/50/10
		          	.backgroundColor('transparent')
		          	.forceEngine('ngraph')
		          	//Node Styling
		          	.nodeLabel('id')
		         	.nodeOpacity(0.75)
		         	.nodeColor(node => node.type=="OK" ? '#4caf50' : '#f44336')
		         	.nodeVal(node => node.val==0 ? 30 : (node.val==1 ? 15 : (node.val==2 ? 10 : (node.val==3 ? 5 : (node.val==4 ? 3 : 1)))))
		         	.onNodeHover(node => document.getElementById("infoCarto3D").style.cursor = 'pointer')
		         	//Link Styling
		         	.linkOpacity(1)
		         	.linkColor(link => link.type=="" ? 'white' : (link.type=="OK" ? '#4caf50' : '#f44336'))
		         	.linkWidth(0.5)
		         	//We create the 3D force graph
					.graphData({nodes: nodes, links: links})   
					.centerAt(0,0)
		    };
		  	dataSet(Graph); // Load dataSet`
@vasturiano
Copy link
Owner

@Doni44 only the d3 force engine has centering functionality (by default using the forceCenter built-in force type). The ngraph engine does not. I would recommend switching to .forceEngine('d3') if you wish to keep your graph centered.

@Doni44
Copy link
Author

Doni44 commented May 18, 2018

Thanks so much!

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

2 participants