Published
Edited
Sep 21, 2018
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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more