Compute color contrast in PHP

Moved logic to compute whether black or white contrasts with Legend
color value to PHP
Simplified color logic in JS