Fix bug in show/hide when legend is clicked