Skip to content

Commit

Permalink
[getredash#1414] Add word frequency select to the Word Cloud visual…
Browse files Browse the repository at this point in the history
…ization
  • Loading branch information
mohamagdy committed Mar 29, 2019
1 parent 2b1cb50 commit 0dfd113
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
22 changes: 20 additions & 2 deletions client/app/visualizations/word-cloud/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -32,11 +42,19 @@ 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 = [];

const values = Object.keys(wordsHash).map(key => wordsHash[key]);
const maxValue = Math.max.apply(null, values);

Expand Down
6 changes: 6 additions & 0 deletions client/app/visualizations/word-cloud/word-cloud-editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@
<select ng-options="name for name in queryResult.getColumnNames()" ng-model="visualization.options.column" class="form-control"></select>
</div>
</div>
<div class="form-group">
<label class="col-lg-6">Word Cloud Frequency Column Name</label>
<div class="col-lg-6">
<select ng-options="name for name in [''].concat(queryResult.getColumnNames())" ng-model="visualization.options.frequency" class="form-control"></select>
</div>
</div>
</div>

0 comments on commit 0dfd113

Please sign in to comment.