def METHOD_NAME(nodes, mode, spacing):
    r"""
    Aligns the passed nodes horizontally and apply the minimum spacing
    between them.
    """
    modes = ['horizontal', 'vertical']
    if not nodes:
        return
    if mode not in modes:
        raise ValueError('invalid mode, choices are: ' + ', '.join(modes))
    get_0 = lambda x: x.x
    get_1 = lambda x: x.y
    set_0 = lambda x, v: setattr(x, 'x', v)
    set_1 = lambda x, v: setattr(x, 'y', v)
    if mode == 'vertical':
        get_0, get_1 = get_1, get_0
        set_0, set_1 = set_1, set_0
    nodes = [graphnode.GraphNode(n) for n in nodes]
    nodes.sort(key=lambda n: get_0(n.position))
    midpoint = graphnode.find_nodes_mid(nodes)
    # Apply the spacing between the nodes relative to the coordinate-systems
    # origin. We can offset them later because we now the nodes' midpoint
    # already.
    first_position = nodes[0].position
    new_positions = []
    prev_offset = 0
    for node in nodes:
        # Compute the relative position of the node.
        position = node.position
        set_0(position, get_0(position) - get_0(first_position))
        # Obtain it's size and check if the node needs to be re-placed.
        size = node.size
        if get_0(position) < prev_offset:
            set_0(position, prev_offset)
            prev_offset += spacing + get_0(size)
        else:
            prev_offset = get_0(position) + get_0(size) + spacing
        set_1(position, get_1(midpoint))
        new_positions.append(position)
    # Center the nodes again.
    bbox_size = prev_offset - spacing
    bbox_size_2 = bbox_size * 0.5
    for node, position in itertools.izip(nodes, new_positions):
        # TODO: Here is some issue with offsetting the nodes. Some value
        # dependent on the spacing must be added here to not make the nodes
        # move horizontally/vertically although they have already been
        # aligned.
        set_0(position, get_0(midpoint) + get_0(position) - bbox_size_2 + spacing)
        node.position = position