@evergis/color
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -468,2 +468,32 @@ /** | ||
export { Color }; | ||
class ColorScale { | ||
constructor(palette) { | ||
this.palette = palette; | ||
} | ||
getColor(p) { | ||
const palette = this.palette.slice(); | ||
palette[0][0] = 0; | ||
palette[palette.length - 1][0] = 1; | ||
let colors = palette.map(item => { return new Color(item[1]); }); | ||
if (p >= 1) { | ||
let color = new Color(palette[palette.length - 1][1]); | ||
color.a = 255; | ||
return color.toString(); | ||
} | ||
for (let i = 0; i < palette.length; i++) { | ||
if (palette[i][0] > p) { | ||
let width = palette[i][0] - palette[i - 1][0]; | ||
let color1 = colors[i - 1]; | ||
let color2 = colors[i]; | ||
let k = (p - palette[i - 1][0]) / width; | ||
let channels = ['r', 'g', 'b', 'a'].map(function (ch) { return Math.round(color1[ch] + (color2[ch] - color1[ch]) * k); }); | ||
channels[3] = 1; | ||
return 'rgba(' + channels.join(',') + ')'; | ||
} | ||
} | ||
return null; | ||
} | ||
; | ||
} | ||
export { Color, ColorScale }; |
@@ -474,3 +474,34 @@ (function (global, factory) { | ||
class ColorScale { | ||
constructor(palette) { | ||
this.palette = palette; | ||
} | ||
getColor(p) { | ||
const palette = this.palette.slice(); | ||
palette[0][0] = 0; | ||
palette[palette.length - 1][0] = 1; | ||
let colors = palette.map(item => { return new Color(item[1]); }); | ||
if (p >= 1) { | ||
let color = new Color(palette[palette.length - 1][1]); | ||
color.a = 255; | ||
return color.toString(); | ||
} | ||
for (let i = 0; i < palette.length; i++) { | ||
if (palette[i][0] > p) { | ||
let width = palette[i][0] - palette[i - 1][0]; | ||
let color1 = colors[i - 1]; | ||
let color2 = colors[i]; | ||
let k = (p - palette[i - 1][0]) / width; | ||
let channels = ['r', 'g', 'b', 'a'].map(function (ch) { return Math.round(color1[ch] + (color2[ch] - color1[ch]) * k); }); | ||
channels[3] = 1; | ||
return 'rgba(' + channels.join(',') + ')'; | ||
} | ||
} | ||
return null; | ||
} | ||
; | ||
} | ||
exports.Color = Color; | ||
exports.ColorScale = ColorScale; | ||
@@ -477,0 +508,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
{ | ||
"name": "@evergis/color", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "", | ||
@@ -11,2 +11,3 @@ "main": "dist/lib/index.js", | ||
"build": "cross-env NODE_ENV=production rollup --config rollup.config.js", | ||
"dev": "cross-env NODE_ENV=production rollup --config rollup.config.js --watch", | ||
"prepublishOnly": "npm i && npm run build" | ||
@@ -13,0 +14,0 @@ }, |
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
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
66033
15
1986