@swimlane/ngx-charts
Version:
Declarative Charting Framework for Angular2 and beyond!
97 lines (85 loc) • 2.31 kB
text/typescript
import {
Component,
Input,
Output,
EventEmitter,
OnChanges,
ViewChild,
SimpleChanges,
ChangeDetectionStrategy
} from '@angular/core';
import { YAxisTicksComponent } from './y-axis-ticks.component';
export class YAxisComponent implements OnChanges {
yScale;
dims;
tickFormatting;
showGridLines = false;
showLabel;
labelText;
yAxisTickInterval;
dimensionsChanged = new EventEmitter();
yAxisClassName: string = 'y axis';
yAxisTickCount: any;
tickArguments: any;
offset: any;
transform: any;
yAxisOffset: number = -5;
yOrient: string = 'left';
labelOffset: number = 80;
fill: string = 'none';
stroke: string = '#CCC';
tickStroke: string = '#CCC';
strokeWidth: number = 1;
ticksComponent: YAxisTicksComponent;
ngOnChanges(changes: SimpleChanges): void {
this.update();
}
update(): void {
this.offset = this.yAxisOffset;
if (this.yOrient === 'right') {
this.transform = `translate(${this.offset + this.dims.width} , 0)`;
} else {
this.transform = `translate(${this.offset} , 0)`;
}
if (this.yAxisTickCount !== undefined) {
this.tickArguments = [this.yAxisTickCount];
}
}
emitTicksWidth({ width }): void {
if (width !== this.labelOffset) {
this.labelOffset = width;
setTimeout(() => {
this.dimensionsChanged.emit({width});
}, 0);
}
}
}