Platform
Resources
Pricing
Sign in
Get started
Ville Saarinen
Staff engineer at Oura, co-founder at @lucified
Workspace
Fork
Published
By
Ville Saarinen
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.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
luminanceCutoff
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
textColorLuminance
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
yiqCutoff
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
textColorRGB
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
colorRows
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
generateTable
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
cellWidth
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
cellHeight
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
darkTextColor
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
lightTextColor
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
d3Color
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML