Published
Edited
Mar 25, 2021
1 fork
3 stars
Insert cell
Insert cell
Insert cell
viewof view = vl.markSquare({size: 4, opacity: 1})
.data(vl.data().name('colors')) // empty named dataset, we will populate below!
.encode(
vl.x().fieldQ('0').scale({domain: [-100, 100]}).title('a*'),
vl.y().fieldQ('1').scale({domain: [-120, 100]}).title('b*'),
vl.color().fieldN('2').scale(null)
)
.width(400).height(440)
.render()
Insert cell
// update view data when backing colors update
view.data('colors', colors).runAsync(), md`${colors.length} colors!`
Insert cell
colors = {
const inGamut = v => (0 <= v && v <= 255);
const data = [];

// generate full grid of a-b coordinates
d3.cross(d3.range(-100, 101, 1), d3.range(-120, 101, 1))
.forEach(([a, b]) => {
// generate LAB color, keep those within RGB gamut
const c = d3.rgb(d3.lab(L, a, b));
if (inGamut(c.r) && inGamut(c.g) && inGamut(c.b)) {
data.push([a, b, c + ''])
}
});

return data;
}
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