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/plugins/metric_vis/public/metric_vis.js b/src/plugins/metric_vis/public/metric_vis.js index 0e5b99c4e225f..2c85ab91cf8c7 100644 --- a/src/plugins/metric_vis/public/metric_vis.js +++ b/src/plugins/metric_vis/public/metric_vis.js @@ -23,6 +23,7 @@ define(function (require) { template: require('plugins/metric_vis/metric_vis.html'), params: { defaults: { + handleNoResults: true, fontSize: 60 }, editor: require('plugins/metric_vis/metric_vis_params.html') diff --git a/src/plugins/metric_vis/public/metric_vis_controller.js b/src/plugins/metric_vis/public/metric_vis_controller.js index 3ac2ef17c7d22..fa374d353a395 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,13 +9,21 @@ define(function (require) { var metrics = $scope.metrics = []; + function isInvalid(val) { + return _.isUndefined(val) || _.isNull(val) || _.isNaN(val); + } + $scope.processTableGroups = function (tableGroups) { tableGroups.tables.forEach(function (table) { table.columns.forEach(function (column, i) { var fieldFormatter = table.aggConfig(column).fieldFormatter(); + var value = table.rows[0][i]; + + value = isInvalid(value) ? '?' : fieldFormatter(value); + metrics.push({ label: column.title, - value: fieldFormatter(table.rows[0][i]) + value: value }); }); }); diff --git a/src/ui/public/agg_types/metrics/MetricAggType.js b/src/ui/public/agg_types/metrics/MetricAggType.js index 85c7c98abdc56..a33d7a9c16437 100644 --- a/src/ui/public/agg_types/metrics/MetricAggType.js +++ b/src/ui/public/agg_types/metrics/MetricAggType.js @@ -19,10 +19,17 @@ 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) { - return bucket[agg.id].value; + // Metric types where an empty set equals `zero` + 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] && 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..15c3a74e98399 100644 --- a/src/ui/public/agg_types/metrics/percentile_ranks.js +++ b/src/ui/public/agg_types/metrics/percentile_ranks.js @@ -49,7 +49,7 @@ define(function (require) { getValue: function (agg, bucket) { // 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 101ee08318f61..1b859a4293d47 100644 --- a/src/ui/public/agg_types/metrics/percentiles.js +++ b/src/ui/public/agg_types/metrics/percentiles.js @@ -44,7 +44,7 @@ define(function (require) { getValue: function (agg, bucket) { // 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); }); } diff --git a/src/ui/public/visualize/visualize.html b/src/ui/public/visualize/visualize.html index ca5c3dc43c29f..5d8f7763033bb 100644 --- a/src/ui/public/visualize/visualize.html +++ b/src/ui/public/visualize/visualize.html @@ -1,6 +1,4 @@ -
+
@@ -8,9 +6,7 @@

No results found

-
+