@swimlane/ngx-charts
Version:
Declarative Charting Framework for Angular2 and beyond!
93 lines (80 loc) • 2.23 kB
text/typescript
import {
Component,
Input,
SimpleChanges,
Output,
EventEmitter,
OnChanges,
ViewChild,
ChangeDetectionStrategy
} from '@angular/core';
import { XAxisTicksComponent } from './x-axis-ticks.component';
export class XAxisComponent implements OnChanges {
xScale;
dims;
tickFormatting;
showGridLines = false;
showLabel;
labelText;
xAxisTickInterval;
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;
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});
}, 0);
}
}
}