🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

color-mapping

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

color-mapping

Flexible library to map scalar values to colors

1.0.0-1
latest
npm
Version published
Maintainers
1
Created
Source

npm package CircleCI codecov

color-mapping

A flexible library to map numerical values to colors

Install

npm install -S color-mapping

Basic Usage

import { createColorMap, linearScale } from "color-mapping";

let colors = [
  [1, 0, 0],
  [0, 1, 0],
  [0, 0, 1]
];
let domain = [0, 100];
let range = [0, 1];
let scale = linearScale(domain, range);
let colorMap = createColorMap(colors, scale);
let values = [0, 25, 50, 75, 100];
let output = values.map(v => colorMap(v));
// output is [[1,0,0], [0.5,0.5,0], [0,1,0], [0,0.5,0.5], [0,0,1]]

Advanced Usage

The colors array doesn't necessarily need to span evenly the [0, 1] interval.

import { createColorMap, linearScale } from "color-mapping";

let colors = [
  { value: -1.0, color: [0, 0, 1] },
  { value: 0.0, color: [1, 0, 0] },
  { value: 0.5, color: [0, 1, 0] },
  { value: 2.0, color: [0, 0, 1] }
];
let domain = [0, 100];
let range = [-1, 2];
let scale = linearScale(domain, range);
let colorMap = createColorMap(colors, scale);
let values = [0, 25, 50, 75, 100];
let output = values.map(v => colorMap(v));
// output is [[0,0,1], [0.75,0,0.25], [0,1,0], [0,0.5,0.5], [0,0,1]]

FAQs

Package last updated on 29 Apr 2019

Did you know?

Socket

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.

Install

Related posts