树可视化库 - 计算给定树数据的所有节点和线坐标的库
(视觉)C++ 世界。我有一个树结构,想要将其可视化。更具体地说:
我有一个树数据。我想要处理这些数据并计算每个节点以及连接它们的每条线的坐标(在任何逻辑坐标空间中,例如 2000x2000 逻辑像素)的库。连接两个节点的线可能不是简单的直线,它可能是曲线或由直线段组成的某种路径。理想情况下,我希望也为给定的树节点坐标计算定义路径的线,以防用户拖动并重新排列节点。
很快,我需要一个库来为我计算给定图形的所有必要的几何坐标。然后我将使用这些坐标通过 GDI 根据需要绘制图形。
我听说过 Graphviz、点语言等等。但我不确定它(或其替代品,如 OGDF 或 igraph)是否可以实现我想要的功能。我想要实现的想法是自己渲染图形,但需要生成坐标的帮助。此外,用户必须能够重新定位节点,因此必须可以重新计算连接重新排列的节点的线路径,以便例如线不会穿过任何现有节点。
(Visual) C++ world. I have a tree structure, want to visualize it. More specifically:
I have a tree data. I want the library that processes this data and computes coordinates (in any logical coordinate space, say 2000x2000 logical pixels) for each nodes, AND for each lines connecting them. Line connecting the two nodes might not be a simple straight line, it might be curve or some sort of path consisting of straight line segments. Ideally I'd like the line defining path to be calculated for the given tree nodes' coordinates as well, in case the user will drag and rearrange the nodes.
Shortly, I need the library that will compute all the necessary geometrical coordinates for me, for the given graph. Then I'll use these coordinates to draw the graph as I wish, using GDI.
I've heard of Graphviz, dot-language, and such. But I'm not sure whether it (or its alternatives like OGDF or igraph) can do what I want. The idea I want to accomplish is to render the graph myself, but need the assistance in generating coordinates. Also user must be able to reposition the nodes, so the re-computation of line path that connects rearranged nodes must be possible, so that e.g. lines do not cross any existing nodes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,graphviz 可以做到这一点。
布局有向图
假设您在
tree.gv
中有以下图:dot
可以布局此图:dot tree.gv
其结果in所有坐标都可以在输出中找到。如果您需要有关如何绘制图表的更多详细信息,您可以尝试使用
xdot
格式:dot -Txdot tree.gv
有关此格式的详细信息可以在 graphviz 网站上找到。
仅布局边/重新计算边
您可以使用上述输出之一,修改任何节点的位置,并且使用它作为以下命令的输入:
这将仅重新计算边缘(有关neato dot和neato选项的更多信息可以在其手册页)。
下面您可以看到未修改和修改的布局的示例 - 我更改了 b 和 g 节点的位置。
自动布局:
修改后的布局:
Yes, graphviz can do this.
Layout a directed graph
Let's say you have the following graph in
tree.gv
:dot
can lay out this graph:dot tree.gv
which results inAll the coordinates can be found in the output. If you need even more details on how to draw the graph, you may try using the
xdot
format:dot -Txdot tree.gv
Detailed information about this format can be found on the graphviz web site.
Layout only edges / recompute edges
You may use one of the above outputs, modify positions of any nodes, and use it as input for the following command:
This will recompute only the edges (more information on neato dot and neato options can be found on their manual pages).
Below you can see an example of an unmodified and a modified layout - I changed positions for the b and g nodes.
Automatic layout:
Modified layout: