[英]Prefuse : Organizing edges for clarity
我正在用Java / Eclipse開發我的個人家譜,很高興碰到圖形表示形式的流行。 到目前為止,對於我的數據庫提要,結果看起來已經足夠了,但是我仍然缺少要點,以便於瀏覽。
要點1:頂點表示一個人或一個工會,而我的圖表是從老年人到年輕人的。 這由邊緣上的箭頭反映。 但是,我只想將箭頭按1個方向分組(如果您願意,我想將幾代人分組在一起),但是我無法開始尋找做到這一點的方法。 有關信息,到目前為止,我正在使用NodeLinkTreeLayout。
要點2:除了圖形本身之外,我的應用程序主窗口還包含第二個JPanel,我想在其中修改/插入成員。 因此,我想向每個節點添加一個操作以調用第二個JPanel中的過程。 到目前為止,我對如何從節點訪問Java類的研究尚無定論,似乎入門入門包中的所有示例都僅基於圖交互。
在那里。 您可能已經了解到,我是新手,不是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);
}
}
因此,經過大量研究,如果有人遇到相同的問題,我將回答自己的問題:
至於第1點:ForceDirectedGraph比NodeLinkTreeLayout好很多,尤其是當圖形開始計數許多成員時。 家庭分支比查看各代人更有意義。
至於第2點:與節點相關的操作是通過ControlListener進行的方式:
addControlListener(new ControlAdapter() { public void itemClicked(VisualItem item, MouseEvent e) { // anything you need here // even filter right and left click for a sub menu } });
還有一件事:如果您向圖表中添加動作(搜索,謂詞...),請確保在需要重新構建圖表時將其停止。 如果不這樣做,您的操作將產生錯誤,您將花費數小時(如果不是幾天的話)進行調試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.