code: def to_graphviz(
      dsk,
      data_attributes=None,
      function_attributes=None,
      rankdir="BT",
      graph_attr=None,
      node_attr=None,
      edge_attr=None,
      collapse_outputs=False,
      verbose=False,
      **kwargs,
  ):
      graphviz = import_required(
          "graphviz",
          "Drawing dask graphs with the graphviz engine requires the `graphviz` "
          "python library and the `graphviz` system library.\n\n"
          "Please either conda or pip install as follows:\n\n"
          "  conda install python-graphviz     # either conda install\n"
          "  python -m pip install graphviz    # or pip install and follow installation instructions",
      )
  
      data_attributes = data_attributes or {}
      function_attributes = function_attributes or {}
      graph_attr = graph_attr or {}
      node_attr = node_attr or {}
      edge_attr = edge_attr or {}
  
      graph_attr["rankdir"] = rankdir
      node_attr["fontname"] = "helvetica"
  
      graph_attr.update(kwargs)
      g = graphviz.Digraph(
          graph_attr=graph_attr,
          node_attr=node_attr,
          edge_attr=edge_attr,
      )
  
      seen = set()
      connected = set()
  
      for k, v in dsk.items():
          k_name = name(k)
          if istask(v):
              func_name = (
                  name((k, "function"))
                  if not collapse_outputs
                  else k_name
              )
              if collapse_outputs or func_name not in seen:
                  seen.add(func_name)
                  attrs = function_attributes.get(k, {}).copy()
                  attrs.setdefault("label", key_split(k))
                  attrs.setdefault("shape", "circle")
                  g.node(func_name, **attrs)
              if not collapse_outputs:
                  g.edge(func_name, k_name)
                  connected.add(func_name)
                  connected.add(k_name)
  
              for dep in get_dependencies(dsk, k):
                  dep_name = name(dep)
                  if dep_name not in seen:
                      seen.add(dep_name)
                      attrs = data_attributes.get(dep, {}).copy()
                      attrs.setdefault("label", box_label(dep, verbose))
                      attrs.setdefault("shape", "box")
                      g.node(dep_name, **attrs)
                  g.edge(dep_name, func_name)
                  connected.add(dep_name)
                  connected.add(func_name)
  
          elif ishashable(v) and v in dsk:
              v_name = name(v)
              g.edge(v_name, k_name)
              connected.add(v_name)
              connected.add(k_name)
  
          if (
              not collapse_outputs or k_name in connected
          ) and k_name not in seen:
              seen.add(k_name)
              attrs = data_attributes.get(k, {}).copy()
              attrs.setdefault("label", box_label(k, verbose))
              attrs.setdefault("shape", "box")
              g.node(k_name, **attrs)
      return g
  
file_path: dask/dask/dot.py
imports: from __future__ import annotations
  import os
  import re
  from functools import partial
  from dask.core import get_dependencies, ishashable, istask
  from dask.utils import apply, funcname, import_required, key_split
label_desc: Use image node_id 6 for calling a global function with example usage: to_graphviz(dsk, data_attributes, function_attributes, rankdir, graph_attr, node_attr, edge_attr, collapse_outputs, verbose) and returns: g