heatmaps: part 9

This commit is contained in:
nym21
2026-05-31 23:35:19 +02:00
parent 7860c5a8bd
commit 3b7734a61a
8 changed files with 321 additions and 32 deletions
+18
View File
@@ -29,6 +29,24 @@ export function intensityColor({ light, dark }) {
};
}
/**
* @param {Object} args
* @param {ArrayLike<number>} args.light
* @param {ArrayLike<number>} args.dark
* @returns {HeatmapColorFn}
*/
export function logIntensityColor({ light, dark }) {
return (value, context) => {
if (!Number.isFinite(value) || value <= 0) return 0x00000000;
const max = context.grid.getMaxValue(context.col);
if (max <= 0) return 0x00000000;
const lut = context.dark ? dark : light;
const t = Math.log2(value + 1) / Math.log2(max + 1);
const index = Math.min(255, Math.max(0, Math.round(t * 255)));
return lut[index] ?? 0x00000000;
};
}
/**
* @param {number[][]} stops - Tuples of [position, red, green, blue].
*/