{
const svg = d3
.create("svg")
.attr("width", width)
.attr("height", height)
.style("overflow", "visible");
const container = html`<div>
<style>.tooltip {
font: sans-serif 12pt;
background: #eeeeeeee;
pointer-events: none;
border-radius: 2px;
padding: 5px;
position: absolute;
top: 0px;
left: 0px;
z-index: 1;
}</style>
<div class="tooltip"></div>
${svg.node()}
</div>`
const g = svg
.append("g")
.attr("transform", `translate(${margin.top}, ${margin.right})`);
g.append("g")
.call(d3.axisBottom(x))
.attr("transform", `translate(0, ${iheight})`);
g.append("g").call(d3.axisLeft(y));
const gPoints = g.append("g").attr("class", "gPoints");
const tooltip = d3.select(container).select(".tooltip");
gPoints
.selectAll("circle")
.data(data)
.join("circle")
.attr("cx", (d) => x(d[xAttr]))
.attr("cy", (d) => y(d[yAttr]))
.attr("fill", "steelblue")
.attr("r", 3)
.on("mouseenter", (evt, d) => {
const [mx, my] = d3.pointer(evt);
const tooltipText = `
<strong>${xAttr}</strong>: ${d[xAttr]}
<br>
<strong>${yAttr}</strong>: ${d[yAttr]}`;
tooltip
.style("top", `${my}px`)
.style("left", `${mx}px`)
.html(tooltipText);
})
.on("mouseout", () => tooltip.text());
return container;
}