Merge legends

Extending only HorizontalLegend to cover Legend functionality.

Orignal PR #1415.
You can use d3.select(this).

Also, unless you really want to pick the last valid value, you can return immediately.