Apples are falling down Introduction

There is an Apple tree trunk positioned between -2 to 2 on the x-axis, where some apples fall down around it:

        |   |
        |   |
&lt;-------|---|-------&gt;
       -2   2


Everyday, n apples fall down. Each apple maintains its x coordinate as falls straight to the ground.

But if it lands on top of another apple, it will roll according to the following rules until it reaches the ground or a supporting layer of apples:


If the space at x+1 at its current height is empty the current apple goes there.
Else if the space at x-1 is empty the current apple goes there.
Otherwise the current apple stays where it is on top of that other apple.


Challenge

The input will be the n starting positions of each apple in order. You can take it as an array or as separated numbers or in any other valid way, just make sure you explain it in your answer.

The output should be an ASCII drawing of the tree trunk and the apples around. You are not required to draw the x-axis to the left of the leftmost apple and to the right of the rightmost apple, but you do need to draw it anywhere it is beneath some apple. You can also extend the tree above the highest apple.

You can assume all x-coordinates are between -100 and 100, but not between -2 and 2.

This is code-golf .. The shortest answer in bytes wins!

Examples

Input: [-3, 5, 5, -4, -4, 5, -3]

Output:

  a|   |
aaa|   | aaa
---|---|----




Input: [3, 3, 3, 3, 8, 9]

Output:

|   |a
|   |aaa  aa
|---|-------




Input: [-5, -5, -5, -5, -5, -5, -5, -5, -5]

Output:

  a  |   |
 aaa |   |
aaaaa|   |
-----|---|
PHP, 230 bytes



I've added the first two newlines for readibility.

function($l){for($y=count($l);$y&gt;=0;$f[]="$a|   |$a")$a=str_repeat($y--?$w=' ':'-',99);
foreach($l as$x){for($x+=101,$s=$y=0;!$s;$b[$x]!=$w?$b[$x+1]!=$w?$b[$x-1]!=$w?$s=1:--$x
:++$x:0)$b=$f[$y++];$f[$y-2][$x]=a;}echo join('
',$f);};


Ideone

Here is the ungolfed version:

function drawApples(array $listStartX)
{
    $field = [];
    $maximalHeight = count($listStartX);
    for ($y = $maximalHeight; $y &gt;= 0; --$y)
    {
        $line = str_repeat($y &gt; 0 ? ' ' : '-', 98);
        $field[] = $line .'|   |'. $line;
    }

    foreach ($listStartX as $x)
    {
        $x += 100;
        for ($y = 0; true; ++$y)
        {
            if ($field[$y][$x] === ' ') {
                continue;
            }

            if ($field[$y][$x + 1] === ' ') {
                ++$x;
                continue;
            }

            if ($field[$y][$x - 1] === ' ') {
                --$x;
                continue;
            }

            $field[$y - 1][$x] = 'a';
            break;
        }
    }

    echo implode("\n", $field);
}