Sanitize CSS class names applied on Legend rows/entries

Previously, short names and numbers would be applied as CSS classes, but they would be invalid class names and it would thus be impossible to apply styles to them.

Close #1321.
You should be able to inline the regex like
name.match(/[_a-zA-Z]/)