Graph with Black background and white edges

Asked by snehalpatil

Hello,

I am generating a graph using YifanHuLayout by reading .gexf file and wanted to have graph as a black background and white edges. I am generating graph exactly opposite of this as of now. Does anyone know what should I do to get black background and white edges.

Also, I want to change the thickness of edges with weight of edges. Does anyone know how to go about it?

Here is a code that I am using.

public class Headless {

 public void getGraph(){
  //Init a project - and therefore a workspace
  ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
  pc.newProject();
  Workspace workspace = pc.getCurrentWorkspace();

  //Get models and controllers for this new workspace - will be useful later
  AttributeModel attributeModel = Lookup.getDefault().lookup(AttributeController.class).getModel();
  GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getModel();
  PreviewModel model = Lookup.getDefault().lookup(PreviewController.class).getModel();
  ImportController importController = Lookup.getDefault().lookup(ImportController.class);
  FilterController filterController = Lookup.getDefault().lookup(FilterController.class);
  RankingController rankingController = Lookup.getDefault().lookup(RankingController.class);

  //Import file
  Container container;
  try {
   URL url = getClass().getResource("test1.gexf");
   System.out.println(url);
      File file = new File(getClass().getResource("test1.gexf").toURI());
      container = importController.importFile(file);
      container.getLoader().setEdgeDefault(EdgeDefault.DIRECTED); //Force DIRECTED
  } catch (Exception ex) {
      ex.printStackTrace();
      return;
  }

  //Append imported data to GraphAPI
  importController.process(container, new DefaultProcessor(), workspace);

  //See if graph is well imported
  DirectedGraph graph = graphModel.getDirectedGraph();
  System.out.println("Nodes: " + graph.getNodeCount());
  System.out.println("Edges: " + graph.getEdgeCount());

  //See visible graph stats
  UndirectedGraph graphVisible = graphModel.getUndirectedGraphVisible();
  System.out.println("Nodes: " + graphVisible.getNodeCount());
  System.out.println("Edges: " + graphVisible.getEdgeCount());

  //Run YifanHuLayout for 100 passes - The layout always takes the current visible view
  YifanHuLayout layout = new YifanHuLayout(null, new StepDisplacement(1f));
  layout.setGraphModel(graphModel);
  layout.resetPropertiesValues();
  layout.setOptimalDistance(200f);

  for (int i = 0; i < 1000 && layout.canAlgo(); i++) {
   layout.goAlgo();
  }

  //Get Centrality
  GraphDistance distance = new GraphDistance();
  distance.setDirected(true);
  distance.execute(graphModel, attributeModel);

  //Rank color by Degree
  NodeRanking degreeRanking = rankingController.getRankingModel().getDegreeRanking();
  ColorTransformer colorTransformer = rankingController.getObjectColorTransformer(degreeRanking);
  colorTransformer.setColors(new Color[]{new Color(0xFEF0D9), new Color(0xB30000)});
  rankingController.transform(colorTransformer);

  //Rank size by centrality
  AttributeColumn centralityColumn = attributeModel.getNodeTable().getColumn(GraphDistance.BETWEENNESS);
  NodeRanking centralityRanking = rankingController.getRankingModel().getNodeAttributeRanking(centralityColumn);
  SizeTransformer sizeTransformer = rankingController.getObjectSizeTransformer(centralityRanking);
  sizeTransformer.setMinSize(3);
  sizeTransformer.setMaxSize(10);
  rankingController.transform(sizeTransformer);

  //Preview
  model.getNodeSupervisor().setShowNodeLabels(Boolean.TRUE);
  ColorizerFactory colorizerFactory = Lookup.getDefault().lookup(ColorizerFactory.class);
  model.getUniEdgeSupervisor().setColorizer((EdgeColorizer) colorizerFactory.createCustomColorMode(Color.BLACK)); //Set edges black
  model.getBiEdgeSupervisor().setColorizer((EdgeColorizer) colorizerFactory.createCustomColorMode(Color.BLACK)); //Set mutual edges black
  model.getNodeSupervisor().setBaseNodeLabelFont(model.getNodeSupervisor().getBaseNodeLabelFont().deriveFont(8));
  model.getUndirectedEdgeSupervisor().setCurvedFlag(false);
  model.getUniEdgeSupervisor().setCurvedFlag(false);
  model.getUniEdgeSupervisor().setArrowSize(0.0f);
  //Export
  ExportController ec = Lookup.getDefault().lookup(ExportController.class);
  try {
      ec.exportFile(new File("test4.pdf"));
  } catch (IOException ex) {
      ex.printStackTrace();
      return;
  }
 }
 public static void main(String[] args){
  Headless headLess = new Headless();
  headLess.getGraph();
 }

}

I appreciate your help!

Thanks!

Question information

Language:
English Edit question
Status:
Answered
For:
Gephi Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Mathieu Bastian (mathieu.bastian) said :
#1

Hello, yes that is possible

* How to change background color in Preview (and therefore PDF/SVG export)

PreviewController previewController = Lookup.getDefault().lookup(PreviewController.class);
previewController .setBackgroundColor(java.awt.Color color);

However there is the bug 583386 that keeps the background white in the PDF export. This bug is now fixed in the trunk, but not in the toolkit. I suggest to either get the latest toolkit JAR from the trunk and build it (see http://wiki.gephi.org/index.php/How_to_build_the_Gephi_Toolkit) or wait two weeks for the next toolkit release (with 0.7beta).

* How to change nodes & edges color to white

model.getUniEdgeSupervisor().setColorizer((EdgeColorizer) colorizerFactory.createCustomColorMode(Color.WHITE)); //Set edges gray
model.getNodeSupervisor().setNodeColorizer((NodeColorizer) colorizerFactory.createCustomColorMode(Color.WHITE)); //Set nodes white
model.getNodeSupervisor().setNodeLabelColorizer((NodeChildColorizer) colorizerFactory.createCustomColorMode(Color.WHITE)); //Set nodes labels white);

Revision history for this message
snehalpatil (snehal-patil) said :
#2

Hello Mathieu Bastian,

Thank you so much for your reply !

I got now how to get it done, however I am facing problem with getting new jar file. I will work on that.

Do u you know how to get thinkness to edges as per their weight?

I know we can scale the edges using 'setEdgeScale' method however, it scale for whole graph...not sure how to put scaling for every edge as per their weight.

Thanks!!

Revision history for this message
Mathieu Bastian (mathieu.bastian) said :
#3

Let me know if you have any issue building the toolkit.

The edges thickness should depend on the weight directly. You can change the weight by doing edge.setWeight()

Revision history for this message
snehalpatil (snehal-patil) said :
#4

Hello Mathieu,

I am facing lot of problem to build new tar file..

I had set up all system variables but it gives me diff error like...unable to find tools.jar and other it says error occured while executing this line in build.xml...

I can not understand these errors and cant fix them..

Is there any way around? can I get tar file from someone else?

Snehal

Revision history for this message
Mathieu Bastian (mathieu.bastian) said :
#5

As many changes were done recently to meet 0.7beta objectives, the toolkit target may have been broken for a while. I repaired it now and it should be working now. Sorry for this problem...

Let me know if you get the toolkit JAR normally

Revision history for this message
Mathieu Bastian (mathieu.bastian) said :
#6

We are doing some more changes for the beta today, so I recommend to get the source code at revision 1754 to have a Toolkit that builds

Revision history for this message
snehalpatil (snehal-patil) said :
#7

Hello,

I tried it again and it failed again.

You said beta version is getting released soon. Do you know when it is going to get released?

Snehal

Revision history for this message
Mathieu Bastian (mathieu.bastian) said :
#8

What are the errors? I tried and it works fine here.

Did you try to call the 'clean' target to delete the content of the build folder.

The beta is getting released later this week

Can you help with this problem?

Provide an answer of your own, or ask snehalpatil for more information if necessary.

To post a message you must log in.