]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
f7024f7238770679c96b1cfc7e1ede60c846c759
[ceph-ci.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()
12   histogram: any;
13   valuesStyle: any;
14   last = {};
15
16   ngOnChanges() {
17     this.render();
18   }
19
20   hexdigits(v: number): string {
21     const i = Math.floor(v * 255).toString(16);
22     return i.length === 1 ? '0' + i : i;
23   }
24
25   hexcolor(r: number, g: number, b: number) {
26     return '#' + this.hexdigits(r) + this.hexdigits(g) + this.hexdigits(b);
27   }
28
29   render() {
30     if (!this.histogram) {
31       return;
32     }
33     let max = 0;
34
35     _.each(this.histogram.values, (row, i) => {
36       _.each(row, (col, j) => {
37         let val;
38         if (this.last && this.last[i] && this.last[i][j]) {
39           val = col - this.last[i][j];
40         } else {
41           val = col;
42         }
43         max = Math.max(max, val);
44       });
45     });
46
47     this.valuesStyle = this.histogram.values.map((row: any, i: number) => {
48       return row.map((col: any, j: number) => {
49         const val = this.last && this.last[i] && this.last[i][j] ? col - this.last[i][j] : col;
50         const g = max ? val / max : 0;
51         const r = 1 - g;
52         return { backgroundColor: this.hexcolor(r, g, 0) };
53       });
54     });
55
56     this.last = this.histogram.values;
57   }
58 }