heatmaps: part 4

This commit is contained in:
nym21
2026-05-30 11:36:49 +02:00
parent e43b53b429
commit cc8fde59e8
11 changed files with 688 additions and 78 deletions
+17
View File
@@ -1,3 +1,5 @@
/** @import { HeatmapColorFn } from "./types.js" */
const INFERNO_STOPS = [
[0, 0, 0, 0],
[0.13, 40, 11, 84],
@@ -12,6 +14,21 @@ const INFERNO_STOPS = [
export const INFERNO_LUT = createColorLut(INFERNO_STOPS);
/**
* @param {Object} args
* @param {ArrayLike<number>} args.light
* @param {ArrayLike<number>} args.dark
* @returns {HeatmapColorFn}
*/
export function intensityColor({ light, dark }) {
return (value, context) => {
if (!Number.isFinite(value)) return 0x00000000;
const lut = context.dark ? dark : light;
const index = Math.min(255, Math.max(0, Math.round(value * 255)));
return lut[index] ?? 0x00000000;
};
}
/**
* @param {number[][]} stops - Tuples of [position, red, green, blue].
*/