Invisible Nodes with Gephi Toolkit 0.9.1

Screenshots, Vectorial Preview and printable exports
Post Reply
littleBobbyTables
Posts: 8
Joined: 10 Jun 2016 18:19

Invisible Nodes with Gephi Toolkit 0.9.1

Post by littleBobbyTables » 12 Jun 2016 17:15

Hello,

I am having an issue where I am trying to create an display a graph manually (i.e. not importing from an external file) but the nodes are not showing up. They seem just entirely invisible. I have tried changing the background color to see if they were just white on a white background, but that does not appear to be the issue. The edges show up just fine, but the nodes just don't seem to appear. My code, shown below, is mostly just pieces of the demo code from the toolkit being put together to get my desired output. Also attached is a screenshot of my display. Any help would be much appreciated. Thank you!

Code: Select all

import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.JFrame;

import org.gephi.graph.api.DirectedGraph;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.Node;
import org.gephi.preview.api.G2DTarget;
import org.gephi.preview.api.PreviewController;
import org.gephi.preview.api.PreviewModel;
import org.gephi.preview.api.PreviewProperty;
import org.gephi.preview.api.RenderTarget;
import org.gephi.preview.types.DependantColor;
import org.gephi.project.api.ProjectController;
import org.gephi.project.api.Workspace;
import org.gephi.toolkit.demos.plugins.preview.PreviewSketch;
import org.openide.util.Lookup;

/**
 *
 * @author JasonB
 *
 */
public class BasicGraphBuild {

	public static void main(String[] args) {
		BasicGraphBuild bscGraphBuild = new BasicGraphBuild();
		bscGraphBuild.script();
	}

	public void script() {
		ProjectController pc =
				Lookup.getDefault().lookup(ProjectController.class);
		pc.newProject();
		Workspace workspace = pc.getCurrentWorkspace();

		GraphModel graphModel = Lookup.getDefault()
				.lookup(GraphController.class).getGraphModel();

		Node n0 = graphModel.factory().newNode("n0");
		n0.setLabel("Node 0");
		n0.setX((float) ((0.01 + Math.random()) * 1000) - 500);
		n0.setY((float) ((0.01 + Math.random()) * 1000) - 500);
		Node n1 = graphModel.factory().newNode("n1");
		n1.setLabel("Node 1");
		n1.setX((float) ((0.01 + Math.random()) * 1000) - 500);
		n1.setY((float) ((0.01 + Math.random()) * 1000) - 500);
		Node n2 = graphModel.factory().newNode("n2");
		n2.setLabel("Node 2");
		n2.setX((float) ((0.01 + Math.random()) * 100) - 50);
		n2.setY((float) ((0.01 + Math.random()) * 100) - 50);

		Edge e1 = graphModel.factory().newEdge(n0, n1, 0, 1.0, true);
		Edge e2 = graphModel.factory().newEdge(n0, n2, 0, 1.0, true);

		DirectedGraph directedGraph = graphModel.getDirectedGraph();
		directedGraph.addNode(n0);
		directedGraph.addNode(n1);
		directedGraph.addNode(n2);
		directedGraph.addEdge(e1);
		directedGraph.addEdge(e2);

		// Preview configuration
		PreviewController previewController =
				Lookup.getDefault().lookup(PreviewController.class);
		PreviewModel previewModel = previewController.getModel();
		previewModel.getProperties().putValue(PreviewProperty.EDGE_CURVED,
				Boolean.FALSE);
		previewModel.getProperties().putValue(PreviewProperty.DIRECTED,
				Boolean.TRUE);
		previewModel.getProperties().putValue(PreviewProperty.NODE_BORDER_COLOR,
				new DependantColor(Color.BLACK));
		previewModel.getProperties().putValue(PreviewProperty.SHOW_NODE_LABELS,
				Boolean.TRUE);
		previewModel.getProperties().putValue(PreviewProperty.NODE_OPACITY,
				100);
		previewModel.getProperties().putValue(PreviewProperty.EDGE_OPACITY, 50);
		previewModel.getProperties().putValue(PreviewProperty.EDGE_RADIUS, 10f);
		previewModel.getProperties().putValue(PreviewProperty.BACKGROUND_COLOR,
				Color.WHITE);

		// New Processing target, get the PApplet
		G2DTarget target = (G2DTarget) previewController
				.getRenderTarget(RenderTarget.G2D_TARGET);
		PreviewSketch previewSketch = new PreviewSketch(target);
		previewController.refreshPreview();
		previewSketch.resetZoom();

		// Add the applet to a JFrame and display
		JFrame frame = new JFrame("Test Preview");
		frame.setLayout(new BorderLayout());

		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.add(previewSketch, BorderLayout.CENTER);

		frame.setSize(1024, 768);
		frame.setVisible(true);

	}

}
Attachments
No_Nodes.PNG
The display from the referenced code.

User avatar
eduramiba
Gephi Code Manager
Posts: 954
Joined: 22 Mar 2010 15:30
Location: Madrid, Spain

Re: Invisible Nodes with Gephi Toolkit 0.9.1

Post by eduramiba » 12 Jun 2016 20:01

Hi,
Can you try to set node opacity as a float (100f)? Not sure this is the problem but might be.

littleBobbyTables
Posts: 8
Joined: 10 Jun 2016 18:19

Re: Invisible Nodes with Gephi Toolkit 0.9.1

Post by littleBobbyTables » 12 Jun 2016 20:17

Thanks for your suggestion! I just tried that, but no luck. they still don't show up.

Node231
Posts: 7
Joined: 08 Jun 2016 19:36

Re: Invisible Nodes with Gephi Toolkit 0.9.1

Post by Node231 » 16 Jun 2016 20:01

Today I had a relatively similar issue, using 0.8.2 though

my workaround was installing an older version of java, other than that I have no idea :(

I used:
http://www.oracle.com/technetwork/java/ ... 19409.html
jre-6u38-windows-x64

littleBobbyTables
Posts: 8
Joined: 10 Jun 2016 18:19

Re: Invisible Nodes with Gephi Toolkit 0.9.1

Post by littleBobbyTables » 16 Jun 2016 20:08

Sadly, I can't do that. I need Java 8 for the rests of the project. Thanks, though!

littleBobbyTables
Posts: 8
Joined: 10 Jun 2016 18:19

Re: Invisible Nodes with Gephi Toolkit 0.9.1

Post by littleBobbyTables » 11 Jul 2016 15:48

Sorry this has taken so long to update, but I have (sort of) fixed this problem with a rather strange workaround. Instead of building the graph the way I have done above, I instead used an ImportController and ImportContainer and with that used NodeDraftImpl objects and EdgeDraftImpl objects. I don't know why this solves the problem and makes nodes visible, but it worked for me. Most all of the methods that exist to modify the nodes and edges in the other method still exist in some regard with this method. The other thing to keep in mind is that you need to remember to process the container after building the graph in it (that's the point of the ImportController). That's how I solved this. I hope it helps anyone with a similar issue!

semen.kosyachenko
Posts: 1
Joined: 23 Nov 2016 15:32

Re: Invisible Nodes with Gephi Toolkit 0.9.1

Post by semen.kosyachenko » 23 Nov 2016 15:36

hi, I have same problem, and I don't know what to do with it.
I can see edges, but not nodes(((
so littleBobbyTables could you post the code how you make graph manualy using ImportController and ImportContainer?
thanks.

Post Reply