refactor
This commit is contained in:
@@ -45,7 +45,9 @@ export const getColor = (temperature: number, unit = 'celsius'): string => {
|
||||
} else if (temperature >= 60) {
|
||||
index = colorScaleHex.length - 1;
|
||||
} else {
|
||||
index = Math.round(temperature) + 45;
|
||||
// clamp: the scale has exactly 100 entries (-45..54), temperatures in
|
||||
// [55, 60) would otherwise index past the end
|
||||
index = Math.min(colorScaleHex.length - 1, Math.max(0, Math.round(temperature) + 45));
|
||||
}
|
||||
|
||||
return colorScaleHex[index];
|
||||
|
||||
Reference in New Issue
Block a user