src/app/ceph/cluster/osd/osd-performance-histogram/osd-performance-histogram.component.ts
selector | cd-osd-performance-histogram |
styleUrls | ./osd-performance-histogram.component.scss |
templateUrl | ./osd-performance-histogram.component.html |
Properties |
Methods |
Inputs |
constructor()
|
histogram | |
Type : any
|
|
hexcolor | ||||||||
hexcolor(r, g, b)
|
||||||||
Parameters :
Returns :
string
|
hexdigits | ||||
hexdigits(v)
|
||||
Parameters :
Returns :
string
|
ngOnChanges |
ngOnChanges()
|
Returns :
void
|
render |
render()
|
Returns :
void
|
last |
Type : object
|
Default value : {}
|
valuesStyle |
Type : any
|
import { Component, Input, OnChanges } from '@angular/core';
import * as _ from 'lodash';
@Component({
selector: 'cd-osd-performance-histogram',
templateUrl: './osd-performance-histogram.component.html',
styleUrls: ['./osd-performance-histogram.component.scss']
})
export class OsdPerformanceHistogramComponent implements OnChanges {
@Input()
histogram: any;
valuesStyle: any;
last = {};
constructor() {}
ngOnChanges() {
this.render();
}
hexdigits(v): string {
const i = Math.floor(v * 255).toString(16);
return i.length === 1 ? '0' + i : i;
}
hexcolor(r, g, b) {
return '#' + this.hexdigits(r) + this.hexdigits(g) + this.hexdigits(b);
}
render() {
if (!this.histogram) {
return;
}
let max = 0;
_.each(this.histogram.values, (row, i) => {
_.each(row, (col, j) => {
let val;
if (this.last && this.last[i] && this.last[i][j]) {
val = col - this.last[i][j];
} else {
val = col;
}
max = Math.max(max, val);
});
});
this.valuesStyle = this.histogram.values.map((row, i) => {
return row.map((col, j) => {
const val = this.last && this.last[i] && this.last[i][j] ? col - this.last[i][j] : col;
const g = max ? val / max : 0;
const r = 1 - g;
return { backgroundColor: this.hexcolor(r, g, 0) };
});
});
this.last = this.histogram.values;
}
}
<table>
<tr style="height: 10px;"
*ngFor="let row of valuesStyle">
<td style="width: 10px; height: 10px;"
*ngFor="let col of row"
[ngStyle]="col">
</td>
</tr>
</table>
./osd-performance-histogram.component.scss