Returning the newly added legend component from this function might be useful.