wordCloud = (data,word,url,frequency,maxSize,type) => {
const height = 500;
let svg = d3.select(html`<svg></svg>`)
.attr('width', width)
.attr('height', height);
const colors = d3.schemePaired
.slice(0,new Set(data.map(d=> d[type])).size-1)
const r = d3.scaleSqrt()
.domain([0, d3.max(data, d => d[frequency])])
.range([0, maxSize]);
const simulation = d3.forceSimulation(data)
.force("x", d3.forceX().strength(0.008))
.force("y", d3.forceY().strength(0.05))
.force("collide", d3.forceCollide().radius(d=> r(d[frequency]) + 0.5).iterations(2))
.force('center', d3.forceCenter(width/2, height/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 => colors[+d[type]])
.attr('fill-opacity', 0.2)
.attr('stroke', d => colors[+d[type]])
.attr('stroke-width', 1)
.attr('cursor','pointer')
.on("click", d => window.open(d.url) );
let text= bubble
.append('text');
const textLabels = text
.text( d => (d[word]))
.style('text-anchor','middle')
.attr("dominant-baseline", "central")
.attr("font-family", "Roboto, sans-serif")
.attr('fill', d => colors[+d[type]])
.attr('stroke',d => colors[+d[type]])
.attr('stroke-width', 1)
.attr('font-size', d => r(d[frequency]))
.attr('font-weight','normal')
.attr('cursor','pointer')
.on("click", d => window.open(d.url) );
gBubble = gBubble
.merge(bubble);
gBubble.call(drag(simulation));
simulation.on('tick', () => {
gBubble
.attr('transform', d => 'translate('+ (d.x) +','+ (d.y)+')');
})
return svg.node();
}