Просмотр исходного кода

Implemented segmented loading in histogram panel

Rashid Khan 13 лет назад
Родитель
Сommit
ced5f47960
2 измененных файлов с 25 добавлено и 11 удалено
  1. 23 9
      panels/histogram/module.js
  2. 2 2
      panels/timepicker/module.js

+ 23 - 9
panels/histogram/module.js

@@ -45,13 +45,15 @@ angular.module('kibana.histogram', [])
     $scope.get_data();
   }
 
-  $scope.get_data = function() {
+  $scope.get_data = function(segment) {
     // Make sure we have everything for the request to complete
     if(_.isUndefined($scope.panel.index) || _.isUndefined($scope.time))
       return
 
+    _segment = _.isUndefined(segment) ? 0 : segment
+
     $scope.panel.loading = true;
-    var request = $scope.ejs.Request().indices($scope.panel.index);
+    var request = $scope.ejs.Request().indices($scope.panel.index[_segment]);
     
     // Build the question part of the query
     var queries = [];
@@ -81,25 +83,37 @@ angular.module('kibana.histogram', [])
     results.then(function(results) {
       $scope.panel.loading = false;
       $scope.hits = results.hits.total;
-      $scope.data = [];
+      if(_segment == 0)
+        $scope.data = [];
+      
       _.each(results.facets, function(v, k) {
         // Null values at each end of the time range ensure we see entire range
-        var data = [[$scope.time.from.getTime(), null]];
+        if(_.isUndefined($scope.data[k]) || _segment == 0) {
+          var data = [[$scope.time.from.getTime(), null]];
+        } else {
+          var data = $scope.data[k].data
+        }
+
         _.each(v.entries, function(v, k) {
           data.push([v['time'],v['count']])
         });
         data.push([$scope.time.to.getTime(), null])
         
-        var series = { data: {
-          label: $scope.panel.query[k].label || k, 
-          data: data,
-        }};
+        var series = { 
+          data: {
+            label: $scope.panel.query[k].label || k, 
+            data: data,
+          }
+        };
 
         if (!(_.isUndefined($scope.panel.query[k].color)))
           series.data.color = $scope.panel.query[k].color;
-        $scope.data.push(series.data)
+        
+        $scope.data[k] = series.data
       });
       $scope.$emit('render')
+      if(_segment < $scope.panel.index.length-1) 
+        $scope.get_data(_segment+1)
     });
   }
 

+ 2 - 2
panels/timepicker/module.js

@@ -182,7 +182,7 @@ angular.module('kibana.timepicker', [])
     // in a single object. Not sure if I like this.
     if($scope.panel.timed_indices) {
       indices($scope.time.from,$scope.time.to).then(function (p) {
-        $scope.time.index = p.join();
+        $scope.time.index = p;
         eventBus.broadcast($scope.$id,$scope.panel.group,'time',$scope.time)
       });
     } else {
@@ -207,7 +207,7 @@ angular.module('kibana.timepicker', [])
     });
 
     return all_indices().then(function(p) {
-      var indices = _.intersection(p,possible);
+      var indices = _.intersection(possible,p);
       indices.reverse();
       return indices.length == 0 ? [$scope.panel.defaultindex] : indices;
     })