Move legend rendering in to template