// Assume w, b in [0, 1] and h is an angle in degrees
// (CSS4 states that w, b outside [0, 1] are invalid)
// Returns RGB coordinates in [0, 255]
varcol=d3.hsl(h,1,0.5).rgb(),
s=w+b;
// Normalise whiteness and blackness
if(s>1){
w/=s;
b/=s;
s=1;
}
return[col.r,col.g,col.b].map(x=>x*(1-s)+w*255);
}
functionrgb2hwb(r,g,b){
// Essentially an inverse to the hwb2rgb function defined above
return[d3.hsl(d3.rgb(r,g,b)).h,
Math.min(r,g,b)/255,
1-Math.max(r,g,b)/255];
}
rgb2hwb(...hwb2rgb(hue,whiteness,blackness))
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.