Thursday, May 10, 2012

Graph This - rendering your graph with Graphviz.

Triggered by a user question, let me just very briefly highlight a nice and easy graph visualization feature.

Sometimes, you just want to fast see what you are putting in your little example graph. In Neo4j, there is a well hidden gem-the Graphviz Component. To very shortly output a graphviz rendering, look at this test, demonstrating the basic usage (this code is actually taking a traversal instruction to walk the graph, you can easily just use the whole graph):









And gives you the following output in the Graphviz DOT notation: With this piped into a file, say neo4j.dot, you can now do (after installing graphviz and dot on your machine):

dot -Tpng -O neo4j.dot


And get an output file of neo4j.dot.png, pictured below.






















Voila, your are done and can see what you just programmed!


Happy hacking!


/peter

11 comments:

Anonymous said...

Hi, I was wondering if you can output the cluster style / subgraphs from graphviz with org.neo4j.visualization.graphviz according to this:

<a href="http://www.graphviz.org/content/cluster>graphviz.org/content/cluster</a>

Thanks

Peter Neubauer said...

Hi there,
for this, you can implement your own GrapStyle, see https://github.com/neo4j/community/blob/master/graphviz/src/main/java/org/neo4j/visualization/graphviz/GraphStyle.java

When you do it, please let us know, contribution is welcome!

Mark Needham said...

I was trying to visualise a continuous integration pipeline by parsing its Xml representation into a neo4j graph and then spitting out a graphviz representation but I couldn't work out how to get the 'title' of a node to be the 'name' property on the neo node.

Is there anyway to do that? I looked at the source for a bit at the time but couldn't see an easy way to do what I wanted.

Peter Neubauer said...

Mmh, not sure. Probably needs somethings like
public void nodeTitle( String pattern )
{
final PatternParser parser = new PatternParser( pattern );
styles.add( new StyleParameter.NodeTitle()
{
public String getTitle( Node container )
{
return parser.parse( container );
}
} );
}


in ConfigurationParser. A test to change the title property and a pull request is highly appreciated, seems not to be covered.

Federico Gobbo said...

Hi, your link to the well hidden Gem

https://github.com/neo4j/community/tree/master/graphviz

does not work anymore. Do you still use graphviz into Neo4J? Thanks!

Federico Gobbo said...

Hi, the link you provided

https://github.com/neo4j/community/tree/master/graphviz

does not work anymore. Do you still use Graphviz
into Neo4J?

Thanks

Anonymous said...

Repository is moved. Particular graphviz dir can be found here - https://github.com/neo4j/neo4j/tree/master/community/graphviz

David Butler said...

In case anyone was looking for it, here's where they moved it:

https://github.com/neo4j/neo4j/blob/master/community/graphviz/src/test/java/org/neo4j/visualization/graphviz/TestNewGraphvizWriter.java

David Butler said...

In case anyone was looking for it, here's where they moved it:

https://github.com/neo4j/neo4j/blob/master/community/graphviz/src/test/java/org/neo4j/visualization/graphviz/TestNewGraphvizWriter.java

David Butler said...

In case anyone was looking for it, here's where they moved it:

https://github.com/neo4j/neo4j/blob/master/community/graphviz/src/test/java/org/neo4j/visualization/graphviz/TestNewGraphvizWriter.java

David Butler said...

In case anyone was looking for it, here's where they moved it:

https://github.com/neo4j/neo4j/blob/master/community/graphviz/src/test/java/org/neo4j/visualization/graphviz/TestNewGraphvizWriter.java