]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
c3f06450659fb01959e16dd58732f89437f6c24d
[ceph.git] /
1 import { Component, Input, OnChanges } from '@angular/core';
2
3 import * as _ from 'lodash';
4
5 @Component({
6   selector: 'cd-osd-performance-histogram',
7   templateUrl: './osd-performance-histogram.component.html',
8   styleUrls: ['./osd-performance-histogram.component.scss']
9 })
10 export class OsdPerformanceHistogramComponent implements OnChanges {
11   @Input() histogram: any;
12   valuesStyle: any;
13   last = {};
14
15   constructor() { }
16
17   ngOnChanges() {
18     this.render();
19   }
20
21   hexdigits(v): string {
22     const i = Math.floor(v * 255).toString(16);
23     return i.length === 1 ? '0' + i : i;
24   }
25
26   hexcolor(r, g, b) {
27     return '#' + this.hexdigits(r) + this.hexdigits(g) + this.hexdigits(b);
28   }
29
30   render() {
31     if (!this.histogram) {
32       return;
33     }
34     let sum = 0;
35     let max = 0;
36
37     _.each(this.histogram.values, (row, i) => {
38       _.each(row, (col, j) => {
39         let val;
40         if (this.last && this.last[i] && this.last[i][j]) {
41           val = col - this.last[i][j];
42         } else {
43           val = col;
44         }
45         sum += val;
46         max = Math.max(max, val);
47       });
48     });
49
50     this.valuesStyle = this.histogram.values.map((row, i) => {
51       return row.map((col, j) => {
52         const val = this.last && this.last[i] && this.last[i][j] ? col - this.last[i][j] : col;
53         const g = max ? val / max : 0;
54         const r = 1 - g;
55         return {backgroundColor: this.hexcolor(r, g, 0)};
56       });
57     });
58
59     this.last = this.histogram.values;
60   }
61 }