From 6b6355e6194a96827ecc1a947ff709726531dfd8 Mon Sep 17 00:00:00 2001 From: Rashid Khan Date: Fri, 3 May 2013 13:54:29 -0700 Subject: [PATCH] Added ability to customize interval in histogram, issue #7. Also fixed bug that caused editor and panel to be in different scopes --- js/directives.js | 13 +++++++++++ panels/column/editor.html | 2 +- panels/dashcontrol/editor.html | 2 +- panels/debug/editor.html | 2 +- panels/fields/editor.html | 2 +- panels/fields/module.js | 5 ++--- panels/histogram/editor.html | 40 ++++++++++++++++++++-------------- panels/histogram/module.js | 40 ++++++++++++++++++++++++---------- panels/hits/editor.html | 2 +- panels/map/editor.html | 2 +- panels/pie/editor.html | 2 +- panels/stringquery/editor.html | 2 +- panels/table/editor.html | 2 +- panels/text/editor.html | 2 +- panels/timepicker/editor.html | 2 +- partials/paneleditor.html | 3 ++- partials/roweditor.html | 2 +- 17 files changed, 82 insertions(+), 43 deletions(-) diff --git a/js/directives.js b/js/directives.js index d3c6fa31af773..ddc058ec01492 100644 --- a/js/directives.js +++ b/js/directives.js @@ -15,6 +15,19 @@ angular.module('kibana.directives', []) } }; }) +.directive('addPanel', function($compile) { + return { + restrict: 'A', + link: function(scope, elem, attrs) { + scope.$watch('panel.type', function(n,o) { + if(!_.isUndefined(scope.panel.type)) { + var template = '
'; + elem.html($compile(angular.element(template))(scope)); + } + }) + } + }; +}) .directive('arrayJoin', function() { return { restrict: 'A', diff --git a/panels/column/editor.html b/panels/column/editor.html index e5dec0361b40c..05873f27850f7 100644 --- a/panels/column/editor.html +++ b/panels/column/editor.html @@ -1,4 +1,4 @@ -
+

Add Panel to Column

diff --git a/panels/dashcontrol/editor.html b/panels/dashcontrol/editor.html index c95a1f014d102..83b6f1c467ed7 100644 --- a/panels/dashcontrol/editor.html +++ b/panels/dashcontrol/editor.html @@ -1,4 +1,4 @@ -
+
Allow saving to
diff --git a/panels/debug/editor.html b/panels/debug/editor.html index afd0586f5b87b..769d53b7cd10e 100644 --- a/panels/debug/editor.html +++ b/panels/debug/editor.html @@ -1,4 +1,4 @@ -
+
Length
diff --git a/panels/fields/editor.html b/panels/fields/editor.html index cea7c968beb24..42ddee0315e4c 100644 --- a/panels/fields/editor.html +++ b/panels/fields/editor.html @@ -1,4 +1,4 @@ -
+
Popup Position
diff --git a/panels/fields/module.js b/panels/fields/module.js index dcafdb463604f..3b21f6d4d97be 100644 --- a/panels/fields/module.js +++ b/panels/fields/module.js @@ -13,7 +13,7 @@ ### Group Events #### Recieves * table_documents :: An object containing the documents in the table panel - *** Sends + #### Sends * fields :: an object containing the sort order, existing fields and selected fields */ @@ -42,7 +42,6 @@ angular.module('kibana.fields', []) $scope.docs = docs.docs; }); eventBus.register($scope,"get_fields", function(event,id) { - console.log("field.get_fields"); eventBus.broadcast($scope.$id,$scope.panel.group,"selected_fields",$scope.active); }); } @@ -79,7 +78,7 @@ angular.module('kibana.fields', []) } $scope.build_search = function(field, value,negate) { - $scope.panel.query = add_to_query($scope.panel.query,field,value,negate) + $scope.panel.query = [add_to_query($scope.panel.query,field,value,negate)] eventBus.broadcast($scope.$id,$scope.panel.group,'query',$scope.panel.query); } diff --git a/panels/histogram/editor.html b/panels/histogram/editor.html index 0a4831a029357..68d0c4663ffbf 100644 --- a/panels/histogram/editor.html +++ b/panels/histogram/editor.html @@ -1,4 +1,4 @@ -
+
@@ -23,9 +23,8 @@
Query
-
- - + +
@@ -34,29 +33,38 @@
Query
Chart Options
-
-
-
-
-
-
-
+
+
+
+
+
+
+
- +
- +
-
+
- + +
+
+
- + +
+
+ +
+
+
Panel Spy
diff --git a/panels/histogram/module.js b/panels/histogram/module.js index 9ec721b0ca936..ee5f0eea05375 100644 --- a/panels/histogram/module.js +++ b/panels/histogram/module.js @@ -10,7 +10,8 @@ * query :: an array of objects as such: {query: 'somequery', label 'legent text'}. this is usually populated by a stringquery panel wher the query and label parameter are the same - * interval :: Generated automatically. Tells ES how to bucket the data points + * auto_int :: Auto calculate data point interval? + * interval :: Datapoint interval in elasticsearch date math format (eg 1d, 1w, 1y, 5y) * fill :: Only applies to line charts. Level of area shading from 0-10 * linewidth :: Only applies to line charts. How thick the line should be in pixels While the editor only exposes 0-10, this can be any numeric value. @@ -44,7 +45,8 @@ angular.module('kibana.histogram', []) var _d = { group : "default", query : [ {query: "*", label:"Query"} ], - interval : secondsToHms(calculate_interval($scope.from,$scope.to,40,0)/1000), + auto_int : true, + interval : '5m', fill : 3, linewidth : 3, timezone : 'browser', // browser, utc or a standard timezone @@ -102,6 +104,9 @@ angular.module('kibana.histogram', []) if(_.isUndefined($scope.panel.index) || _.isUndefined($scope.time)) return + if ($scope.panel.auto_int) + $scope.panel.interval = secondsToHms(calculate_interval($scope.time.from,$scope.time.to,50,0)/1000); + $scope.panel.loading = true; var _segment = _.isUndefined(segment) ? 0 : segment var request = $scope.ejs.Request().indices($scope.panel.index[_segment]); @@ -206,7 +211,7 @@ angular.module('kibana.histogram', []) // function $scope.zoom // factor :: Zoom factor, so 0.5 = cuts timespan in half, 2 doubles timespan $scope.zoom = function(factor) { - eventBus.broadcast($scope.$id,$scope.panel.group,'zoom',factor) + eventBus.broadcast($scope.$id,$scope.panel.group,'zoom',factor); } // I really don't like this function, too much dom manip. Break out into directive? @@ -220,11 +225,24 @@ angular.module('kibana.histogram', []) } } + $scope.set_refresh = function (state) { + $scope.refresh = state; + } + + $scope.close_edit = function() { + if($scope.refresh) + $scope.get_data(); + $scope.refresh = false; + $scope.$emit('render'); + } + $scope.set_time = function(time) { $scope.time = time; - $scope.panel.index = _.isUndefined(time.index) ? $scope.panel.index : time.index - $scope.panel.interval = secondsToHms( - calculate_interval(time.from,time.to,50,0)/1000); + // Should I be storing the index on the panel? It causes errors if the index + // goes away. Hmmm. + $scope.panel.index = time.index || $scope.panel.index + // Only calculate interval if auto_int is set, otherwise don't touch it + $scope.get_data(); } @@ -234,8 +252,6 @@ angular.module('kibana.histogram', []) restrict: 'A', link: function(scope, elem, attrs, ctrl) { - var height = scope.panel.height || scope.row.height; - // Receive render events scope.$on('render',function(){ render_panel(); @@ -248,6 +264,7 @@ angular.module('kibana.histogram', []) // Function for rendering panel function render_panel() { + // Set barwidth based on specified interval var barwidth = interval_to_seconds(scope.panel.interval)*1000 @@ -288,7 +305,7 @@ angular.module('kibana.histogram', []) }, selection: { mode: "x", - color: '#999' + color: '#ccc' }, grid: { backgroundColor: '#fff', @@ -323,15 +340,16 @@ angular.module('kibana.histogram', []) } function tt(x, y, contents) { + // If the tool tip already exists, don't recreate it, just update it var tooltip = $('#pie-tooltip').length ? $('#pie-tooltip') : $('
'); - //var tooltip = $('#pie-tooltip') + tooltip.html(contents).css({ position: 'absolute', top : y + 5, left : x + 5, color : "#000", - border : '2px solid #000', + border : '1px solid #000', padding : '10px', 'font-size': '11pt', 'font-weight' : 200, diff --git a/panels/hits/editor.html b/panels/hits/editor.html index 9d7fa903269d7..801d7fe041b78 100644 --- a/panels/hits/editor.html +++ b/panels/hits/editor.html @@ -1,4 +1,4 @@ -
+
diff --git a/panels/map/editor.html b/panels/map/editor.html index 95039c4e1e752..9335cb82dbb2d 100644 --- a/panels/map/editor.html +++ b/panels/map/editor.html @@ -1,4 +1,4 @@ -
+
The map panel uses 2 letter country or US state codes to plot concentrations on a map. Darker terroritories mean more records matched that area. If multiple queries are sent from a single panel the first query will be displayed
diff --git a/panels/pie/editor.html b/panels/pie/editor.html index 4a9b1d1f4b96c..9411e027630ac 100644 --- a/panels/pie/editor.html +++ b/panels/pie/editor.html @@ -1,4 +1,4 @@ -
+
diff --git a/panels/stringquery/editor.html b/panels/stringquery/editor.html index a057ca99b0f0c..4e3948556fb7d 100644 --- a/panels/stringquery/editor.html +++ b/panels/stringquery/editor.html @@ -1,4 +1,4 @@ -
+
diff --git a/panels/table/editor.html b/panels/table/editor.html index 73c30b5e65ff9..f724fcaf895be 100644 --- a/panels/table/editor.html +++ b/panels/table/editor.html @@ -1,4 +1,4 @@ -
+
Query
diff --git a/panels/text/editor.html b/panels/text/editor.html index b49fff3bbd852..02177bc34d567 100644 --- a/panels/text/editor.html +++ b/panels/text/editor.html @@ -1,4 +1,4 @@ -
+
diff --git a/panels/timepicker/editor.html b/panels/timepicker/editor.html index 3d30ef8def13a..67f75e79ecdd8 100644 --- a/panels/timepicker/editor.html +++ b/panels/timepicker/editor.html @@ -1,4 +1,4 @@ -
+
Default Mode
diff --git a/partials/paneleditor.html b/partials/paneleditor.html index 8b445b73bea41..4f27d7744c3a4 100644 --- a/partials/paneleditor.html +++ b/partials/paneleditor.html @@ -13,5 +13,6 @@

{{panel.type}} panel settings \ No newline at end of file diff --git a/partials/roweditor.html b/partials/roweditor.html index 59bf6e18fdad8..13a9751aad610 100644 --- a/partials/roweditor.html +++ b/partials/roweditor.html @@ -25,7 +25,7 @@

New Panel

-
+