import { Component, ElementRef, OnInit, Input, Output, ContentChild, EventEmitter } from '@angular/core'; import { CfCoreComponent } from '../core/core.component'; import { ChartStylingModel } from '../../models/chart/chart-styling.model'; /** *
Main chart component. Uses ngx-charts library.
*/ @Component({ selector: 'cf-chart', template: "Chart component model object. Refer to ../models/chart/chart.model.ts.
*/ @Input() properties: any; /** *The styling object of the chart component. Refer to ../models/chart/chart-styling.model.ts
*/ @Input() styling: ChartStylingModel; /** *Data to show in the chart format
*/ @Input() data: any[]; /** *The event will be emitted when the chart is clicked
*/ @Output() onClick: EventEmitterChart size, object in the format {width, height}
*/ @Input() size: any; /** *Fill elements with a gradient instead of a solid color
*/ @Input() gradient: boolean = false; /** *Show or hide the legend
*/ @Input() showLegend: boolean = true; /** *The color scheme of the chart
*/ @Input() colorScheme: any = { domain: ['#5AA454', '#A10A28', '#C7B42C', '#AAAAAA'] }; /** *Show or hide the x axis
*/ @Input() showXAxis: boolean = true; /** *Show or hide the y axis
*/ @Input() showYAxis: boolean = true; /** *Show or hide the x axis label
*/ @Input() showXAxisLabel: boolean = true; /** *Show or hide the y axis label
*/ @Input() showYAxisLabel: boolean = true; /** *The x axis label text
*/ @Input() xAxisLabel: string = ''; /** *The y axis label text
*/ @Input() yAxisLabel: string = ''; constructor(public elementRef: ElementRef) { super(elementRef); } ngOnInit(): void { if (! this.styling) { this.styling = new ChartStylingModel(); } if (this.size) { this.styling.width = this.size.width; this.styling.height = this.size.height; } } /** *The method will emit event when the chart is clicked
*/ onSelect(event) { this.onClick.emit(event); } setCommonProperties(): void { if (this.data) { this.properties.data = this.data; } if (this.gradient) { this.properties.gradient = this.gradient; } if (this.showLegend) { this.properties.showLegend = this.showLegend; } if (this.colorScheme) { this.properties.colorScheme = this.colorScheme; } if (this.showXAxis) { this.properties.showXAxis = this.showXAxis; } if (this.showYAxis) { this.properties.showYAxis = this.showYAxis; } if (this.showXAxisLabel) { this.properties.showXAxisLabel = this.showXAxisLabel; } if (this.showYAxisLabel) { this.properties.showYAxisLabel = this.showYAxisLabel; } if (this.xAxisLabel) { this.properties.xAxisLabel = this.xAxisLabel; } if (this.yAxisLabel) { this.properties.yAxisLabel = this.yAxisLabel; } } }