d3 - 将配色方案改为粉彩

d3 - Shift color scheme to pastels

我想使用其中一个 d3 color schemes 但制作它的粉彩版本。我不希望浅色太浅或深色太深

目前有:

intColor = d3.scaleOrdinal()
    .domain(locations.map(d => d.id))
    .range(d3.quantize(t => d3.interpolateSpectral(t * .8 + .1), locations.length))

但 t 函数(* .8 拉入右侧,+ .1 拉入左侧)不可控。想要一些我可以说在一定亮度范围内使用 d3.interpolateRdYlGn 的东西。

最后我把颜色分离成它的LCH成分,并给Colorness和Lightness赋予了特定的值

intColor = d3.scaleOrdinal()
    .domain(internalLocations.map(d => d.id))
    .range(d3.quantize(t => {
      const {l, c, h} = d3.lch(d3.interpolateSpectral()(t))
      return d3.lch(80, 30, h) // 80 is high lightness and 30 is low colorness.
    }, locations.length))