chart = {
const svg = d3
.create("svg")
.attr("viewBox", [-14, 0, width + 28, height])
.style("margin", "0 -14px")
.style("background", "#000")
.style("color", "#fff")
.style("display", "block")
.attr("fill", "currentColor")
.attr("font-family", "sans-serif")
.attr("font-size", 10);
svg
.append("g")
.selectAll("circle")
.data(data)
.join("circle")
.attr("cx", d => x(d.color))
.attr("cy", d => y(d.absolute_magnitude))
.attr("fill", d => z(d.color))
.attr("r", 0.5);
svg
.append("g")
.attr("transform", `translate(${margin.left},0)`)
.call(
d3.axisLeft(
d3.scaleLog(y.domain().map(m => Math.pow(10, 4.83 - m)), y.range())
)
);
svg
.append("g")
.attr("transform", `translate(${width - margin.right},0)`)
.call(d3.axisRight(y).ticks(null, "+"));
svg
.append("g")
.attr("transform", `translate(0,${margin.top})`)
.call(d3.axisTop(d3.scaleLinear(x.domain().map(temperature), x.range())));
svg
.append("g")
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x).ticks(null, "+f"));
svg.selectAll(".domain").remove();
svg
.append("text")
.attr("dy", 12)
.attr("text-anchor", "middle")
.attr(
"transform",
`translate(${margin.left},${(margin.top + height - margin.bottom) /
2}) rotate(-90)`
)
.call(text =>
text
.append("tspan")
.attr("fill-opacity", 0.8)
.text("← darker\xa0")
)
.call(text =>
text
.append("tspan")
.attr("font-weight", "bold")
.text("\xa0Luminosity L☉\xa0")
)
.call(text =>
text
.append("tspan")
.attr("fill-opacity", 0.8)
.text("\xa0brighter →")
);
svg
.append("text")
.attr("dy", -6)
.attr("text-anchor", "middle")
.attr(
"transform",
`translate(${width - margin.right},${(margin.top +
height -
margin.bottom) /
2}) rotate(-90)`
)
.call(text =>
text
.append("tspan")
.attr("fill-opacity", 0.8)
.text("← darker\xa0")
)
.call(text =>
text
.append("tspan")
.attr("font-weight", "bold")
.text("\xa0Absolute magnitude M\xa0")
)
.call(text =>
text
.append("tspan")
.attr("fill-opacity", 0.8)
.text("\xa0brighter →")
);
svg
.append("text")
.attr("x", (margin.left + width - margin.right) / 2)
.attr("y", margin.top)
.attr("dy", 12)
.attr("text-anchor", "middle")
.call(text =>
text
.append("tspan")
.attr("fill-opacity", 0.8)
.text("← hotter\xa0")
)
.call(text =>
text
.append("tspan")
.attr("font-weight", "bold")
.text("\xa0Temperature K\xa0")
)
.call(text =>
text
.append("tspan")
.attr("fill-opacity", 0.8)
.text("\xa0colder →")
);
svg
.append("text")
.attr("x", (margin.left + width - margin.right) / 2)
.attr("y", height - margin.bottom)
.attr("dy", -6)
.attr("text-anchor", "middle")
.call(text =>
text
.append("tspan")
.attr("fill-opacity", 0.8)
.text("← blue\xa0")
)
.call(text =>
text
.append("tspan")
.attr("font-weight", "bold")
.text("\xa0Color B-V\xa0")
)
.call(text =>
text
.append("tspan")
.attr("fill-opacity", 0.8)
.text("\xa0red →")
);
return html`<div style="position: relative">${svg.node()}<div style="position: absolute; top: ${margin.top +
20}px; left: ${margin.left + 20}px; width: ${width -
margin.left -
margin.right -
40}px; height: ${height -
margin.top -
margin.bottom -
40}px;" class="cover"></div>`;
}