@Override public void writeGraph(OutputStream os) throws IOException { writeDot(os); }
public VizJSHtmlWriter(Graph graph) { this.writer = new DotWriter(graph, "G", "qualifiedName", DotGraphType.DIGRAPH, "8pt"); }
private void writeDot(OutputStream os) throws IOException { writeGraphTag(os); }
private void writeGraphTag(OutputStream os) throws IOException { String name = this.getDotSafeName(graphName); IOUtils.write(graphType.getName()+" "+name+"{" + DotConstants.NL, os); writeGraphNodes(os); writeGraphEdges(os); IOUtils.write("}", os); }
private void writeGraphEdge(String label, String source, String target, OutputStream os) throws IOException { final String startTag = getDotSafeName(source) + graphType.getEdge() + getDotSafeName(target); final String endTag = DotConstants.END_LINE; IOUtils.write(startTag, os); if(StringUtils.isNotBlank(label)) { writeOptions(os, new String[] {"label", label}, new String[]{"fontsize", fontSize}); } IOUtils.write(endTag, os); }
private void writeGraphNode(String id, String label, OutputStream os) throws IOException { final String tag = DotConstants.INDENT + getDotSafeName(id) + "[label = \""+label+"\", fontsize = \""+fontSize+"\"]" + DotConstants.END_LINE; IOUtils.write(tag, os); }
private void writeOptions(OutputStream os, String[]... options) throws IOException { Map<String, String> map = new HashMap<String, String>(); for(String[] option : options) { String key = option[0]; String value = option[1]; map.put(key, value); } writeOptions(map, os); }
private void writeGraphEdges(OutputStream os) throws IOException { for(Edge edge : graph.getEdges()) { String label = edge.getLabel(); String source = ""+edge.getVertex(Direction.IN).getId().hashCode(); String target = ""+edge.getVertex(Direction.OUT).getId().hashCode(); writeGraphEdge(label, source, target, os); } }
private void writeGraphNodes(OutputStream os) throws IOException { //iterate the nodes. for(Vertex vertex : graph.getVertices()) { String id = ""+vertex.getId().hashCode(); String label = vertex.getProperty(vertexLabelProperty); if(StringUtils.isBlank(label)) { label = vertex.toString(); } writeGraphNode(id, label, os); } }
@Override public void writeGraph(OutputStream os) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); super.writeGraph(baos); try { StringBuilder builder = new StringBuilder(); builder.append(IOUtils.toString(this.getClass().getClassLoader().getResourceAsStream("vizjs/viz.js"))); builder.append("var result = new Viz(dotGraph);"); String script = builder.toString(); ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript"); Compilable compilingEngine = (Compilable) engine; CompiledScript cscript = compilingEngine.compile(script); //Bindings bindings = cscript.getEngine().createBindings(); Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE); for(Map.Entry me : bindings.entrySet()) { System.out.printf("%s: %s\n",me.getKey(),String.valueOf(me.getValue())); } bindings.put("dotGraph", baos.toString()); //cscript.eval(); Object result = cscript.eval(bindings); LOG.info("Result:" +ReflectionToStringBuilder.toString(result)); } catch (Exception e) { throw new IOException("Exception generating graph.", e); } } }
private void writeGraphTag(OutputStream os) throws IOException { String name = this.getDotSafeName(graphName); IOUtils.write(graphType.getName()+" "+name+"{" + DotConstants.NL, os); writeGraphNodes(os); writeGraphEdges(os); IOUtils.write("}", os); }
private void writeGraphEdge(String label, String source, String target, OutputStream os) throws IOException { final String startTag = getDotSafeName(source) + graphType.getEdge() + getDotSafeName(target); final String endTag = DotConstants.END_LINE; IOUtils.write(startTag, os); if(StringUtils.isNotBlank(label)) { writeOptions(os, new String[] {"label", label}, new String[]{"fontsize", fontSize}); } IOUtils.write(endTag, os); }
@Override public void writeGraph(OutputStream os) throws IOException { writeDot(os); }
public VizJSHtmlWriter(Graph graph) { this.writer = new DotWriter(graph, "G", "qualifiedName", DotGraphType.DIGRAPH, "8pt"); }
private void writeDot(OutputStream os) throws IOException { writeGraphTag(os); }
private void writeGraphNode(String id, String label, OutputStream os) throws IOException { final String tag = DotConstants.INDENT + getDotSafeName(id) + "[label = \""+label+"\", fontsize = \""+fontSize+"\"]" + DotConstants.END_LINE; IOUtils.write(tag, os); }
private void writeOptions(OutputStream os, String[]... options) throws IOException { Map<String, String> map = new HashMap<String, String>(); for(String[] option : options) { String key = option[0]; String value = option[1]; map.put(key, value); } writeOptions(map, os); }
private void writeGraphEdges(OutputStream os) throws IOException { for(Edge edge : graph.getEdges()) { String label = edge.getLabel(); String source = ""+edge.getVertex(Direction.IN).getId().hashCode(); String target = ""+edge.getVertex(Direction.OUT).getId().hashCode(); writeGraphEdge(label, source, target, os); } }
private void writeGraphNodes(OutputStream os) throws IOException { //iterate the nodes. for(Vertex vertex : graph.getVertices()) { String id = ""+vertex.getId().hashCode(); String label = vertex.getProperty(vertexLabelProperty); if(StringUtils.isBlank(label)) { label = vertex.toString(); } writeGraphNode(id, label, os); } }
@Override public void writeGraph(OutputStream os) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); super.writeGraph(baos); try { StringBuilder builder = new StringBuilder(); builder.append(IOUtils.toString(this.getClass().getClassLoader().getResourceAsStream("vizjs/viz.js"))); builder.append("var result = new Viz(dotGraph);"); String script = builder.toString(); ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript"); Compilable compilingEngine = (Compilable) engine; CompiledScript cscript = compilingEngine.compile(script); //Bindings bindings = cscript.getEngine().createBindings(); Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE); for(Map.Entry me : bindings.entrySet()) { System.out.printf("%s: %s\n",me.getKey(),String.valueOf(me.getValue())); } bindings.put("dotGraph", baos.toString()); //cscript.eval(); Object result = cscript.eval(bindings); LOG.info("Result:" +ReflectionToStringBuilder.toString(result)); } catch (Exception e) { throw new IOException("Exception generating graph.", e); } } }