Split ranges calculation into separate function

This allows the user to dynamically re-calculate the range values when data changes