Published
Edited
Jun 8, 2020
Importers
Insert cell
Insert cell
Insert cell
function getKey (color, prec=2) {
const hsl = d3.cubehelix(color)
let rc = '', h, s, l
if(prec < 0){
const k = -prec
const ck = k/2
const jk = k/3
const li = Math.round(+hsl.l * 256)
l = Math.round(Math.round(+hsl.l * 256) / jk) * jk / 256
s = Math.round(Math.round(+hsl.s * 256) / ck) * ck / 256
h = Math.round(Math.round(+hsl.h / k)) * k
}
else{
l = hsl.l.toFixed(prec)
s = hsl.s.toFixed(prec)
h = hsl.h.toFixed(prec)
}
return d3.color(d3.cubehelix(h,s,l)).hex()
}
Insert cell
hueScale = d3.scaleLinear()
.domain([0,360])
.range([0,100])
Insert cell
function intern (c, prec=2) {
const key = getKey(c, prec)
const rgbHex = c.hex()
if(key in cindex){
cindex[key].push(rgbHex)
} else {
cindex[key] = [rgbHex]
}
return key
}
Insert cell
function clear () {
for (let member in cindex) delete cindex[member];
}
Insert cell
//cstrings = ['aqua', 'yellow', 'pink', 'orange']
Insert cell
//cstrings.forEach(cs => intern(d3.color(cs), 3))
Insert cell
//intern(d3.color('orange'))
Insert cell
d3.color(getKey(d3.color('lavender'), -4))
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