Question about JUNG assignment

I have a graph that I want to display using JUNG2 , as in the image below.

enter image description here

I played with some JUNG2 layouts, but I always get the image like this:

enter image description here

Is it possible to lay out a schedule as I wish without writing a new layout?

Thanks in advance

Dmitry

UPD: Here is the code I used to render the chart:

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<String, String> graph = createGraph();
    final VisualizationImageServer<String, String> 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<String, String> createServer(
    final Graph<String, String> aGraph) {
final Layout<String, String> layout = new FRLayout<String, String>(
        aGraph);

layout.setSize(new Dimension(300, 300));
final VisualizationImageServer<String, String> vv =
        new VisualizationImageServer<String, String>(
                layout, new Dimension(350, 350));
vv.getRenderContext().setVertexLabelTransformer(
        new ToStringLabeller<String>());
return vv;
}

private Graph<String, String> createGraph() {
final Graph<String, String> graph =
        new DirectedSparseMultigraph<String, String>();
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;
}

UPD 03/17/2011

Now I can draw a graph like this:

enter image description here

+3
source share
3 answers

If you want to snap places to specific vertices, do the following for each of them after creating it Layoutand before adding it to VisualizationViewer/ VisualizationImageServer:

layout.setLocation (v, location);
layout.lock (v, true);

http://jung.sourceforge.net/doc/api/edu/uci/ics/jung/algorithms/layout/Layout.html

+4

, JUNG.

headstart createVertices() createEdges() JUNG WorldMapGraphDemo.class edu.uci.ics.jung.samples jung-samples-2.0.1.jar JUNG 2.0 Framework.

, , , Map . .

, PluggableRendererDemo.class, (, Renderer). edu.uci.ics.jung.visualization.decorators edu.uci.ics.jung.visualization.renderers , , , , ..)

+1

Okay ... Now I understand what you really want to solve. Dmitry, you can check out another JUNG example, L2RTreeLayoutDemo.class ... it looks so close to what you want to achieve.

Or you can study the SO post below: Can Jung graphs appear in the same place every time?

+1
source

All Articles