Reorganize the html: move legend dialog out