|
|
|
@ -1,36 +1,60 @@
|
|
|
|
|
import { BarSerie, BarOptions, Datapoint, Color, ValueX, OpacityFormatter } from '../types'; |
|
|
|
|
import { BarSerie, BarOptions, Datapoint, Color, ValueX, OpacityFormatter, BarPodType } from '../types'; |
|
|
|
|
|
|
|
|
|
import * as _ from 'lodash'; |
|
|
|
|
|
|
|
|
|
export type DataRow = { |
|
|
|
|
key: number, // x
|
|
|
|
|
values: number[], // y list
|
|
|
|
|
colors: string[], |
|
|
|
|
opacity: number[], |
|
|
|
|
serieTarget: string, |
|
|
|
|
key: number; // x
|
|
|
|
|
data: { |
|
|
|
|
[serieTarget: string]: { |
|
|
|
|
values: number[]; // y list
|
|
|
|
|
colors: string[]; |
|
|
|
|
opacity: number[]; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
maxSumm: number; |
|
|
|
|
minSubtraction: number; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export class DataProcessor { |
|
|
|
|
_formattedDataRows: DataRow[]; |
|
|
|
|
|
|
|
|
|
constructor(protected series: BarSerie[], protected options: BarOptions) { |
|
|
|
|
|
|
|
|
|
this.setDataRowsForNonDiscreteType(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public get dataRows(): DataRow[] { |
|
|
|
|
return this._formattedDataRows; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected setDataRowsForDiscreteType(): void { |
|
|
|
|
const groupByList = ( |
|
|
|
|
this.options.type[BarPodType.DISCRETE].groupBy.x || |
|
|
|
|
_.map(_.first(this.series).datapoints, datapoint => datapoint[0]) |
|
|
|
|
); |
|
|
|
|
let rows = []; |
|
|
|
|
// TODO: not effective
|
|
|
|
|
for(let groupItem of groupByList) { |
|
|
|
|
for(let serie of this.series) { |
|
|
|
|
const datapoint = _.find(serie.datapoints, ) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected setDataRowsForNonDiscreteType(): void { |
|
|
|
|
for(let serie of this.series) { |
|
|
|
|
const rows = _.map(serie.datapoints, (datapoint: Datapoint) => { |
|
|
|
|
const values = _.tail(datapoint); |
|
|
|
|
return { |
|
|
|
|
key: datapoint[0], // x
|
|
|
|
|
data: { |
|
|
|
|
[serie.target]: { |
|
|
|
|
values, // y list
|
|
|
|
|
colors: this.getColorsForEachValue(values, serie.color, datapoint[0], serie.target), |
|
|
|
|
opacity: this.getOpacityForEachValue(values, serie.opacityFormatter, datapoint[0], serie.target), |
|
|
|
|
target: serie.target, |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
maxSumm: this.getMaxSumm(values), // max y axis scale
|
|
|
|
|
minSubtraction: this.getMinSubtraction(values), // min y axis scale
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
this._formattedDataRows = _.concat(this._formattedDataRows, rows); |
|
|
|
@ -57,4 +81,12 @@ export class DataProcessor {
|
|
|
|
|
} |
|
|
|
|
return _.map(values, (value, i) => opacity({ value, barIndex: i, key, target }));
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getMaxSumm(values: number[]): number { |
|
|
|
|
return values.reduce((prev, curr) => curr > 0 ? prev + curr : prev, 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getMinSubtraction(values: number[]): number { |
|
|
|
|
return values.reduce((prev, curr) => curr < 0 ? prev + curr : prev, 0); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|