updateLayoutParameters method

void updateLayoutParameters({
  1. required double width,
  2. required double height,
  3. required double nodeRadius,
})

Specify the graph layout area and the radius of each node.

The layout algorithm must be aware of the node radius so that it does not produce a layout where some part of a node lies outside the node area boundaries.

Implementation

void updateLayoutParameters({
  required double width,
  required double height,
  required double nodeRadius,
}) {
  stableThreshold = 0.0001 * min(width, height);
  this.nodeRadius = nodeRadius;

  // Scale node positions according to the change in layout dimensions.
  final scaleFactor = Vector2(width, height);
  scaleFactor.divide(layoutDimensions);
  for (final node in nodeLayout.keys) {
    nodeLayout[node]!.multiply(scaleFactor);
  }

  layoutDimensions = Vector2(width, height);
  layoutCentre = layoutDimensions / 2;
}