From 99eec1bf8a1943bf9ef09810287896ec2ec92d9b Mon Sep 17 00:00:00 2001 From: Kalabint Date: Mon, 30 Sep 2024 23:49:53 +0200 Subject: [PATCH] Align code to lambda syntax --- src/common/util/colors.js | 12 +++++------- src/map/MapRoutePath.js | 2 +- src/map/MapRoutePoints.js | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/common/util/colors.js b/src/common/util/colors.js index 440e9107af..4e8ef70664 100644 --- a/src/common/util/colors.js +++ b/src/common/util/colors.js @@ -5,27 +5,25 @@ const turboPolynomials = { b: [0.10667330, 12.64194608, -60.58204836, 110.36276771, -89.90310912, 27.34824973], }; -function interpolateChannel(normalizedValue, coeffs) { +const interpolateChannel = (normalizedValue, coeffs) => { let result = 0; for (let i = 0; i < coeffs.length; i += 1) { result += coeffs[i] * (normalizedValue ** i); } return Math.max(0, Math.min(1, result)); -} +}; -function interpolateTurbo(value) { +const interpolateTurbo = (value) => { const normalizedValue = Math.max(0, Math.min(1, value)); return [ Math.round(255 * interpolateChannel(normalizedValue, turboPolynomials.r)), Math.round(255 * interpolateChannel(normalizedValue, turboPolynomials.g)), Math.round(255 * interpolateChannel(normalizedValue, turboPolynomials.b)), ]; -} +}; -const getSpeedColor = (speed, maxSpeed) => { +export const getSpeedColor = (speed, maxSpeed) => { const normalizedSpeed = Math.max(0, Math.min(1, speed / maxSpeed)); const [r, g, b] = interpolateTurbo(normalizedSpeed); return `rgb(${r}, ${g}, ${b})`; }; - -export default getSpeedColor; diff --git a/src/map/MapRoutePath.js b/src/map/MapRoutePath.js index ae905676ae..6338e47918 100644 --- a/src/map/MapRoutePath.js +++ b/src/map/MapRoutePath.js @@ -2,7 +2,7 @@ import { useTheme } from '@mui/styles'; import { useId, useEffect } from 'react'; import { useSelector } from 'react-redux'; import { map } from './core/MapView'; -import getSpeedColor from '../common/util/colors'; +import { getSpeedColor } from '../common/util/colors'; const MapRoutePath = ({ positions }) => { const id = useId(); diff --git a/src/map/MapRoutePoints.js b/src/map/MapRoutePoints.js index 7ee4dc6363..ee216aec9e 100644 --- a/src/map/MapRoutePoints.js +++ b/src/map/MapRoutePoints.js @@ -1,6 +1,6 @@ import { useId, useCallback, useEffect } from 'react'; import { map } from './core/MapView'; -import getSpeedColor from '../common/util/colors'; +import { getSpeedColor } from '../common/util/colors'; const MapRoutePoints = ({ positions, onClick }) => { const id = useId();