# distinct-colors

> Generate a palette of visually distinct colors. It's great for charts.

Latest version **3.0.0** (published 2020-04-29) · ISC license · 0 weekly downloads

## Install

```sh
npm install distinct-colors
pnpm add distinct-colors
yarn add distinct-colors
bun add distinct-colors
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2020-04-29 |
| First published | 2015-08-12 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 24.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 125 |
| Author | Bryan Morris |
| Maintainers | internalfx |
| Keywords | palette, colors, charts, graphs |

## Links

- npm: https://www.npmjs.com/package/distinct-colors
- Repository: https://github.com/internalfx/distinct-colors
- Homepage: https://github.com/internalfx/distinct-colors#readme
- Issues: https://github.com/internalfx/distinct-colors/issues
- npm.io page: https://npm.io/package/distinct-colors

## Dependencies (3)

- [mout](https://npm.io/package/mout.md) ^1.2.2
- [chroma-js](https://npm.io/package/chroma-js.md) ^2.1.0
- [@types/chroma-js](https://npm.io/package/@types/chroma-js.md) ^2.0.0

## Alternatives

- [d3-force-3d](https://npm.io/package/d3-force-3d.md) — 1.0M weekly downloads
- [ng2-charts](https://npm.io/package/ng2-charts.md) — 486.8K weekly downloads
- [@arcgis/core](https://npm.io/package/@arcgis/core.md) — 257.8K weekly downloads
- [react-sparklines](https://npm.io/package/react-sparklines.md) — 249.3K weekly downloads
- [react-native-gifted-charts](https://npm.io/package/react-native-gifted-charts.md) — 182.3K weekly downloads

## Recent versions

- 3.0.0 (latest) — 2020-04-29
- 2.1.0 — 2020-01-11
- 2.0.1 — 2020-01-10
- 2.0.0 — 2020-01-03
- 1.0.4 — 2015-10-10
- 1.0.3 — 2015-10-10
- 1.0.2 — 2015-10-10
- 1.0.1 — 2015-08-20
- 0.0.4 — 2015-08-12
- 0.0.3 — 2015-08-12
- 0.0.2 — 2015-08-12
- 0.0.1 — 2015-08-12

## README

# Distinct Colors

[![npm version](https://img.shields.io/npm/v/distinct-colors.svg)](https://www.npmjs.com/package/distinct-colors)
[![license](https://img.shields.io/npm/l/distinct-colors.svg)](https://github.com/internalfx/distinct-colors/blob/master/LICENSE)

This is a complete rewrite of (but is heavily inspired by) [Mathieu Jacomy's](https://github.com/jacomyma) [Palette Generator](https://github.com/medialab/iwanthue/blob/master/js/libs/chroma.palette-gen.js)

I have taken the ideas and the theories, and put them into a simple modular library. I have also optimized it for speed.

This library generates a palette of *visually* distinct colors, and returns an array of [chroma-js](https://github.com/gka/chroma.js) objects.

distinct-colors is highly configurable:

- Choose how many colors are in the palette
- Restrict the hue to a specific range
- Restrict the chroma (saturation) to a specific range
- Restrict the lightness to a specific range
- Configure general quality of the palette

To get an example of how to use this (and what it produces), check out [I want hue](http://tools.medialab.sciences-po.fr/iwanthue/).

---

Special thanks to [Arthur Andrew Medical](http://www.arthurandrew.com/) for sponsoring this project.

Arthur Andrew Medical manufactures products with ingredients that have extensive clinical research for safety and efficacy. We specialize in Enzymes, Probiotics and Antioxidants.

---

## Installation

```
npm install distinct-colors
```

## Getting Started

```javascript
// ESM
import distinctColors from 'distinct-colors'

// CommonJS
var distinctColors = require('distinct-colors').default

var palette = distinctColors() // You may pass an optional config object

// Thats it!
```

## API

#### distinctColors([options])

Generates a new palette. Returns an array of [chroma-js](https://github.com/gka/chroma.js) objects.

#### Options

| Name | Type | Valid Range | Default | Description |
| --- | --- | --- | --- | --- |
| count | integer | `0-Infinity` | `5` | The number of colors the palette should contain |
| hueMin | integer | `0-360` | `0` | The minimum hue for colors in the palette. |
| hueMax | integer | `0-360` | `360` | The maximum hue for colors in the palette. |
| chromaMin | integer | `0-100` | `0` | The minimum chroma (color) for colors in the palette. |
| chromaMax | integer | `0-100` | `100` | The maximum chroma (color) for colors in the palette. |
| lightMin | integer | `0-100` | `0` | The minimum lightness for colors in the palette. |
| lightMax | integer | `0-100` | `100` | The maximum lightness for colors in the palette. |
| quality | integer | `1-Infinity` | `50` | The number of steps for [k-means](https://en.wikipedia.org/wiki/K-means_clustering) convergence. Will break early if the result has converged. |
| samples | integer | `1-Infinity` | `800` | The number of color samples to choose from. |

---
_Source: https://npm.io/package/distinct-colors · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
