fix legend width calculation