2017-07-12 258 views
0

我正在從GraphStream顯示數據庫中的數據。 但它創建節點和邊緣非常緩慢。我正在使用this非常基本的例子。GraphStream渲染節點和邊緣緩慢

這裏是我的代碼:

public class GraphExplore { 
    static Connection conn2; 
    static String result, result2; 
    static JFrame frame; 
    static JPanel panel; 
    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 { 

     frame = new JFrame("GRAPH TESTING"); 

     Graph graph = new SingleGraph("tutorial 1"); 
     graph.setAutoCreate(true); 
     graph.setStrict(false); 
     graph.display(); 

     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 20"); 
     while (rs2.next()) { 
      result = rs2.getString("ANUMBER"); 
      result2 = rs2.getString("BNUMBER"); 
      graph.addNode(result); 
      graph.addNode(result2); 
      for (i = 0; i < totalRows; i++) 
       graph.addEdge("string" + i, result, result2); 
     } 

     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;z-index: 0;}"); 
     graph.addAttribute("ui.stylesheet", "edge { shape:line ; fill-color: #222;}"); 
     conn2.close(); 
    } 

} 

現在,我只是用20行,它需要3-4秒。但我需要一次顯示更多的記錄(可能超過100萬)。任何人都可以告訴我如何提高渲染速度?

回答

0

這裏只是一個瘋狂的猜測。你是否已經嘗試了計時的具體時間JDBC是用來返回查詢結果?我會從這裏開始。如果你發現查詢很快就會回來,這不是數據庫的問題。如果是這樣,您可以考慮使用索引來更快地返回結果。

如果查詢不是問題,您可以查看圖表功能。我的猜測會讓我相信渲染速度很慢,因爲圖形設置爲顯示,然後將節點和邊緣添加到它,因此它會實時呈現。在開始渲染圖形之前,可以預先加載節點和邊緣,從而減少繪製調用的次數。