Published
Edited
Apr 6, 2021
Importers
5 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
textColorLuminance = (bgColor) => d3Color.hsl(bgColor).l >= luminanceCutoff ? darkTextColor : lightTextColor
Insert cell
Insert cell
Insert cell
Insert cell
textColorRGB = bgColor => {
const c = d3Color.rgb(bgColor)
const yiq = (c.r * 299 + c.g * 587 + c.b * 114) / 1000;
return yiq >= yiqCutoff ? darkTextColor : lightTextColor;
}
Insert cell
Insert cell
colorRows = Array.from({ length: 15 }).map(() => Array.from({ length: 8 }).map(() => `#${Math.floor(Math.random()*16777215).toString(16).padStart(6, '0')}`))
Insert cell
generateTable = textColorFunction => html`<table>${colorRows.map(row => html`<tr>${row.map(color => html`<td style="width: ${cellWidth}px; height: ${cellHeight}px; background-color: ${color}; color: ${textColorFunction(color)}; text-align: center; padding-top: 8px">Hello!</td>`)}</tr>`)}</table>`
Insert cell
cellWidth = 100
Insert cell
cellHeight = 20
Insert cell
darkTextColor = '#24477B'
Insert cell
lightTextColor = 'white'
Insert cell
import { Range } from '@observablehq/inputs'
Insert cell
d3Color = require('d3-color')
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