beeswarm = {
const height = 300;
const width = 1000;
const data = dataA_long
const svg = d3.create("svg")
.attr("height", height)
.attr("width", width)
const max_val = d3.max(data, d => d.value)
const xScale = d3.scaleTime().domain(d3.extent(data, d => d.month)).range([0, width]).clamp(true)
const rScale = d3.scaleSqrt().domain([0, max_val]).range([0, 12])
const force = d3.forceSimulation(data)
.force('forceX', d3.forceX(d => xScale(d.month)).strength(1))
.force('forceY', d3.forceY(height/2).strength(0.1))
.force('collide', d3.forceCollide(d => rScale(d.value) + 0.75))
.stop();
const iterations = 100;
for (let i = 0; i < iterations; ++i) {
force.tick();
};
force.stop();
svg.selectAll("circle")
.data(data)
.join('circle')
.attr("cx", d => d.x)
.attr("cy", d => d.y)
.attr("r", d => rScale(d.value))
.style("fill", d => colorScale(d.category));
svg.selectAll('circle')
.on("mouseover", function(e,d) {
tooltip
.html(`<b>Term</b>: ${d.term}`);
let tooltipWidth = tooltip.node().offsetWidth;
let tooltipHeight = tooltip.node().offsetHeight;
tooltip
.style("left", e.pageX - tooltipWidth/2 +'px')
.style("top", e.pageY-tooltipHeight - 10+'px')
.style('visibility', 'visible');
})
.on("mousemove", function(e,d) {
let tooltipWidth = tooltip.node().offsetWidth;
let tooltipHeight = tooltip.node().offsetHeight;
tooltip
.style("left", e.pageX - tooltipWidth/2 +'px')
.style("top", e.pageY-tooltipHeight - 10+'px')
.style('visibility', 'visible');
})
.on("mouseout", function(e,d) {
tooltip
.style('visibility', 'hidden');
});
svg.append("g")
.call(d3.axisTop(xScale))
.style("transform", `translateY(${height*0.75}px`)
return svg.node();
}