Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/core_plugins/tagcloud/public/__tests__/tag_cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ describe('tag cloud tests', function () {
const midValue = (minValue + maxValue) / 2;
const baseTest = {
data: [
{ text: 'foo', value: minValue },
{ text: 'bar', value: midValue },
{ text: 'foobar', value: maxValue },
{ rawText: 'foo', displayText: 'foo', value: minValue },
{ rawText: 'bar', displayText: 'bar', value: midValue },
{ rawText: 'foobar', displayText: 'foobar', value: maxValue },
],
options: {
orientation: 'single',
Expand Down
25 changes: 9 additions & 16 deletions src/core_plugins/tagcloud/public/tag_cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class TagCloud extends EventEmitter {
}

setData(data) {
this._words = data.map(toWordTag);
this._words = data;
this._invalidate(false);
}

Expand Down Expand Up @@ -206,7 +206,7 @@ class TagCloud extends EventEmitter {
const self = this;
enteringTags.on({
click: function (event) {
self.emit('select', event.text);
self.emit('select', event.rawText);
},
mouseover: function () {
d3.select(this).style('cursor', 'pointer');
Expand Down Expand Up @@ -267,7 +267,7 @@ class TagCloud extends EventEmitter {
return {
refreshLayout: true,
size: this._size.slice(),
words: this._words.map(toWordTag)
words: this._words
};
}

Expand All @@ -281,7 +281,8 @@ class TagCloud extends EventEmitter {
y: tag.y,
rotate: tag.rotate,
size: tag.size,
text: tag.text
rawText: tag.text,
displayText: tag.displayText
};
})
};
Expand Down Expand Up @@ -315,7 +316,7 @@ class TagCloud extends EventEmitter {
tagCloudLayoutGenerator.random(seed);
tagCloudLayoutGenerator.spiral(this._spiral);
tagCloudLayoutGenerator.words(job.words);
tagCloudLayoutGenerator.text(getText);
tagCloudLayoutGenerator.text(getDisplayText);
tagCloudLayoutGenerator.timeInterval(this._timeInterval);

this._layoutIsUpdating = true;
Expand All @@ -337,7 +338,8 @@ class TagCloud extends EventEmitter {
const debug = {};
debug.positions = this._completedJob ? this._completedJob.words.map(tag => {
return {
text: tag.text,
displayText: tag.displayText,
rawText: tag.text,
x: tag.x,
y: tag.y,
rotate: tag.rotate
Expand All @@ -358,17 +360,8 @@ function seed() {
return 0.5;//constant seed (not random) to ensure constant layouts for identical data
}

function toWordTag(word) {
return {
displayText: word.displayText ? word.displayText : word.text,
text: word.text,
value: word.value
};
}


function getText(word) {
return word.text;
return word.rawText;
}

function getDisplayText(word) {
Expand Down
51 changes: 14 additions & 37 deletions src/core_plugins/tagcloud/public/tag_cloud_controller.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import _ from 'lodash';
import { uiModules } from 'ui/modules';
import TagCloud from 'plugins/tagcloud/tag_cloud';
import AggConfigResult from 'ui/vis/agg_config_result';
import { FilterBarClickHandlerProvider } from 'ui/filter_bar/filter_bar_click_handler';

const module = uiModules.get('kibana/tagcloud', ['kibana']);
module.controller('KbnTagCloudController', function ($scope, $element, Private, getAppState) {
module.controller('KbnTagCloudController', function ($scope, $element) {

const containerNode = $element[0];
const filterBarClickHandler = Private(FilterBarClickHandlerProvider);
const maxTagCount = 200;
let truncated = false;
let bucketAgg;

const tagCloud = new TagCloud(containerNode);
tagCloud.on('select', (event) => {
const appState = getAppState();
const clickHandler = filterBarClickHandler(appState);
const aggs = $scope.vis.getAggConfig().getResponseAggs();
const aggConfigResult = new AggConfigResult(aggs[0], false, event, event);
clickHandler({ point: { aggConfigResult: aggConfigResult } });
if (!bucketAgg) return;
const aggConfigResult = new AggConfigResult(bucketAgg, false, event, event);
$scope.vis.API.events.filter({ point: { aggConfigResult: aggConfigResult } });
$scope.$apply();
});

Expand Down Expand Up @@ -48,28 +44,22 @@ module.controller('KbnTagCloudController', function ($scope, $element, Private,
$scope.renderComplete();
});

$scope.$watch('esResponse', function (response) {
$scope.$watch('esResponse', async function (response) {

if (!response) {
if (!response || !response.tables.length) {
tagCloud.setData([]);
return;
}

const bucketsAgg = _.first($scope.vis.getAggConfig().bySchemaName.segment);
const tagsAggId = _.get(bucketsAgg, 'id');
if (!tagsAggId || !response.aggregations) {
tagCloud.setData([]);
return;
}

const metricsAgg = _.first($scope.vis.getAggConfig().bySchemaName.metric);
const buckets = response.aggregations[tagsAggId].buckets;
const data = response.tables[0];
bucketAgg = data.columns[0].aggConfig;

const tags = buckets.map((bucket) => {
const tags = data.rows.map(row => {
const [tag, count] = row;
return {
displayText: bucketsAgg.fieldFormatter()(bucket.key),
text: bucket.key,
value: getValue(metricsAgg, bucket)
displayText: bucketAgg ? bucketAgg.fieldFormatter()(tag) : tag,
rawText: tag,
value: count
};
});

Expand All @@ -91,17 +81,4 @@ module.controller('KbnTagCloudController', function ($scope, $element, Private,
tagCloud.resize();
});

function getValue(metricsAgg, bucket) {
let size = metricsAgg.getValue(bucket);
if (typeof size !== 'number' || isNaN(size)) {
try {
size = bucket[1].values[0].value;//lift out first value (e.g. median aggregations return as array)
} catch (e) {
size = 1;//punt
}
}
return size;
}


});
2 changes: 1 addition & 1 deletion src/core_plugins/tagcloud/public/tag_cloud_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ VisTypesRegistryProvider.register(function TagCloudProvider(Private) {
},
template: tagCloudTemplate,
},
responseHandler: 'none',
responseHandler: 'tabify',
editorConfig: {
collections: {
scales: ['linear', 'log', 'square root'],
Expand Down