Published
Edited
Dec 13, 2020
4 stars
Insert cell
Insert cell
Insert cell
Insert cell
ramp(d3.interpolateViridis)
Insert cell
ramp(chroma.scale('viridis').mode('hcl'))
Insert cell
chroma.scale('viridis').colors(15)
Insert cell
d3.quantize(d3.scaleLinear().range(threeViridisColors).domain([0, 0.5, 1]).interpolate(d3.interpolateHcl), 5)
Insert cell
Insert cell
ramp(d3.scaleLinear().range(threeViridisColors).domain([0, 0.5, 1]).interpolate(d3.interpolateHcl), viridisCount)
Insert cell
ramp(d3.scaleLinear().range(viridis).domain(d3.range(256).map(n => n/256)).interpolate(d3.interpolateHcl), viridisCount)
Insert cell
ramp(d3.interpolateViridis, viridisCount)
Insert cell
Insert cell
Insert cell
Insert cell
ramp(d3.scaleLinear().range(['red', 'yellow', 'green']).domain([0, 0.5, 1]).interpolate(d3.interpolateHcl))
Insert cell
ramp(chroma.bezier(['red', 'blue', 'purple', 'green']).scale())
Insert cell
chroma.bezier(['orange', 'green', 'purple', 'darkblue']).scale().correctLightness().colors(5)
Insert cell
ramp(d3.interpolateHcl('blue', 'green'))
Insert cell
md`-------------
#### Comparing HCL and RGB interpolation

In general HCL interpolation will render a more natural and balanced color scale`
Insert cell
ramp(d3.interpolateRgb('pink', 'darkblue'))
Insert cell
ramp(d3.interpolateHsl('pink', 'darkblue'))
Insert cell
ramp(d3.interpolateHcl('pink', 'darkblue'))
Insert cell
d3.rgb("pink") // d3.hsl("pink") // d3.hcl("pink")
Insert cell
d3.hcl("yellow")
Insert cell
ramp(d3.interpolateHclLong("#94FD05", "#1E2E53"))
Insert cell
d3.hcl("#212A4D")
Insert cell
d3.hcl(d3.interpolateHclLong("#94FD05", "#1E2E53")(1))
Insert cell
Insert cell
ramp(chroma.scale(['yellow', 'purple']).mode('hcl'))
Insert cell
Insert cell
ramp(chroma.bezier(['yellow', 'red', 'purple']).scale().correctLightness())
Insert cell
Insert cell
Insert cell
ramp(d3.interpolateBlues, bluesCount)
Insert cell
ramp(function(ratio){return blues[ratio * (bluesCount-1)];}, bluesCount)
Insert cell
blues = d3.schemeBlues[bluesCount]
Insert cell
Insert cell
doInterpolate(d3.interpolateBlues, bluesCount)
Insert cell
doInterpolate = function(scale, n){
const arr = [];
for (let i = 0; i < n; ++i) {
arr.push(d3.color(scale(i / (n - 1))).hex());
}
return arr;
};
Insert cell
d3.hcl('steelblue')
Insert cell
d3.hcl('steelblue').darker()
Insert cell
Insert cell
hclInputs = [[0,80,60],
[58,73,60],
[120,80,60],
[174,51,64],
[240,79,60],
[300,80,60]

];
Insert cell
(hclInputs.map(c => chroma.hcl(...c).hex())).toString()
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.
Learn more