|
|
|
@ -123,8 +123,8 @@ export class ChartwerkBarPod extends ChartwerkPod<BarTimeSerie, BarOptions> {
|
|
|
|
|
if(series.length === 0) { |
|
|
|
|
throw new Error('There is no visible series'); |
|
|
|
|
} |
|
|
|
|
const keysColumn = _.map(series[0].datapoints, row => row[1]); |
|
|
|
|
const valuesColumns = _.map(series, serie => _.map(serie.datapoints, row => row[0])); |
|
|
|
|
const keysColumn = _.map(series[0].datapoints, row => row[0]); |
|
|
|
|
const valuesColumns = _.map(series, serie => _.map(serie.datapoints, row => row[1])); |
|
|
|
|
// @ts-ignore
|
|
|
|
|
const additionalValuesColumns = _.map(series, serie => _.map(serie.datapoints, row => row[2] !== undefined ? row[2] : null)); |
|
|
|
|
const zippedAdditionalValuesColumn = _.zip(...additionalValuesColumns); |
|
|
|
@ -135,10 +135,10 @@ export class ChartwerkBarPod extends ChartwerkPod<BarTimeSerie, BarOptions> {
|
|
|
|
|
return data; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public renderSharedCrosshair(timestamp: number): void { |
|
|
|
|
public renderSharedCrosshair(values: { x?: number, y?: number }): void { |
|
|
|
|
this.crosshair.style('display', null); |
|
|
|
|
|
|
|
|
|
const x = this.xScale(timestamp); |
|
|
|
|
const x = this.xScale(values.x); |
|
|
|
|
this.crosshair.select('#crosshair-line-x') |
|
|
|
|
.attr('x1', x) |
|
|
|
|
.attr('x2', x); |
|
|
|
@ -247,11 +247,11 @@ export class ChartwerkBarPod extends ChartwerkPod<BarTimeSerie, BarOptions> {
|
|
|
|
|
|
|
|
|
|
get barWidth(): number { |
|
|
|
|
// TODO: here we use first value + timeInterval as bar width. It is not a good idea
|
|
|
|
|
const xAxisStartValue = _.first(this.series[0].datapoints)[1]; |
|
|
|
|
const xAxisStartValue = _.first(this.series[0].datapoints)[0]; |
|
|
|
|
let width = this.xScale(xAxisStartValue + this.timeInterval) / 2; |
|
|
|
|
if(this.options.barWidth !== undefined) { |
|
|
|
|
// barWidth now has axis-x dimension
|
|
|
|
|
width = this.xScale(this.minValueX + this.options.barWidth); |
|
|
|
|
width = this.xScale(this.state.getMinValueX() + this.options.barWidth); |
|
|
|
|
} |
|
|
|
|
let rectColumns = this.visibleSeries.length; |
|
|
|
|
if(this.options.stacked === true) { |
|
|
|
@ -299,15 +299,15 @@ export class ChartwerkBarPod extends ChartwerkPod<BarTimeSerie, BarOptions> {
|
|
|
|
|
|
|
|
|
|
get yScale(): d3.ScaleLinear<number, number> { |
|
|
|
|
if( |
|
|
|
|
this.minValue === undefined || |
|
|
|
|
this.maxValue === undefined |
|
|
|
|
this.state.getMinValueY() === undefined || |
|
|
|
|
this.state.getMaxValueY() === undefined |
|
|
|
|
) { |
|
|
|
|
return this.d3.scaleLinear() |
|
|
|
|
.domain([1, 0]) |
|
|
|
|
.range([0, this.height]); |
|
|
|
|
} |
|
|
|
|
return this.d3.scaleLinear() |
|
|
|
|
.domain([this.maxValue, Math.min(this.minValue, 0)]) |
|
|
|
|
.domain([this.maxValue, Math.min(this.state.getMinValueY(), 0)]) |
|
|
|
|
.range([0, this.height]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -322,20 +322,21 @@ export class ChartwerkBarPod extends ChartwerkPod<BarTimeSerie, BarOptions> {
|
|
|
|
|
if(this.options.stacked === true) { |
|
|
|
|
if(this.options.matching === true && this.seriesUniqKeys.length > 0) { |
|
|
|
|
const maxValues = this.seriesForMatching.map(series => { |
|
|
|
|
const valuesColumns = _.map(series, serie => _.map(serie.datapoints, row => row[0])); |
|
|
|
|
const valuesColumns = _.map(series, serie => _.map(serie.datapoints, row => row[1])); |
|
|
|
|
const zippedValuesColumn = _.zip(...valuesColumns); |
|
|
|
|
return maxValue = _.max(_.map(zippedValuesColumn, row => _.sum(row))); |
|
|
|
|
}); |
|
|
|
|
return _.max(maxValues); |
|
|
|
|
} else { |
|
|
|
|
const valuesColumns = _.map(this.visibleSeries, serie => _.map(serie.datapoints, row => row[0])); |
|
|
|
|
const valuesColumns = _.map(this.visibleSeries, serie => _.map(serie.datapoints, row => row[1])); |
|
|
|
|
const zippedValuesColumn = _.zip(...valuesColumns); |
|
|
|
|
maxValue = _.max(_.map(zippedValuesColumn, row => _.sum(row)));
|
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
console.log('else') |
|
|
|
|
maxValue = _.max( |
|
|
|
|
this.visibleSeries.map( |
|
|
|
|
serie => _.maxBy<number[]>(serie.datapoints, dp => dp[0])[0] |
|
|
|
|
serie => _.maxBy<number[]>(serie.datapoints, dp => dp[1])[0] |
|
|
|
|
) |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
@ -358,8 +359,10 @@ export const VueChartwerkBarChartObject = {
|
|
|
|
|
mixins: [VueChartwerkPodMixin], |
|
|
|
|
methods: { |
|
|
|
|
render() { |
|
|
|
|
console.time('bar-render'); |
|
|
|
|
const pod = new ChartwerkBarPod(document.getElementById(this.id), this.series, this.options); |
|
|
|
|
pod.render(); |
|
|
|
|
console.timeEnd('bar-render'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|