One of the biggest difficulties I have with Observable (due to Javascript) is understanding how to pass values through nested functions… Here is an example:
I would like users to pick a color them and see the swatches that will be used for the amount of data they have.
Observable with this set up: Scales to Swatch Generator / kalmdown / Observable
The cell to pick a color from:
viewof intScale = Inputs.select(Object.keys(scales), {value: 'viridis', label: 'Internal locations color scheme'})
The interpolator using the scale:
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(80, 30, h)
}, internalLocations.length + 1))
Trying to use the scale directly. Expect 4 swatches.
swatches(scales[intScale],internalLocations)
Trying to use the scale through the interpolator. Expect same 4 swatches.
swatches(scales[intScale](internalLocations.map((d,i) => i)))
My imports:
import { scales } from '@makio135/give-me-colors'
import { select } from '@jashkenas/inputs'
import { ramp, swatches } from '@mbostock/working-with-color'
For a cells description it would be helpful if Observable could provide better info on the function it thinks it is returning, instead of just “ƒ(i)”
In this case, is it returning d3.interpolateViridis…no way to know.