Is there any reason to do this check here rather than doing the check outside the ``with`` statement?  That is, can you imagine a situation where you'd want the renderer to open and close a legend with nothing in it?