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.
Because of the name === "" from above, this can be the more precise
if (name.length === 1) name = "_" + name