void initYifanHu() {
   layout = yifanHu.buildLayout();
   layout.setGraphModel(graphModel);
   layout.resetPropertiesValues();
   layout.setAdaptiveCooling(false);
   layout.setStepRatio(stepRatio);
   layout.setOptimalDistance(optimalDistance);
   layout.setBarnesHutTheta(barnesHutTheta);
   layout.setQuadTreeMaxLevel(quadTreeMaxLevel);
   layout.initAlgo();
 }
  public void goAlgo() {
    HierarchicalGraph newGraph = graphModel.getHierarchicalGraphVisible();
    if (newGraph.getView().getViewId() != initedView) {
      setConverged(true);
      layout.endAlgo();
      endAlgo();
      return;
    }
    this.graph = newGraph;
    if (layout.canAlgo()) {
      layout.goAlgo();
    } else {
      layout.endAlgo();
      if (level > 0) {
        coarseningStrategy.refine(graph);
        level--;

        initYifanHu();
      } else {
        setConverged(true);
        layout = null;
      }
    }
  }
Esempio n. 3
0
  private void doPoetGraph(String path, String poet) {
    System.out.println(poet);
    ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
    pc.newProject();
    Workspace workspace = pc.getCurrentWorkspace();
    GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getModel();
    UndirectedGraph directedGraph = graphModel.getUndirectedGraph();

    ExportController ec = Lookup.getDefault().lookup(ExportController.class);

    ArrayList<String> queue = new ArrayList<String>();
    ArrayList<Integer> depthqueue = new ArrayList<Integer>();
    queue.add(poet);
    depthqueue.add(0);
    int depth = 0;
    int nodecount = 0;

    while (queue.size() != 0 && depth < 3 && nodecount < 20) {
      String name = queue.remove(0);
      depth = depthqueue.remove(0);

      Node n = directedGraph.getNode(name);
      if (n == null) {
        n = graphModel.factory().newNode(name);
        n.getNodeData().setLabel(name);
        directedGraph.addNode(n);
        nodecount++;
      }

      Iterator<String> it = edges.get(poet).keySet().iterator();
      while (it.hasNext()) {
        String to = it.next();
        Node slave = directedGraph.getNode(to);
        if (slave == null) {
          slave = graphModel.factory().newNode(to);
          slave.getNodeData().setLabel(to);
          directedGraph.addNode(slave);
        }
        Edge e = graphModel.factory().newEdge(n, slave, edges.get(poet).get(to) * 15, false);
        directedGraph.addEdge(e);
        queue.add(to);
        depthqueue.add(depth + 1);
      }
    }

    // Preview
    PreviewModel previewModel = Lookup.getDefault().lookup(PreviewController.class).getModel();
    previewModel.getProperties().putValue(PreviewProperty.SHOW_NODE_LABELS, Boolean.TRUE);
    previewModel.getProperties().putValue(PreviewProperty.EDGE_COLOR, new EdgeColor(Color.BLUE));
    previewModel.getProperties().putValue(PreviewProperty.EDGE_THICKNESS, new Float(0.005f));
    previewModel
        .getProperties()
        .putValue(PreviewProperty.NODE_LABEL_COLOR, new DependantOriginalColor(Color.RED));
    previewModel
        .getProperties()
        .putValue(
            PreviewProperty.NODE_LABEL_FONT,
            previewModel
                .getProperties()
                .getFontValue(PreviewProperty.NODE_LABEL_FONT)
                .deriveFont(12));

    YifanHuLayout layout = new YifanHuLayout(null, new StepDisplacement(1f));
    layout.setGraphModel(graphModel);
    layout.resetPropertiesValues();
    layout.setOptimalDistance(120f);

    layout.initAlgo();
    for (int i = 0; i < 100 && layout.canAlgo(); i++) {
      layout.goAlgo();
    }

    try {
      ec.exportFile(new File(path + poet + ".svg"));
    } catch (IOException ex) {
      ex.printStackTrace();
      return;
    }
  }