import {
Component, Input, OnChanges, trigger, style, transition,
animate, ViewContainerRef, ChangeDetectionStrategy, EventEmitter,
Output, SimpleChanges
} from '@angular/core';
import { InjectionService } from '../../services';
@Component({
providers: [InjectionService],
selector: 'ngx-charts-chart',
template: `
`,
changeDetection: ChangeDetectionStrategy.OnPush,
animations: [
trigger('animationState', [
transition('void => *', [
style({ opacity: 0 }),
animate('500ms 100ms', style({ opacity: 1 }))
])
])
]
})
export class ChartComponent implements OnChanges {
@Input() view;
@Input() showLegend = false;
@Input() legendOptions: any;
// remove
@Input() data;
@Input() legendData;
@Input() legendType: any;
@Input() legendTitle = 'Legend';
@Input() colors: any;
@Input() activeEntries: any[];
@Output() legendLabelClick: EventEmitter = new EventEmitter();
@Output() legendLabelActivate: EventEmitter = new EventEmitter();
@Output() legendLabelDeactivate: EventEmitter = new EventEmitter();
chartWidth: any;
title: any;
legendWidth: any;
constructor(
private vcr: ViewContainerRef,
private injectionService: InjectionService) {
this.injectionService.setRootViewContainer(vcr);
}
ngOnChanges(changes: SimpleChanges): void {
this.update();
}
update(): void {
let legendColumns = 0;
if (this.showLegend) {
this.legendType = this.getLegendType();
if (this.legendType === 'scaleLegend') {
legendColumns = 1;
} else {
legendColumns = 2;
}
}
let chartColumns = 12 - legendColumns;
this.chartWidth = this.view[0] * chartColumns / 12.0;
this.legendWidth = this.view[0] * legendColumns / 12.0;
}
getLegendType(): string {
if (this.legendOptions.scaleType === 'linear') {
return 'scaleLegend';
} else {
return 'legend';
}
}
}