File

src/app/ceph/cluster/osd/osd-performance-histogram/osd-performance-histogram.component.ts

Implements

OnChanges

Metadata

selector cd-osd-performance-histogram
styleUrls ./osd-performance-histogram.component.scss
templateUrl ./osd-performance-histogram.component.html

Index

Properties
Methods
Inputs

Constructor

constructor()

Inputs

histogram
Type : any

Methods

hexcolor
hexcolor(r, g, b)
Parameters :
Name Optional
r No
g No
b No
Returns : string
hexdigits
hexdigits(v)
Parameters :
Name Optional
v No
Returns : string
ngOnChanges
ngOnChanges()
Returns : void
render
render()
Returns : void

Properties

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

Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""