我正在使用graphstream库来构建应用程序。当我使用 view.getCamera((.setPercent(( 缩放图形时,一些节点将被隐藏,直到现在都没有问题。我的问题是,当缩放图形后隐藏由边缘连接的拖曳节点时,其边缘也会被隐藏。我想保持这个边缘的外观,即使它的四肢被隐藏了。我尝试了以下代码来解释我的问题:
public class Zoom {
public static void main(String[] args) {
//create a simple graph
Graph graph = new SingleGraph("Zoom");
graph.setAttribute("ui.stylesheet", "node{size:30px; fill-color:red; text-size:20;}");
Node[] nodes = new Node[2];
for (int i = 0; i < 2; i++) {
nodes[i] = graph.addNode("" + i);
nodes[i].setAttribute("ui.label", "" + i);
}
graph.addEdge("01", "0", "1");
//create the viewer
Viewer viewer = new Viewer(graph, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
viewer.enableAutoLayout();
ViewPanel view_panel = viewer.addDefaultView(false);
//create the main frame
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setLayout(new GridLayout());
frame.setLocation(new Point(200, 200));
frame.setPreferredSize(new Dimension(600, 400));
//the function responsible of zooming
frame.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseWheelMoved(MouseWheelEvent mwe) {
double scaleZoom;
if (Event.ALT_MASK != 0) {
scaleZoom = viewer.getDefaultView().getCamera().getViewPercent();
if (mwe.getWheelRotation() > 0) {
scaleZoom += 0.05;
viewer.getDefaultView().getCamera().setViewPercent(scaleZoom);
} else if (mwe.getWheelRotation() < 0) {
if (scaleZoom > 0.05) {
scaleZoom -= 0.05;
viewer.getDefaultView().getCamera().setViewPercent(scaleZoom);
}
}
}
}
});
view_panel.setPreferredSize(new Dimension(frame.getPreferredSize()));
frame.add(view_panel);
frame.pack();
frame.setVisible(true);
}
}
请帮忙。
不幸的是,当边缘的两个组成部分消失时,边缘也会隐藏。这是节省内存的自然行为,我认为您无法避免这种情况。
此外,对于常规缩放,graphstream 使用页面向上/向下键自然处理它,您不必自己制作。