fix legend generation