chartOnly = {
const id = DOM.uid("chart").id;
const svg = d3
.create("svg")
.attr("class", id)
.attr("viewBox", [0, 0, width, height])
.call((svg) => svg.append("defs").html(fonts(`.${id}`)));
const g = svg.append("g").attr("text-anchor", "middle");
let text = g.selectAll("text");
const tooltip = new Tooltip();
svg.append(() => tooltip.node);
const t = svg.transition().duration(800);
const root = pack(
d3
.hierarchy({
children: data.sort((a, b) => b[selected_value] - a[selected_value])
})
.sum((d) => d[selected_value])
);
const thresholds = [0.005, 0.025, 0.05, 0.1, 0.8].map((d) =>
Math.floor(d * d3.max(data, (d) => d[selected_value]))
);
const colour = d3.scaleThreshold().domain(thresholds).range(colourScheme);
// enter
// .append("circle")
// .attr("cx", (d) => d.x)
// .attr("cy", (d) => d.y)
// .attr("r", (d) => d.r)
// .attr("fill", (d) => colourSchemeZdc(d))
// // (update) =>
// // update.call((update) =>
// // update
// // .transition(t)
// // .attr("cx", (d) => d.x)
// // .attr("cy", (d) => d.y)
// // .attr("r", (d) => d.r)
// // .attr("fill", (d) => colourSchemeZdc(d))
// // ),
// // (exit) => exit.remove()
// );
let circles = g
.selectAll("circle")
.data(root.leaves(), (d) => d.data.key)
.join("circle")
.attr("cx", (d) => d.x)
.attr("cy", (d) => d.y)
.attr("r", (d) => d.r)
.attr("fill", (d) => colourSchemeZdc(d));
// .on("mouseout", () => tooltip.hide())
// .on("mouseover", (d) => tooltip.show(d.data.key, d))
// .on("mousemove", function () {
// let [xm, ym] = d3.clientPoint(this.closest("svg"), d3.event);
// if (navigator.userAgent.includes("Firefox")) {
// xm = d3.select(this).attr("cx");
// ym = d3.select(this).attr("cy");
// }
// xm += 10;
// if (xm + tooltip.width > width) xm -= tooltip.width + 20;
// if (ym + tooltip.height > height - margin.bottom)
// ym = height - margin.bottom - tooltip.height - 10;
// tooltip.position(xm, ym);
// });
// text = text
// .data(root.leaves(), (d) => d.data.key)
// .join(
// (enter) =>
// enter
// .append("text")
// .attr("transform", (d) => `translate(${d.x}, ${d.y})`)
// // (update) =>
// // update.call((update) =>
// // update
// // .transition(t)
// // .attr("transform", (d) => `translate(${d.x}, ${d.y})`)
// // ),
// // (exit) => exit.remove()
// );
// text
// .style("fill", (d) => {
// const bgColor = colourSchemeZdc(d);
// return pickTextColorBasedOnBackground(bgColor);
// })
// .selectAll("tspan")
// .data((d) => formatBubbleText(d))
// .join("tspan")
// .attr("x", 0)
// .attr("y", (d, i, nodes) =>
// i === nodes.length - 1
// ? `${i - nodes.length / 2 + 1.1}em`
// : `${i - nodes.length / 2 + 0.8}em`
// )
// .attr("fill-opacity", (d, i, nodes) =>
// i === nodes.length - 1 ? 0.7 : null
// )
// .style("font", (d, i, nodes) =>
// i === nodes.length - 1
// ? "14px var(--trase-mono)"
// : "bold 18px var(--trase-sans-serif)"
// )
// .style("letter-spacing", (d, i, nodes) =>
// i === nodes.length - 1 ? "0.03em" : null
// )
// .text((d) => d)
// .style("pointer-events", "none");
text = g
.selectAll("text")
.data(root.leaves(), (d) => d.data.key)
.join("text")
.attr("transform", (d) => `translate(${d.x}, ${d.y})`)
.style("fill", (d) => {
const bgColor = colourSchemeZdc(d);
return pickTextColorBasedOnBackground(bgColor);
})
.selectAll("tspan")
.data((d) => formatBubbleText(d))
.join("tspan")
.attr("x", 0)
.attr("y", (d, i, nodes) =>
i === nodes.length - 1
? `${i - nodes.length / 2 + 1.1}em`
: `${i - nodes.length / 2 + 0.8}em`
)
.attr("fill-opacity", (d, i, nodes) =>
i === nodes.length - 1 ? 0.7 : null
)
.style("font", (d, i, nodes) =>
i === nodes.length - 1
? "14px var(--trase-mono)"
: "bold 18px var(--trase-sans-serif)"
)
.style("letter-spacing", (d, i, nodes) =>
i === nodes.length - 1 ? "0.03em" : null
)
.text((d) => d)
.style("pointer-events", "none");
// circles
// .on("mouseout", () => tooltip.hide())
// .on("mouseover", (d) => tooltip.show(d.data.key, d))
// .on("mousemove", function () {
// let [xm, ym] = d3.clientPoint(this.closest("svg"), d3.event);
// if (navigator.userAgent.includes("Firefox")) {
// xm = d3.select(this).attr("cx");
// ym = d3.select(this).attr("cy");
// }
// xm += 10;
// if (xm + tooltip.width > width) xm -= tooltip.width + 20;
// if (ym + tooltip.height > height - margin.bottom)
// ym = height - margin.bottom - tooltip.height - 10;
// tooltip.position(xm, ym);
// });
svg.append("g").call(annotate);
circles.call(hover, svg, selected_value);
return svg.node();
}