Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
mthh committed Jan 4, 2024
1 parent b8ffdaa commit 0724e8d
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
> - [Masataka Okabe and Kei Ito's Color Universal Design (CUD) palette](https://jfly.uni-koeln.de/color/)
> - [Joshua Stevens' palettes](https://www.joshuastevens.net/)
[Browse all the available palettes](https://observablehq.com/@mthh/hello-dicopal)
[Browse all the available palettes](https://observablehq.com/@mthh/hello-dicopal)
[Example about the creation of asymmetric diverging palettes](https://observablehq.com/@mthh/asymmetric-diverging-schemes-with-dicopal)

## Installation

Expand Down Expand Up @@ -158,6 +159,48 @@ const providers = getPaletteNames('colorbrewer');
const numClasses = getPaletteNumbers('Pastel2');
```

### Generating colors for asymmetric diverging palettes

The `getAsymmetricDivergingPalette` function enables the creation of asymmetric diverging palettes
(e.g. 3 colors for the left side and 4 colors for the right side),
either balanced (i.e. the perceptual distance between the colors is the same on both sides) or not.

It takes the following arguments:
- `divergingSchemeName` (string): the name of the diverging scheme to use (e.g. 'RdYlBu')
- `leftNumber` (number): the number of colors to use on the left side
- `rightNumber` (number): the number of colors to use on the right side
- `centralClass` (boolean - optional): whether to include a central class (default: false)
- `balanced` (boolean - optional): whether to balance the colors on both sides (default: false)

#### Balanced

```javascript
const pal = getAsymmetricDivergingColors('RdYlBu', 7, 2, true, true);
```

#### Unbalanced

```javascript
const pal = getAsymmetricDivergingColors('RdYlBu', 7, 2, true, false);
```

### Generating colors for (interpolated) sequential palettes

Sometimes, a palette exists only in a limited number of colors (e.g. 3-to-9 colors) but you need
a palette with a different number of colors (e.g. 12 colors).

The `getSequentialColors` function enables the creation of interpolated sequential palettes with a custom number of colors.

It takes the following arguments:

- `sequentialSchemeName` (string): the name of the sequential scheme to use (e.g. 'Blues')
- `classNumber` (number): the number of colors to use
- `reverse` (boolean - optional): whether to reverse the palette (default: false)

```javascript
const pal = getSequentialColors('Blues', 12);
```

### Not a fan of the proposed API ? Just get the raw description of the palettes and use them as you wish

For a given provider:
Expand All @@ -172,6 +215,14 @@ For all the provider (default):
getRawData();
```

## Contributing

Contributions of all kinds are welcome, through issues and pull requests.

If you use the library and feel that the API could be improved / simplified / enriched / etc.,
don't hesitate to come and discuss it in the issues!


## Other information

Palette information is stored in the `src/palette.json` file.
Expand Down

0 comments on commit 0724e8d

Please sign in to comment.