diff --git a/client/app/visualizations/word-cloud/index.js b/client/app/visualizations/word-cloud/index.js index aa328b6a41..1c92df09ad 100644 --- a/client/app/visualizations/word-cloud/index.js +++ b/client/app/visualizations/word-cloud/index.js @@ -22,6 +22,16 @@ function findWordFrequencies(data, columnName) { return wordsHash; } +function extractWordFrequency(data, columnName, frequencyColumnName) { + const wordsHash = {}; + + data.forEach((row) => { + wordsHash[row[columnName]] = row[frequencyColumnName]; + }); + + return wordsHash; +} + function wordCloudRenderer() { return { restrict: 'E', @@ -32,13 +42,24 @@ function wordCloudRenderer() { const data = $scope.queryResult.getData(); let wordsHash = {}; - if ($scope.visualization.options.column) { - wordsHash = findWordFrequencies(data, $scope.visualization.options.column); + const columnName = $scope.visualization.options.column; + + if (columnName) { + if ($scope.visualization.options.frequency) { + const frequencyColumnName = $scope.visualization.options.frequency; + wordsHash = extractWordFrequency(data, columnName, frequencyColumnName); + } else { + wordsHash = findWordFrequencies(data, columnName); + } } const wordList = []; - each(wordsHash, (v, key) => { - wordList.push({ text: key, size: 10 + Math.pow(v, 2) }); + + const values = Object.keys(wordsHash).map(key => wordsHash[key]); + const maxValue = Math.max.apply(null, values); + + each(wordsHash, (value, key) => { + wordList.push({ text: key, size: 120 * value / maxValue }); }); const fill = d3.scale.category20(); diff --git a/client/app/visualizations/word-cloud/word-cloud-editor.html b/client/app/visualizations/word-cloud/word-cloud-editor.html index 91b4c3211f..64d7c853bb 100644 --- a/client/app/visualizations/word-cloud/word-cloud-editor.html +++ b/client/app/visualizations/word-cloud/word-cloud-editor.html @@ -5,4 +5,10 @@ +
+ +
+ +
+