From 7f7be3ce0cd97421ee832cbdae39b8c1c783b051 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Wed, 25 Nov 2015 15:19:25 -0800 Subject: [PATCH 01/15] init commit. Added inline controller to the visualize directive to exclude metric vis from showing no results. The metric vis should fall through to its own controller. --- src/plugins/metric_vis/public/metric_vis.html | 8 ++++---- src/ui/public/visualize/visualize.html | 4 ++-- src/ui/public/visualize/visualize.js | 13 +++++++++++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/plugins/metric_vis/public/metric_vis.html b/src/plugins/metric_vis/public/metric_vis.html index ef30d0404d8c1..c1d9150b679a2 100644 --- a/src/plugins/metric_vis/public/metric_vis.html +++ b/src/plugins/metric_vis/public/metric_vis.html @@ -1,6 +1,6 @@
-
-
{{metric.value}}
-
{{metric.label}}
-
+
+
{{metric.value}}
+
{{metric.label}}
+
diff --git a/src/ui/public/visualize/visualize.html b/src/ui/public/visualize/visualize.html index 6b105e5c8fab9..3f175945c0583 100644 --- a/src/ui/public/visualize/visualize.html +++ b/src/ui/public/visualize/visualize.html @@ -1,4 +1,4 @@ -
@@ -7,7 +7,7 @@

No results found

-
diff --git a/src/ui/public/visualize/visualize.js b/src/ui/public/visualize/visualize.js index 10d9b0dfd01a1..354d3cc998c97 100644 --- a/src/ui/public/visualize/visualize.js +++ b/src/ui/public/visualize/visualize.js @@ -24,6 +24,19 @@ define(function (require) { esResp: '=?', }, template: require('ui/visualize/visualize.html'), + controller: function ($scope) { + // Show no results message when hasZeroHits is true and it requires search + $scope.showNoResultsMessage = function (hasZeroHits) { + var requiresSearch = _.get($scope, 'vis.type.requiresSearch'); + + if (requiresSearch && hasZeroHits) { + // The metric vis does not show a no results message + return _.get($scope, 'vis.type.name') !== 'metric'; + } + + return false; + }; + }, link: function ($scope, $el, attr) { var chart; // set in "vis" watcher var minVisChartHeight = 180; From 39bc45f7d572505fbd6ccf3b0f23eb04d3b463bc Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Mon, 30 Nov 2015 14:19:40 -0800 Subject: [PATCH 02/15] Closes #3682. Adds ability for metric visualizations to return 0 or ? for empty sets where appropropriate. --- src/plugins/metric_vis/public/metric_vis_controller.js | 4 +++- src/ui/public/agg_types/metrics/MetricAggType.js | 9 ++++++++- src/ui/public/agg_types/metrics/percentile_ranks.js | 2 ++ src/ui/public/agg_types/metrics/percentiles.js | 2 ++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/plugins/metric_vis/public/metric_vis_controller.js b/src/plugins/metric_vis/public/metric_vis_controller.js index 3ac2ef17c7d22..6c80be2f3fdfc 100644 --- a/src/plugins/metric_vis/public/metric_vis_controller.js +++ b/src/plugins/metric_vis/public/metric_vis_controller.js @@ -12,9 +12,11 @@ define(function (require) { tableGroups.tables.forEach(function (table) { table.columns.forEach(function (column, i) { var fieldFormatter = table.aggConfig(column).fieldFormatter(); + var value = typeof table.rows[0][i] !== 'undefined' ? table.rows[0][i] : '?'; + var isString = typeof value === 'string'; metrics.push({ label: column.title, - value: fieldFormatter(table.rows[0][i]) + value: !isString ? fieldFormatter(value) : value }); }); }); diff --git a/src/ui/public/agg_types/metrics/MetricAggType.js b/src/ui/public/agg_types/metrics/MetricAggType.js index 85c7c98abdc56..fc0843473678a 100644 --- a/src/ui/public/agg_types/metrics/MetricAggType.js +++ b/src/ui/public/agg_types/metrics/MetricAggType.js @@ -19,9 +19,16 @@ define(function (require) { /** * Read the values for this metric from the * @param {[type]} bucket [description] - * @return {[type]} [description] + * @return {*} [description] */ MetricAggType.prototype.getValue = function (agg, bucket) { + var zeroable = ['Unique Count', 'Sum']; + var isSettableToZero = zeroable.indexOf(agg.__type.title) !== -1; + var isCount = agg.__type.title === 'Count'; + + // Return proper values when no buckets are present + if (!bucket[agg.id] && !isCount) return isSettableToZero ? 0 : '?'; + return bucket[agg.id].value; }; diff --git a/src/ui/public/agg_types/metrics/percentile_ranks.js b/src/ui/public/agg_types/metrics/percentile_ranks.js index 4e167c8016776..231079d7cc3eb 100644 --- a/src/ui/public/agg_types/metrics/percentile_ranks.js +++ b/src/ui/public/agg_types/metrics/percentile_ranks.js @@ -47,6 +47,8 @@ define(function (require) { return fieldFormats.getInstance('percent') || fieldFormats.getDefaultInstance('number'); }, getValue: function (agg, bucket) { + if (!bucket[agg.parentId]) return '?'; + // values for 1, 5, and 10 will come back as 1.0, 5.0, and 10.0 so we // parse the keys and respond with the value that matches return _.find(bucket[agg.parentId].values, function (value, key) { diff --git a/src/ui/public/agg_types/metrics/percentiles.js b/src/ui/public/agg_types/metrics/percentiles.js index 101ee08318f61..e035a2ee8ff28 100644 --- a/src/ui/public/agg_types/metrics/percentiles.js +++ b/src/ui/public/agg_types/metrics/percentiles.js @@ -42,6 +42,8 @@ define(function (require) { }); }, getValue: function (agg, bucket) { + if (!bucket[agg.parentId]) return '?'; + // percentiles for 1, 5, and 10 will come back as 1.0, 5.0, and 10.0 so we // parse the keys and respond with the value that matches return _.find(bucket[agg.parentId].values, function (value, key) { From 2b0b9ff1d8665f053da9c40b1d4a5891287cf390 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Mon, 30 Nov 2015 15:09:21 -0800 Subject: [PATCH 03/15] adding comments, adding ability for std deviation metric to return , and cleaning up code in the metric vis controller. --- src/plugins/metric_vis/public/metric_vis_controller.js | 8 +++++--- src/ui/public/agg_types/metrics/MetricAggType.js | 2 ++ src/ui/public/agg_types/metrics/percentile_ranks.js | 1 + src/ui/public/agg_types/metrics/percentiles.js | 1 + src/ui/public/agg_types/metrics/stdDeviation.js | 2 ++ 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/plugins/metric_vis/public/metric_vis_controller.js b/src/plugins/metric_vis/public/metric_vis_controller.js index 6c80be2f3fdfc..ba88759ca8147 100644 --- a/src/plugins/metric_vis/public/metric_vis_controller.js +++ b/src/plugins/metric_vis/public/metric_vis_controller.js @@ -12,11 +12,13 @@ define(function (require) { tableGroups.tables.forEach(function (table) { table.columns.forEach(function (column, i) { var fieldFormatter = table.aggConfig(column).fieldFormatter(); - var value = typeof table.rows[0][i] !== 'undefined' ? table.rows[0][i] : '?'; - var isString = typeof value === 'string'; + var value = table.rows[0][i]; + + value = typeof value === 'string' ? value : fieldFormatter(value); + metrics.push({ label: column.title, - value: !isString ? fieldFormatter(value) : value + value: value }); }); }); diff --git a/src/ui/public/agg_types/metrics/MetricAggType.js b/src/ui/public/agg_types/metrics/MetricAggType.js index fc0843473678a..02a3dcb35d6b2 100644 --- a/src/ui/public/agg_types/metrics/MetricAggType.js +++ b/src/ui/public/agg_types/metrics/MetricAggType.js @@ -22,11 +22,13 @@ define(function (require) { * @return {*} [description] */ MetricAggType.prototype.getValue = function (agg, bucket) { + // Metric types where an empty set equals `zero` var zeroable = ['Unique Count', 'Sum']; var isSettableToZero = zeroable.indexOf(agg.__type.title) !== -1; var isCount = agg.__type.title === 'Count'; // Return proper values when no buckets are present + // `Count` handles empty sets properly if (!bucket[agg.id] && !isCount) return isSettableToZero ? 0 : '?'; return bucket[agg.id].value; diff --git a/src/ui/public/agg_types/metrics/percentile_ranks.js b/src/ui/public/agg_types/metrics/percentile_ranks.js index 231079d7cc3eb..2b874ad644225 100644 --- a/src/ui/public/agg_types/metrics/percentile_ranks.js +++ b/src/ui/public/agg_types/metrics/percentile_ranks.js @@ -47,6 +47,7 @@ define(function (require) { return fieldFormats.getInstance('percent') || fieldFormats.getDefaultInstance('number'); }, getValue: function (agg, bucket) { + // The percentile rank of an empty set is undefined. if (!bucket[agg.parentId]) return '?'; // values for 1, 5, and 10 will come back as 1.0, 5.0, and 10.0 so we diff --git a/src/ui/public/agg_types/metrics/percentiles.js b/src/ui/public/agg_types/metrics/percentiles.js index e035a2ee8ff28..f5d45021953af 100644 --- a/src/ui/public/agg_types/metrics/percentiles.js +++ b/src/ui/public/agg_types/metrics/percentiles.js @@ -42,6 +42,7 @@ define(function (require) { }); }, getValue: function (agg, bucket) { + // The percentile of an empty set is undefined. if (!bucket[agg.parentId]) return '?'; // percentiles for 1, 5, and 10 will come back as 1.0, 5.0, and 10.0 so we diff --git a/src/ui/public/agg_types/metrics/stdDeviation.js b/src/ui/public/agg_types/metrics/stdDeviation.js index 9a7a7ad27ddc5..8e1c9dadb8e76 100644 --- a/src/ui/public/agg_types/metrics/stdDeviation.js +++ b/src/ui/public/agg_types/metrics/stdDeviation.js @@ -54,6 +54,8 @@ define(function (require) { }, getValue: function (agg, bucket) { + // The std deviation of an empty set is undefined + if (!bucket[agg.parentId]) return '?'; return _.get(bucket[agg.parentId], agg.valProp()); } }); From 576cb3f782eeb4bc4c9db5316c1475d1602f9f74 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Mon, 30 Nov 2015 15:18:03 -0800 Subject: [PATCH 04/15] adding comment --- src/plugins/metric_vis/public/metric_vis_controller.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins/metric_vis/public/metric_vis_controller.js b/src/plugins/metric_vis/public/metric_vis_controller.js index ba88759ca8147..bab3cc8ea00eb 100644 --- a/src/plugins/metric_vis/public/metric_vis_controller.js +++ b/src/plugins/metric_vis/public/metric_vis_controller.js @@ -14,6 +14,7 @@ define(function (require) { var fieldFormatter = table.aggConfig(column).fieldFormatter(); var value = table.rows[0][i]; + // Return string when value is '?' value = typeof value === 'string' ? value : fieldFormatter(value); metrics.push({ From 99a2fa9a530c1eaa4d3a89a17f4a6dcc6e2b25e8 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Wed, 2 Dec 2015 11:02:02 -0800 Subject: [PATCH 05/15] Fixing issue with NaN and blank values being displayed. It turns out that null and NaN values can be returned and needed to be handled. I re-organized the code to handle null, undefined, and NaN values in the metric controller. --- src/plugins/metric_vis/public/metric_vis_controller.js | 7 ++++++- src/ui/public/agg_types/metrics/MetricAggType.js | 7 +++---- src/ui/public/agg_types/metrics/percentile_ranks.js | 3 +-- src/ui/public/agg_types/metrics/percentiles.js | 3 +-- src/ui/public/agg_types/metrics/stdDeviation.js | 3 ++- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/plugins/metric_vis/public/metric_vis_controller.js b/src/plugins/metric_vis/public/metric_vis_controller.js index bab3cc8ea00eb..e4f08e6959340 100644 --- a/src/plugins/metric_vis/public/metric_vis_controller.js +++ b/src/plugins/metric_vis/public/metric_vis_controller.js @@ -1,4 +1,5 @@ define(function (require) { + var _ = require('lodash'); // get the kibana/metric_vis module, and make sure that it requires the "kibana" module if it // didn't already var module = require('ui/modules').get('kibana/metric_vis', ['kibana']); @@ -8,6 +9,10 @@ define(function (require) { var metrics = $scope.metrics = []; + $scope.isNullorNaN = function (val) { + return _.isNull(val) || isNaN(val); + }; + $scope.processTableGroups = function (tableGroups) { tableGroups.tables.forEach(function (table) { table.columns.forEach(function (column, i) { @@ -15,7 +20,7 @@ define(function (require) { var value = table.rows[0][i]; // Return string when value is '?' - value = typeof value === 'string' ? value : fieldFormatter(value); + value = $scope.isNullorNaN(value) ? '?' : fieldFormatter(value); metrics.push({ label: column.title, diff --git a/src/ui/public/agg_types/metrics/MetricAggType.js b/src/ui/public/agg_types/metrics/MetricAggType.js index 02a3dcb35d6b2..269d592b97087 100644 --- a/src/ui/public/agg_types/metrics/MetricAggType.js +++ b/src/ui/public/agg_types/metrics/MetricAggType.js @@ -23,13 +23,12 @@ define(function (require) { */ MetricAggType.prototype.getValue = function (agg, bucket) { // Metric types where an empty set equals `zero` - var zeroable = ['Unique Count', 'Sum']; - var isSettableToZero = zeroable.indexOf(agg.__type.title) !== -1; - var isCount = agg.__type.title === 'Count'; + var isSettableToZero = ['Unique Count', 'Sum'].indexOf(agg.__type.title) !== -1; // Return proper values when no buckets are present // `Count` handles empty sets properly - if (!bucket[agg.id] && !isCount) return isSettableToZero ? 0 : '?'; + if (!bucket[agg.id] && isSettableToZero) return 0; + if (!bucket[agg.id]) return; return bucket[agg.id].value; }; diff --git a/src/ui/public/agg_types/metrics/percentile_ranks.js b/src/ui/public/agg_types/metrics/percentile_ranks.js index 2b874ad644225..ab14e00234db1 100644 --- a/src/ui/public/agg_types/metrics/percentile_ranks.js +++ b/src/ui/public/agg_types/metrics/percentile_ranks.js @@ -47,8 +47,7 @@ define(function (require) { return fieldFormats.getInstance('percent') || fieldFormats.getDefaultInstance('number'); }, getValue: function (agg, bucket) { - // The percentile rank of an empty set is undefined. - if (!bucket[agg.parentId]) return '?'; + if (!bucket[agg.parentId]) return; // values for 1, 5, and 10 will come back as 1.0, 5.0, and 10.0 so we // parse the keys and respond with the value that matches diff --git a/src/ui/public/agg_types/metrics/percentiles.js b/src/ui/public/agg_types/metrics/percentiles.js index f5d45021953af..61f99b5d16f93 100644 --- a/src/ui/public/agg_types/metrics/percentiles.js +++ b/src/ui/public/agg_types/metrics/percentiles.js @@ -42,8 +42,7 @@ define(function (require) { }); }, getValue: function (agg, bucket) { - // The percentile of an empty set is undefined. - if (!bucket[agg.parentId]) return '?'; + if (!bucket[agg.parentId]) return; // percentiles for 1, 5, and 10 will come back as 1.0, 5.0, and 10.0 so we // parse the keys and respond with the value that matches diff --git a/src/ui/public/agg_types/metrics/stdDeviation.js b/src/ui/public/agg_types/metrics/stdDeviation.js index 8e1c9dadb8e76..8385ce6b811f2 100644 --- a/src/ui/public/agg_types/metrics/stdDeviation.js +++ b/src/ui/public/agg_types/metrics/stdDeviation.js @@ -54,8 +54,9 @@ define(function (require) { }, getValue: function (agg, bucket) { + if (!bucket[agg.parentId]) return; + // The std deviation of an empty set is undefined - if (!bucket[agg.parentId]) return '?'; return _.get(bucket[agg.parentId], agg.valProp()); } }); From f023e4bdfcaf2148a4455b26f4d55bc12921f891 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Fri, 4 Dec 2015 10:38:35 -0800 Subject: [PATCH 06/15] switch from using isNaN to _.isNaN, and adding check for undefined values. --- src/plugins/metric_vis/public/metric_vis_controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/metric_vis/public/metric_vis_controller.js b/src/plugins/metric_vis/public/metric_vis_controller.js index e4f08e6959340..3e7f353e63c85 100644 --- a/src/plugins/metric_vis/public/metric_vis_controller.js +++ b/src/plugins/metric_vis/public/metric_vis_controller.js @@ -10,7 +10,7 @@ define(function (require) { var metrics = $scope.metrics = []; $scope.isNullorNaN = function (val) { - return _.isNull(val) || isNaN(val); + return !val || _.isNull(val) || _.isNaN(val); }; $scope.processTableGroups = function (tableGroups) { From 348d2fc75209934e3e6d1682731be4b1cb693bb1 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Tue, 15 Dec 2015 11:48:26 -0800 Subject: [PATCH 07/15] updating pr based on @rashidkpc review --- .../public/metric_vis_controller.js | 8 +++--- .../public/agg_types/metrics/MetricAggType.js | 3 +-- src/ui/public/visualize/visualize.html | 4 +-- src/ui/public/visualize/visualize.js | 26 +++++++++---------- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/plugins/metric_vis/public/metric_vis_controller.js b/src/plugins/metric_vis/public/metric_vis_controller.js index 3e7f353e63c85..2f089817f7628 100644 --- a/src/plugins/metric_vis/public/metric_vis_controller.js +++ b/src/plugins/metric_vis/public/metric_vis_controller.js @@ -9,9 +9,9 @@ define(function (require) { var metrics = $scope.metrics = []; - $scope.isNullorNaN = function (val) { - return !val || _.isNull(val) || _.isNaN(val); - }; + function isNullorNaN(val) { + return _.isNull(val) || _.isNaN(val); + } $scope.processTableGroups = function (tableGroups) { tableGroups.tables.forEach(function (table) { @@ -20,7 +20,7 @@ define(function (require) { var value = table.rows[0][i]; // Return string when value is '?' - value = $scope.isNullorNaN(value) ? '?' : fieldFormatter(value); + value = isNullorNaN(value) ? '?' : fieldFormatter(value); metrics.push({ label: column.title, diff --git a/src/ui/public/agg_types/metrics/MetricAggType.js b/src/ui/public/agg_types/metrics/MetricAggType.js index 269d592b97087..15a4741f3c65a 100644 --- a/src/ui/public/agg_types/metrics/MetricAggType.js +++ b/src/ui/public/agg_types/metrics/MetricAggType.js @@ -23,12 +23,11 @@ define(function (require) { */ MetricAggType.prototype.getValue = function (agg, bucket) { // Metric types where an empty set equals `zero` - var isSettableToZero = ['Unique Count', 'Sum'].indexOf(agg.__type.title) !== -1; + var isSettableToZero = ['Unique Count', 'Sum'].indexOf(agg.__type.name) !== -1; // Return proper values when no buckets are present // `Count` handles empty sets properly if (!bucket[agg.id] && isSettableToZero) return 0; - if (!bucket[agg.id]) return; return bucket[agg.id].value; }; diff --git a/src/ui/public/visualize/visualize.html b/src/ui/public/visualize/visualize.html index 3f175945c0583..3898850d9bf26 100644 --- a/src/ui/public/visualize/visualize.html +++ b/src/ui/public/visualize/visualize.html @@ -1,4 +1,4 @@ -
@@ -7,7 +7,7 @@

No results found

-
diff --git a/src/ui/public/visualize/visualize.js b/src/ui/public/visualize/visualize.js index 354d3cc998c97..b28cd0f2e22a4 100644 --- a/src/ui/public/visualize/visualize.js +++ b/src/ui/public/visualize/visualize.js @@ -24,19 +24,6 @@ define(function (require) { esResp: '=?', }, template: require('ui/visualize/visualize.html'), - controller: function ($scope) { - // Show no results message when hasZeroHits is true and it requires search - $scope.showNoResultsMessage = function (hasZeroHits) { - var requiresSearch = _.get($scope, 'vis.type.requiresSearch'); - - if (requiresSearch && hasZeroHits) { - // The metric vis does not show a no results message - return _.get($scope, 'vis.type.name') !== 'metric'; - } - - return false; - }; - }, link: function ($scope, $el, attr) { var chart; // set in "vis" watcher var minVisChartHeight = 180; @@ -55,6 +42,19 @@ define(function (require) { var getVisEl = getter('.visualize-chart'); var getSpyEl = getter('visualize-spy'); + // Show no results message when hasZeroHits is true and it requires search + $scope.showNoResultsMessage = function () { + var requiresSearch = _.get($scope, 'vis.type.requiresSearch'); + var isZeroHits = attr.esResp && attr.esResp.hits.total === 0; + + if (requiresSearch && isZeroHits) { + // The metric vis does not show a no results message + return _.get($scope, 'vis.type.name') !== 'metric'; + } + + return false; + }; + $scope.fullScreenSpy = false; $scope.spy = {}; $scope.spy.mode = ($scope.uiState) ? $scope.uiState.get('spy.mode', {}) : {}; From 55ebeb22eaf5238ee1952896d5bc1c842dc2d1d7 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Tue, 15 Dec 2015 15:33:27 -0800 Subject: [PATCH 08/15] moving business logic out of the view and removing early returns --- src/plugins/metric_vis/public/metric_vis_controller.js | 7 +++---- src/ui/public/agg_types/metrics/MetricAggType.js | 4 ++-- src/ui/public/agg_types/metrics/percentile_ranks.js | 4 +--- src/ui/public/agg_types/metrics/percentiles.js | 4 +--- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/plugins/metric_vis/public/metric_vis_controller.js b/src/plugins/metric_vis/public/metric_vis_controller.js index 2f089817f7628..fa374d353a395 100644 --- a/src/plugins/metric_vis/public/metric_vis_controller.js +++ b/src/plugins/metric_vis/public/metric_vis_controller.js @@ -9,8 +9,8 @@ define(function (require) { var metrics = $scope.metrics = []; - function isNullorNaN(val) { - return _.isNull(val) || _.isNaN(val); + function isInvalid(val) { + return _.isUndefined(val) || _.isNull(val) || _.isNaN(val); } $scope.processTableGroups = function (tableGroups) { @@ -19,8 +19,7 @@ define(function (require) { var fieldFormatter = table.aggConfig(column).fieldFormatter(); var value = table.rows[0][i]; - // Return string when value is '?' - value = isNullorNaN(value) ? '?' : fieldFormatter(value); + value = isInvalid(value) ? '?' : fieldFormatter(value); metrics.push({ label: column.title, diff --git a/src/ui/public/agg_types/metrics/MetricAggType.js b/src/ui/public/agg_types/metrics/MetricAggType.js index 15a4741f3c65a..a33d7a9c16437 100644 --- a/src/ui/public/agg_types/metrics/MetricAggType.js +++ b/src/ui/public/agg_types/metrics/MetricAggType.js @@ -23,13 +23,13 @@ define(function (require) { */ MetricAggType.prototype.getValue = function (agg, bucket) { // Metric types where an empty set equals `zero` - var isSettableToZero = ['Unique Count', 'Sum'].indexOf(agg.__type.name) !== -1; + var isSettableToZero = ['cardinality', 'sum'].indexOf(agg.__type.name) !== -1; // Return proper values when no buckets are present // `Count` handles empty sets properly if (!bucket[agg.id] && isSettableToZero) return 0; - return bucket[agg.id].value; + return bucket[agg.id] && bucket[agg.id].value; }; /** diff --git a/src/ui/public/agg_types/metrics/percentile_ranks.js b/src/ui/public/agg_types/metrics/percentile_ranks.js index ab14e00234db1..15c3a74e98399 100644 --- a/src/ui/public/agg_types/metrics/percentile_ranks.js +++ b/src/ui/public/agg_types/metrics/percentile_ranks.js @@ -47,11 +47,9 @@ define(function (require) { return fieldFormats.getInstance('percent') || fieldFormats.getDefaultInstance('number'); }, getValue: function (agg, bucket) { - if (!bucket[agg.parentId]) return; - // values for 1, 5, and 10 will come back as 1.0, 5.0, and 10.0 so we // parse the keys and respond with the value that matches - return _.find(bucket[agg.parentId].values, function (value, key) { + return _.find(bucket[agg.parentId] && bucket[agg.parentId].values, function (value, key) { return agg.key === parseFloat(key); }) / 100; } diff --git a/src/ui/public/agg_types/metrics/percentiles.js b/src/ui/public/agg_types/metrics/percentiles.js index 61f99b5d16f93..1b859a4293d47 100644 --- a/src/ui/public/agg_types/metrics/percentiles.js +++ b/src/ui/public/agg_types/metrics/percentiles.js @@ -42,11 +42,9 @@ define(function (require) { }); }, getValue: function (agg, bucket) { - if (!bucket[agg.parentId]) return; - // percentiles for 1, 5, and 10 will come back as 1.0, 5.0, and 10.0 so we // parse the keys and respond with the value that matches - return _.find(bucket[agg.parentId].values, function (value, key) { + return _.find(bucket[agg.parentId] && bucket[agg.parentId].values, function (value, key) { return agg.key === parseFloat(key); }); } From 7a0c4f22e6d4eb573272c7bf0669f4cd0b64e6c8 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Tue, 15 Dec 2015 16:10:09 -0800 Subject: [PATCH 09/15] adding parameter to vis that tells the visualize directive whether the vis type handles no results. --- src/plugins/metric_vis/public/metric_vis.js | 1 + src/ui/public/visualize/visualize.js | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/plugins/metric_vis/public/metric_vis.js b/src/plugins/metric_vis/public/metric_vis.js index 0e5b99c4e225f..8c5d5b1f50cf5 100644 --- a/src/plugins/metric_vis/public/metric_vis.js +++ b/src/plugins/metric_vis/public/metric_vis.js @@ -22,6 +22,7 @@ define(function (require) { icon: 'fa-calculator', template: require('plugins/metric_vis/metric_vis.html'), params: { + handleNoResults: true, defaults: { fontSize: 60 }, diff --git a/src/ui/public/visualize/visualize.js b/src/ui/public/visualize/visualize.js index b28cd0f2e22a4..879f66077e207 100644 --- a/src/ui/public/visualize/visualize.js +++ b/src/ui/public/visualize/visualize.js @@ -48,11 +48,10 @@ define(function (require) { var isZeroHits = attr.esResp && attr.esResp.hits.total === 0; if (requiresSearch && isZeroHits) { - // The metric vis does not show a no results message - return _.get($scope, 'vis.type.name') !== 'metric'; + // if the vis type handles instances when there are no results, + // do not show a no results message + return _.get($scope, 'vis.handleNoResults') ? false : true; } - - return false; }; $scope.fullScreenSpy = false; From 16f3dc364946c5757b4536cd813b50e1ed18d984 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Tue, 15 Dec 2015 16:55:53 -0800 Subject: [PATCH 10/15] cleaning up code and moving handleNoResults param to defaults in metric vis --- src/plugins/metric_vis/public/metric_vis.js | 2 +- src/ui/public/visualize/visualize.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/metric_vis/public/metric_vis.js b/src/plugins/metric_vis/public/metric_vis.js index 8c5d5b1f50cf5..2c85ab91cf8c7 100644 --- a/src/plugins/metric_vis/public/metric_vis.js +++ b/src/plugins/metric_vis/public/metric_vis.js @@ -22,8 +22,8 @@ define(function (require) { icon: 'fa-calculator', template: require('plugins/metric_vis/metric_vis.html'), params: { - handleNoResults: true, defaults: { + handleNoResults: true, fontSize: 60 }, editor: require('plugins/metric_vis/metric_vis_params.html') diff --git a/src/ui/public/visualize/visualize.js b/src/ui/public/visualize/visualize.js index 879f66077e207..ad8f4a5f51a16 100644 --- a/src/ui/public/visualize/visualize.js +++ b/src/ui/public/visualize/visualize.js @@ -45,12 +45,12 @@ define(function (require) { // Show no results message when hasZeroHits is true and it requires search $scope.showNoResultsMessage = function () { var requiresSearch = _.get($scope, 'vis.type.requiresSearch'); - var isZeroHits = attr.esResp && attr.esResp.hits.total === 0; + var isZeroHits = _.get($scope,'esResp.hits.total') === 0; if (requiresSearch && isZeroHits) { // if the vis type handles instances when there are no results, // do not show a no results message - return _.get($scope, 'vis.handleNoResults') ? false : true; + return _.get($scope, 'vis.params.handleNoResults') ? false : true; } }; From 6daa5284ecafb350ea10a7887289c4c3e5e4a7b1 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Tue, 15 Dec 2015 17:02:49 -0800 Subject: [PATCH 11/15] refactoring --- src/ui/public/visualize/visualize.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ui/public/visualize/visualize.js b/src/ui/public/visualize/visualize.js index ad8f4a5f51a16..4de31bbe00d37 100644 --- a/src/ui/public/visualize/visualize.js +++ b/src/ui/public/visualize/visualize.js @@ -46,11 +46,12 @@ define(function (require) { $scope.showNoResultsMessage = function () { var requiresSearch = _.get($scope, 'vis.type.requiresSearch'); var isZeroHits = _.get($scope,'esResp.hits.total') === 0; + var shouldNotShowMessage = _.get($scope, 'vis.params.handleNoResults'); if (requiresSearch && isZeroHits) { // if the vis type handles instances when there are no results, // do not show a no results message - return _.get($scope, 'vis.params.handleNoResults') ? false : true; + return shouldNotShowMessage ? false : true; } }; From 504c7c3b982da26cbf4bbd4d547fd77dc7ff5a90 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Tue, 15 Dec 2015 17:06:37 -0800 Subject: [PATCH 12/15] removing early return --- src/ui/public/agg_types/metrics/stdDeviation.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ui/public/agg_types/metrics/stdDeviation.js b/src/ui/public/agg_types/metrics/stdDeviation.js index 8385ce6b811f2..2429dd472e2c7 100644 --- a/src/ui/public/agg_types/metrics/stdDeviation.js +++ b/src/ui/public/agg_types/metrics/stdDeviation.js @@ -54,8 +54,6 @@ define(function (require) { }, getValue: function (agg, bucket) { - if (!bucket[agg.parentId]) return; - // The std deviation of an empty set is undefined return _.get(bucket[agg.parentId], agg.valProp()); } From 8c90fff83270101031df1e3cb002e5fe8cdae984 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Tue, 15 Dec 2015 17:07:14 -0800 Subject: [PATCH 13/15] removing comments --- src/ui/public/agg_types/metrics/stdDeviation.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ui/public/agg_types/metrics/stdDeviation.js b/src/ui/public/agg_types/metrics/stdDeviation.js index 2429dd472e2c7..9a7a7ad27ddc5 100644 --- a/src/ui/public/agg_types/metrics/stdDeviation.js +++ b/src/ui/public/agg_types/metrics/stdDeviation.js @@ -54,7 +54,6 @@ define(function (require) { }, getValue: function (agg, bucket) { - // The std deviation of an empty set is undefined return _.get(bucket[agg.parentId], agg.valProp()); } }); From 3269b0287c3bf28379c7678eae38a31a9c5abdf9 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Tue, 15 Dec 2015 22:19:50 -0800 Subject: [PATCH 14/15] refactoring based on @jbudz review --- src/ui/public/visualize/visualize.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/ui/public/visualize/visualize.js b/src/ui/public/visualize/visualize.js index 423a43734a961..d4dd67b2d9d03 100644 --- a/src/ui/public/visualize/visualize.js +++ b/src/ui/public/visualize/visualize.js @@ -44,17 +44,13 @@ define(function (require) { var getVisEl = getter('.visualize-chart'); var getVisContainer = getter('.vis-container'); - // Show no results message when hasZeroHits is true and it requires search + // Show no results message when isZeroHits is true and it requires search $scope.showNoResultsMessage = function () { - var requiresSearch = _.get($scope, 'vis.type.requiresSearch'); + var requiresSearch = _.has($scope, 'vis.type.requiresSearch'); var isZeroHits = _.get($scope,'esResp.hits.total') === 0; - var shouldNotShowMessage = _.get($scope, 'vis.params.handleNoResults'); + var shouldShowMessage = !_.has($scope, 'vis.params.handleNoResults'); - if (requiresSearch && isZeroHits) { - // if the vis type handles instances when there are no results, - // do not show a no results message - return shouldNotShowMessage ? false : true; - } + return Boolean(requiresSearch && isZeroHits && shouldShowMessage); }; $scope.fullScreenSpy = false; From 4e74cc27a87313501c88c8fffa37ee0406612d23 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Wed, 16 Dec 2015 10:58:49 -0800 Subject: [PATCH 15/15] reverting _.has back to _.get --- src/ui/public/visualize/visualize.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ui/public/visualize/visualize.js b/src/ui/public/visualize/visualize.js index d4dd67b2d9d03..77aa01b6bdb6a 100644 --- a/src/ui/public/visualize/visualize.js +++ b/src/ui/public/visualize/visualize.js @@ -46,9 +46,9 @@ define(function (require) { // Show no results message when isZeroHits is true and it requires search $scope.showNoResultsMessage = function () { - var requiresSearch = _.has($scope, 'vis.type.requiresSearch'); + var requiresSearch = _.get($scope, 'vis.type.requiresSearch'); var isZeroHits = _.get($scope,'esResp.hits.total') === 0; - var shouldShowMessage = !_.has($scope, 'vis.params.handleNoResults'); + var shouldShowMessage = !_.get($scope, 'vis.params.handleNoResults'); return Boolean(requiresSearch && isZeroHits && shouldShowMessage); };