(diagram, merged_morphisms)
return grid
r"""
        Lays out the diagram in "sequential" layout.  This method
        will attempt to produce a result as close to a line as
        possible.  For linear diagrams, the result will actually be a
        line.
r"""
        Lays out the diagram in "sequential" layout.  This method
        will attempt to produce a result as close to a line as
        possible.  For linear diagrams, the result will actually be a
        line.
r Lays out the diagram in sequential layout . This method will attempt to produce a result as close to a line as possible . For linear diagrams the result will actually be a line .
def _sequential_layout(diagram, merged_morphisms):
        r"""
        Lays out the diagram in "sequential" layout.  This method
        will attempt to produce a result as close to a line as
        possible.  For linear diagrams, the result will actually be a
        line.
        """
        objects = diagram.objects
        sorted_objects = sorted(objects, key=default_sort_key)

        # Set up the adjacency lists of the underlying undirected
        # graph of ``merged_morphisms``.
        adjlists = DiagramGrid._get_undirected_graph(objects, merged_morphisms)

        # Find an object with the minimal degree.  This is going to be
        # the root.
        root = sorted_objects[0]
        mindegree = len(adjlists[root])
        for obj in sorted_objects:
            current_degree = len(adjlists[obj])
            if current_degree < mindegree:
                root = obj
                mindegree = current_degree

        grid = _GrowableGrid(1, 1)
        grid[0, 0] = root

        placed_objects = set([root])

        def place_objects(pt, placed_objects):
            """
            Does depth-first search in the underlying graph of the
            diagram and places the objects en route.
            """
            # We will start placing new objects from here.
            new_pt = (pt[0], pt[1] + 1)

            for adjacent_obj in adjlists[grid[pt]]:
                if adjacent_obj in placed_objects:
                    # This object has already been placed.
                    continue

                DiagramGrid._put_object(new_pt, adjacent_obj, grid, [])
                placed_objects.add(adjacent_obj)
                placed_objects.update(place_objects(new_pt, placed_objects))

                new_pt = (new_pt[0] + 1, new_pt[1])

            return placed_objects

        place_objects((0, 0), placed_objects)

        return grid
def _sequential_layout ( diagram , merged_morphisms ) : objects = diagram . objects sorted_objects = sorted ( objects , key = default_sort_key ) # Set up the adjacency lists of the underlying undirected # graph of ``merged_morphisms``. adjlists = DiagramGrid . _get_undirected_graph ( objects , merged_morphisms ) # Find an object with the minimal degree.  This is going to be # the root. root = sorted_objects [ 0 ] mindegree = len ( adjlists [ root ] ) for obj in sorted_objects : current_degree = len ( adjlists [ obj ] ) if current_degree < mindegree : root = obj mindegree = current_degree grid = _GrowableGrid ( 1 , 1 ) grid [ 0 , 0 ] = root placed_objects = set ( [ root ] ) def place_objects ( pt , placed_objects ) : """
            Does depth-first search in the underlying graph of the
            diagram and places the objects en route.
            """ # We will start placing new objects from here. new_pt = ( pt [ 0 ] , pt [ 1 ] + 1 ) for adjacent_obj in adjlists [ grid [ pt ] ] : if adjacent_obj in placed_objects : # This object has already been placed. continue DiagramGrid . _put_object ( new_pt , adjacent_obj , grid , [ ] ) placed_objects . add ( adjacent_obj ) placed_objects . update ( place_objects ( new_pt , placed_objects ) ) new_pt = ( new_pt [ 0 ] + 1 , new_pt [ 1 ] ) return placed_objects place_objects ( ( 0 , 0 ) , placed_objects ) return grid