From: H.N. de R. <hnr...@gr...> - 2012-06-27 07:45:45
|
On Mon, Jun 25, 2012 at 12:36:54PM -0700, rima asmar wrote: > Hey Ernst! > This is the part of code i added to export to .dot format: > > DOTExporter dOTExporter = new DOTExporter(); > > > > File file = new File("flight_DOT"); > Writer fileWriter = null; > try { > fileWriter = new BufferedWriter(new FileWriter (file)); > } > catch (IOException e) { > throw new RuntimeException(e); > } > > > dOTExporter.export(fileWriter, g); > > So what lines of code do I have to add exactly to export vertex and edges > attributes? Something like this (warning, not tested): Reconstructing the maps at every call to getComponentAttributes() is just my laziness. If all vertices, resp. edges, have the same attributes, you'd rather want to construct this map only once. ComponentAttributeProvider<String> vertexAttributeProvider = new ComponentAttributeProvider<String>() { /* For every vertex v, return a single attribute with name "shape" * and value "box". (The vertex is drawn as a rectangle) */ public Map<String, String> getComponentAttributes(String v) { Map<String, String> map = new LinkedHashMap<String, String>(); map.put("shape", "box"); return map; } }; ComponentAttributeProvider<String> edgeAttributeProvider = new ComponentAttributeProvider<DefaultEdge>() { /* For every vertex e, return two attributes, "dir" with value * "forward" and "arrowhead" with value "normal". (Edges are drawn * directed, with an arrowhead.) */ public Map<String, String> getComponentAttributes(DefaultEdge e) { Map<String, String> map = new LinkedHashMap<String, String>(); map.put("dir", "forward"); map.put("arrowhead", "normal"); return map; } }; DOTExporter dOTExporter = new DOTExporter( new IntegerNameProvider<String>(), // vertex ids new StringNameProvider<String>(), // vertex labels new StringEdgeNameProvider<String>(), //edge labels vertexAttributeProvider, // vertex attributes edgeAttributeProvider); // edge attributes File file = new File("flight_DOT"); Writer fileWriter = null; try { fileWriter = new BufferedWriter(new FileWriter (file)); } catch (IOException e) { throw new RuntimeException(e); } dOTExporter.export(fileWriter, g); -- Information System on Graph Classes and their Inclusions (ISGCI) http://www.graphclasses.org |