Published
Edited
Oct 27, 2020
2 stars
Insert cell
Insert cell
Insert cell
col1 = 'coral'
Insert cell
col2 = 'aquamarine'
Insert cell
minCol = '#eee'
Insert cell
nSteps = 4
Insert cell
blendMode = 'multiply'; // 'multiply', 'darken', 'lighten', 'screen', 'overlay', 'burn', 'dodge'
Insert cell
drawScale = {
// bivariate color settings
let scaleSettings = { col1, col2, minCol, nSteps, blendMode }

// Build the color scale
let bvScale = new BivariateColorscale(scaleSettings);
//let colors = bvScale.getScale();
let nScaleSteps = bvScale.getNumSteps();
console.log(nScaleSteps);

// Draw the scale (for demo purposes)
let w = 200;
let h = 200;
let svg = d3.select('#scale')
.html('')
.append('svg')
.attr('width', w)
.attr('height', h);

let rectMargin = 2;
let rectHeight = (h / nScaleSteps) - rectMargin;
let rectWidth = (w / nScaleSteps) - rectMargin;
// loop over each step in the scale, add rectangle at each
for (let i = 0; i < nScaleSteps; i++) {
for (let j = 0; j < nScaleSteps; j++) {
svg.append('rect')
.attr('x', i * (rectWidth + rectMargin))
.attr('y', j * (rectHeight + rectMargin))
.attr('width', rectWidth)
.attr('height', rectHeight)
.attr('fill', bvScale.getColorAtIdx(i,j));
}
}
}
Insert cell
Insert cell
_ = require('lodash');
Insert cell
chroma = require('chroma-js');
Insert cell
d3 = require("d3-selection", "d3-selection-multi")
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