/**
   * Saves a given graph to a dot file, it also creates the file, or overwrites the old one
   *
   * @param g : The jung graph to save
   * @param filename : A string that points to the destination of the save
   * @param labeler : A node object -> Node name converter object
   * @param graphName : The name of the graph to export (usually this is set the project's name)
   * @throws IOException On IO error
   */
  public void save(Graph<V, E> g, String filename, Transformer<V, String> labeler, String graphName)
      throws IOException {
    SortedSet<V> nodes = new TreeSet<V>();
    Map<V, SortedSet<V>> successors = new HashMap<V, SortedSet<V>>();
    for (V source : g.getVertices()) {
      Collection<V> actSuccessors = g.getSuccessors(source);
      SortedSet<V> successorTree = new TreeSet<V>();
      for (V destination : actSuccessors) {
        successorTree.add(destination);
      }

      nodes.add(source);
      successors.put(source, successorTree);
    }

    BufferedWriter writer =
        new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename), "UTF-8"));
    writer.write("digraph \"" + graphName + "\" {\n");
    for (V from : nodes) {
      Collection<V> actSuccessors = successors.get(from);
      for (V to : actSuccessors) {
        writer.write(
            "\t\"" + labeler.transform(from) + "\" -> \"" + labeler.transform(to) + "\";\n");
      }

      if (g.getPredecessorCount(from) == 0 && actSuccessors.isEmpty()) {
        writer.write("\t\"" + labeler.transform(from) + "\";\n");
      }
    }

    writer.write("}");
    writer.close();
  }
示例#2
0
  @Override
  public void dryRun(NodeRenderingProperty p) {
    this.nodeNumber++;

    // find maximum degree
    int degree = graph.getPredecessorCount(p.node);
    maxDegree = Math.max(maxDegree, degree);

    // find maximum importance
    Double impObj = importances.get(p.node);
    double importance = (null == impObj) ? 0.0 : impObj.doubleValue();
    maxImportance = Math.max(maxImportance, importance);

    // store costly informations to retrieve at each frame.
    p.pluginStore.put(this, new NodeColorData(importance, degree));
  }