Merge pull request #5532 from stormpython/fix/3682

Metric vis should display a `?` or 0 for empty sets
This commit is contained in:
Shelby Sturgis 2015-12-16 11:15:07 -08:00
commit e6257c7f6a
8 changed files with 37 additions and 15 deletions

View file

@ -1,6 +1,6 @@
<div ng-controller="KbnMetricVisController" class="metric-vis">
<div class="metric-container" ng-repeat="metric in metrics">
<div class="metric-value" ng-style="{'font-size': vis.params.fontSize+'pt'}">{{metric.value}}</div>
<div>{{metric.label}}</div>
</div>
<div class="metric-container" ng-repeat="metric in metrics">
<div class="metric-value" ng-style="{'font-size': vis.params.fontSize+'pt'}">{{metric.value}}</div>
<div>{{metric.label}}</div>
</div>
</div>

View file

@ -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')

View file

@ -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
});
});
});

View file

@ -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;
};
/**

View file

@ -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;
}

View file

@ -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);
});
}

View file

@ -1,6 +1,4 @@
<div
ng-if="vis.type.requiresSearch && esResp.hits.total === 0"
class="text-center visualize-error visualize-chart">
<div ng-if="showNoResultsMessage()" class="text-center visualize-error visualize-chart">
<div class="item top"></div>
<div class="item">
<h2 aria-hidden="true"><i aria-hidden="true" class="fa fa-meh-o"></i></h2>
@ -8,9 +6,7 @@
</div>
<div class="item bottom"></div>
</div>
<div
ng-hide="vis.type.requiresSearch && esResp.hits.total === 0"
class="vis-container">
<div div ng-hide="showNoResultsMessage()" class="vis-container">
<div
ng-style="loadingStyle"
ng-class="{ loading: vis.type.requiresSearch && searchSource.activeFetchCount > 0 }"

View file

@ -44,6 +44,15 @@ define(function (require) {
var getVisEl = getter('.visualize-chart');
var getVisContainer = getter('.vis-container');
// Show no results message when isZeroHits is true and it requires search
$scope.showNoResultsMessage = function () {
var requiresSearch = _.get($scope, 'vis.type.requiresSearch');
var isZeroHits = _.get($scope,'esResp.hits.total') === 0;
var shouldShowMessage = !_.get($scope, 'vis.params.handleNoResults');
return Boolean(requiresSearch && isZeroHits && shouldShowMessage);
};
$scope.fullScreenSpy = false;
$scope.spy = {};
$scope.spy.mode = ($scope.uiState) ? $scope.uiState.get('spy.mode', {}) : {};