Accepted answer

Define your scale's domain with your leaves' parent nodes:

color = d3.scaleOrdinal()
.domain(treemap(data).leaves().map(d => {return}))

And fill your leaf nodes with the corresponding gradient of color from the range, indexed by data value, applied to the opacity attribute:

.attr("fill", d => { return color( })
.attr("fill-opacity", d => { 
        let min = d3.min(root.leaves().map(leaf =>
        let max = d3.max(root.leaves().map(leaf =>
        return (  

You get only 3 colors, because you have only 3 parent nodes, but the colors correspond to the those in the docs

See example

EDITED per comment

Related Query

More Query from same tag