statementsToData function

Map<String, List<String>> statementsToData(
  1. List<Statement> statements,
  2. bool inlineSubgraphs
)

Implementation

Map<String, List<String>> statementsToData(List<Statement> statements, bool inlineSubgraphs) {
  final result = <String, List<String>>{};

  for (final statement in statements) {
    if (statement is NodeStatement) {
      result[statement.id.toString()] ??= [];
    } else if (statement is EdgeStatement) {
      final starts = getAllNodes(statement.origin);
      final ends = getAllNodes(statement).skip(starts.length);

      for (final start in starts) {
        result[start.toString()] ??= [];
        result[start.toString()]!.addAll(ends.map((id) => id.toString()));
      }
    } else if (statement is Subgraph && inlineSubgraphs) {
      result.addAll(statementsToData(statement.stmtList.statements, inlineSubgraphs));
    }
  }

  return result;
}