import { Component, Input, SimpleChanges, Output, EventEmitter, OnChanges, ViewChild, ChangeDetectionStrategy } from '@angular/core'; import { XAxisTicksComponent } from './x-axis-ticks.component'; @Component({ selector: 'g[ngx-charts-x-axis]', template: ` `, changeDetection: ChangeDetectionStrategy.OnPush }) export class XAxisComponent implements OnChanges { @Input() xScale; @Input() dims; @Input() tickFormatting; @Input() showGridLines = false; @Input() showLabel; @Input() labelText; @Input() xAxisTickInterval; @Output() dimensionsChanged = new EventEmitter(); xAxisTickCount: any; xAxisClassName: string = 'x axis'; xOrient: string = 'bottom'; tickArguments: any; transform: any; labelOffset: number = 80; fill: string = 'none'; stroke: string = 'stroke'; tickStroke: string = '#ccc'; strokeWidth: string = 'none'; xAxisOffset: number = 5; @ViewChild(XAxisTicksComponent) ticksComponent: XAxisTicksComponent; ngOnChanges(changes: SimpleChanges): void { this.update(); } update(): void { this.transform = `translate(0,${this.xAxisOffset + this.dims.height})`; if (typeof this.xAxisTickCount !== 'undefined') { this.tickArguments = [this.xAxisTickCount]; } } emitTicksHeight({ height }): void { let newLabelOffset = height + 25 + 5; if (newLabelOffset !== this.labelOffset) { this.labelOffset = newLabelOffset; setTimeout(() => { this.dimensionsChanged.emit({height: height}); }, 0); } } }