Public
Edited
Apr 9, 2024
6 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
unbalanceColorRampStretch = (divVal, colorRampBalanced) =>
divVal==0? t=>colorRampBalanced(0.5+t*0.5) :
divVal==1? t=>colorRampBalanced(t*0.5) :
(t) =>
t < divVal
? colorRampBalanced(0.5*t/divVal)
: colorRampBalanced((0.5 * t + 0.5-divVal) / (1-divVal))
Insert cell
Insert cell
unbalanceColorRampPrune = (divVal, colorRampBalanced) =>
divVal >0.5? t=>colorRampBalanced(0.5*t/divVal):
t=>colorRampBalanced((0.5*t+0.5-divVal)/(1-divVal))
Insert cell
Insert cell
colRU = (type=="stretch" ? unbalanceColorRampStretch: unbalanceColorRampPrune)(
divVal,
colR
)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
dicopal.getPalettes({ name: "blues" })[0].type
Insert cell
Insert cell
Insert cell
function pickTextColorBasedOnBgColor(bgColor) {
let lightColor = "white";
let darkColor = "black";
var color = bgColor.charAt(0) === "#" ? bgColor.substring(1, 7) : bgColor;
var r = parseInt(color.substring(0, 2), 16); // hexToR
var g = parseInt(color.substring(2, 4), 16); // hexToG
var b = parseInt(color.substring(4, 6), 16); // hexToB
return r * 0.299 + g * 0.587 + b * 0.114 > 186 ? darkColor : lightColor;
}
Insert cell
dicopal = require("dicopal")
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