import { Component, OnInit, Input,AfterViewInit } from '@angular/core'; import { IColorMap, IColor, IColorEntry,ILayer } from '../../models'; @Component({ selector: 'layer-legend', templateUrl: './legend.component.html', styleUrls: ['./legend.component.scss'] }) export class LegendComponent implements OnInit,AfterViewInit { constructor() { } ngOnInit() { } ngAfterViewInit() { } @Input() layer: ILayer; @Input() legend: string; @Input() histogram: string; @Input() showTitle: boolean = true; @Input() histogramenabled: boolean; @Input() legendunit: string; @Input() histogramunit: string; onClickHistoGram(): void { this.histogramenabled = !this.histogramenabled; } public getHex(color: IColor): string { return '#' + this.componentToHex(color.red) + this.componentToHex(color.green) + this.componentToHex(color.blue); } public componentToHex(c: number): string { const hex = c.toString(16); return hex.length === 1 ? `0${hex}` : hex; } private getPart(colorMap: IColorMap, colorEntry: IColorEntry): string { let sumOfValue = colorMap.entries.reduce((sum, item) => sum + item.value, 0); let part = ((colorEntry.value / sumOfValue) * 100) + "%"; return part; } }