Note that there are some explanatory texts on larger screens.

plurals
  1. POJUNG layout question
    text
    copied!<p>I have some graph, which I want to display using <a href="http://jung.sourceforge.net/" rel="nofollow noreferrer">JUNG2</a> like in the image below.</p> <p><img src="https://i.stack.imgur.com/RkEeZ.jpg" alt="enter image description here"></p> <p>I've played with some layouts of JUNG2, but I'm always getting an image like this:</p> <p><img src="https://i.stack.imgur.com/Gq40X.png" alt="enter image description here"></p> <p>Is it possible to lay out the graph as I wish without writing a new layout?</p> <p>Thanks in advance</p> <p>Dmitri</p> <p>UPD: Here is the code I used for visualizing the graph:</p> <pre><code>private Embedded createSampleGraph() { Embedded imageComponent = null; try { final DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory .newInstance(); final DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); final Document document = docBuilder.newDocument(); final Element svgelem = document.createElement("svg"); document.appendChild(svgelem); final SVGGraphics2D graphic2d = new SVGGraphics2D(document); final Graph&lt;String, String&gt; graph = createGraph(); final VisualizationImageServer&lt;String, String&gt; server = createServer(graph); server.printAll(graphic2d); final Element el = graphic2d.getRoot(); el.setAttributeNS(null, "viewBox", "0 0 350 350"); el.setAttributeNS(null, "style", "width:100%;height:100%;"); final ByteArrayOutputStream bout = new ByteArrayOutputStream(); final Writer out = new OutputStreamWriter(bout, "UTF-8"); graphic2d.stream(el, out); final JungResource source = new JungResource(bout); TPTApplication.getCurrentApplication().addResource(source); imageComponent = new Embedded("", source); imageComponent.setWidth(DEFAULT_WIDTH_PIXELS, UNITS_PIXELS); imageComponent.setHeight(DEFAULT_HEIGHT_PIXELS, UNITS_PIXELS); imageComponent.setMimeType("image/svg+xml"); addComponent(imageComponent); } catch (final UnsupportedEncodingException exception) { LOGGER.error(ErrorCodes.M_001_UNSUPPORTED_ENCONDING, exception); } catch (final SVGGraphics2DIOException exception) { LOGGER.error(ErrorCodes.M_002_SVG_GRAPHICS_2D_IO, exception); } catch (final ParserConfigurationException exception) { LOGGER.error(ErrorCodes.M_003_PARSER_CONFIGURATION, exception); } return imageComponent; } private VisualizationImageServer&lt;String, String&gt; createServer( final Graph&lt;String, String&gt; aGraph) { final Layout&lt;String, String&gt; layout = new FRLayout&lt;String, String&gt;( aGraph); layout.setSize(new Dimension(300, 300)); final VisualizationImageServer&lt;String, String&gt; vv = new VisualizationImageServer&lt;String, String&gt;( layout, new Dimension(350, 350)); vv.getRenderContext().setVertexLabelTransformer( new ToStringLabeller&lt;String&gt;()); return vv; } private Graph&lt;String, String&gt; createGraph() { final Graph&lt;String, String&gt; graph = new DirectedSparseMultigraph&lt;String, String&gt;(); final String vertex1 = "IE"; final String vertex2 = "P1"; final String vertex3 = "P2"; final String vertex4 = "P3"; final String vertex5 = "FE"; graph.addVertex(vertex1); graph.addVertex(vertex2); graph.addVertex(vertex3); graph.addVertex(vertex4); graph.addVertex(vertex5); graph.addEdge("1", vertex1, vertex2, EdgeType.DIRECTED); graph.addEdge("2", vertex2, vertex3, EdgeType.DIRECTED); graph.addEdge("3", vertex3, vertex5, EdgeType.DIRECTED); graph.addEdge("4", vertex1, vertex4, EdgeType.DIRECTED); graph.addEdge("5", vertex4, vertex5, EdgeType.DIRECTED); return graph; } </code></pre> <p>UPD 17.03.2011</p> <p>Now I can draw a graph like this:</p> <p><img src="https://i.stack.imgur.com/nQb3U.png" alt="enter image description here"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload