我有一些图表,我想使用JUNG2显示,如下图所示。

我尝试过JUNG2的一些布局,但我总是得到这样的图像:

是否可以在不编写新布局的情况下像我希望的那样布局图形?
提前感谢
Dmitri
更新:这是我用来可视化图形的代码:
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;
}更新17.03.2011
现在我可以画一张这样的图:

发布于 2011-03-14 10:43:25
这与您如何在JUNG中创建顶点和边有关。
首先,我建议您参考JUNG 2.0框架库中jung-samples-2.0.1.jar下的JUNG example WorldMapGraphDemo.class in edu.uci.ics.jung.samples包中的createVertices()和createEdges()方法。
与使用Map对象存储用户定义的顶点和边信息的其他提供的示例相比,这些方法中使用的方法更加清晰。其余部分使用随机生成、库生成或文件生成的信息。
一旦你清楚了这一点,你就可以参考PluggableRendererDemo.class来改进你的图形(就像装饰edu.uci.ics.jung.visualization.decorators和edu.uci.ics.jung.visualization.renderers包下的转换器和渲染器类,用于装饰和渲染顶点、边、方向箭头、形状、大小等)。
发布于 2011-03-14 22:01:19
Ok...Now我知道你真正想解决的是什么Dmitri,你可以查看另一个JUNG示例,L2RTreeLayoutDemo.class...it看起来非常接近你想要实现的目标。
或者,你可以在下面的帖子中学习:Can Jung graphics appear in the same place every time?
https://stackoverflow.com/questions/5287002
复制相似问题