import { Component, Input, Output, EventEmitter, SimpleChanges, ElementRef, OnChanges, ChangeDetectionStrategy } from '@angular/core'; import { id } from "../utils/id"; import d3 from '../d3'; @Component({ selector: 'g[ngx-charts-heat-map-cell]', template: ` `, changeDetection: ChangeDetectionStrategy.OnPush }) export class HeatMapCellComponent implements OnChanges { @Input() fill; @Input() x; @Input() y; @Input() width; @Input() height; @Input() data; @Input() label; @Input() gradient: boolean = false; @Output() select = new EventEmitter(); element: HTMLElement; transform: string; activeRange: any[]; startOpacity: number; gradientId: string; gradientUrl: string; gradientStops: any[]; constructor(element: ElementRef) { this.element = element.nativeElement; } ngOnChanges(changes: SimpleChanges): void { this.transform = `translate(${this.x} , ${this.y})`; let pageUrl = window.location.href; this.startOpacity = 0.3; this.gradientId = 'grad' + id().toString(); this.gradientUrl = `url(${pageUrl}#${this.gradientId})`; this.gradientStops = this.getGradientStops(); this.loadAnimation(); } getGradientStops() { return [ { offset: 0, color: this.fill, opacity: this.startOpacity }, { offset: 100, color: this.fill, opacity: 1 }]; } loadAnimation(): void { let node = d3.select(this.element).select('.cell'); node.attr('opacity', 0); this.animateToCurrentForm(); } animateToCurrentForm(): void { let node = d3.select(this.element).select('.cell'); node.transition().duration(750) .attr('opacity', 1); } onClick() { this.select.emit(this.data); } }