GraphStream中更好的图形可视化 - JAVA [英] Better graph visualization in GraphStream - JAVA

查看:401
本文介绍了GraphStream中更好的图形可视化 - JAVA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为java编写,获得对 Camera ,并用它设置缩放比例和中心。

  viewPanel.getCamera ().setViewPercent(0.25); 
viewPanel.getCamera()。setViewCenter(0,0,0);

一旦选择了任何节点或 viewPanel 获得重点

  viewPanel.requestFocusInWindow(); 




  • 使用

  • 使用

    I am working on GraphStream Library for java. But I am facing a problem here. I tried to query 10,000 records having 2 columns from database. And the graph create 2 nodes and one edge for each row. But when I try to run the program, the graph looks very complicated. See the below image.

    Here is my code:

    public class GraphExplore {
        static Connection conn2;
        static String result, result2;
        static int totalRows, i;
    
        public static void main(String args[]) throws SQLException {
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    try {
                        showData();
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                }
            });
        }
    
        private static void showData() throws SQLException {
    
            JFrame frame = new JFrame("GRAPH");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            @SuppressWarnings("serial")
            JPanel panel = new JPanel(new GridLayout()) {
                @Override
                public Dimension getPreferredSize() {
                    return new Dimension(640, 480);
                }
            };
            panel.setBorder(BorderFactory.createLineBorder(Color.blue, 5));
    
            Graph graph = new SingleGraph("Tutorial", false, true);
    
            try {
                Class.forName("org.h2.Driver");
                conn2 = DriverManager.getConnection("jdbc:h2:file:G:/hs_data/h2_db/test", "sa", "sa");
    
            } catch (Exception e) {
                e.printStackTrace();
            }
            Statement stmt2 = conn2.createStatement();
            ResultSet rs = stmt2.executeQuery("SELECT count(*) FROM cdr");
            while (rs.next()) {
                totalRows = rs.getInt(1);
            }
            ResultSet rs2 = stmt2.executeQuery("SELECT ANUMBER,BNUMBER FROM CDR LIMIT 1000");
            while (rs2.next()) {
                result = rs2.getString("ANUMBER");
                result2 = rs2.getString("BNUMBER");
                graph.addNode(result);
                graph.addNode(result2);
                for (i = 0; i < 1000; i++)
                    graph.addEdge("string" + i, result, result2);
            }
    
            graph.setAutoCreate(true);
            graph.setStrict(false);
            Viewer viewer = new Viewer(graph, Viewer.ThreadingModel.GRAPH_IN_GUI_THREAD);
            ViewPanel viewPanel = viewer.addDefaultView(false);
            viewer.enableAutoLayout();
            panel.add(viewPanel);
            frame.add(panel);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
    
            for (Node node : graph) {
                node.addAttribute("ui.label", node.getId());
            }
    
            // graph.addAttribute("ui.stylesheet", "graph { fill-color: red; }");text-mode:
            // hidden;
            graph.addAttribute("ui.stylesheet", "node {size:12px;fill-color:#ff0000;}");
            graph.addAttribute("ui.stylesheet", "edge { shape:angle ;fill-color:#222;}");
    
        }
    
    }
    

    Can anyone tell me, how to give better visualization to this graph. OR I have to use some other graphs available. I am using the very basic example of GraphStream.

    解决方案

    From the ViewPanel, get a reference to the Camera and use it to set the zoom percentage and center.

    viewPanel.getCamera().setViewPercent(0.25);
    viewPanel.getCamera().setViewCenter(0, 0, 0);
    

    Once any node is selected or the viewPanel gains focus,

    viewPanel.requestFocusInWindow();
    

    • Use the , , or keys to pan.

    • Use the page up and page down keys to zoom.

    这篇关于GraphStream中更好的图形可视化 - JAVA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆