Exemplo n.º 1
0
  /**
   * Converts the prefuse graph data into the jung graph data.
   *
   * @param vg the prefuse visual graph
   * @return graph the jung graph data
   */
  public static edu.uci.ics.jung.graph.Graph<String, String> convertJungGraph(VisualGraph vg) {

    edu.uci.ics.jung.graph.Graph<String, String> graph =
        new UndirectedSparseGraph<String, String>();

    if (vg != null) {
      Iterator<?> nodeIter = vg.nodes();
      while (nodeIter.hasNext()) {
        VisualItem node = (VisualItem) nodeIter.next();
        String nodeId = node.getString("id");
        // System.out.println("node id == " + nodeId);
        graph.addVertex(nodeId);
      }

      Iterator<?> edgeIter = vg.edges();
      while (edgeIter.hasNext()) {
        VisualItem edge = (VisualItem) edgeIter.next();
        String node1 = edge.getString("node1");
        String node2 = edge.getString("node2");
        String edgeId = node1 + node2;
        // System.out.println("edge id == " + edgeId);
        graph.addEdge(edgeId, node1, node2, EdgeType.UNDIRECTED);
      }
    }
    return graph;
  }
Exemplo n.º 2
0
 /**
  * Finds a node by node id.
  *
  * @param vg
  * @param nodeId
  * @return VisualItem the node
  */
 public static VisualItem findNode(VisualGraph vg, String nodeId) {
   if (vg != null) {
     Iterator<?> nodeIter = vg.nodes();
     while (nodeIter.hasNext()) {
       VisualItem node = (VisualItem) nodeIter.next();
       if (node.getString("id").equals(nodeId)) {
         return node;
       }
     }
   }
   return null;
 }
Exemplo n.º 3
0
  private void initDataGroups() {
    // create sample graph
    // 9 nodes broken up into 3 interconnected cliques
    Graph g = new Graph();
    for (int i = 0; i < 3; ++i) {
      Node n1 = g.addNode();
      Node n2 = g.addNode();
      Node n3 = g.addNode();
      g.addEdge(n1, n2);
      g.addEdge(n1, n3);
      g.addEdge(n2, n3);
    }
    g.addEdge(0, 3);
    g.addEdge(3, 6);
    g.addEdge(6, 0);

    // add visual data groups
    VisualGraph vg = m_vis.addGraph(GRAPH, g);
    m_vis.setInteractive(EDGES, null, false);
    m_vis.setValue(NODES, null, VisualItem.SHAPE, new Integer(Constants.SHAPE_ELLIPSE));

    at = m_vis.addAggregates(AGGR);
    at.addColumn(VisualItem.POLYGON, float[].class);
    at.addColumn("id", int.class);

    // add nodes to aggregates
    // create an aggregate for each 3-clique of nodes
    Iterator nodes = vg.nodes();
    for (int i = 0; i < 3; ++i) {
      AggregateItem aitem = (AggregateItem) at.addItem();
      aitem.setInt("id", i);
      for (int j = 0; j < 3; ++j) {
        aitem.addItem((VisualItem) nodes.next());
      }
    }
  }