(i, j, target_j, grid, morphisms_str_info,
                                     object_coords)
return (curving, label_pos)
Produces the information required for constructing the string
        representation of a horizontal morphism.  This function is
        invoked from ``_process_morphism``.

        See Also
        ========

        _process_morphism
Produces the information required for constructing the string
        representation of a horizontal morphism.  This function is
        invoked from ``_process_morphism``.
Produces the information required for constructing the string representation of a horizontal morphism . This function is invoked from _process_morphism .
def _process_horizontal_morphism(i, j, target_j, grid, morphisms_str_info,
                                     object_coords):
        """
        Produces the information required for constructing the string
        representation of a horizontal morphism.  This function is
        invoked from ``_process_morphism``.

        See Also
        ========

        _process_morphism
        """
        # The arrow is horizontal.  Check if it goes from left to
        # right (``backwards == False``) or from right to left
        # (``backwards == True``).
        backwards = False
        start = j
        end = target_j
        if end < start:
            (start, end) = (end, start)
            backwards = True

        # Let's see which objects are there between ``start`` and
        # ``end``, and then count how many morphisms stick out
        # upwards, and how many stick out downwards.
        #
        # For example, consider the situation:
        #
        #    B1 C1
        #    |  |
        # A--B--C--D
        #    |
        #    B2
        #
        # Between the objects `A` and `D` there are two objects:
        # `B` and `C`.  Further, there are two morphisms which
        # stick out upward (the ones between `B1` and `B` and
        # between `C` and `C1`) and one morphism which sticks out
        # downward (the one between `B and `B2`).
        #
        # We need this information to decide how to curve the
        # arrow between `A` and `D`.  First of all, since there
        # are two objects between `A` and `D``, we must curve the
        # arrow.  Then, we will have it curve downward, because
        # there is more space (less morphisms stick out downward
        # than upward).
        up = []
        down = []
        straight_horizontal = []
        for k in xrange(start + 1, end):
            obj = grid[i, k]
            if not obj:
                continue

            for m in morphisms_str_info:
                if m.domain == obj:
                    (end_i, end_j) = object_coords[m.codomain]
                elif m.codomain == obj:
                    (end_i, end_j) = object_coords[m.domain]
                else:
                    continue

                if end_i > i:
                    down.append(m)
                elif end_i < i:
                    up.append(m)
                elif not morphisms_str_info[m].curving:
                    # This is a straight horizontal morphism,
                    # because it has no curving.
                    straight_horizontal.append(m)

        if len(up) < len(down):
            # More morphisms stick out downward than upward, let's
            # curve the morphism up.
            if backwards:
                curving = "_"
                label_pos = "_"
            else:
                curving = "^"
                label_pos = "^"

            # Assure that the straight horizontal morphisms have
            # their labels on the lower side of the arrow.
            for m in straight_horizontal:
                (i1, j1) = object_coords[m.domain]
                (i2, j2) = object_coords[m.codomain]

                m_str_info = morphisms_str_info[m]
                if j1 < j2:
                    m_str_info.label_position = "_"
                else:
                    m_str_info.label_position = "^"

                # Don't allow any further modifications of the
                # position of this label.
                m_str_info.forced_label_position = True
        else:
            # More morphisms stick out downward than upward, let's
            # curve the morphism up.
            if backwards:
                curving = "^"
                label_pos = "^"
            else:
                curving = "_"
                label_pos = "_"

            # Assure that the straight horizontal morphisms have
            # their labels on the upper side of the arrow.
            for m in straight_horizontal:
                (i1, j1) = object_coords[m.domain]
                (i2, j2) = object_coords[m.codomain]

                m_str_info = morphisms_str_info[m]
                if j1 < j2:
                    m_str_info.label_position = "^"
                else:
                    m_str_info.label_position = "_"

                # Don't allow any further modifications of the
                # position of this label.
                m_str_info.forced_label_position = True

        return (curving, label_pos)
def _process_horizontal_morphism ( i , j , target_j , grid , morphisms_str_info , object_coords ) : # The arrow is horizontal.  Check if it goes from left to # right (``backwards == False``) or from right to left # (``backwards == True``). backwards = False start = j end = target_j if end < start : ( start , end ) = ( end , start ) backwards = True # Let's see which objects are there between ``start`` and # ``end``, and then count how many morphisms stick out # upwards, and how many stick out downwards. # # For example, consider the situation: # #    B1 C1 #    |  | # A--B--C--D #    | #    B2 # # Between the objects `A` and `D` there are two objects: # `B` and `C`.  Further, there are two morphisms which # stick out upward (the ones between `B1` and `B` and # between `C` and `C1`) and one morphism which sticks out # downward (the one between `B and `B2`). # # We need this information to decide how to curve the # arrow between `A` and `D`.  First of all, since there # are two objects between `A` and `D``, we must curve the # arrow.  Then, we will have it curve downward, because # there is more space (less morphisms stick out downward # than upward). up = [ ] down = [ ] straight_horizontal = [ ] for k in xrange ( start + 1 , end ) : obj = grid [ i , k ] if not obj : continue for m in morphisms_str_info : if m . domain == obj : ( end_i , end_j ) = object_coords [ m . codomain ] elif m . codomain == obj : ( end_i , end_j ) = object_coords [ m . domain ] else : continue if end_i > i : down . append ( m ) elif end_i < i : up . append ( m ) elif not morphisms_str_info [ m ] . curving : # This is a straight horizontal morphism, # because it has no curving. straight_horizontal . append ( m ) if len ( up ) < len ( down ) : # More morphisms stick out downward than upward, let's # curve the morphism up. if backwards : curving = "_" label_pos = "_" else : curving = "^" label_pos = "^" # Assure that the straight horizontal morphisms have # their labels on the lower side of the arrow. for m in straight_horizontal : ( i1 , j1 ) = object_coords [ m . domain ] ( i2 , j2 ) = object_coords [ m . codomain ] m_str_info = morphisms_str_info [ m ] if j1 < j2 : m_str_info . label_position = "_" else : m_str_info . label_position = "^" # Don't allow any further modifications of the # position of this label. m_str_info . forced_label_position = True else : # More morphisms stick out downward than upward, let's # curve the morphism up. if backwards : curving = "^" label_pos = "^" else : curving = "_" label_pos = "_" # Assure that the straight horizontal morphisms have # their labels on the upper side of the arrow. for m in straight_horizontal : ( i1 , j1 ) = object_coords [ m . domain ] ( i2 , j2 ) = object_coords [ m . codomain ] m_str_info = morphisms_str_info [ m ] if j1 < j2 : m_str_info . label_position = "^" else : m_str_info . label_position = "_" # Don't allow any further modifications of the # position of this label. m_str_info . forced_label_position = True return ( curving , label_pos )