@swimlane/ngx-charts
Version:
Declarative Charting Framework for Angular2 and beyond!
82 lines (71 loc) • 1.7 kB
text/typescript
import {
Component,
OnChanges,
Input,
Output,
SimpleChanges,
EventEmitter,
ChangeDetectionStrategy
} from '@angular/core';
export class TreeMapCellSeriesComponent implements OnChanges {
data;
dims;
colors;
select = new EventEmitter();
cells: any[];
ngOnChanges(changes: SimpleChanges): void {
this.cells = this.getCells();
}
getCells(): any[] {
return this.data.children
.filter((d) => {
return d.depth === 1;
})
.map((d, index) => {
let label = d.id;
return {
x: d.x0,
y: d.y0,
width: d.x1 - d.x0,
height: d.y1 - d.y0,
fill: this.colors.getColor(label),
label,
value: d.value,
valueType: d.valueType
};
});
}
getTooltipText({ label, value }): string {
return `
<span class="tooltip-label">${label}</span>
<span class="tooltip-val">${value.toLocaleString()}</span>
`;
}
onClick(data): void {
this.select.emit(data);
}
trackBy(index, item): string {
return item.label;
}
}