layout method

LayoutResult<V> layout(
  1. LayoutInput<V> input
)

Computes vertex positions and optional edge routes for input.

Implementation

LayoutResult<V> layout(LayoutInput<V> input) {
  final list = input.vertices;
  if (list.isEmpty) {
    return LayoutResult.empty<V>();
  }

  if (packDisconnectedComponents && input.packComponents) {
    final comps = components(input);
    if (comps.length > 1) {
      final compResults = <LayoutResult<V>>[];
      for (final comp in comps) {
        final compSet = comp.toSet();
        final compInput = LayoutInput<V>(
          vertices: comp,
          successorsOf: (v) => input.successorsOf(v).where(compSet.contains),
          predecessorsOf: input.isDirected
              ? (v) => input.predecessorsOf!(v).where(compSet.contains)
              : null,
          vertexSize: input.vertexSize,
          edgeWeight: input.edgeWeight,
          vertexStrategy: input.vertexStrategy,
          packComponents: false,
          componentDirection: input.componentDirection,
        );
        compResults.add(layoutComponent(compInput));
      }
      return packComponents(compResults, direction: input.componentDirection);
    }
  }

  return layoutComponent(input);
}