getNodeDepth static method

int getNodeDepth(
  1. ElectricalNode? root,
  2. String nodeId
)

Get depth of a node in tree (root = 0)

Implementation

static int getNodeDepth(ElectricalNode? root, String nodeId) {
  if (root == null) return -1;
  if (root.id == nodeId) return 0;

  return root.map(
    source: (node) => _getDepthInChildren(node.children, nodeId, 1),
    protection: (node) => _getDepthInChildren(node.children, nodeId, 1),
    panel: (node) => _getDepthInChildren(node.children, nodeId, 1),
    load: (_) => -1,
  );
}