
Security News
Vite Releases Technical Preview of Rolldown-Vite, a Rust-Based Bundler
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
linear-gradient
Advanced tools
Calculates the color representing a number based on the gradient supplied
calculates the color representing a number based on the gradient supplied
When using charts and maps to visualize data, it is useful to map values to a color gradient. This package provides the functions to map values to color gradients.
Instantiate object with the graident palette, then use it to calculate the color representing a value
var Gradient = require('linear-gradient');
// instantiate with an RGB palette
var grad1 = new Gradient([
[0,0,0],
[0,80,0],
[0,160,80],
[80,80,80],
[160,40,40],
[255,0,0]
]);
// now we are ready to calculate the colors
// the input value should be normalized to the range between 0 and 1
console.log(grad1.calcArray(0)); // -> [0,0,0] (0 -> first color of the palette)
console.log(grad1.calcArray(1)); // -> [255,0,0] (1 -> last color of the palette)
console.log(grad1.calcArray(0.25)); // -> [0,100,20] (weighted average between [0,80,0] and [0,160,80])
console.log(grad1.calcArray(0.5));
console.log(grad1.calcArray(0.75));
console.log(grad1.calcHex(1)); // -> '#ffffff'
console.log(grad1.calcHex(0.25)); // -> '#006416'
FAQs
Calculates the color representing a number based on the gradient supplied
The npm package linear-gradient receives a total of 92 weekly downloads. As such, linear-gradient popularity was classified as not popular.
We found that linear-gradient demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.