run method

  1. @override
Size run(
  1. Graph? graph,
  2. double shiftX,
  3. double shiftY
)
override

Executes the algorithm. @param shiftY Shifts the y-coordinate origin @param shiftX Shifts the x-coordinate origin @return The size of the graph

Implementation

@override
Size run(Graph? graph, double shiftX, double shiftY) {
  var size = findBiggestSize(graph!) * graph.nodeCount();
  graphWidth = size;
  graphHeight = size;

  var nodes = graph.nodes;
  var edges = graph.edges;

  tick = 0.1 * sqrt(graphWidth / 2 * graphHeight / 2);

  init(graph);

  for (var i = 0; i < iterations; i++) {
    calculateRepulsion(nodes);
    calculateAttraction(edges);
    limitMaximumDisplacement(nodes);

    cool(i);

    if (done()) {
      break;
    }
  }

  if (focusedNode == null) {
    positionNodes(graph);
  }

  shiftCoordinates(graph, shiftX, shiftY);

  return calculateGraphSize(graph);
}