abc = {
const height = 750;
const marginLeft = 175;
const marginTop = 40;
const rotation = 300;
const width = 600;
const data = [...final_data.get("R"), final_data.get("D")];
const svg = d3
.select(DOM.svg(width, height))
.attr("viewBox", `-${marginLeft} -${marginTop} ${width} ${height}`);
const tooltip = html`<div class="svg-tooltip">I'm the tooltip</div>`;
const container = html`<div>
<style>
.svg-tooltip {
position: absolute;
padding: 12px 6px;
background: #fff;
border: 1px solid #333;
pointer-events: none;
}
</style>
${tooltip}
${svg.node()}
</div>`;
const x = d3
.scaleBand()
.domain(age_groups)
.range([0, width - margin.left - margin.right]);
svg
.append("g")
.call(d3.axisTop(x))
.call((axis) =>
axis
.append("text")
.text("jgg")
.style("fill", "black")
.style("font-weight", "800")
.style("font-size", "10pt")
.style("text-anchor", "middle")
.style("position", "absolute")
.attr(
"transform",
`translate( ${(width - margin.left - margin.right) / 2}, ${-30})`
)
);
const y = d3
.scaleBand()
.domain(listOfStates(data))
.range([0, height - 70]);
const yAxis = d3.axisLeft(y);
svg
.append("g")
.call(d3.axisLeft(y))
.call(
(axis) =>
axis
.append("text")
.text("jkk")
.style("fill", "black")
.style("font-weight", "800")
.style("font-size", "10pt")
.attr(
"transform",
`translate( ${-120}, ${height / 3}) rotate(${-90})`
)
// .style("text-anchor", "end")
); //yaxis
const color = d3
.scaleSequential(d3.interpolatePuRd) //interpolateRdYlBu
.domain([0, d3.max(data, (d) => d["count"])]); //d3.max(data, (d) => d["count"])
const div = d3.select(container).append("div").classed("tooltip", true);
const mouseover = (d) => {
console.log("does this work?", tooltip);
tooltip.style("opacity", 1);
};
const mousemove = function (d) {
tooltip.html("The exact value of<br>this cell is: ");
// .style("left", d3.mouse(this)[0] + 70 + "px")
// .style("top", d3.mouse(this)[1] + "px");
};
function tooltipContents(datum) {
const { x, y } = datum;
return `x: ${x}, y: ${y}`;
}
const tip = svg
.selectAll("rect")
.data(data)
.enter()
.append("rect")
.attr("x", (d) => x(d.age))
.attr("y", (d) => y(d.state))
.attr("width", x.bandwidth())
.attr("height", y.bandwidth())
.attr("fill", (d) => color(d.count))
.call((rect) => rect.append("title").text((d) => `count : ${d?.count}`));
// .on("click", (evt, d) => {
// mutable obj = d;
// console.log(d);
// });
// .on("mouseover", async function (evt, d) {
// const [x, y] = d3.pointer(evt);
// d3.select(tooltip)
// .style("display", "block")
// .style("top", `${y}px`)
// .style("left", `${x}px`);
// tooltip.innerHTML ="";
// tooltip.appendChild(htl.html`<h3>${
// d.age
// }</h3><div>I'm fancy like this ${d.count}
// ${await vl
// .markBar()
// .encode(vl.y().fieldN("age"), vl.x().fieldQ("count"))
// .data(data.filter(e => e.state === d.state ))
// .render()}
// </div>`);
// return tooltip.style("visibility", "visible");
// })
// .on("mouseout", () => {
// // hide the tooltip
// })
// .on("mousemove", (event) => {
// // move the tooltip,
// // passing the native browser event
// });
return svg.node(); //container
}