From 7b2a21994f2fe8c0fda085e6686273075affb3c9 Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Sun, 10 Apr 2016 20:51:21 -0700 Subject: [PATCH 1/5] Moved mappings to new tab, added rangeMaps feature --- .../app/plugins/panel/singlestat/editor.html | 32 ------- .../plugins/panel/singlestat/mappings.html | 84 +++++++++++++++++++ public/app/plugins/panel/singlestat/module.ts | 65 +++++++++++--- 3 files changed, 137 insertions(+), 44 deletions(-) create mode 100644 public/app/plugins/panel/singlestat/mappings.html diff --git a/public/app/plugins/panel/singlestat/editor.html b/public/app/plugins/panel/singlestat/editor.html index 437445a2400..7deb697e508 100644 --- a/public/app/plugins/panel/singlestat/editor.html +++ b/public/app/plugins/panel/singlestat/editor.html @@ -192,35 +192,3 @@ - -
-
-
-
    -
  • - Value to text mapping -
  • -
  • - -
  • -
  • - -
  • -
  • - -
  • -
  • - -
  • - -
  • - - - -
  • - -
-
-
-
-
diff --git a/public/app/plugins/panel/singlestat/mappings.html b/public/app/plugins/panel/singlestat/mappings.html new file mode 100644 index 00000000000..eab9b0030b6 --- /dev/null +++ b/public/app/plugins/panel/singlestat/mappings.html @@ -0,0 +1,84 @@ +
+
+
+
    +
  • + Type +
  • +
  • + +
  • +
+
+
+
+
+
+
+
+
    +
  • + Value to text mapping +
  • +
  • + +
  • +
  • + +
  • +
  • + +
  • +
  • + +
  • + +
  • + + + +
  • + +
+
+
+
+
+
+
Set range mappings
+
+
+
+
    +
  • + +
  • +
  • + From +
  • +
  • + +
  • +
  • + To +
  • +
  • + +
  • +
  • + Text +
  • +
  • + +
  • +
+
+
+
+ + +
+
diff --git a/public/app/plugins/panel/singlestat/module.ts b/public/app/plugins/panel/singlestat/module.ts index 8033e73468d..84e89b48bc6 100644 --- a/public/app/plugins/panel/singlestat/module.ts +++ b/public/app/plugins/panel/singlestat/module.ts @@ -34,6 +34,14 @@ class SingleStatCtrl extends MetricsPanelCtrl { valueMaps: [ { value: 'null', op: '=', text: 'N/A' } ], + mappingTypes: [ + {name: 'value to text', value: 1}, + {name: 'range to text', value: 2}, + ], + rangeMaps: [ + { from: 'null', to: 'null', text: 'N/A' } + ], + mappingType: 1, nullPointMode: 'connected', valueName: 'avg', prefixFontSize: '50%', @@ -71,6 +79,7 @@ class SingleStatCtrl extends MetricsPanelCtrl { onInitEditMode() { this.fontSizes = ['20%', '30%','50%','70%','80%','100%', '110%', '120%', '150%', '170%', '200%']; this.addEditorTab('Options', 'public/app/plugins/panel/singlestat/editor.html', 2); + this.addEditorTab('Mappings', 'public/app/plugins/panel/singlestat/mappings.html', 3); this.unitFormats = kbn.getUnitFormats(); } @@ -195,23 +204,45 @@ class SingleStatCtrl extends MetricsPanelCtrl { } } - // check value to text mappings - for (var i = 0; i < this.panel.valueMaps.length; i++) { - var map = this.panel.valueMaps[i]; - // special null case - if (map.value === 'null') { - if (data.value === null || data.value === void 0) { + // check value to text mappings if its enabled + if (this.panel.mappingType === 1) { + for (var i = 0; i < this.panel.valueMaps.length; i++) { + var map = this.panel.valueMaps[i]; + // special null case + if (map.value === 'null') { + if (data.value === null || data.value === void 0) { + data.valueFormated = map.text; + return; + } + continue; + } + + // value/number to text mapping + var value = parseFloat(map.value); + if (value === data.valueRounded) { data.valueFormated = map.text; return; } - continue; } + } else if (this.panel.mappingType === 2) { + for (var i = 0; i < this.panel.rangeMaps.length; i++) { + var map = this.panel.rangeMaps[i]; + // special null case + if (map.from === 'null' && map.to === 'null') { + if (data.value === null || data.value === void 0) { + data.valueFormated = map.text; + return; + } + continue; + } - // value/number to text mapping - var value = parseFloat(map.value); - if (value === data.valueRounded) { - data.valueFormated = map.text; - return; + // value/number to range mapping + var from = parseFloat(map.from); + var to = parseFloat(map.to); + if (to >= data.valueRounded && from <= data.valueRounded) { + data.valueFormated = map.text; + return; + } } } @@ -230,6 +261,16 @@ class SingleStatCtrl extends MetricsPanelCtrl { this.panel.valueMaps.push({value: '', op: '=', text: '' }); } + removeRangeMap(rangeMap) { + var index = _.indexOf(this.panel.rangeMaps, rangeMap); + this.panel.rangeMaps.splice(index, 1); + this.render(); + }; + + addRangeMap() { + this.panel.rangeMaps.push({from: '', to: '', text: ''}); + } + link(scope, elem, attrs, ctrl) { var $location = this.$location; var linkSrv = this.linkSrv; From 5defc2a3d23190526bdf0475e8aba6895f604ef1 Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Sun, 10 Apr 2016 23:21:42 -0700 Subject: [PATCH 2/5] Fixed remove mapping function --- public/app/plugins/panel/singlestat/mappings.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/app/plugins/panel/singlestat/mappings.html b/public/app/plugins/panel/singlestat/mappings.html index eab9b0030b6..5c3d604fa13 100644 --- a/public/app/plugins/panel/singlestat/mappings.html +++ b/public/app/plugins/panel/singlestat/mappings.html @@ -52,7 +52,7 @@
  • - +
  • From From c1cd1fedf42bd7bfdd599816dae0488f643a0533 Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Tue, 26 Apr 2016 01:54:25 -0700 Subject: [PATCH 3/5] Added relevant tests --- .../singlestat/specs/singlestat-specs.ts | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/public/app/plugins/panel/singlestat/specs/singlestat-specs.ts b/public/app/plugins/panel/singlestat/specs/singlestat-specs.ts index dc85454b64a..3d6c565443b 100644 --- a/public/app/plugins/panel/singlestat/specs/singlestat-specs.ts +++ b/public/app/plugins/panel/singlestat/specs/singlestat-specs.ts @@ -84,4 +84,29 @@ describe('SingleStatCtrl', function() { expect(ctx.data.valueFormated).to.be('OK'); }); }); + + singleStatScenario('When range to text mapping is specifiedfor first range', function(ctx) { + ctx.setup(function() { + ctx.datapoints = [[41,50]]; + ctx.ctrl.panel.mappingType = 2; + ctx.ctrl.panel.rangeMaps = [{from: '10', to: '50', text: 'OK'},{from: '51', to: '100', text: 'NOT OK'}]; + }); + + it('Should replace value with text OK', function() { + expect(ctx.data.valueFormated).to.be('OK'); + }); + }); + + singleStatScenario('When range to text mapping is specified for other ranges', function(ctx) { + ctx.setup(function() { + ctx.datapoints = [[65,75]]; + ctx.ctrl.panel.mappingType = 2; + ctx.ctrl.panel.rangeMaps = [{from: '10', to: '50', text: 'OK'},{from: '51', to: '100', text: 'NOT OK'}]; + }); + + it('Should replace value with text NOT OK', function() { + expect(ctx.data.valueFormated).to.be('NOT OK'); + }); + }); + }); From b42064acdb470f324bbb32a45546c0b563f53bb2 Mon Sep 17 00:00:00 2001 From: bergquist Date: Mon, 2 May 2016 10:40:28 +0200 Subject: [PATCH 4/5] tech(singlestat): fixes indentation --- .../plugins/panel/singlestat/mappings.html | 90 +++++++++---------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/public/app/plugins/panel/singlestat/mappings.html b/public/app/plugins/panel/singlestat/mappings.html index 5c3d604fa13..749681be2f1 100644 --- a/public/app/plugins/panel/singlestat/mappings.html +++ b/public/app/plugins/panel/singlestat/mappings.html @@ -1,17 +1,17 @@
    -
    -
    -
      -
    • - Type -
    • -
    • - -
    • -
    -
    -
    +
    +
    +
      +
    • + Type +
    • +
    • + +
    • +
    +
    +
    @@ -46,39 +46,39 @@
    -
    Set range mappings
    -
    -
    -
    -
      -
    • - -
    • -
    • - From -
    • -
    • - -
    • +
      Set range mappings
      +
      +
      +
      +
      • - To -
      • -
      • - -
      • + +
      • - Text -
      • -
      • - -
      • -
      -
      -
      -
      + From + +
    • + +
    • +
    • + To +
    • +
    • + +
    • +
    • + Text +
    • +
    • + +
    • +
    +
    +
    +
    - -
    + +
From 91047ffa30bf43c1ec93cf353b766e30b55edcf9 Mon Sep 17 00:00:00 2001 From: bergquist Date: Mon, 2 May 2016 11:39:33 +0200 Subject: [PATCH 5/5] tech(singlestat): convert to gf-form --- .../plugins/panel/singlestat/mappings.html | 126 +++++++----------- public/app/plugins/panel/singlestat/module.ts | 2 +- 2 files changed, 51 insertions(+), 77 deletions(-) diff --git a/public/app/plugins/panel/singlestat/mappings.html b/public/app/plugins/panel/singlestat/mappings.html index 749681be2f1..a1105a159dd 100644 --- a/public/app/plugins/panel/singlestat/mappings.html +++ b/public/app/plugins/panel/singlestat/mappings.html @@ -1,84 +1,58 @@
-
-
-
    -
  • - Type -
  • -
  • - -
  • -
-
-
-
+
+
+ + Type + +
+ +
+
+
-
-
-
    -
  • - Value to text mapping -
  • -
  • - -
  • -
  • - -
  • -
  • - -
  • -
  • - -
  • +
    Set valuea mappings
    +
    +
    + + + + + + + + +
    -
  • - - - -
  • - -
-
-
-
+
+ +
+
-
Set range mappings
-
-
-
-
    -
  • - -
  • -
  • - From -
  • -
  • - -
  • -
  • - To -
  • -
  • - -
  • -
  • - Text -
  • -
  • - -
  • -
-
-
-
+
Set range mappings
+
+
+ + + + From + + To + + Text + +
- -
+
+ +
+
diff --git a/public/app/plugins/panel/singlestat/module.ts b/public/app/plugins/panel/singlestat/module.ts index 9cf78eff680..e2e529d00c7 100644 --- a/public/app/plugins/panel/singlestat/module.ts +++ b/public/app/plugins/panel/singlestat/module.ts @@ -81,7 +81,7 @@ class SingleStatCtrl extends MetricsPanelCtrl { onInitEditMode() { this.fontSizes = ['20%', '30%','50%','70%','80%','100%', '110%', '120%', '150%', '170%', '200%']; this.addEditorTab('Options', 'public/app/plugins/panel/singlestat/editor.html', 2); - this.addEditorTab('Mappings', 'public/app/plugins/panel/singlestat/mappings.html', 3); + this.addEditorTab('Value Mappings', 'public/app/plugins/panel/singlestat/mappings.html', 3); this.unitFormats = kbn.getUnitFormats(); }