Update val to be min when less, max when greater.

This was causing an issue in rendering when values were greater than max, the value would be reset to `0`, which seemed odd. It should at the very least cap it at the max.