-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Metric Visualization #1928
Merged
Merged
Metric Visualization #1928
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
define(function (require) { | ||
require('registry/vis_types').register(function (Private) { | ||
return Private(require('plugins/metric_vis/metric_vis')); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div ng-controller="KbnMetricVisController" class="MetricVis"> | ||
<div class="MetricValue">{{metric.value}}</div> | ||
<div>{{metric.label}}</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
define(function (require) { | ||
// we need to load the css ourselves | ||
require('css!plugins/metric_vis/metric_vis.css'); | ||
|
||
// we also need to load the controller and used by the template | ||
require('plugins/metric_vis/metric_vis_controller'); | ||
|
||
return function (Private) { | ||
var TemplateVisType = Private(require('plugins/vis_types/template/template_vis_type')); | ||
var Schemas = Private(require('plugins/vis_types/_schemas')); | ||
|
||
// return the visType object, which kibana will use to display and configure new | ||
// Vis object of this type. | ||
return new TemplateVisType({ | ||
name: 'metric', | ||
title: 'Metric', | ||
icon: 'fa-calculator', | ||
template: require('text!plugins/metric_vis/metric_vis.html'), | ||
schemas: new Schemas([ | ||
{ | ||
group: 'metrics', | ||
name: 'metric', | ||
title: 'Metric', | ||
min: 1, | ||
max: 1, | ||
defaults: [ | ||
{ type: 'count', schema: 'metric' } | ||
] | ||
} | ||
]) | ||
}); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.MetricVis { | ||
width: 100%; | ||
text-align: center; | ||
|
||
.MetricValue { | ||
font-size: 5em; | ||
font-weight: bold; | ||
white-space: nowrap; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
define(function (require) { | ||
// get the kibana/metric_vis module, and make sure that it requires the "kibana" module if it | ||
// didn't already | ||
var module = require('modules').get('kibana/metric_vis', ['kibana']); | ||
|
||
module.controller('KbnMetricVisController', function ($scope) { | ||
var metric = $scope.metric = { | ||
label: null, | ||
value: null | ||
}; | ||
|
||
$scope.$watch('esResponse', function (resp) { | ||
if (!resp) { | ||
metric.label = metric.value = null; | ||
} else { | ||
var agg = $scope.vis.aggs[0]; | ||
metric.label = agg.makeLabel(); | ||
if (agg.type.name === 'count') metric.value = resp.hits.total; | ||
else metric.value = resp.aggregations[agg.id].value; | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
test/unit/specs/plugins/metric_vis/metric_vis_controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
define(function (require) { | ||
var metricVis = { | ||
aggs: [{ | ||
type: {name: 'count'}, | ||
schema: 'metric', | ||
makeLabel: function () { | ||
return 'Count of documents'; | ||
} | ||
}] | ||
}; | ||
|
||
var averageVis = { | ||
aggs: [{ | ||
id: 'agg', | ||
type: {name: 'average'}, | ||
schema: 'metric', | ||
makeLabel: function () { | ||
return 'Average bytes'; | ||
} | ||
}] | ||
}; | ||
|
||
describe('metric vis', function () { | ||
var $scope; | ||
|
||
beforeEach(module('kibana/metric_vis')); | ||
beforeEach(inject(function ($rootScope, $controller) { | ||
$scope = $rootScope.$new(); | ||
$controller('KbnMetricVisController', {$scope: $scope}); | ||
$scope.$digest(); | ||
})); | ||
|
||
it('should set the metric', function () { | ||
expect($scope).to.have.property('metric'); | ||
}); | ||
|
||
it('should set the metric label and value for count', function () { | ||
expect($scope.metric.label).to.not.be.ok; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expect.js required that you call ok()
|
||
expect($scope.metric.value).to.not.be.ok; | ||
|
||
$scope.vis = metricVis; | ||
$scope.esResponse = {hits: {total: 4826}}; | ||
$scope.$digest(); | ||
|
||
expect($scope.metric.label).to.be('Count of documents'); | ||
expect($scope.metric.value).to.be($scope.esResponse.hits.total); | ||
}); | ||
|
||
it('should set the metric value for average', function () { | ||
expect($scope.metric.label).to.not.be.ok; | ||
expect($scope.metric.value).to.not.be.ok; | ||
|
||
$scope.vis = averageVis; | ||
$scope.esResponse = {hits: {total: 4826}, aggregations: {agg: {value: 1234}}}; | ||
$scope.$digest(); | ||
|
||
expect($scope.metric.label).to.be('Average bytes'); | ||
expect($scope.metric.value).to.be($scope.esResponse.aggregations.agg.value); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mind updating your class names to be hyphenated-like-attributes?