Skip to content

Instantly share code, notes, and snippets.

@peterneubauer
Created May 10, 2012 09:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterneubauer/2652082 to your computer and use it in GitHub Desktop.
Save peterneubauer/2652082 to your computer and use it in GitHub Desktop.
Basic Graphviz
Transaction tx = neo.beginTx();
try
{
final Node emil = neo.createNode();
emil.setProperty( "name", "Emil Eifrém" );
emil.setProperty( "age", 30 );
final Node tobias = neo.createNode();
tobias.setProperty( "name", "Tobias \"thobe\" Ivarsson" );
tobias.setProperty( "age", 23 );
tobias.setProperty( "hours", new int[] { 10, 10, 4, 4, 0 } );
final Node johan = neo.createNode();
johan.setProperty( "!<>)", "!<>)" );
johan.setProperty( "name", "!<>Johan '\\n00b' !<>Svensson" );
final Relationship emilKNOWStobias = emil.createRelationshipTo(
tobias, type.KNOWS );
emilKNOWStobias.setProperty( "since", "2003-08-17" );
final Relationship johanKNOWSemil = johan.createRelationshipTo(
emil, type.KNOWS );
final Relationship tobiasKNOWSjohan = tobias.createRelationshipTo(
johan, type.KNOWS );
final Relationship tobiasWORKS_FORemil = tobias
.createRelationshipTo( emil, type.WORKS_FOR );
OutputStream out = new ByteArrayOutputStream();
GraphvizWriter writer = new GraphvizWriter();
writer.emit( out, Walker.crosscut( emil.traverse( Order.DEPTH_FIRST,
StopEvaluator.END_OF_GRAPH, ReturnableEvaluator.ALL, type.KNOWS,
Direction.BOTH, type.WORKS_FOR, Direction.BOTH ), type.KNOWS, type.WORKS_FOR ) );
tx.success();
System.out.println( out.toString() );
}
finally
{
tx.finish();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment