'Returns the Xy-pic representation of ``diagram`` laid out in
``grid``.
Consider the following simple triangle diagram.
>>> from sympy.categories import Object, NamedMorphism, Diagram
>>> from sympy.categories import DiagramGrid, XypicDiagramDrawer
>>> A = Object("A")
>>> B = Object("B")
>>> C = Object("C")
>>> f = NamedMorphism(A, B, "f")
>>> g = NamedMorphism(B, C, "g")
>>> diagram = Diagram([f, g], {g * f: "unique"})
To draw this diagram, its objects need to be laid out with a
:class:`DiagramGrid`::
>>> grid = DiagramGrid(diagram)
Finally, the drawing:
>>> drawer = XypicDiagramDrawer()
>>> print(drawer.draw(diagram, grid))
\xymatrix{
A \ar[d]_{g\circ f} \ar[r]^{f} & B \ar[ld]^{g} \\
C &
The argument ``masked`` can be used to skip morphisms in the
presentation of the diagram:
>>> print(drawer.draw(diagram, grid, masked=[g * f]))
\xymatrix{
A \ar[r]^{f} & B \ar[ld]^{g} \\
C &
Finally, the ``diagram_format`` argument can be used to
specify the format string of the diagram.  For example, to
increase the spacing by 1 cm, proceeding as follows:
>>> print(drawer.draw(diagram, grid, diagram_format="@+1cm"))
\xymatrix@+1cm{
A \ar[d]_{g\circ f} \ar[r]^{f} & B \ar[ld]^{g} \\
C &'

def draw(self, diagram, grid, masked=None, diagram_format=''):

    if (not masked):
        morphisms_props = grid.morphisms
    else:
        morphisms_props = {}
        for (m, props) in grid.morphisms.items():
            if (m in masked):
                continue
            morphisms_props[m] = props
    object_coords = {}
    for i in range(grid.height):
        for j in range(grid.width):
            if grid[(i, j)]:
                object_coords[grid[(i, j)]] = (i, j)
    morphisms = sorted(morphisms_props, key=(lambda m: XypicDiagramDrawer._morphism_sort_key(m, object_coords)))
    morphisms_str_info = {}
    for morphism in morphisms:
        string_description = self._process_morphism(diagram, grid, morphism, object_coords, morphisms, morphisms_str_info)
        if self.default_arrow_formatter:
            self.default_arrow_formatter(string_description)
        for prop in morphisms_props[morphism]:
            if (prop.name in self.arrow_formatters):
                formatter = self.arrow_formatters[prop.name]
                formatter(string_description)
        morphisms_str_info[morphism] = string_description
    self._push_labels_out(morphisms_str_info, grid, object_coords)
    return XypicDiagramDrawer._build_xypic_string(diagram, grid, morphisms, morphisms_str_info, diagram_format)
