code: function collectNodeIds(stmt) {
    var ids = {},
        stack = [],
        curr;
  
    var push = stack.push.bind(stack);
  
    push(stmt);
    while(stack.length) {
      curr = stack.pop();
      switch(curr.type) {
        case "node": ids[curr.id] = true; break;
        case "edge": _.each(curr.elems, push); break;
        case "subgraph": _.each(curr.stmts, push); break;
      }
    }
  
    return _.keys(ids);
  }
docs: Collect all nodes involved in a subgraph statement