@swimlane/ngx-charts
Version:
Declarative Charting Framework for Angular2 and beyond!
102 lines (86 loc) • 2.12 kB
text/typescript
import {
Component,
Input,
SimpleChanges,
Output,
EventEmitter,
OnChanges,
ChangeDetectionStrategy
} from '@angular/core';
export class HeatCellSeriesComponent implements OnChanges {
data;
colors;
xScale;
yScale;
gradient: boolean;
select = new EventEmitter();
cells: any[];
ngOnChanges(changes: SimpleChanges): void {
this.update();
}
update(): void {
this.cells = this.getCells();
}
getCells() {
let cells = [];
this.data.map((row) => {
row.series.map((cell) => {
let value = cell.value;
let label = cell.name;
let tooltipLabel = label;
if (tooltipLabel.constructor.name === 'Date') {
tooltipLabel = tooltipLabel.toLocaleDateString();
}
cells.push({
x: this.xScale(row.name),
y: this.yScale(cell.name),
width: this.xScale.bandwidth(),
height: this.yScale.bandwidth(),
fill: this.colors.getColor(value),
data: value,
label,
series: row.name
});
});
});
return cells;
}
getTooltipText({ label, data, series }): string {
return `
<span class="tooltip-label">${series} • ${label}</span>
<span class="tooltip-val">${data.toLocaleString()}</span>
`;
}
trackBy(index, item): string {
return item.tooltipText;
}
onClick(value, label, series): void {
this.select.emit({
name: label,
value,
series
});
}
}