@swimlane/ngx-charts
Version:
Declarative Charting Framework for Angular2 and beyond!
113 lines (99 loc) • 3.01 kB
text/typescript
import {
Component, Input, OnChanges, trigger, style, transition,
animate, ViewContainerRef, ChangeDetectionStrategy, EventEmitter,
Output, SimpleChanges
} from '@angular/core';
import { TooltipService } from '../tooltip';
export class ChartComponent implements OnChanges {
view;
showLegend = false;
legendOptions: any;
// remove
data;
legendData;
legendType: any;
legendTitle = 'Legend';
colors: any;
activeEntries: any[];
legendLabelClick: EventEmitter<any> = new EventEmitter();
legendLabelActivate: EventEmitter<any> = new EventEmitter();
legendLabelDeactivate: EventEmitter<any> = new EventEmitter();
chartWidth: any;
title: any;
legendWidth: any;
constructor(
private vcr: ViewContainerRef,
private tooltipService: TooltipService) {
this.tooltipService.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';
}
}
}