Flip legend order; fix bugs described in #97

By “Flip legend order”, I mean:

![screen shot 2014-10-10 at 15 50 28](https://cloud.githubusercontent.com/assets/464193/4594121/d75314e4-508c-11e4-9580-b76e7fcb1d0c.png)

Instead of:

![screen shot 2014-10-10 at 15 50 39](https://cloud.githubusercontent.com/assets/464193/4594123/db7153a6-508c-11e4-83d4-250c42672abc.png)

I’ve also made the fixes suggested by @denglend in #97.