docs: def do_graph(graph, prog=None, format=None, target=None, type=None, string=None, options=None):  # noqa: E501
      """do_graph(graph, prog=conf.prog.dot, format="svg",
           target="| conf.prog.display", options=None, [string=1]):
      string: if not None, simply return the graph string
      graph: GraphViz graph description
      format: output type (svg, ps, gif, jpg, etc.), passed to dot's "-T" option
      target: filename or redirect. Defaults pipe to Imagemagick's display program  # noqa: E501
      prog: which graphviz program to use
      options: options to be passed to prog"""
  
      if format is None:
          if WINDOWS:
              format = "png"  # use common format to make sure a viewer is installed  # noqa: E501
          else:
              format = "svg"
      if string:
          return graph
      if type is not None:
          format = type
      if prog is None:
          prog = conf.prog.dot
      start_viewer = False
      if target is None:
          if WINDOWS:
              target = get_temp_file(autoext="." + format)
              start_viewer = True
          else:
              with ContextManagerSubprocess("do_graph()", conf.prog.display):
                  target = subprocess.Popen([conf.prog.display],
                                            stdin=subprocess.PIPE).stdin
      if format is not None:
          format = "-T%s" % format
      if isinstance(target, str):
          if target.startswith('|'):
              target = subprocess.Popen(target[1:].lstrip(), shell=True,
                                        stdin=subprocess.PIPE).stdin
          elif target.startswith('>'):
              target = open(target[1:].lstrip(), "wb")
          else:
              target = open(os.path.abspath(target), "wb")
      proc = subprocess.Popen("\"%s\" %s %s" % (prog, options or "", format or ""),  # noqa: E501
                              shell=True, stdin=subprocess.PIPE, stdout=target)
      proc.stdin.write(bytes_encode(graph))
      proc.stdin.close()
      proc.wait()
      try:
          target.close()
      except Exception:
          pass
      if start_viewer:
          # Workaround for file not found error: We wait until tempfile is written.  # noqa: E501
          waiting_start = time.time()
          while not os.path.exists(target.name):
              time.sleep(0.1)
              if time.time() - waiting_start > 3:
                  warning("Temporary file '%s' could not be written. Graphic will not be displayed.", tempfile)  # noqa: E501
                  break
          else:
              if conf.prog.display == conf.prog._default:
                  os.startfile(target.name)
              else:
                  with ContextManagerSubprocess("do_graph()", conf.prog.display):
                      subprocess.Popen([conf.prog.display, target.name])