@swimlane/ngx-charts
Version:
Declarative Charting Framework for Angular2 and beyond!
107 lines (93 loc) • 2.31 kB
text/typescript
import {
Component,
Input,
Output,
EventEmitter,
SimpleChanges,
ElementRef,
OnChanges,
ChangeDetectionStrategy
} from '@angular/core';
import { id } from '../utils/id';
import d3 from '../d3';
export class HeatMapCellComponent implements OnChanges {
fill;
x;
y;
width;
height;
data;
label;
gradient: boolean = false;
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);
}
}