@swimlane/ngx-charts
Version:
Declarative Charting Framework for Angular2 and beyond!
88 lines (77 loc) • 2.16 kB
text/typescript
import {
Component,
SimpleChanges,
Input,
OnChanges,
ChangeDetectionStrategy
} from '@angular/core';
export class GridPanelSeriesComponent implements OnChanges {
gridPanels: any[];
data;
dims;
xScale;
yScale;
orient;
ngOnChanges(changes: SimpleChanges): void {
this.update();
}
update(): void {
this.gridPanels = this.getGridPanels();
}
getGridPanels(): any[] {
return this.data.map((d, i) => {
let offset;
let width;
let height;
let x;
let y;
let className = 'odd';
if (this.orient === 'vertical') {
let position: number = this.xScale(d.name);
let positionIndex = Number.parseInt((position / this.xScale.step()).toString());
if (positionIndex % 2 === 1) {
className = 'even';
}
offset = this.xScale.bandwidth() * this.xScale.paddingInner();
width = this.xScale.bandwidth() + offset;
height = this.dims.height;
x = this.xScale(d.name) - offset / 2;
y = 0;
} else if (this.orient === 'horizontal') {
let position = this.yScale(d.name);
let positionIndex = Number.parseInt((position / this.yScale.step()).toString());
if (positionIndex % 2 === 1) {
className = 'even';
}
offset = this.yScale.bandwidth() * this.yScale.paddingInner();
width = this.dims.width;
height = this.yScale.bandwidth() + offset;
x = 0;
y = this.yScale(d.name) - offset / 2;
}
return {
name: d.name,
class: className,
height,
width,
x,
y
};
});
}
}