All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jungrapht.samples.util.LayoutFunction Maven / Gradle / Ivy

The newest version!
package org.jungrapht.samples.util;

import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.Function;
import org.jungrapht.visualization.layout.algorithms.BalloonLayoutAlgorithm;
import org.jungrapht.visualization.layout.algorithms.CircleLayoutAlgorithm;
import org.jungrapht.visualization.layout.algorithms.DAGLayoutAlgorithm;
import org.jungrapht.visualization.layout.algorithms.EdgeAwareTreeLayoutAlgorithm;
import org.jungrapht.visualization.layout.algorithms.FRLayoutAlgorithm;
import org.jungrapht.visualization.layout.algorithms.ForceAtlas2LayoutAlgorithm;
import org.jungrapht.visualization.layout.algorithms.GEMLayoutAlgorithm;
import org.jungrapht.visualization.layout.algorithms.ISOMLayoutAlgorithm;
import org.jungrapht.visualization.layout.algorithms.KKLayoutAlgorithm;
import org.jungrapht.visualization.layout.algorithms.LayoutAlgorithm;
import org.jungrapht.visualization.layout.algorithms.MultiRowEdgeAwareTreeLayoutAlgorithm;
import org.jungrapht.visualization.layout.algorithms.MultiRowTreeLayoutAlgorithm;
import org.jungrapht.visualization.layout.algorithms.RadialEdgeAwareTreeLayoutAlgorithm;
import org.jungrapht.visualization.layout.algorithms.RadialTreeLayoutAlgorithm;
import org.jungrapht.visualization.layout.algorithms.SpringLayoutAlgorithm;
import org.jungrapht.visualization.layout.algorithms.TidierRadialTreeLayoutAlgorithm;
import org.jungrapht.visualization.layout.algorithms.TidierTreeLayoutAlgorithm;
import org.jungrapht.visualization.layout.algorithms.TreeLayoutAlgorithm;
import org.jungrapht.visualization.layout.algorithms.repulsion.BarnesHutFA2Repulsion;

public class LayoutFunction
    implements Function, ?>> {

  Map, ?>> map = new LinkedHashMap<>();

  public static class Layout {
    public final String name;
    public final LayoutAlgorithm.Builder, ?> builder;

    public static  Layout of(String name, LayoutAlgorithm.Builder builder) {
      return new Layout(name, builder);
    }

    private Layout(String name, LayoutAlgorithm.Builder, ?> builder) {
      this.name = name;
      this.builder = builder;
    }
  }

  public Collection getNames() {
    return map.keySet();
  }

  public LayoutFunction(Layout... layouts) {
    Arrays.stream(layouts).forEach(e -> map.put(e.name, e.builder));
  }

  @Override
  public LayoutAlgorithm.Builder, ?> apply(String s) {
    return map.get(s);
  }

  public static class FullLayoutFunction extends LayoutFunction {
    public FullLayoutFunction() {
      super(
          Layout.of("Kamada Kawai", KKLayoutAlgorithm.builder()),
          Layout.of("Circle", CircleLayoutAlgorithm.builder().reduceEdgeCrossing(false)),
          Layout.of(
              "Reduced Xing Circle", CircleLayoutAlgorithm.builder().reduceEdgeCrossing(true)),
          Layout.of("Self Organizing Map", ISOMLayoutAlgorithm.builder()),
          Layout.of("Fruchterman Reingold", FRLayoutAlgorithm.builder()),
          Layout.of(
              "ForceAtlas2",
              ForceAtlas2LayoutAlgorithm.builder()
                  .repulsionContractBuilder(BarnesHutFA2Repulsion.builder().repulsionK(50))),
          Layout.of("Spring", SpringLayoutAlgorithm.builder()),
          Layout.of("GEM", GEMLayoutAlgorithm.edgeAwareBuilder()),
          Layout.of("DAG", DAGLayoutAlgorithm.builder()),
          Layout.of("Tree", TreeLayoutAlgorithm.builder()),
          Layout.of("Tidier Tree", TidierTreeLayoutAlgorithm.edgeAwareBuilder()),
          Layout.of("Tidier Radial Tree", TidierRadialTreeLayoutAlgorithm.edgeAwareBuilder()),
          Layout.of("EdgeAware Tree", EdgeAwareTreeLayoutAlgorithm.edgeAwareBuilder()),
          Layout.of("Multirow Tree", MultiRowTreeLayoutAlgorithm.builder()),
          Layout.of(
              "EdgeAwareMultirow Tree",
              MultiRowEdgeAwareTreeLayoutAlgorithm.edgeAwareBuilder()),
          Layout.of("Balloon", BalloonLayoutAlgorithm.builder()),
          Layout.of("Radial", RadialTreeLayoutAlgorithm.builder()),
          Layout.of(
              "EdgeAwareRadial", RadialEdgeAwareTreeLayoutAlgorithm.edgeAwareBuilder()));
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy