gitmyhub

chroma.js

JavaScript ★ 11k updated 19d ago

JavaScript library for all kinds of color manipulations

A small, dependency-free JavaScript library for converting between color formats, adjusting colors, and building smooth color scales for data visualization, works in browsers and Node.js.

JavaScriptsetup: easycomplexity 2/5

Chroma.js is a small JavaScript library with no external dependencies for working with colors in code. It handles color conversions, color manipulation such as darkening or lightening a color, and generating smooth color scales between two or more colors. It works in both browsers and Node.js and is available through npm.

The most common use is converting colors from one format to another and adjusting them programmatically. For example, you can pass in a hex color code, darken it, and get a new hex value back in a single line. You can also create a gradient scale between two colors and ask for the color at any point along that scale as a percentage.

One of the more useful features is the ability to choose which color space is used for interpolation when building a scale. Interpolating in the Lab color space, for instance, produces transitions that look more visually even to human eyes than simple RGB blending does. The library also has built-in support for the Color Brewer palette sets, which are color schemes designed specifically for data visualization work such as maps and charts. Scales can use custom value ranges, quantile bucketing, or logarithmic spacing.

The library was written by Gregor Aisch and is released under the BSD license. Versions before 0.4 used a GPL license. An interactive documentation page lets you explore the API and see live examples without writing any code. There is also a static version of the docs in the repository.

The README includes a note in the FAQ section addressing why the commit history sometimes goes quiet for long stretches: the author treats the library as stable and focuses on fixes and improvements rather than ongoing cosmetic changes. The project has a Discord channel for contributors and anyone who wants to discuss it.

Where it fits