Show and hide legend based on tab selection