diff --git a/public/app/panels/table/controller.ts b/public/app/panels/table/controller.ts index 281deec2852..4ae5a1807fa 100644 --- a/public/app/panels/table/controller.ts +++ b/public/app/panels/table/controller.ts @@ -37,15 +37,18 @@ export class TablePanelCtrl { transform: 'timeseries_to_rows', pageSize: 50, showHeader: true, - columns: [{ - pattern: '/.*/', - unit: 'short', - decimals: 2, - colors: ["rgba(245, 54, 54, 0.9)", "rgba(237, 129, 40, 0.89)", "rgba(50, 172, 45, 0.97)"], - }], + columns: [], }; - _.defaults($scope.panel, panelDefaults); + $scope.init = function() { + _.defaults($scope.panel, panelDefaults); + + if ($scope.panel.columns.length === 0) { + $scope.addColumnStyle(); + } + + panelSrv.init($scope); + }; $scope.setUnitFormat = function(column, subItem) { column.unit = subItem.value; @@ -73,7 +76,32 @@ export class TablePanelCtrl { panelHelper.broadcastRender($scope, $scope.table); }; - panelSrv.init($scope); + $scope.getColumnNames = function() { + if (!$scope.table) { + return []; + } + return _.map($scope.table.columns, function(col: any) { + return col.text; + }); + }; + + $scope.addColumnStyle = function() { + var columnStyleDefaults = { + unit: 'short', + decimals: 2, + colors: ["rgba(245, 54, 54, 0.9)", "rgba(237, 129, 40, 0.89)", "rgba(50, 172, 45, 0.97)"], + pattern: '/.*/', + colorMode: 'value', + }; + + $scope.panel.columns.push(angular.copy(columnStyleDefaults)); + }; + + $scope.removeColumnStyle = function(col) { + $scope.panel.columns = _.without($scope.panel.columns, col); + }; + + $scope.init(); } } diff --git a/public/app/panels/table/module.ts b/public/app/panels/table/module.ts index b804336efc4..39cd1056290 100644 --- a/public/app/panels/table/module.ts +++ b/public/app/panels/table/module.ts @@ -42,10 +42,10 @@ export function tablePanelDirective() { function createColumnFormater(style) { return function(v) { - if (v === null) { + if (v === null || v === void 0) { return '-'; } - if (_.isString(v)) { + if (_.isString(v) || style) { return v; } let valueFormater = kbn.valueFormats[style.unit]; @@ -79,7 +79,8 @@ export function tablePanelDirective() { let rowElements = $(document.createDocumentFragment()); let rowEnd = Math.min(panel.pageSize, data.rows.length); let rowStart = 0; - + // reset formater cache + formaters = []; for (var y = rowStart; y < rowEnd; y++) { let row = data.rows[y]; diff --git a/public/app/panels/table/options.html b/public/app/panels/table/options.html index f92241d53ec..c1d4ca658ac 100644 --- a/public/app/panels/table/options.html +++ b/public/app/panels/table/options.html @@ -41,76 +41,76 @@
Column Styles
-
-
-
    -
  • - -
  • - -
  • - Name or regex -
  • - -
  • - -
  • - -
  • - Unit -
  • - -
  • - Decimals -
  • -
  • - -
  • -
-
-
-
-
    -
  • - -
  • -
  • - Coloring -
  • -
  • - +
  • +
  • + Unit +
  • + +
  • + Decimals +
  • +
  • + +
  • +
+
+
+
+
    +
  • + +
  • +
  • + Coloring +
  • +
  • + -
  • -
  • - ThresholdsComma seperated values -
  • -
  • - -
  • -
  • - Colors -
  • -
  • - - - -
  • -
  • - invert order -
  • -
-
+ ng-change="render()" + style="width: 150px" + > + +
  • + ThresholdsComma seperated values +
  • +
  • + +
  • +
  • + Colors +
  • +
  • + + + +
  • +
  • + invert order +
  • + +
    +
    -
    - diff --git a/public/app/panels/table/specs/transformers_specs.ts b/public/app/panels/table/specs/transformers_specs.ts index cbe4fd6312b..ea3eb609976 100644 --- a/public/app/panels/table/specs/transformers_specs.ts +++ b/public/app/panels/table/specs/transformers_specs.ts @@ -30,7 +30,7 @@ describe('when transforming time series table', () => { expect(table.rows[0][1]).to.be('series1'); expect(table.rows[1][1]).to.be('series1'); expect(table.rows[2][1]).to.be('series2'); - expect(table.rows[0][2]).to.be('12.12'); + expect(table.rows[0][2]).to.be(12.12); }); it('should return 3 rows', () => { @@ -59,12 +59,12 @@ describe('when transforming time series table', () => { it ('should return 2 rows', () => { expect(table.rows.length).to.be(2); - expect(table.rows[0][1]).to.be('12.12'); - expect(table.rows[0][2]).to.be('16.12'); + expect(table.rows[0][1]).to.be(12.12); + expect(table.rows[0][2]).to.be(16.12); }); - it ('should show - when no value for timestamp', () => { - expect(table.rows[1][2]).to.be('-'); + it ('should be undefined when no value for timestamp', () => { + expect(table.rows[1][2]).to.be(undefined); }); }); });