Platform
Solutions
Resources
Pricing
Sign in
Sign up
kalmdown
Learning...
Workspace
Fork
Published
By
kalmdown
Edited
Oct 14, 2021
Insert cell
#
Scales to Swatch Generator
Insert cell
things
=
[
'one'
,
'two'
,
'three'
,
'four'
,
'five'
,
'six'
]
Insert cell
viewof
counter
=
Inputs
.
button
(
[
[
"Increment"
,
value
=>
value
+
1
]
,
[
"Decrement"
,
value
=>
value
-
1
]
,
[
"Reset"
,
value
=>
0
]
]
,
{
value
:
0
,
label
:
"Counter"
}
)
Insert cell
internalLocations
=
[
...
Array
(
counter
)
.
keys
(
)
]
Insert cell
viewof
intScale
=
Inputs
.
select
(
Object
.
keys
(
scales
)
,
{
value
:
'viridis'
,
label
:
'Internal locations color scheme'
}
)
Insert cell
intColor
=
d3
.
scaleOrdinal
(
)
.
domain
(
internalLocations
.
map
(
d
=>
d
.
id
)
)
.
range
(
d3
.
quantize
(
t
=>
{
const
{
l
,
c
,
h
}
=
d3
.
lch
(
scales
[
intScale
]
(
t
)
)
return
d3
.
lch
(
l
,
c
,
h
)
// Usually manipulate these to get pastels...leaving alone to debug why they are in different order.
}
,
internalLocations
.
length
+
1
)
)
Insert cell
swatches
(
d3
.
quantize
(
intColor
,
internalLocations
.
length
)
)
Insert cell
swatches
(
d3
.
quantize
(
scales
[
intScale
]
,
internalLocations
.
length
)
)
Insert cell
// WRONG - swatches([intColor(internalLocations.map((d, i) => i))])
Insert cell
// WRONG - swatches(scales[intScale](internalLocations.map((d,i) => i)))
Insert cell
import
{
scales
}
from
'@makio135/give-me-colors'
Insert cell
import
{
select
}
from
'@jashkenas/inputs'
Insert cell
import
{
ramp
,
swatches
}
from
'@mbostock/working-with-color'
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.
Try it for free
Learn more
Fork
View
Export
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
things
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
counter
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
internalLocations
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
intScale
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
intColor
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
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
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML