canvas-heatmap
Advanced tools
Comparing version 1.5.2 to 1.6.0
{ | ||
"name": "canvas-heatmap", | ||
"version": "1.5.2", | ||
"version": "1.6.0", | ||
"description": "Interactive heatmap, capable of displaying 1,000,000+ data points using canvas and d3. ", | ||
@@ -40,3 +40,3 @@ "main": "src/index.js", | ||
"@rollup/plugin-node-resolve": "^11.2.1", | ||
"rollup": "^2.39.1", | ||
"rollup": "^2.79.1", | ||
"rollup-plugin-terser": "^7.0.2", | ||
@@ -43,0 +43,0 @@ "serve": "^11.3.2" |
@@ -25,38 +25,42 @@ export const convertToRGB = (hex) => { | ||
const colorCache = new Map(); | ||
export const getRGBAColor = (value, min, max, colors) => { | ||
if (value === null || isNaN(value)) { | ||
return [255, 255, 255, 0]; | ||
if (value === null || isNaN(value)) return [255, 255, 255, 0]; | ||
if (value < min || value > max) return [0, 0, 0, 0]; | ||
const cacheKey = `${value}-${min}-${max}`; | ||
if (colorCache.has(cacheKey)) { | ||
return colorCache.get(cacheKey); | ||
} | ||
if (value > max) { | ||
return [0, 0, 0, 0]; | ||
} | ||
if (value < min) { | ||
return [0, 0, 0, 0]; | ||
} | ||
var loc = (value - min) / (max - min); | ||
const range = max - min; | ||
const loc = (value - min) / range; | ||
if (loc < 0 || loc > 1) { | ||
colorCache.set(cacheKey, [255, 255, 255, 0]); | ||
return [255, 255, 255, 0]; | ||
} else { | ||
var index = 0; | ||
for (var i = 0; i < colors.length - 1; i++) { | ||
if (loc >= colors[i].point && loc <= colors[i + 1].point) { | ||
index = i; | ||
break; | ||
} | ||
} | ||
let low = 0; | ||
let high = colors.length - 1; | ||
while (low < high) { | ||
const mid = Math.floor((low + high) / 2); | ||
if (loc < colors[mid].point) { | ||
high = mid - 1; | ||
} else if (loc > colors[mid + 1].point) { | ||
low = mid + 1; | ||
} else { | ||
low = mid; | ||
break; | ||
} | ||
var color1 = colors[index].rgba; | ||
var color2 = colors[index + 1].rgba; | ||
var f = | ||
(loc - colors[index].point) / | ||
(colors[index + 1].point - colors[index].point); | ||
var rgb = [ | ||
color1[0] + (color2[0] - color1[0]) * f, | ||
color1[1] + (color2[1] - color1[1]) * f, | ||
color1[2] + (color2[2] - color1[2]) * f, | ||
255, | ||
]; | ||
return rgb; | ||
} | ||
const index = low; | ||
const { rgba: color1 } = colors[index]; | ||
const { rgba: color2 } = colors[index + 1]; | ||
const factor = (loc - colors[index].point) / (colors[index + 1].point - colors[index].point); | ||
const rgb = [ | ||
color1[0] + (color2[0] - color1[0]) * factor, | ||
color1[1] + (color2[1] - color1[1]) * factor, | ||
color1[2] + (color2[2] - color1[2]) * factor, | ||
255 | ||
]; | ||
colorCache.set(cacheKey, rgb); | ||
return rgb; | ||
}; | ||
@@ -63,0 +67,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
965476
12
8307
1