code: def preview_diagram(
      diagram,
      masked=None,
      diagram_format="",
      groups=None,
      output="png",
      viewer=None,
      euler=True,
      **hints,
  ):
      """
      Combines the functionality of ``xypic_draw_diagram`` and
      ``sympy.printing.preview``.  The arguments ``masked``,
      ``diagram_format``, ``groups``, and ``hints`` are passed to
      ``xypic_draw_diagram``, while ``output``, ``viewer, and ``euler``
      are passed to ``preview``.
  
      Examples
      ========
  
      >>> from sympy.categories import Object, NamedMorphism, Diagram
      >>> from sympy.categories import preview_diagram
      >>> A = Object("A")
      >>> B = Object("B")
      >>> C = Object("C")
      >>> f = NamedMorphism(A, B, "f")
      >>> g = NamedMorphism(B, C, "g")
      >>> d = Diagram([f, g], {g * f: "unique"})
      >>> preview_diagram(d)
  
      See Also
      ========
  
      XypicDiagramDrawer
      """
      from sympy.printing import preview
  
      latex_output = xypic_draw_diagram(
          diagram, masked, diagram_format, groups, **hints
      )
      preview(latex_output, output, viewer, euler, ("xypic",))
  
imports: from sympy.categories import CompositeMorphism, IdentityMorphism, NamedMorphism, Diagram
  from sympy.core import Dict, Symbol, default_sort_key
  from sympy.printing.latex import latex
  from sympy.sets import FiniteSet
  from sympy.utilities.iterables import iterable
  from sympy.utilities.decorator import doctest_depends_on
  from itertools import chain
label_desc: Use image node_id 2 for calling a global function with example usage: preview_diagram(diagram, masked, diagram_format, groups, output, viewer, euler) without return types