-
Notifications
You must be signed in to change notification settings - Fork 35
/
create_word_cloud.js
52 lines (38 loc) · 1.46 KB
/
create_word_cloud.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function processWordClouds() {
$( ".smartconnect_wordcloud" ).each(function() {
if ($(this).attr("data-processed")) return;
console.log('Setting wordclouds for '+$(this).attr("data-userid"));
var cloud_dom_element = $(this).get(0);
var relevantTermsRaw = $(this).attr("data-relevantterms");
if (!relevantTermsRaw)
return;
var relevantTerms = relevantTermsRaw.split(',');
var tags = [];
relevantTerms.slice(0,50).forEach(function(term) {
splittedTerm = term.split('|');
tags.push([splittedTerm[0],parseInt(splittedTerm[1])]);
});
// Adjusting word size according to card size
wordsSizeFactor = ($(this).outerWidth() > 400 ? 3.0 : 5.0)
var tags_list = tags.map(function(word) { return [word[0], Math.round(word[1]/wordsSizeFactor)]; })
WordCloud(cloud_dom_element, {
gridSize: 12,
weightFactor: 2,
rotateRatio: 0.5,
list : tags_list,
wait: 10
});
$(this).attr("data-processed","true");
var clicked = function(ev) {
if (ev.target.nodeName === "SPAN") {
var tag = ev.target.textContent;
window.location.href = "/"+tag.replace(' ','+').toLowerCase();
}
}
cloud_dom_element.addEventListener("click", clicked);
});
}
$( window ).load(function() {
processWordClouds();
});
processWordClouds();