コード例 #1
0
ファイル: Visualize.java プロジェクト: cehrler/castro
    public VertexShapeSizeAspect(Functionality.Graph graphIn) {
      for (int i = 0; i < graphIn.getNodes().size(); i++) {
        if (graphIn.getNodes().get(i).GetRelevance() > maxRelevance
            && graphIn.getNodes().get(i).GetRelevance() < 1.1)
          maxRelevance = graphIn.getNodes().get(i).GetRelevance();
      }

      this.graph = graphIn;
      setSizeTransformer(
          new Transformer<V, Integer>() {

            public Integer transform(V v) {
              if (scale) {
                // return 20;
                double rel = ((Functionality.Node) v).GetRelevance();
                if (rel > 1.1) rel = 1.1;
                int retScale = (int) ((rel / maxRelevance) * 30) + 20;
                if (retScale > 80) {
                  retScale = 80;
                }
                return retScale;
              } else return 20;
            }
          });
      setAspectRatioTransformer(
          new Transformer<V, Float>() {

            public Float transform(V v) {
              return 1.0f;
            }
          });
    }
コード例 #2
0
ファイル: Visualize.java プロジェクト: cehrler/castro
  private void InitializeClusterGraphLayout() {
    int numClusters = myGraph.GetNumberOfClusters();
    double radius = Math.min(layout_width, layout_height) / 3.5;
    double angleShift = (2 * Math.PI) / numClusters;

    List<Functionality.Node> ln = myGraph.getNodes();

    Node n;
    int clusterID;
    for (int i = 0; i < ln.size(); i++) {
      n = ln.get(i);
      clusterID = n.GetCluster();

      if (clusterID == -1) continue;

      double xnew =
          (layout_width / 2)
              + Math.cos(angleShift * clusterID) * radius
              + (50 - Math.random() * 100);
      double ynew =
          (layout_height / 2)
              + Math.sin(angleShift * clusterID) * radius
              + (50 - Math.random() * 100);

      layout.setLocation(n, xnew, ynew);
    }
  }
コード例 #3
0
ファイル: Visualize.java プロジェクト: cehrler/castro
  public void CenterGraph(int borderSpacing, boolean _repaint) {
    List<Functionality.Node> ln = myGraph.getNodes();

    double xsum = 0;
    double ysum = 0;

    for (int i = 0; i < ln.size(); i++) {
      xsum += layout.getX(ln.get(i));
      ysum += layout.getY(ln.get(i));
    }

    double xmean = xsum / ln.size();
    double ymean = ysum / ln.size();

    double xcoef = (layout_width - borderSpacing * 2) / (double) layout_width;
    double ycoef = (layout_height - borderSpacing * 2) / (double) layout_height;

    for (int i = 0; i < ln.size(); i++) {
      double xnew = layout.getX(ln.get(i)) + (layout_width / 2 - xmean);
      double ynew = layout.getY(ln.get(i)) + (layout_height / 2 - ymean);

      layout.setLocation(ln.get(i), xnew, ynew);
    }

    for (int i = 0; i < ln.size(); i++) {
      double xnew = borderSpacing + layout.getX(ln.get(i)) * xcoef;
      double ynew = borderSpacing + layout.getY(ln.get(i)) * ycoef;

      layout.setLocation(ln.get(i), xnew, ynew);
    }

    if (_repaint == true) vv.repaint();
  }
コード例 #4
0
ファイル: Visualize.java プロジェクト: cehrler/castro
  public void init(Functionality.Graph g, int _layout_width, int _layout_height) {
    myGraph = g;
    layout_width = _layout_width;
    layout_height = _layout_height;
    qt = new UndirectedSparseGraph();

    Iterator<Functionality.Node> nodeIterator = g.getNodes().iterator();
    while (nodeIterator.hasNext()) {
      qt.addVertex(nodeIterator.next());
    }

    Iterator<Functionality.Edge> edgeIterator = g.getEdges().iterator();
    while (edgeIterator.hasNext()) {
      Functionality.Edge currEdge = edgeIterator.next();
      qt.addEdge(currEdge, currEdge.getNode1(), currEdge.getNode2());
    }

    vv = null;
    layout = null;
  }
コード例 #5
0
ファイル: Visualize.java プロジェクト: cehrler/castro
  public JComponent drawGraph() {
    // System.out.println("The graph qt"+qt.toString()); // DEBUG
    // ISOMLayout
    layout = new SpringLayoutWeighted(this.qt);
    layout.setSize(new Dimension(layout_width, layout_height));
    // layout.setSize(new Dimension(layout_width, layout_height));

    vv = new MyVisualizationViewer<Functionality.Node, Functionality.Edge>(layout);
    vv.setBackground(Color.WHITE);
    vv.setPreferredSize(new Dimension(layout_width, layout_height));
    vv.setIgnoreRepaint(true);

    // Show vertex and edge labels
    vv.getRenderContext().setVertexLabelTransformer(new DefaultToStringLabeller());
    // BasicVertexLabelRenderer<Functionality.Node, Functionality.Edge> bvlr =  new
    // (BasicVertexLabelRenderer<Functionality.Node,
    // Functionality.Edge>)(vv.getRenderContext().getVertexLabelRenderer());

    BasicRenderer<Functionality.Node, Functionality.Edge> br = new BasicRenderer<Node, Edge>();
    // br.setVertexLabelRenderer(new BasicVertexLabelRenderer<Functionality.Node,
    // Functionality.Edge>(Position.CNTR));

    vv.setRenderer(br);

    // MyVertexLabelRenderer dvlr = new MyVertexLabelRenderer(Color.red);

    // vv.getRenderContext().setVertexLabelRenderer(dvlr);

    // bvlr.setPosition(Position.CNTR);

    // vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());
    vv.setDoubleBuffered(true);

    // layout = new SpringLayout2<Functionality.Node, Functionality.Edge>(this.qt);
    layout.initialize();

    if (myGraph.GetNumberOfClusters() > 1) {
      InitializeClusterGraphLayout();
    }

    layout.step();
    layout.step();
    layout.step();
    layout.step();
    layout.step();
    layout.step();
    layout.step();
    layout.step();
    layout.step();
    layout.step();
    layout.step();
    layout.step();
    layout.lock(true);
    CenterGraph(10, false);

    // Create a graph mouse and add it to the visualization component
    // DefaultModalGraphMouse gm = new DefaultModalGraphMouse();
    DefaultModalGraphMouse gm = new DefaultModalGraphMouse();
    gm.setMode(ModalGraphMouse.Mode.PICKING);
    vv.addMouseListener(this);
    VertexMouseMenu vMouseMenu = new VertexMouseMenu();
    JPopupMenu vertexMenu = new MyVertexMenu();
    vMouseMenu.setVertexPopup(vertexMenu);
    gm.add(vMouseMenu);

    vv.setGraphMouse(gm);

    setEdgeWeightStrokeFunction();
    vv.getRenderContext()
        .setVertexShapeTransformer(
            new VertexShapeSizeAspect<Functionality.Node, Functionality.Edge>(myGraph));
    vv.getRenderContext().setVertexFillPaintTransformer(VertexColorTransformer.vctInstance);

    MyGraphZoomScrollPane graphPane = new MyGraphZoomScrollPane(vv);

    return graphPane;
  }