我正在研究我在 Java/Eclipse 中的个人家谱,并且很高兴地遇到了图形表示方面的问题。到目前为止,就我的数据库提要而言,结果看起来已经足够了,但我仍然缺少关键点以使其更易于浏览。
第 1 点:顶点代表一个人或一个工会,我的图表是从年长成员到年轻成员的。这由边缘上的箭头反映出来。然而,我只想将箭头组合在一个方向上(如果你愿意,我会尝试将几代人组合在一起),但我无法开始找到如何做到这一点。有关信息,我现在正在使用 NodeLinkTreeLayout。
第 2 点:除了图形本身,我的应用程序主窗口还包含第二个 JPanel,我想在其中修改/插入成员。所以我想为每个节点添加一个动作来调用第二个 JPanel 中的过程。到目前为止,我对如何从节点访问 java 类的研究尚无定论,似乎所有来自 starter prefuse 包的示例都仅基于图形交互。
它在那里。您可能已经明白我对 prefuse 非常陌生,而不是 Java 专业人士。因此,任何评论/指示/建议将不胜感激。我将添加一个 screecap 和我的图形代码,以便您了解可以做得更好的地方。
感谢您抽出宝贵时间,并期待阅读您的见解。约兰
public class ShowGraph extends Display {
public static final String EDGES = "graph.edges";
public ShowGraph() {
super(new Visualization());
Graph mG = FamGraph.getGraph();
m_vis.addGraph("graph", mG);
m_vis.setInteractive("graphe.edges", null, false);
m_vis.setValue("graph.nodes", null, VisualItem.SHAPE, new Integer(Constants.SHAPE_ELLIPSE));
EdgeRenderer edgeR = new EdgeRenderer(Constants.EDGE_TYPE_CURVE, Constants.EDGE_ARROW_FORWARD);
LabelRenderer nodeR = new LabelRenderer("name");
nodeR.setRoundedCorner(8, 8);
nodeR.setHorizontalAlignment(Constants.LEFT);
DefaultRendererFactory drf = new DefaultRendererFactory();
drf.setDefaultRenderer(nodeR);
drf.setDefaultEdgeRenderer(edgeR);
m_vis.setRendererFactory(drf);
int[] palette = new int[] {
ColorLib.rgb(255, 180, 180), ColorLib.rgb(190, 190, 255)
};
DataColorAction nFill = new DataColorAction("graph.nodes", "label", Constants.NOMINAL, VisualItem.FILLCOLOR, palette);
ColorAction edges = new ColorAction("graph.edges", VisualItem.STROKECOLOR, ColorLib.gray(230));
ColorAction arrow = new ColorAction("graph.edges", VisualItem.FILLCOLOR, ColorLib.gray(230));
ColorAction text = new ColorAction("graph.nodes", VisualItem.TEXTCOLOR, ColorLib.gray(0));
ActionList color = new ActionList();
color.add(nFill);
color.add(edges);
color.add(arrow);
color.add(text);
ActionList layout = new ActionList(Activity.INFINITY);
//layout.add(new ForceDirectedLayout("graph", true));
layout.add(new NodeLinkTreeLayout("graph"));
layout.add(new RepaintAction());
m_vis.putAction("color", color);
m_vis.putAction("layout", layout);
setSize(1200, 900); //size controlled by parent jpanel - Comment out after tests
pan(360, 250);
setHighQuality(true);
addControlListener(new DragControl());
addControlListener(new PanControl());
addControlListener(new ZoomControl());
addControlListener(new ZoomToFitControl());
m_vis.run("color");
m_vis.run("layout");
}
public static void main(String[] args) {
Fulltree.fireUp();
ShowGraph mG = new ShowGraph();
JFrame frame = new JFrame("My family chart");
JPanel thePanel = new JPanel();
frame.getContentPane().add(thePanel);
thePanel.add(mG);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}