diff --git a/src/core_plugins/tagcloud/public/__tests__/tag_cloud.js b/src/core_plugins/tagcloud/public/__tests__/tag_cloud.js index 2fe354421c4f5..2e3c942d71bf8 100644 --- a/src/core_plugins/tagcloud/public/__tests__/tag_cloud.js +++ b/src/core_plugins/tagcloud/public/__tests__/tag_cloud.js @@ -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', diff --git a/src/core_plugins/tagcloud/public/tag_cloud.js b/src/core_plugins/tagcloud/public/tag_cloud.js index b611de801e74b..380272ab3ccc4 100644 --- a/src/core_plugins/tagcloud/public/tag_cloud.js +++ b/src/core_plugins/tagcloud/public/tag_cloud.js @@ -94,7 +94,7 @@ class TagCloud extends EventEmitter { } setData(data) { - this._words = data.map(toWordTag); + this._words = data; this._invalidate(false); } @@ -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'); @@ -267,7 +267,7 @@ class TagCloud extends EventEmitter { return { refreshLayout: true, size: this._size.slice(), - words: this._words.map(toWordTag) + words: this._words }; } @@ -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 }; }) }; @@ -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; @@ -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 @@ -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) { diff --git a/src/core_plugins/tagcloud/public/tag_cloud_controller.js b/src/core_plugins/tagcloud/public/tag_cloud_controller.js index 0423914f26fd8..28ea70da770f1 100644 --- a/src/core_plugins/tagcloud/public/tag_cloud_controller.js +++ b/src/core_plugins/tagcloud/public/tag_cloud_controller.js @@ -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(); }); @@ -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 }; }); @@ -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; - } - - }); diff --git a/src/core_plugins/tagcloud/public/tag_cloud_vis.js b/src/core_plugins/tagcloud/public/tag_cloud_vis.js index 050b20a67e42b..df1975d701fa2 100644 --- a/src/core_plugins/tagcloud/public/tag_cloud_vis.js +++ b/src/core_plugins/tagcloud/public/tag_cloud_vis.js @@ -27,7 +27,7 @@ VisTypesRegistryProvider.register(function TagCloudProvider(Private) { }, template: tagCloudTemplate, }, - responseHandler: 'none', + responseHandler: 'tabify', editorConfig: { collections: { scales: ['linear', 'log', 'square root'],