Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// w[1] = Math.max(w[1]*scale, min_size);
wordList = wordList.map(w => [w[0], Math.max(getBaseLog(w[1], 6) * scale, minSize)]);
/*
//@albertcui implementation of scaling
max = max > 1000 ? 1000 : max;
var scale = 300/max;
//scale the words, min 10, max 400
word_list.forEach(function(w){
w[1] = Math.min(Math.max(Math.log(w[1])*w[1]*scale, 10), Math.min(Math.log(max)*400, 400));
});
*/
// sort the list to ensure most frequent words get displayed
wordList = wordList.sort((a, b) => b[1] - a[1]);
wordcloud(document.getElementById(cloudDomId), {
list: wordList,
backgroundColor: 'transparent',
color: 'random-light',
wait: 1,
});
}
canvasSettings.click = WordcloudCanvas.wordcloudClick;
WordCloud(document.getElementById('wordcloud-canvas'), canvasSettings);
} else if (!NavigatorCheck.isSmartphone() && !Session.get('isLandingPagePomodoroActive')) {
PomodoroTimer.setCloudShown(true);
this.setConfig();
canvasSettings.list = this.getContent();
if (Meteor.settings.public.welcome.fakeStatistics) {
this.setWordcloudTheme();
canvasSettings.color = function (word) {
for (let i = 0; i < canvasSettings.list.length; i++) {
if (word === canvasSettings.list[i][0]) {
return canvasSettings.list[i][3];
}
}
};
WordCloud(document.getElementById('wordcloud-canvas'), canvasSettings);
} else {
this.setWordcloudTheme();
canvasSettings.hover = WordcloudCanvas.wordcloudHover;
canvasSettings.click = WordcloudCanvas.wordcloudClick;
WordCloud(document.getElementById('wordcloud-canvas'), canvasSettings);
}
} else {
PomodoroTimer.setCloudShown(false);
}
} else {
setTimeout(function () {
WordcloudCanvas.draw();
}, 100);
}
}
doDrawWordCloud() {
if (!this.el) return;
const {words} = this.props;
const filteredWords = cleaned(words);
const list = _.toPairs(_.countBy(filteredWords));
const weightFactor = Math.max(20, (filteredWords.length / 300));
WordCloudLib(this.el, {
list,
weightFactor,
color,
shape: 'square',
click: this.onClick
});
}
React.useEffect(() => {
if (canvas.current === undefined || props.weights.length === 0) {
return;
}
const width = canvas.current.clientWidth || props.width || 800;
WordCloud2(canvas.current, {
list: weights,
gridSize: Math.round((8 * width) / 800),
weightFactor: (size: number) => {
return (Math.pow(size, 1.1) * width) / 800;
},
fontFamily: 'Times, serif',
color: (word: string, weight: number) => {
return weight >= 38 ? '#f02222' : '#c09292';
},
rotateRatio: 0.5,
rotationSteps: 2,
backgroundColor: '#ffe0e0'
});
}, [weights]);