wordCloud = (data, word, frequency, maxSize, xAxis) => {
if (xAxis === undefined) {
data.map(d => (d.xAxis = 0));
}
const height = 400;
const margin = {
t: 0,
l: 50,
r: 20,
b: 0
};
const padding = 2;
const time = d3.set(bubbleData.map(d => d['timeFrame'])).values();
let x = d3
.scalePoint()
.domain(time)
.range([margin.l, width - margin.l - margin.r]);
let svg = d3
.select(html`<svg></svg>`)
.attr('width', width)
.attr('height', height);
const xaxis = svg
.append("g")
.attr("transform", `translate(0,${height - 50})`)
.call(d3.axisBottom(x))
.attr('font-family', 'Roboto Mono')
.attr('font-size', '12px')
.attr('font-weight', 'normal')
const colorScale = d3.scaleOrdinal(d3.schemeAccent);
const luminance = 50;
const textColor = d3
.scaleQuantile()
.range(["#fff", "#000"])
.domain([0, luminance, 100]);
const r = d3
.scaleSqrt()
.domain([0, d3.max(data, d => d[frequency])])
.range([0, maxSize]);
const simulation = d3
.forceSimulation(data)
.force("x", d3.forceX(d => x(d[xAxis])).strength(1))
.force("y", d3.forceY(height / 2).strength(0.2))
.force(
"collide",
d3
.forceCollide()
.radius(d => r(d[frequency]) + padding)
.iterations(10)
)
.alpha(0.2);
let gBubble = svg.selectAll('gBubble').data(data);
gBubble.exit().remove();
let bubble = gBubble
.enter()
.append('g')
.classed('gBubble', true)
.attr('id', d => d[word]);
bubble
.append('circle')
.attr('r', d => r(d[frequency]))
.attr('fill', d => colorScale(d[word]))
.attr('fill-opacity', 0.8)
const textLabels = bubble
.append('text')
.text(d => d[word])
.style('text-anchor', 'middle')
.attr("dominant-baseline", "central")
.attr('font-family', 'Roboto Mono')
.attr('font-size', '12px')
.attr('font-weight', 'normal')
.style('stroke', 'white')
.style('stroke-width', 1);
const textBck = bubble
.append('text')
.text(d => d[word])
.style('text-anchor', 'middle')
.attr("dominant-baseline", "central")
.attr('font-family', 'Roboto Mono')
.attr('font-size', '12px')
.attr('font-weight', 'normal');
gBubble = gBubble.merge(bubble);
gBubble.call(drag(simulation));
simulation.nodes(data).on('tick', () => {
gBubble.attr('transform', d => 'translate(' + d.x + ',' + d.y + ')');
});
return Object.assign(svg.node());
}