• Stars
    star
    787
  • Rank 57,828 (Top 2 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 8 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Sequential, diverging and categorical color scales.

d3-scale-chromatic

This module provides sequential, diverging and categorical color schemes designed to work with d3-scale’s d3.scaleOrdinal and d3.scaleSequential. Most of these schemes are derived from Cynthia A. Brewer’s ColorBrewer. Since ColorBrewer publishes only discrete color schemes, the sequential and diverging scales are interpolated using uniform B-splines.

For example, to create a categorical color scale using the Accent color scheme:

var accent = d3.scaleOrdinal(d3.schemeAccent);

To create a sequential discrete nine-color scale using the Blues color scheme:

var blues = d3.scaleOrdinal(d3.schemeBlues[9]);

To create a diverging, continuous color scale using the PiYG color scheme:

var piyg = d3.scaleSequential(d3.interpolatePiYG);

Installing

If you use npm, npm install d3-scale-chromatic. You can also download the latest release on GitHub. For vanilla HTML in modern browsers, import d3-scale-chromatic from Skypack:

<script type="module">

import {interpolateYlGn} from "https://cdn.skypack.dev/d3-scale-chromatic@3";

const yellow = interpolateYlGn(0); // "rgb(255, 255, 229)"
const yellowGreen = interpolateYlGn(0.5); // "rgb(120, 197, 120)"
const green = interpolateYlGn(1); // "rgb(0, 69, 41)"

</script>

For legacy environments, you can load d3-scale-chromatic’s UMD bundle from an npm-based CDN such as jsDelivr; a d3 global is exported:

<script src="https://cdn.jsdelivr.net/npm/d3-color@3"></script>
<script src="https://cdn.jsdelivr.net/npm/d3-interpolate@3"></script>
<script src="https://cdn.jsdelivr.net/npm/d3-scale-chromatic@3"></script>
<script>

const yellow = d3.interpolateYlGn(0); // "rgb(255, 255, 229)"
const yellowGreen = d3.interpolateYlGn(0.5); // "rgb(120, 197, 120)"
const green = d3.interpolateYlGn(1); // "rgb(0, 69, 41)"

</script>

Try d3-scale-chromatic in your browser.

API Reference

Categorical

# d3.schemeCategory10 <>

category10

An array of ten categorical colors represented as RGB hexadecimal strings.

# d3.schemeAccent <>

Accent

An array of eight categorical colors represented as RGB hexadecimal strings.

# d3.schemeDark2 <>

Dark2

An array of eight categorical colors represented as RGB hexadecimal strings.

# d3.schemePaired <>

Paired

An array of twelve categorical colors represented as RGB hexadecimal strings.

# d3.schemePastel1 <>

Pastel1

An array of nine categorical colors represented as RGB hexadecimal strings.

# d3.schemePastel2 <>

Pastel2

An array of eight categorical colors represented as RGB hexadecimal strings.

# d3.schemeSet1 <>

Set1

An array of nine categorical colors represented as RGB hexadecimal strings.

# d3.schemeSet2 <>

Set2

An array of eight categorical colors represented as RGB hexadecimal strings.

# d3.schemeSet3 <>

Set3

An array of twelve categorical colors represented as RGB hexadecimal strings.

# d3.schemeTableau10 <>

Tableau10

An array of ten categorical colors authored by Tableau as part of Tableau 10 represented as RGB hexadecimal strings.

Diverging

Diverging color schemes are available as continuous interpolators (often used with d3.scaleSequential) and as discrete schemes (often used with d3.scaleOrdinal). Each discrete scheme, such as d3.schemeBrBG, is represented as an array of arrays of hexadecimal color strings. The kth element of this array contains the color scheme of size k; for example, d3.schemeBrBG[9] contains an array of nine strings representing the nine colors of the brown-blue-green diverging color scheme. Diverging color schemes support a size k ranging from 3 to 11.

# d3.interpolateBrBG(t) <>
# d3.schemeBrBG[k]

BrBG

Given a number t in the range [0,1], returns the corresponding color from the “BrBG” diverging color scheme represented as an RGB string.

# d3.interpolatePRGn(t) <>
# d3.schemePRGn[k]

PRGn

Given a number t in the range [0,1], returns the corresponding color from the “PRGn” diverging color scheme represented as an RGB string.

# d3.interpolatePiYG(t) <>
# d3.schemePiYG[k]

PiYG

Given a number t in the range [0,1], returns the corresponding color from the “PiYG” diverging color scheme represented as an RGB string.

# d3.interpolatePuOr(t) <>
# d3.schemePuOr[k]

PuOr

Given a number t in the range [0,1], returns the corresponding color from the “PuOr” diverging color scheme represented as an RGB string.

# d3.interpolateRdBu(t) <>
# d3.schemeRdBu[k]

RdBu

Given a number t in the range [0,1], returns the corresponding color from the “RdBu” diverging color scheme represented as an RGB string.

# d3.interpolateRdGy(t) <>
# d3.schemeRdGy[k]

RdGy

Given a number t in the range [0,1], returns the corresponding color from the “RdGy” diverging color scheme represented as an RGB string.

# d3.interpolateRdYlBu(t) <>
# d3.schemeRdYlBu[k]

RdYlBu

Given a number t in the range [0,1], returns the corresponding color from the “RdYlBu” diverging color scheme represented as an RGB string.

# d3.interpolateRdYlGn(t) <>
# d3.schemeRdYlGn[k]

RdYlGn

Given a number t in the range [0,1], returns the corresponding color from the “RdYlGn” diverging color scheme represented as an RGB string.

# d3.interpolateSpectral(t) <>
# d3.schemeSpectral[k]

Spectral

Given a number t in the range [0,1], returns the corresponding color from the “Spectral” diverging color scheme represented as an RGB string.

Sequential (Single Hue)

Sequential, single-hue color schemes are available as continuous interpolators (often used with d3.scaleSequential) and as discrete schemes (often used with d3.scaleOrdinal). Each discrete scheme, such as d3.schemeBlues, is represented as an array of arrays of hexadecimal color strings. The kth element of this array contains the color scheme of size k; for example, d3.schemeBlues[9] contains an array of nine strings representing the nine colors of the blue sequential color scheme. Sequential, single-hue color schemes support a size k ranging from 3 to 9.

# d3.interpolateBlues(t) <>
# d3.schemeBlues[k]

Blues

Given a number t in the range [0,1], returns the corresponding color from the “Blues” sequential color scheme represented as an RGB string.

# d3.interpolateGreens(t) <>
# d3.schemeGreens[k]

Greens

Given a number t in the range [0,1], returns the corresponding color from the “Greens” sequential color scheme represented as an RGB string.

# d3.interpolateGreys(t) <>
# d3.schemeGreys[k]

Greys

Given a number t in the range [0,1], returns the corresponding color from the “Greys” sequential color scheme represented as an RGB string.

# d3.interpolateOranges(t) <>
# d3.schemeOranges[k]

Oranges

Given a number t in the range [0,1], returns the corresponding color from the “Oranges” sequential color scheme represented as an RGB string.

# d3.interpolatePurples(t) <>
# d3.schemePurples[k]

Purples

Given a number t in the range [0,1], returns the corresponding color from the “Purples” sequential color scheme represented as an RGB string.

# d3.interpolateReds(t) <>
# d3.schemeReds[k]

Reds

Given a number t in the range [0,1], returns the corresponding color from the “Reds” sequential color scheme represented as an RGB string.

Sequential (Multi-Hue)

Sequential, multi-hue color schemes are available as continuous interpolators (often used with d3.scaleSequential) and as discrete schemes (often used with d3.scaleOrdinal). Each discrete scheme, such as d3.schemeBuGn, is represented as an array of arrays of hexadecimal color strings. The kth element of this array contains the color scheme of size k; for example, d3.schemeBuGn[9] contains an array of nine strings representing the nine colors of the blue-green sequential color scheme. Sequential, multi-hue color schemes support a size k ranging from 3 to 9.

# d3.interpolateTurbo(t) <>

turbo

Given a number t in the range [0,1], returns the corresponding color from the “turbo” color scheme by Anton Mikhailov.

# d3.interpolateViridis(t) <>

viridis

Given a number t in the range [0,1], returns the corresponding color from the “viridis” perceptually-uniform color scheme designed by van der Walt, Smith and Firing for matplotlib, represented as an RGB string.

# d3.interpolateInferno(t) <>

inferno

Given a number t in the range [0,1], returns the corresponding color from the “inferno” perceptually-uniform color scheme designed by van der Walt and Smith for matplotlib, represented as an RGB string.

# d3.interpolateMagma(t) <>

magma

Given a number t in the range [0,1], returns the corresponding color from the “magma” perceptually-uniform color scheme designed by van der Walt and Smith for matplotlib, represented as an RGB string.

# d3.interpolatePlasma(t) <>

plasma

Given a number t in the range [0,1], returns the corresponding color from the “plasma” perceptually-uniform color scheme designed by van der Walt and Smith for matplotlib, represented as an RGB string.

# d3.interpolateCividis(t) <>

cividis

Given a number t in the range [0,1], returns the corresponding color from the “cividis” color vision deficiency-optimized color scheme designed by Nuñez, Anderton, and Renslow, represented as an RGB string.

# d3.interpolateWarm(t) <>

warm

Given a number t in the range [0,1], returns the corresponding color from a 180° rotation of Niccoli’s perceptual rainbow, represented as an RGB string.

# d3.interpolateCool(t) <>

cool

Given a number t in the range [0,1], returns the corresponding color from Niccoli’s perceptual rainbow, represented as an RGB string.

# d3.interpolateCubehelixDefault(t) <>

cubehelix

Given a number t in the range [0,1], returns the corresponding color from Green’s default Cubehelix represented as an RGB string.

# d3.interpolateBuGn(t) <>
# d3.schemeBuGn[k]

BuGn

Given a number t in the range [0,1], returns the corresponding color from the “BuGn” sequential color scheme represented as an RGB string.

# d3.interpolateBuPu(t) <>
# d3.schemeBuPu[k]

BuPu

Given a number t in the range [0,1], returns the corresponding color from the “BuPu” sequential color scheme represented as an RGB string.

# d3.interpolateGnBu(t) <>
# d3.schemeGnBu[k]

GnBu

Given a number t in the range [0,1], returns the corresponding color from the “GnBu” sequential color scheme represented as an RGB string.

# d3.interpolateOrRd(t) <>
# d3.schemeOrRd[k]

OrRd

Given a number t in the range [0,1], returns the corresponding color from the “OrRd” sequential color scheme represented as an RGB string.

# d3.interpolatePuBuGn(t) <>
# d3.schemePuBuGn[k]

PuBuGn

Given a number t in the range [0,1], returns the corresponding color from the “PuBuGn” sequential color scheme represented as an RGB string.

# d3.interpolatePuBu(t) <>
# d3.schemePuBu[k]

PuBu

Given a number t in the range [0,1], returns the corresponding color from the “PuBu” sequential color scheme represented as an RGB string.

# d3.interpolatePuRd(t) <>
# d3.schemePuRd[k]

PuRd

Given a number t in the range [0,1], returns the corresponding color from the “PuRd” sequential color scheme represented as an RGB string.

# d3.interpolateRdPu(t) <>
# d3.schemeRdPu[k]

RdPu

Given a number t in the range [0,1], returns the corresponding color from the “RdPu” sequential color scheme represented as an RGB string.

# d3.interpolateYlGnBu(t) <>
# d3.schemeYlGnBu[k]

YlGnBu

Given a number t in the range [0,1], returns the corresponding color from the “YlGnBu” sequential color scheme represented as an RGB string.

# d3.interpolateYlGn(t) <>
# d3.schemeYlGn[k]

YlGn

Given a number t in the range [0,1], returns the corresponding color from the “YlGn” sequential color scheme represented as an RGB string.

# d3.interpolateYlOrBr(t) <>
# d3.schemeYlOrBr[k]

YlOrBr

Given a number t in the range [0,1], returns the corresponding color from the “YlOrBr” sequential color scheme represented as an RGB string.

# d3.interpolateYlOrRd(t) <>
# d3.schemeYlOrRd[k]

YlOrRd

Given a number t in the range [0,1], returns the corresponding color from the “YlOrRd” sequential color scheme represented as an RGB string.

Cyclical

# d3.interpolateRainbow(t) <>

rainbow

Given a number t in the range [0,1], returns the corresponding color from d3.interpolateWarm scale from [0.0, 0.5] followed by the d3.interpolateCool scale from [0.5, 1.0], thus implementing the cyclical less-angry rainbow color scheme.

# d3.interpolateSinebow(t) <>

sinebow

Given a number t in the range [0,1], returns the corresponding color from the “sinebow” color scheme by Jim Bumgardner and Charlie Loyd.

More Repositories

1

d3

Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript
106,311
star
2

d3-shape

Graphical primitives for visualization, such as lines and areas.
JavaScript
2,458
star
3

d3-plugins

[DEPRECATED] A repository for sharing D3.js V3 plugins.
JavaScript
1,808
star
4

d3-force

Force-directed graph layout using velocity Verlet integration.
JavaScript
1,702
star
5

d3-scale

Encodings that map abstract data to visual representation.
JavaScript
1,567
star
6

d3-queue

Evaluate asynchronous tasks with configurable concurrency.
JavaScript
1,411
star
7

d3-hierarchy

2D layout algorithms for visualizing hierarchical data.
JavaScript
1,064
star
8

d3-geo-projection

Extended geographic projections for d3-geo.
JavaScript
1,058
star
9

d3-geo

Geographic projections, spherical shapes and spherical trigonometry.
JavaScript
988
star
10

d3-sankey

Visualize flow between nodes in a directed acyclic network.
JavaScript
763
star
11

d3-format

Format numbers for human consumption.
JavaScript
611
star
12

d3-delaunay

Compute the Voronoi diagram of a set of two-dimensional points.
JavaScript
606
star
13

d3-ease

Easing functions for smooth animation.
JavaScript
604
star
14

d3-selection

Transform the DOM by selecting elements and joining to data.
JavaScript
547
star
15

d3-zoom

Pan and zoom SVG, HTML or Canvas using mouse or touch input.
JavaScript
495
star
16

d3-contour

Compute contour polygons using marching squares.
JavaScript
487
star
17

d3-interpolate

Interpolate numbers, colors, strings, arrays, objects, whatever!
JavaScript
482
star
18

d3-array

Array manipulation, ordering, searching, summarizing, etc.
JavaScript
452
star
19

d3-dsv

A parser and formatter for delimiter-separated values, such as CSV and TSV.
JavaScript
416
star
20

d3-color

Color spaces! RGB, HSL, Cubehelix, CIELAB, and more.
JavaScript
389
star
21

d3-drag

Drag and drop SVG, HTML or Canvas using mouse or touch input.
JavaScript
328
star
22

d3-time-format

Parse and format times, inspired by strptime and strftime.
JavaScript
324
star
23

d3-voronoi

Compute the Voronoi diagram of a set of two-dimensional points.
JavaScript
250
star
24

d3-hexbin

Group two-dimensional points into hexagonal bins.
JavaScript
231
star
25

d3-time

A calculator for humanity’s peculiar conventions of time.
JavaScript
227
star
26

d3-quadtree

Two-dimensional recursive spatial subdivision.
JavaScript
225
star
27

d3-transition

Animated transitions for D3 selections.
JavaScript
219
star
28

d3-fetch

Convenient parsing for Fetch.
JavaScript
215
star
29

d3-axis

Human-readable reference marks for scales.
JavaScript
204
star
30

d3.github.com

The D3 website.
JavaScript
195
star
31

d3-path

Serialize Canvas path commands to SVG.
JavaScript
192
star
32

d3-timer

An efficient queue for managing thousands of concurrent animations.
JavaScript
159
star
33

d3-brush

Select a one- or two-dimensional region using the mouse or touch.
JavaScript
154
star
34

d3-3.x-api-reference

An archive of the D3 3.x API Reference.
153
star
35

d3-random

Generate random numbers from various distributions.
JavaScript
136
star
36

d3-chord

Visualizations relationships or network flow with a circular layout.
JavaScript
122
star
37

d3-tile

Compute the quadtree tiles to display in a rectangular viewport.
JavaScript
120
star
38

d3-collection

Handy data structures for elements keyed by string.
JavaScript
111
star
39

d3-request

A convenient alternative to XMLHttpRequest.
JavaScript
109
star
40

d3-geo-polygon

Clipping and geometric operations for spherical polygons.
JavaScript
102
star
41

d3-polygon

Geometric operations for two-dimensional polygons.
JavaScript
97
star
42

d3-require

A minimal, promise-based implementation to require asynchronous module definitions.
JavaScript
79
star
43

d3-selection-multi

Multi-value syntax for d3-selection and d3-transition.
JavaScript
75
star
44

d3-dispatch

Register named callbacks and call them with arguments.
JavaScript
75
star
45

versor

a home for Mike Bostock's versor.js
JavaScript
34
star
46

d3-bundler

DEPRECATED; use rollup/rollup.
JavaScript
34
star
47

d3-hsv

The HSV (Hue, Saturation, Value) color space.
JavaScript
26
star
48

d3-logo

D3 brand assets.
23
star
49

d3-cam16

A d3 implementation of the CIECAM16 color appearance model.
JavaScript
22
star
50

d3-hcg

The HCG (Hue, Chroma, Grayness) color space derived from the Munsell color system.
JavaScript
20
star
51

d3-scripts

Common scripts for D3 modules.
JavaScript
15
star
52

d3-hull

DEPRECATED; see d3-polygon’s hull function.
JavaScript
14
star
53

blur-benchmark

temporary benchmark for d3.blur implementations
JavaScript
2
star