Skip to content

Commit

Permalink
Align code to lambda syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalabint committed Sep 30, 2024
1 parent 12c8aac commit 99eec1b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
12 changes: 5 additions & 7 deletions src/common/util/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {

Check failure on line 25 in src/common/util/colors.js

View workflow job for this annotation

GitHub Actions / build

Prefer default export on a file with single export
const normalizedSpeed = Math.max(0, Math.min(1, speed / maxSpeed));
const [r, g, b] = interpolateTurbo(normalizedSpeed);
return `rgb(${r}, ${g}, ${b})`;
};

export default getSpeedColor;
2 changes: 1 addition & 1 deletion src/map/MapRoutePath.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/map/MapRoutePoints.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down

0 comments on commit 99eec1b

Please sign in to comment.