Skip to content

Commit

Permalink
Added statistical modes to histogram panel
Browse files Browse the repository at this point in the history
  • Loading branch information
Rashid Khan committed May 13, 2013
1 parent 45c9bb8 commit 906f3a3
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 22 deletions.
4 changes: 3 additions & 1 deletion js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ angular.module('kibana.controllers', [])
title: "",
editable: true,
rows: [],
last: null
}

$scope.init = function() {
Expand All @@ -24,7 +25,8 @@ angular.module('kibana.controllers', [])

// Load dashboard by event
eventBus.register($scope,'dashboard', function(event,dashboard){
$scope.dashboards = dashboard;
$scope.dashboards = dashboard.dashboard;
$scope.dashboards.last = dashboard.last;
_.defaults($scope.dashboards,_d)
})

Expand Down
7 changes: 4 additions & 3 deletions panels/dashcontrol/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,10 @@ angular.module('kibana.dashcontrol', [])
$scope.dash_load = function(dashboard) {
if(!_.isObject(dashboard))
dashboard = JSON.parse(dashboard)

eventBus.broadcast($scope.$id,'ALL','dashboard',dashboard)
eventBus.broadcast($scope.$id,'ALL','dashboard',{
dashboard : dashboard,
last : $scope.dashboards
})
timer.cancel_all();
}

Expand All @@ -287,7 +289,6 @@ angular.module('kibana.dashcontrol', [])
else
return false
}

})
.directive('dashUpload', function(timer, eventBus){
return {
Expand Down
1 change: 1 addition & 0 deletions panels/fields/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ angular.module('kibana.fields', [])
eventBus.register($scope,'table_documents', function(event, docs) {
$scope.panel.query = docs.query;
$scope.docs = docs.docs;
$scope.index = docs.index;
});
eventBus.register($scope,"get_fields", function(event,id) {
eventBus.broadcast($scope.$id,$scope.panel.group,"selected_fields",$scope.active);
Expand Down
19 changes: 17 additions & 2 deletions panels/histogram/editor.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
<div>
<div class="row-fluid">
<div class="span3">
<label class="small">Mode</label>
<select ng-change="set_refresh(true)" class="input-small" ng-model="panel.mode" ng-options="f for f in ['count','min','mean','max','total']"></select>
</div>
<div class="span3">
<label class="small">Field</label>
<form>
<input ng-change="set_refresh(true)" placeholder="Start typing" bs-typeahead="fields.list" type="text" class="input-small" ng-model="panel.value_field">
</form>
</div>
<div class="span5" ng-show="panel.mode != 'count'">
<label class="small">Note</label><small> In <strong>{{panel.mode}}</strong> mode the configured field <strong>must</strong> be a numeric type</small>
</div>
</div>
<div class="row-fluid">
<div class="span3">
<form style="margin-bottom: 0px">
<h6>Label</h6>
<label class="small">Label</label>
<input type="text" placeholder="New Label" style="width:70%" ng-model="newlabel">
</form>
</div>
<div class="span8">
<label class="small">Query</label>
<form class="input-append" style="margin-bottom: 0px">
<h6>Query</h6>
<input type="text" placeholder="New Query" style="width:80%" ng-model="newquery">
<button class="btn" ng-click="add_query(newlabel,newquery);newlabel='';newquery=''"><i class="icon-plus"></i></button>
</form>
Expand Down
2 changes: 1 addition & 1 deletion panels/histogram/module.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div style="display:inline-block;background:{{series.color}};height:10px;width:10px;border-radius:5px;"></div>
<div class='small' style='display:inline-block'>{{series.label}} ({{series.hits}})</div>
</span>
<span ng-show="panel.legend" class="small"> per <strong>{{panel.interval}}</strong> | (<strong>{{hits}}</strong> total)</span>
<span ng-show="panel.legend" class="small"><span ng-show="panel.value_field && panel.mode != 'count'">{{panel.value_field}}</span> {{panel.mode}} per <strong>{{panel.interval}}</strong> | (<strong>{{hits}}</strong> hits)</span>
</div>
<center><img ng-show='panel.loading && _.isUndefined(data)' src="common/img/load_big.gif"></center>
<div histogram-chart params="{{panel}}" style="height:{{panel.height || row.height}};position:relative"></div>
Expand Down
26 changes: 17 additions & 9 deletions panels/histogram/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ angular.module('kibana.histogram', [])
var _d = {
group : "default",
query : [ {query: "*", label:"Query"} ],
mode : 'count',
value_field: null,
auto_int : true,
interval : '5m',
fill : 3,
Expand Down Expand Up @@ -124,12 +126,20 @@ angular.module('kibana.histogram', [])

// Build the facet part, injecting the query in as a facet filter
_.each(queries, function(v) {
request = request
.facet($scope.ejs.DateHistogramFacet("chart"+_.indexOf(queries,v))
.field($scope.time.field)
.interval($scope.panel.interval)
.facetFilter($scope.ejs.QueryFilter(v))
).size(0)

var facet = $scope.ejs.DateHistogramFacet("chart"+_.indexOf(queries,v))

if($scope.panel.mode === 'count') {
facet = facet.field($scope.time.field)
} else {
if(_.isNull($scope.panel.value_field)) {
$scope.panel.error = "In " + $scope.panel.mode + " mode a field must be specified";
return
}
facet = facet.keyField($scope.time.field).valueField($scope.panel.value_field)
}
facet = facet.interval($scope.panel.interval).facetFilter($scope.ejs.QueryFilter(v))
request = request.facet(facet).size(0)
})

// Populate the inspector panel
Expand Down Expand Up @@ -171,14 +181,12 @@ angular.module('kibana.histogram', [])
// Assemble segments
var segment_data = [];
_.each(v.entries, function(v, k) {
segment_data.push([v['time'],v['count']])
segment_data.push([v['time'],v[$scope.panel.mode]])
hits += v['count']; // The series level hits counter
$scope.hits += v['count']; // Entire dataset level hits counter
});

data.splice.apply(data,[1,0].concat(segment_data)) // Join histogram data


// Create the flot series object
var series = {
data: {
Expand Down
2 changes: 1 addition & 1 deletion panels/stringquery/editor.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div>
<div class="row-fluid">
<div class="span2">
<label class="small">Mulit-query</label><input type="checkbox" ng-change="set_multi(panel.multi) "ng-model="panel.multi" ng-checked="panel.multi">
<label class="small">Multi-query</label><input type="checkbox" ng-change="set_multi(panel.multi) "ng-model="panel.multi" ng-checked="panel.multi">
</div>
<div class="span3" ng-show="panel.multi">
<label class="small">Arrangement</label>
Expand Down
14 changes: 9 additions & 5 deletions panels/table/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ angular.module('kibana.table', [])
eventBus.register($scope,'selected_fields', function(event, fields) {
$scope.panel.fields = _.clone(fields)
});
eventBus.register($scope,'table_documents', function(event, docs) {
$scope.panel.query = docs.query;
$scope.data = docs.docs;
});
eventBus.register($scope,'table_documents', function(event, docs) {
$scope.panel.query = docs.query;
$scope.data = docs.docs;
});
}

$scope.set_sort = function(field) {
Expand Down Expand Up @@ -220,7 +220,11 @@ angular.module('kibana.table', [])
active: $scope.panel.fields
});
eventBus.broadcast($scope.$id,$scope.panel.group,"table_documents",
{query:$scope.panel.query,docs:$scope.data});
{
query: $scope.panel.query,
docs : $scope.data,
index: $scope.index
});
}

function set_time(time) {
Expand Down

0 comments on commit 906f3a3

Please sign in to comment.