Skip to content

Commit

Permalink
Merge pull request #1277 from Kalabint/bugfix/fix-color-normalization
Browse files Browse the repository at this point in the history
Fix Color normalization in Replay
  • Loading branch information
tananaev authored Oct 7, 2024
2 parents 10b8a91 + 0561dc5 commit 524a28f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/common/util/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ const interpolateTurbo = (value) => {
];
};

const getSpeedColor = (speed, maxSpeed) => {
const normalizedSpeed = Math.max(0, Math.min(1, speed / maxSpeed));
const getSpeedColor = (speed, minSpeed, maxSpeed) => {
const normalizedSpeed = (speed - minSpeed) / (maxSpeed - minSpeed);

const [r, g, b] = interpolateTurbo(normalizedSpeed);

return `rgb(${r}, ${g}, ${b})`;
};

Expand Down
4 changes: 3 additions & 1 deletion src/map/MapRoutePoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ const MapRoutePoints = ({ positions, onClick }) => {

useEffect(() => {
const maxSpeed = positions.map((p) => p.speed).reduce((a, b) => Math.max(a, b), -Infinity);
const minSpeed = positions.map((p) => p.speed).reduce((a, b) => Math.min(a, b), Infinity);

map.getSource(id)?.setData({
type: 'FeatureCollection',
features: positions.map((position, index) => ({
Expand All @@ -70,7 +72,7 @@ const MapRoutePoints = ({ positions, onClick }) => {
index,
id: position.id,
rotation: position.course,
color: getSpeedColor(position.speed, maxSpeed),
color: getSpeedColor(position.speed, minSpeed, maxSpeed),
},
})),
});
Expand Down

0 comments on commit 524a28f

Please sign in to comment.