You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.7 KiB
46 lines
1.7 KiB
import { PodState } from '@chartwerk/core'; |
|
import { DataRow } from './data_processor'; |
|
import { BarConfig } from './bar_options'; |
|
|
|
import { BarOptions, BarSerie, BarPodType, DiscreteConfig } from '../types'; |
|
|
|
import * as _ from 'lodash'; |
|
|
|
// It is not a real bar state. Just rewrite some core params. like xScale/yScale |
|
// TODO: import core scale and extend it, same to bar_series and bar_options |
|
|
|
export function setBarScaleX(state: PodState<BarSerie, BarOptions>, dataRows: DataRow[], options: BarConfig): void { |
|
switch(options.barType) { |
|
case BarPodType.DISCRETE: |
|
const config: DiscreteConfig = options.dicreteConfig; |
|
let discreteStep = 0; |
|
if(_.isNumber(config.step)) { |
|
discreteStep = config.step; |
|
} else { |
|
if(!_.isEmpty(dataRows)) { |
|
discreteStep = (_.last(dataRows).key - _.first(dataRows).key) / dataRows.length; |
|
} |
|
} |
|
state.xValueRange = [state.xValueRange[0], state.xValueRange[1] + discreteStep]; |
|
return; |
|
case BarPodType.NON_DISCRETE: |
|
if(!_.isEmpty(options.axis.x.range)) { |
|
return; |
|
} |
|
let nonDiscreteStep = 0; |
|
if(!_.isEmpty(dataRows)) { |
|
nonDiscreteStep = (_.last(dataRows).key - _.first(dataRows).key) / dataRows.length; |
|
} |
|
state.xValueRange = [state.xValueRange[0], state.xValueRange[1] + nonDiscreteStep]; |
|
return; |
|
} |
|
} |
|
|
|
export function setBarScaleY(state: PodState<BarSerie, BarOptions>, dataRows: DataRow[], options: BarOptions): void { |
|
if(!_.isEmpty(options.axis.y.range)) { |
|
return; |
|
} |
|
const maxValue = _.max(_.map(dataRows, (dataRow: DataRow) => dataRow.maxSumm)); |
|
const minValue = _.min(_.map(dataRows, (dataRow: DataRow) => dataRow.minSubtraction)); |
|
state.yValueRange = [minValue, maxValue]; |
|
}
|
|
|