code: def get_subgraph_of_nodes(
      graph: "DiGraph",
      sources: Optional[List[Any]] = None,
      downstream: bool = False,
  ) -> "DiGraph":
      from networkx import dfs_postorder_nodes, reverse_view
  
      if not sources:
          return graph
  
      g = reverse_view(graph) if downstream else graph
      nodes = []
      for source in sources:
          nodes.extend(dfs_postorder_nodes(g, source))
      return graph.subgraph(nodes)
  
file_path: dvc/dvc/repo/graph.py
imports: from typing import TYPE_CHECKING, Any, Iterator, List, Optional, Set, TypeVar
  from dvc.fs import localfs
  from dvc.utils.fs import path_isin
label_desc: Use image node_id 4 for calling a global function with example usage: get_subgraph_of_nodes(graph, sources, downstream) and returns: graph, graph