Fixed legend overflow issue in #2076 with the fix proposed by @patheard