Fix maximum dimensions for legend that is anchored to container [#7072], with thanks to @attatrol for the contribution!