Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

canvas-heatmap

Package Overview
Dependencies
Maintainers
0
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

canvas-heatmap - npm Package Compare versions

Comparing version 1.5.2 to 1.6.0

dist/canvas-heatmap.js

4

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc