function findClosestPaletteColor([r, g, b, a], mode) {
const l = Math.hypot(r, g, b);
const m = Math.hypot(255, 255, 255);
let rgbString;
if (mode === 1) {
rgbString = d3.interpolateTurbo(l / m);
} else {
rgbString = d3.interpolateRainbow(l / m);
}
const [nextR, nextG, nextB] = rgbString
.replace(/rgb\(|/, '')
.split(',')
.map(n => parseInt(n));
return [nextR, nextG, nextB, 255];
}