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

I layout a graph manually ,the graph does not display. #1785

Closed
aoyuanbo opened this issue Sep 19, 2017 · 11 comments
Closed

I layout a graph manually ,the graph does not display. #1785

aoyuanbo opened this issue Sep 19, 2017 · 11 comments
Assignees
Labels

Comments

@aoyuanbo
Copy link

Expected Behavior

I layout a graph manually, the graph does not display.

ForceAtlasLayout layout=new ForceAtlasLayout(null);

layout.setGraphModel(graphModel);

layout.setSpeed(50D);

layout.setGravity(10.0d);

layout.initAlgo();

for (int i = 0; i < 200 && layout.canAlgo(); i++) {

layout.goAlgo();

}

layout.endAlgo();

Current Behavior

Possible Solution

I layout a graph automatically,it`s ok.

`
AutoLayout autoLayout = new AutoLayout(20, TimeUnit.SECONDS);

autoLayout.setGraphModel(graphModel);

ForceAtlasLayout secondLayout = new ForceAtlasLayout(null);

AutoLayout.DynamicProperty adjustBySizeProperty = AutoLayout.createDynamicProperty("forceAtlas.adjustSizes.name", Boolean.TRUE, 0.1f);//True after 10% of layout time

AutoLayout.DynamicProperty repulsionProperty = AutoLayout.createDynamicProperty("forceAtlas.repulsionStrength.name", new Double(500.), 0f);//500 for the complete period

autoLayout.addLayout(secondLayout, 1f, new AutoLayout.DynamicProperty[]{adjustBySizeProperty, repulsionProperty});

autoLayout.execute();`

Steps to Reproduce

Context

Your Environment

  • Version used: Gephi 0.9.1
  • Operating System:windows 7
@eduramiba eduramiba self-assigned this Sep 19, 2017
@eduramiba
Copy link
Member

I think this might be bug #603

@eduramiba
Copy link
Member

Please test setting random positions or use 0.9.2-SNAPSHOT

@aoyuanbo
Copy link
Author

ok,I will have a try.

@eduramiba
Copy link
Member

Great, please report results

@aoyuanbo
Copy link
Author

I have tried with 0.9.2-SNAPSHOT ,it does not still display.

@eduramiba
Copy link
Member

What's the rest of your code? Can you provide the full code and data to reproduce?

@eduramiba
Copy link
Member

Did it work with 0.9.2 release?

@aoyuanbo
Copy link
Author

aoyuanbo commented Oct 26, 2017 via email

@sfc-gh-gmullen
Copy link

I am seeing this same issue. Seems like the RandomLayout works, but YifanHuLayout, FruchtermanReingold and others don't manipulate the underlying X/Y values. Even when manually running the RandomLayout first to force non-zeros, the other Layouts don't change the X/Ys.

@sfc-gh-gmullen
Copy link

`package NetworkBuilder;

import org.gephi.graph.api.*;
import org.gephi.layout.plugin.force.StepDisplacement;
import org.gephi.layout.plugin.force.yifanHu.YifanHuLayout;
import org.gephi.project.api.ProjectController;
import org.gephi.project.api.Workspace;
import org.openide.util.Lookup;

public class buildNetwork {

public static void main(String[] args) {
//Init a project - and therefore a workspace
ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
pc.newProject();
Workspace workspace = pc.getCurrentWorkspace();

 //Get a graph model - it exists because we have a workspace
 GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel(workspace);

 //Create three nodes
 Node n0 = graphModel.factory().newNode("n0");
 n0.setLabel("Node 0");
 Node n1 = graphModel.factory().newNode("n1");
 n1.setLabel("Node 1");
 Node n2 = graphModel.factory().newNode("n2");
 n2.setLabel("Node 2");

 //Create three edges
 Edge e1 = graphModel.factory().newEdge(n1, n2, 0, 1.0, true);
 Edge e2 = graphModel.factory().newEdge(n0, n2, 0, 2.0, true);
 Edge e3 = graphModel.factory().newEdge(n2, n0, 0, 2.0, true);   //This is e2's mutual edge

 //Append as a Directed Graph
 DirectedGraph directedGraph = graphModel.getDirectedGraph();
 directedGraph.addNode(n0);
 directedGraph.addNode(n1);
 directedGraph.addNode(n2);
 directedGraph.addEdge(e1);
 directedGraph.addEdge(e2);
 directedGraph.addEdge(e3);

 //Count nodes and edges
 System.out.println("Nodes: " + directedGraph.getNodeCount() + " Edges: " + directedGraph.getEdgeCount());

 //Get a UndirectedGraph now and count edges
 UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
 System.out.println("Edges: " + undirectedGraph.getEdgeCount());   //The mutual edge is automatically merged

 //Iterate over nodes
 for (Node n : directedGraph.getNodes()) {
     Node[] neighbors = directedGraph.getNeighbors(n).toArray();
     System.out.println(n.getLabel() + " has " + neighbors.length + " neighbors");
 }

 //Iterate over edges
 for (Edge e : directedGraph.getEdges()) {
     System.out.println(e.getSource().getId() + " -> " + e.getTarget().getId());
 }

 //Find node by id
 Node node2 = directedGraph.getNode("n2");

 //Get degree
 System.out.println("Node2 degree: " + directedGraph.getDegree(node2));

 YifanHuLayout layout = new YifanHuLayout(null, new StepDisplacement(1f));
 layout.setGraphModel(graphModel);
 layout.resetPropertiesValues();
 layout.initAlgo();
 for (int i = 0; i < 100 && layout.canAlgo(); i++) {
     layout.goAlgo();
 }
 layout.endAlgo();

 for (Node n : directedGraph.getNodes()) {
     //Note that X/Y values do not change after layout has been run
     System.out.println(n.x() + "," +n.y());
 }

}
}
`

@mbastian
Copy link
Member

There are two issues referred in this thread:

  • For the original request from @aoyuanbo I think the root cause of this issue is not calling the layout.resetPropertiesValues() method upon initialisation. For some layouts like Force Atlas, some properties are only get assigned by this method. For instance, if not defined a cooling of zero will produce NaN (division by zero)
  • For @sfc-gh-gmullen's issue the root cause is most likely not having initial random positions. Some layouts deal with that but some others might not. If all positions are zero it can create an edge case in how the layouts work so I would recommend assigning first a random X/Y position.

Closing the thread but please reopen if it doesn't solve it.

@mbastian mbastian closed this as not planned Won't fix, can't repro, duplicate, stale Dec 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants