Extract legend rendering into render function that can be called multiple times