calculateCenter static method

Offset calculateCenter(
  1. List<NmGraphNodeData> nodes
)

Calculate the center of all nodes.

Implementation

static Offset calculateCenter(List<NmGraphNodeData> nodes) {
  if (nodes.isEmpty) return Offset.zero;

  var sumX = 0.0;
  var sumY = 0.0;

  for (final node in nodes) {
    sumX += node.position.dx;
    sumY += node.position.dy;
  }

  return Offset(sumX / nodes.length, sumY / nodes.length);
}