Platform
Resources
Pricing
Sign in
Get started
John Clarke
Workspace
Fork
Published
By
John Clarke
Edited
Sep 21, 2018
Fork of
Working with Color
•
1 fork
Importers
Insert cell
Insert cell
Insert cell
Insert cell
d3
.
color
(
"#ff3399"
)
// hexadecimal RGB
Insert cell
d3
.
color
(
"hotpink"
)
// named RGB
Insert cell
d3
.
color
(
"hsl(330, 100%, 70.5%)"
)
// HSL
Insert cell
d3
.
color
(
"rgba(128, 0, 128, 0.2)"
)
// RGB with alpha (opacity)
Insert cell
Insert cell
Insert cell
d3
.
hcl
(
"#ff3399"
)
Insert cell
d3
.
hsl
(
"hotpink"
)
Insert cell
d3
.
lab
(
"hsl(330, 100%, 70.5%)"
)
Insert cell
d3
.
cubehelix
(
"rgba(128, 0, 128, 0.2)"
)
Insert cell
Insert cell
Insert cell
d3
.
rgb
(
255
,
51
,
153
)
Insert cell
d3
.
hcl
(
356.51
,
78.96
,
58.56
)
Insert cell
d3
.
lch
(
58.56
,
78.96
,
356.51
)
Insert cell
d3
.
cubehelix
(
318.7
,
1.2
,
0.48
)
Insert cell
Insert cell
Insert cell
d3
.
rgb
(
d3
.
hcl
(
356.51
,
78.96
,
58.56
)
)
Insert cell
d3
.
hcl
(
d3
.
rgb
(
"#ff3399"
)
)
Insert cell
Insert cell
Insert cell
d3
.
hcl
(
356.51
,
78.96
,
58.56
)
.
rgb
(
)
Insert cell
d3
.
rgb
(
"#ff3399"
)
.
rgb
(
)
// Returns itself!
Insert cell
Insert cell
Insert cell
d3
.
hcl
(
356.51
,
78.96
,
58.56
)
+
""
Insert cell
d3
.
hcl
(
356.51
,
78.96
,
58.56
,
0.2
)
+
""
Insert cell
d3
.
hcl
(
356.51
,
78.96
,
58.56
,
0.2
)
.
toString
(
)
Insert cell
d3
.
hcl
(
356.51
,
78.96
,
58.56
)
.
hex
(
)
Insert cell
Insert cell
Insert cell
d3
.
interpolateRgb
(
"red"
,
"blue"
)
(
0.5
)
Insert cell
Insert cell
d3
.
interpolateRgb
.
gamma
(
2.2
)
(
"red"
,
"blue"
)
(
0.5
)
Insert cell
Insert cell
d3
.
interpolateHsl
(
"red"
,
"blue"
)
(
0.5
)
Insert cell
Insert cell
d3
.
interpolateHslLong
(
"red"
,
"blue"
)
(
0.5
)
Insert cell
Insert cell
d3
.
interpolateLab
(
"red"
,
"blue"
)
(
0.5
)
Insert cell
Insert cell
d3
.
interpolate
(
{
foo
:
"red"
}
,
{
foo
:
"blue"
}
)
(
0.5
)
Insert cell
d3
.
interpolate
(
[
"red"
,
"red"
]
,
[
"green"
,
"blue"
]
)
(
0.5
)
Insert cell
Insert cell
Insert cell
d3
.
piecewise
(
d3
.
interpolateRgb
.
gamma
(
2.2
)
,
[
"red"
,
"green"
,
"blue"
]
)
(
0.5
)
Insert cell
Insert cell
Insert cell
d3
.
interpolateRgbBasis
(
[
"red"
,
"green"
,
"blue"
]
)
(
0.5
)
Insert cell
Insert cell
Insert cell
d3
.
scaleLinear
(
)
.
domain
(
[
0
,
0.5
,
1
]
)
.
range
(
[
"red"
,
"green"
,
"blue"
]
)
.
interpolate
(
d3
.
interpolateRgb
.
gamma
(
2.2
)
)
(
0.5
)
Insert cell
Insert cell
Insert cell
d3
.
interpolateSpectral
(
0.5
)
Insert cell
Insert cell
d3
.
interpolatePRGn
(
0.5
)
Insert cell
Insert cell
d3
.
interpolateViridis
(
0.5
)
Insert cell
Insert cell
d3
.
interpolateCubehelixDefault
(
0.5
)
Insert cell
Insert cell
d3
.
interpolateRainbow
(
0.5
)
Insert cell
Insert cell
Insert cell
d3
.
schemeSet1
Insert cell
Insert cell
d3
.
schemeCategory10
Insert cell
Insert cell
d3
.
schemeSpectral
[
7
]
Insert cell
Insert cell
d3
.
schemeSpectral
[
11
]
Insert cell
Insert cell
Insert cell
d3
.
quantize
(
d3
.
interpolateHcl
(
"#fafa6e"
,
"#2A4858"
)
,
10
)
Insert cell
Insert cell
d3
.
quantize
(
d3
.
interpolateHcl
(
"#f4e153"
,
"#362142"
)
,
10
)
Insert cell
Insert cell
d3
.
quantize
(
d3
.
interpolateHcl
(
"#60c96e"
,
"#4d4193"
)
,
10
)
Insert cell
Insert cell
d3
.
quantize
(
d3
.
interpolateHcl
(
"#d66000"
,
"#a9a9b4"
)
,
10
)
Insert cell
Insert cell
Insert cell
{
let
color
=
"pink"
;
color
=
darken
(
color
)
;
color
=
saturate
(
color
,
2
)
;
return
color
.
hex
(
)
;
}
Insert cell
function
darken
(
color
,
k
=
1
)
{
const
{
l
,
c
,
h
}
=
d3
.
lch
(
color
)
;
return
d3
.
lch
(
l
-
18
*
k
,
c
,
h
)
;
}
Insert cell
function
lighten
(
color
,
k
=
1
)
{
const
{
l
,
c
,
h
}
=
d3
.
lch
(
color
)
;
return
d3
.
lch
(
l
+
18
*
k
,
c
,
h
)
;
}
Insert cell
function
saturate
(
color
,
k
=
1
)
{
const
{
l
,
c
,
h
}
=
d3
.
lch
(
color
)
;
return
d3
.
lch
(
l
,
c
+
18
*
k
,
h
)
;
}
Insert cell
Insert cell
d3
.
rgb
(
258
,
0
,
0
)
.
displayable
(
)
Insert cell
d3
.
cubehelix
(
318.7
,
1.3
,
0.48
)
.
displayable
(
)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Compare fork
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
conversion
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
continuous
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
discrete
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
darken
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
lighten
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
saturate
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
swatch
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
swatches
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
ramp
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
d3
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML