chroma.js README

The project's README from github.com/gka/chroma.js. As one markdown file: README.md.

Chroma.js

Chroma.js is a tiny small-ish zero-dependency JavaScript library for all kinds of color conversions and color scales.

Build Status Build size

Usage

Install from npm

npm install chroma-js

Import package into project

import chroma from "chroma-js";

Initiate and manipulate colors:

chroma('#D4F880').darken().hex();  // #a1c550

Working with color scales is easy, too:

scale = chroma.scale(['white', 'red']);
scale(0.5).hex(); // #FF7F7F

Lab/Lch interpolation looks better than RGB

chroma.scale(['white', 'red']).mode('lab');

Custom domains! Quantiles! Color Brewer!!

chroma.scale('RdYlBu').domain(myValues, 7, 'quantiles');

And why not use logarithmic color scales once in your life?

chroma.scale(['lightyellow', 'navy']).domain([1, 100000], 7, 'log');

Like it?

Why not dive into the interactive documentation (there's a static version, too). You can download chroma.min.js or use the hosted version on unpkg.com.

You can use it in node.js, too!

npm install chroma-js

Or you can use it in SASS using chromatic-sass!

Want to contribute?

Come over and say hi in our Discord channel!

Build instructions

First clone the repository and install the dev dependencies:

git clone [email protected]:gka/chroma.js.git
cd chroma.js
npm install

Then compile the coffee-script source files to the build files:

npm run build

Don't forget to tests your changes! You will probably also want to add new test to the /test folder in case you added a feature.

npm test

And to update the documentation just run

npm run docs

To preview the docs locally you can use

npm run docs-preview

Similar Libraries / Prior Art

Author

Chroma.js is written by Gregor Aisch.

License

Released under BSD license. Versions prior to 0.4 were released under GPL.

Further reading

FAQ

There have been no commits in X weeks. Is chroma.js dead?

No! It's just that the author of this library has other things to do than devoting every week of his life to making cosmetic changes to a piece of software that is working just fine as it is, just so that people like you don't feel like it's abandoned and left alone in this world to die. Bugs will be fixed. Some new things will come at some point. Patience.

I want to help maintaining chroma.js!

Yay, that's awesome! Please say hi at our Discord chat to get in touch

chroma.js (gka/chroma.js)

Searching Database…

10.6K ·GitHub
这是干什么的?Chroma.js 是一个小巧、零依赖的 JavaScript 颜色处理库,能做各种颜色转换和色阶——从解析单个颜色到构建多色调调色板。
它是给浏览器用的还是给 Node 用的?都可以——通过独立的 chroma.min.js 或 unpkg.com 上的托管版本就能在浏览器里运行,在 node.js 里则通过 npm 安装使用。甚至还有一个配套的 chromatic-sass,可以在 SASS 里使用它。
怎么把它加到我的项目里?用 'npm install chroma-js' 从 npm 安装,把包引入到你的项目里,然后就可以开始创建和调整颜色了。
好几个星期都没有新提交了——chroma.js 是不是没人维护了?没有——作者本人正面回应过:这个库现在用得好好的,bug 会修,新功能迟早也会有,所以看它的稳定性就好,别只盯着提交频率。
可以免费使用吗?商业项目也行吗?可以——chroma.js 采用 BSD 许可证发布。只有 0.4 之前的版本用的是 GPL,所以现在任何新版本都没问题。
除了转换单个颜色,它还能做什么?色阶是它的第二大招牌功能:比直接用 RGB 插值效果更好的 Lab/Lch 插值、自定义取值范围、分位数、Color Brewer 调色板以及对数色阶。
它支持 SASS 吗?支持——有一个叫 chromatic-sass 的配套包,可以在 SASS 里使用 chroma.js。
其他语言有类似的库吗?README 里列出了 Python 的 GrapeFruit 和 colors.py,Rust 的 Color Art,JavaScript 方面还有 Chromatist 和 d3.js。
Creator
gka
Size
3.3 MB
Stars
10.6K
Age
14y
Commits · 90 Days