|
|
@@ -73,7 +73,7 @@
|
|
|
*/
|
|
|
|
|
|
|
|
|
-angular.module('kibana-dash.panels', [])
|
|
|
+angular.module('kibana.panels', [])
|
|
|
.directive('histogram', function() {
|
|
|
return {
|
|
|
restrict: 'A',
|
|
|
@@ -641,4 +641,148 @@ angular.module('kibana-dash.panels', [])
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
+})
|
|
|
+.directive('map', function() {
|
|
|
+ return {
|
|
|
+ restrict: 'A',
|
|
|
+ link: function(scope, elem, attrs) {
|
|
|
+
|
|
|
+ // Specify defaults for ALL directives
|
|
|
+ var _d = {
|
|
|
+ queries : ["*"],
|
|
|
+ interval: secondsToHms(calculate_interval(scope.from,scope.to,40,0)/1000),
|
|
|
+ colors : ["#BF3030","#1D7373","#86B32D","#A98A21","#411F73"],
|
|
|
+ show : ['bars'],
|
|
|
+ size : 100,
|
|
|
+ exclude : []
|
|
|
+ }
|
|
|
+
|
|
|
+ // Set ready flag and fill parameters (REQUIRED IN EVERY PANEL)
|
|
|
+ scope.$watch(function () {
|
|
|
+ return (attrs.params && scope.index) ? true : false;
|
|
|
+ }, function (ready) {
|
|
|
+ scope.ready = ready;
|
|
|
+ if(ready) {
|
|
|
+ scope.params = JSON.parse(attrs.params);
|
|
|
+ _.each(_d, function(v, k) {
|
|
|
+ scope.params[k] = _.isUndefined(scope.params[k])
|
|
|
+ ? _d[k] : scope.params[k];
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // Also get the data if time frame changes.
|
|
|
+ // (REQUIRED IN EVERY PANEL)
|
|
|
+ scope.$watch(function() {
|
|
|
+ return angular.toJson([scope.from, scope.to, scope.ready])
|
|
|
+ }, function(){
|
|
|
+ if(scope.ready)
|
|
|
+ if (_.isUndefined(attrs.params.interval))
|
|
|
+ scope.params.interval = secondsToHms(
|
|
|
+ calculate_interval(scope.from,scope.to,50,0)/1000),
|
|
|
+ get_data(scope,elem,attrs);
|
|
|
+ });
|
|
|
+
|
|
|
+ // Re-rending the panel if it is resized,
|
|
|
+ scope.$watch('data', function() {
|
|
|
+ render_panel(scope,elem,attrs);
|
|
|
+ });
|
|
|
+
|
|
|
+ // Or if the model changes
|
|
|
+ angular.element(window).bind('resize', function(){
|
|
|
+ render_panel(scope,elem,attrs);
|
|
|
+ });
|
|
|
+
|
|
|
+ // Function for getting data
|
|
|
+ function get_data(scope,elem,attrs) {
|
|
|
+ var params = scope.params;
|
|
|
+ var ejs = scope.ejs;
|
|
|
+ var request = ejs.Request().indices(scope.index);
|
|
|
+
|
|
|
+ // Build the question part of the query
|
|
|
+ var query = ejs.FilteredQuery(
|
|
|
+ ejs.QueryStringQuery(params.query || '*'),
|
|
|
+ ejs.RangeFilter(config.timefield)
|
|
|
+ .from(scope.from)
|
|
|
+ .to(scope.to)
|
|
|
+ .cache(false)
|
|
|
+ );
|
|
|
+
|
|
|
+ // Then the insert into facet and make the request
|
|
|
+ var results = request
|
|
|
+ .facet(ejs.TermsFacet('worldmap')
|
|
|
+ .field(params.field)
|
|
|
+ .size(params['size'])
|
|
|
+ .exclude(params.exclude)
|
|
|
+ .facetFilter(ejs.QueryFilter(query))
|
|
|
+ )
|
|
|
+ .doSearch();
|
|
|
+
|
|
|
+ // Populate scope when we have results
|
|
|
+ results.then(function(results) {
|
|
|
+ scope.hits = results.hits.total;
|
|
|
+ scope.data = results.facets.worldmap.terms;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // Function for rendering panel
|
|
|
+ function render_panel(scope,elem,attrs) {
|
|
|
+ // Parse our params object
|
|
|
+ var params = scope.params;
|
|
|
+
|
|
|
+ // Determine format
|
|
|
+ var show = _.isUndefined(params.show) ? {
|
|
|
+ bars: true, lines: false, points: false, fill: false
|
|
|
+ } : {
|
|
|
+ lines: _.indexOf(params.show,'lines') < 0 ? false : true,
|
|
|
+ bars: _.indexOf(params.show,'bars') < 0 ? false : true,
|
|
|
+ points: _.indexOf(params.show,'points') < 0 ? false : true,
|
|
|
+ fill: _.indexOf(params.show,'fill') < 0 ? false : true
|
|
|
+ }
|
|
|
+
|
|
|
+ scope.graph = [];
|
|
|
+ // Push null values at beginning and end of timeframe
|
|
|
+ _.each(scope.data, function(v, k) {
|
|
|
+ var series = {};
|
|
|
+ var data = [[scope.from.getTime(), null]];
|
|
|
+ _.each(v.entries, function(v, k) {
|
|
|
+ data.push([v['time'],v['count']])
|
|
|
+ });
|
|
|
+ data.push([scope.to.getTime(), null])
|
|
|
+ series.data = {
|
|
|
+ label: params.queries[k],
|
|
|
+ data: data,
|
|
|
+ color: params.colors[k%params.colors.length]
|
|
|
+ };
|
|
|
+ scope.graph.push(series.data)
|
|
|
+ });
|
|
|
+
|
|
|
+ // Set barwidth based on specified interval
|
|
|
+ var barwidth = interval_to_seconds(params.interval)*1000
|
|
|
+ var values = {}
|
|
|
+ _.each(scope.data, function(v) {
|
|
|
+ values[v.term.toUpperCase()] = v.count;
|
|
|
+ });
|
|
|
+ console.log(values)
|
|
|
+
|
|
|
+ // Populate element
|
|
|
+ $('.jvectormap-label,.jvectormap-zoomin,.jvectormap-zoomout').remove();
|
|
|
+ elem.text('');
|
|
|
+ elem.vectorMap({
|
|
|
+ map: 'world_mill_en',
|
|
|
+ regionStyle: {initial: {fill: '#eee'}},
|
|
|
+ zoomOnScroll: false,
|
|
|
+ backgroundColor: '#fff',
|
|
|
+ series: {
|
|
|
+ regions: [{
|
|
|
+ values: values,
|
|
|
+ scale: ['#C8EEFF', '#0071A4'],
|
|
|
+ normalizeFunction: 'polynomial'
|
|
|
+ }]
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //elem.show();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
});
|