Commit 3474ee09 by Rashid Khan

Fix multiple histograms and hit count

parent 802d34ce
...@@ -13,13 +13,13 @@ angular.module('kibana.dashcontrol', []) ...@@ -13,13 +13,13 @@ angular.module('kibana.dashcontrol', [])
load : { load : {
gist: true, gist: true,
elasticsearch: true, elasticsearch: true,
local: true, local: true
}, },
hide_control: false, hide_control: false,
elasticsearch_size: 20, elasticsearch_size: 20,
elasticsearch_saveto: $scope.config.kibana_index, elasticsearch_saveto: $scope.config.kibana_index,
temp: true, temp: true,
temp_ttl: '30d', temp_ttl: '30d'
} }
_.defaults($scope.panel,_d); _.defaults($scope.panel,_d);
...@@ -27,7 +27,7 @@ angular.module('kibana.dashcontrol', []) ...@@ -27,7 +27,7 @@ angular.module('kibana.dashcontrol', [])
var _dash = { var _dash = {
title: "", title: "",
editable: true, editable: true,
rows: [], rows: []
} }
$scope.init = function() { $scope.init = function() {
...@@ -69,7 +69,7 @@ angular.module('kibana.dashcontrol', []) ...@@ -69,7 +69,7 @@ angular.module('kibana.dashcontrol', [])
$scope.elasticsearch = {}; $scope.elasticsearch = {};
} }
$scope.export = function() { $scope.to_file = function() {
var blob = new Blob([angular.toJson($scope.dashboards,true)], {type: "application/json;charset=utf-8"}); var blob = new Blob([angular.toJson($scope.dashboards,true)], {type: "application/json;charset=utf-8"});
saveAs(blob, $scope.dashboards.title+"-"+new Date().getTime()); saveAs(blob, $scope.dashboards.title+"-"+new Date().getTime());
} }
...@@ -93,7 +93,7 @@ angular.module('kibana.dashcontrol', []) ...@@ -93,7 +93,7 @@ angular.module('kibana.dashcontrol', [])
type : type, type : type,
id : id, id : id,
link : location.href.replace(location.hash,"")+"#dashboard/"+type+"/"+id, link : location.href.replace(location.hash,"")+"#dashboard/"+type+"/"+id,
title : title, title : title
}; };
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<h5>Locally</h5> <h5>Locally</h5>
<form> <form>
<ul class="nav nav-list"> <ul class="nav nav-list">
<li><a ng-show="panel.save.local" ng-click="export()"><i class="icon-download"></i> Export to File</a></li> <li><a ng-show="panel.save.local" ng-click="to_file()"><i class="icon-download"></i> Export to File</a></li>
<li><a ng-show="panel.save.default" ng-click="default()"><i class="icon-bookmark"></i> Set as My Default</a></li> <li><a ng-show="panel.save.default" ng-click="default()"><i class="icon-bookmark"></i> Set as My Default</a></li>
<li><a ng-show="panel.save.default" ng-click="purge()"><i class="icon-ban-circle"></i> Clear My Default</a></li> <li><a ng-show="panel.save.default" ng-click="purge()"><i class="icon-ban-circle"></i> Clear My Default</a></li>
</ul> </ul>
......
...@@ -71,11 +71,13 @@ angular.module('kibana.histogram', []) ...@@ -71,11 +71,13 @@ angular.module('kibana.histogram', [])
// Build the facet part // Build the facet part
_.each(queries, function(v) { _.each(queries, function(v) {
request = request request = request
.facet($scope.ejs.DateHistogramFacet(_.indexOf(queries,v)) .facet($scope.ejs.DateHistogramFacet("chart"+_.indexOf(queries,v))
.field($scope.time.field) .field($scope.time.field)
.interval($scope.panel.interval) .interval($scope.panel.interval)
.facetFilter($scope.ejs.QueryFilter(v)) .facetFilter($scope.ejs.QueryFilter(v))
).query(v).size(0) )
.facet($scope.ejs.QueryFacet("query"+_.indexOf(queries,v)).query(v)
).size(0)
}) })
$scope.populate_modal(request); $scope.populate_modal(request);
...@@ -93,16 +95,24 @@ angular.module('kibana.histogram', []) ...@@ -93,16 +95,24 @@ angular.module('kibana.histogram', [])
} }
if($scope.query_id === query_id) { if($scope.query_id === query_id) {
$scope.hits += results.hits.total;
var i = 0;
_.each(results.facets, function(v, k) { _.each(results.facets, function(v, k) {
// If this isn't a date histogram it must be a QueryFacet, get the
// count and return
if(v._type !== 'date_histogram') {
$scope.hits += v.count;
return
}
// Null values at each end of the time range ensure we see entire range // Null values at each end of the time range ensure we see entire range
if(_.isUndefined($scope.data[k]) || _segment == 0) { if(_.isUndefined($scope.data[i]) || _segment == 0) {
var data = [[$scope.time.from.getTime(), null],[$scope.time.to.getTime(), null]]; var data = [[$scope.time.from.getTime(), null],[$scope.time.to.getTime(), null]];
} else { } else {
var data = $scope.data[k].data var data = $scope.data[i].data
} }
// Assemble segments
var segment_data = []; var segment_data = [];
_.each(v.entries, function(v, k) { _.each(v.entries, function(v, k) {
segment_data.push([v['time'],v['count']]) segment_data.push([v['time'],v['count']])
...@@ -110,18 +120,20 @@ angular.module('kibana.histogram', []) ...@@ -110,18 +120,20 @@ angular.module('kibana.histogram', [])
data.splice.apply(data,[1,0].concat(segment_data)) data.splice.apply(data,[1,0].concat(segment_data))
// Create the flot series
var series = { var series = {
data: { data: {
label: $scope.panel.query[k].label || (parseInt(k)+1), label: $scope.panel.query[i].label || "query"+(parseInt(i)+1),
data: data, data: data,
}, },
}; };
if (!(_.isUndefined($scope.panel.query[k].color))) if (!(_.isUndefined($scope.panel.query[i].color)))
series.data.color = $scope.panel.query[k].color; series.data.color = $scope.panel.query[i].color;
$scope.data[k] = series.data $scope.data[i] = series.data
i++;
}); });
eventBus.broadcast($scope.$id,$scope.panel.group,'hits',$scope.hits) eventBus.broadcast($scope.$id,$scope.panel.group,'hits',$scope.hits)
...@@ -205,6 +217,7 @@ angular.module('kibana.histogram', []) ...@@ -205,6 +217,7 @@ angular.module('kibana.histogram', [])
// Populate element. Note that jvectormap appends, does not replace. // Populate element. Note that jvectormap appends, does not replace.
scripts.wait(function(){ scripts.wait(function(){
// Populate element // Populate element
try { try {
var plot = $.plot(elem, scope.data, { var plot = $.plot(elem, scope.data, {
...@@ -244,7 +257,11 @@ angular.module('kibana.histogram', []) ...@@ -244,7 +257,11 @@ angular.module('kibana.histogram', [])
_.each(plot.getData(),function(series) { _.each(plot.getData(),function(series) {
scope.legend.push(_.pick(series,'label','color')) scope.legend.push(_.pick(series,'label','color'))
}) })
// Work around for missing legend at initialization
if(!scope.$$phase)
scope.$apply() scope.$apply()
} catch(e) { } catch(e) {
elem.text(e) elem.text(e)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment