Handle resize and add legend