]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Use human readable units on the sparkline graphs 23446/head
authorTiago Melo <tspmelo@gmail.com>
Mon, 6 Aug 2018 10:32:02 +0000 (11:32 +0100)
committerTiago Melo <tspmelo@gmail.com>
Thu, 16 Aug 2018 14:00:46 +0000 (15:00 +0100)
Fixes: http://tracker.ceph.com/issues/25075
Signed-off-by: Tiago Melo <tmelo@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi/iscsi.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-list/osd-list.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/components/sparkline/sparkline.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/components/sparkline/sparkline.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.html

index 033a65e37a9cbf01bc428c621de0abec47bc0868..d26ac22412973428b07009756f6e39105673b456 100644 (file)
@@ -100,6 +100,7 @@ export class IscsiComponent {
       this.images.map((image) => {
         image.stats_history.rd_bytes = image.stats_history.rd_bytes.map((i) => i[1]);
         image.stats_history.wr_bytes = image.stats_history.wr_bytes.map((i) => i[1]);
+        image.cdIsBinary = true;
         return image;
       });
     });
index 92d19d44f5bb783760aa8fa6413396d27f269aed..51876fdbdd4c099f56c3f6ea0ff2a0005f800d2d 100644 (file)
@@ -75,6 +75,7 @@ export class OsdListComponent implements OnInit {
         osd.collectedStates = this.collectStates(osd);
         osd.stats_history.out_bytes = osd.stats_history.op_out_bytes.map((i) => i[1]);
         osd.stats_history.in_bytes = osd.stats_history.op_in_bytes.map((i) => i[1]);
+        osd.cdIsBinary = true;
         return osd;
       });
     });
index 7b3999d023364f0e2f2ce319821db7cdc17a5d99..2aac85321116ea6569d9a0fe01693e9c6f8ed251 100644 (file)
@@ -1,7 +1,9 @@
-import { NO_ERRORS_SCHEMA } from '@angular/core';
+import { NO_ERRORS_SCHEMA, SimpleChange } from '@angular/core';
 import { ComponentFixture, TestBed } from '@angular/core/testing';
 
 import { configureTestBed } from '../../../../testing/unit-test-helper';
+import { DimlessBinaryPipe } from '../../pipes/dimless-binary.pipe';
+import { FormatterService } from '../../services/formatter.service';
 import { SparklineComponent } from './sparkline.component';
 
 describe('SparklineComponent', () => {
@@ -11,7 +13,8 @@ describe('SparklineComponent', () => {
   configureTestBed({
     declarations: [SparklineComponent],
     schemas: [NO_ERRORS_SCHEMA],
-    imports: []
+    imports: [],
+    providers: [DimlessBinaryPipe, FormatterService]
   });
 
   beforeEach(() => {
@@ -22,5 +25,29 @@ describe('SparklineComponent', () => {
 
   it('should create', () => {
     expect(component).toBeTruthy();
+    expect(component.options.tooltips.custom).toBeDefined();
+  });
+
+  it('should update', () => {
+    expect(component.datasets).toEqual([{ data: [] }]);
+    expect(component.labels.length).toBe(0);
+
+    component.data = [11, 22, 33];
+    component.ngOnChanges({ data: new SimpleChange(null, component.data, false) });
+
+    expect(component.datasets).toEqual([{ data: [11, 22, 33] }]);
+    expect(component.labels.length).toBe(3);
+  });
+
+  it('should not transform the label, if not isBinary', () => {
+    component.isBinary = false;
+    const result = component.options.tooltips.callbacks.label({ yLabel: 1024 });
+    expect(result).toBe(1024);
+  });
+
+  it('should transform the label, if isBinary', () => {
+    component.isBinary = true;
+    const result = component.options.tooltips.callbacks.label({ yLabel: 1024 });
+    expect(result).toBe('1 KiB');
   });
 });
index cd40d8bab175f5ba2f9c1203647b8d3adab7ee21..b289882237e3f67245ca06d7a86ec0a661b8025d 100644 (file)
@@ -2,6 +2,7 @@ import { Component, ElementRef, OnChanges, OnInit, SimpleChanges, ViewChild } fr
 import { Input } from '@angular/core';
 
 import { ChartTooltip } from '../../../shared/models/chart-tooltip';
+import { DimlessBinaryPipe } from '../../pipes/dimless-binary.pipe';
 
 @Component({
   selector: 'cd-sparkline',
@@ -21,6 +22,8 @@ export class SparklineComponent implements OnInit, OnChanges {
     height: '30px',
     width: '100px'
   };
+  @Input()
+  isBinary: boolean;
 
   public colors: Array<any> = [
     {
@@ -51,7 +54,16 @@ export class SparklineComponent implements OnInit, OnChanges {
       enabled: false,
       mode: 'index',
       intersect: false,
-      custom: undefined
+      custom: undefined,
+      callbacks: {
+        label: (tooltipItem) => {
+          if (this.isBinary) {
+            return this.dimlessBinaryPipe.transform(tooltipItem.yLabel);
+          } else {
+            return tooltipItem.yLabel;
+          }
+        }
+      }
     },
     scales: {
       yAxes: [
@@ -75,7 +87,7 @@ export class SparklineComponent implements OnInit, OnChanges {
 
   public labels: Array<any> = [];
 
-  constructor() {}
+  constructor(private dimlessBinaryPipe: DimlessBinaryPipe) {}
 
   ngOnInit() {
     const getStyleTop = (tooltip, positionY) => {
index 6f32e1d618d39dafc2088c990ea0687d1c199c5a..7054312f83ae04a3cad032dfabacf413d093e088 100644 (file)
 </ng-template>
 
 <ng-template #sparklineTpl
+             let-row="row"
              let-value="value">
-  <cd-sparkline [data]="value"></cd-sparkline>
+  <cd-sparkline [data]="value" [isBinary]="row.cdIsBinary"></cd-sparkline>
 </ng-template>
 
 <ng-template #routerLinkTpl