refactoring legend widget