viewof positions = [
{ position: 0.1, label: "Left" },
{ position: 0.3, label: "Center-Left" },
{ position: 0.5, label: "Center" },
{ position: 0.7, label: "Center-Right" },
{ position: 0.9, label: "Right" }
]
viewof colors = ["darkblue", "lightblue", "white", "lightcoral", "darkred"]
width = 800
height = 100
colorScale = d3.scaleLinear()
.domain(positions.map(d => d.position))
.range(colors)
svg = DOM.svg(width, height)
svg.selectAll("rect")
.data(positions)
.enter()
.append("rect")
.attr("x", d => d.position * width)
.attr("width", (1 / positions.length) * width)
.attr("height", height)
.attr("fill", d => colorScale(d.position))
svg.selectAll("text")
.data(positions)
.enter()
.append("text")
.attr("x", d => d.position * width + ((1 / positions.length) * width) / 2)
.attr("y", height / 2)
.attr("text-anchor", "middle")
.attr("dy", "0.35em")
.text(d => d.label)
svg