Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1414] Word Cloud Word Frequency Selection #3668

Closed
wants to merge 8 commits into from
29 changes: 25 additions & 4 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,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();
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>
Copy link

@truebit truebit May 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There will be an extra blank option when creating the word cloud. Demo like below:
图片

after saving it, this symptom will disappear.

</div>
</div>
</div>