Skip to content

Commit

Permalink
fix: fix the stack value in circular, range-column, waterfall
Browse files Browse the repository at this point in the history
  • Loading branch information
kangxiaoting.kk committed Oct 24, 2023
1 parent e5e68ce commit 72a887b
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 5 deletions.
101 changes: 101 additions & 0 deletions packages/vchart/__tests__/unit/data/stack-split.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { stackSplit } from '../../../src/data/transforms/stack-split';
import { DataSet, csvParser, DataView } from '@visactor/vdataset';

const generateDataSet = () => {
const dataSet = new DataSet();
dataSet.registerParser('csv', csvParser);
const dataView = new DataView(dataSet);

const data = `x,type,y
1,1,850
1,2,840
2,2,740
2,3,670
3,3,900
4,4,570
5,5,670`;

dataView.parse(data, {
type: 'csv'
});

return { dataSet, dataView };
};

test('stackSplit of one field', () => {
const { dataView } = generateDataSet();

expect(stackSplit([dataView], { fields: ['x'] })).toEqual({
nodes: {
'1': {
values: [
{ type: '1', x: '1', y: '850' },
{ type: '2', x: '1', y: '840' }
]
},
'2': {
values: [
{ type: '2', x: '2', y: '740' },
{ type: '3', x: '2', y: '670' }
]
},
'3': {
values: [{ type: '3', x: '3', y: '900' }]
},
'4': {
values: [{ type: '4', x: '4', y: '570' }]
},
'5': {
values: [{ type: '5', x: '5', y: '670' }]
}
}
});
});

test('stackSplit of one field', () => {
const { dataView } = generateDataSet();

expect(stackSplit([dataView], { fields: ['x', 'type'] })).toEqual({
nodes: {
'1': {
nodes: {
'1': {
values: [{ type: '1', x: '1', y: '850' }]
},
'2': {
values: [{ type: '2', x: '1', y: '840' }]
}
}
},
'2': {
nodes: {
'2': {
values: [{ type: '2', x: '2', y: '740' }]
},
'3': {
values: [{ type: '3', x: '2', y: '670' }]
}
}
},
'3': {
nodes: {
'3': {
values: [{ type: '3', x: '3', y: '900' }]
}
}
},
'4': {
nodes: {
'4': {
values: [{ type: '4', x: '4', y: '570' }]
}
}
},
'5': {
nodes: {
'5': { values: [{ type: '5', x: '5', y: '670' }] }
}
}
}
});
});
6 changes: 4 additions & 2 deletions packages/vchart/src/series/progress/circular/circular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,16 @@ export class CircularProgressSeries<
x: () => this.angleAxisHelper.center().x,
y: () => this.angleAxisHelper.center().y,
startAngle: () => {
const fieldName = this._stack ? STACK_FIELD_START : this._angleField[0];
const scale = this.angleAxisHelper.getScale(0);
const domain = scale.domain();
return this._getAngleValueStart({ [STACK_FIELD_START]: domain[0] });
return this._getAngleValueStart({ [fieldName]: domain[0] });
},
endAngle: () => {
const fieldName = this._stack ? STACK_FIELD_END : this._angleField[0];
const scale = this.angleAxisHelper.getScale(0);
const domain = scale.domain();
return this._getAngleValueEnd({ [STACK_FIELD_END]: domain[domain.length - 1] });
return this._getAngleValueEnd({ [fieldName]: domain[domain.length - 1] });
},
innerRadius: this._getRadiusValueStart,
outerRadius: this._getRadiusValueEnd,
Expand Down
2 changes: 1 addition & 1 deletion packages/vchart/src/series/range-column/range-column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class RangeColumnSeries<T extends IRangeColumnSeriesSpec = IRangeColumnSe

static readonly mark: SeriesMarkMap = rangeColumnSeriesMark;

protected _supportStack: boolean = true;
protected _stack: boolean = false;
private _minLabelMark?: ITextMark;
private _maxLabelMark?: ITextMark;
private _labelMark?: ITextMark;
Expand Down
5 changes: 3 additions & 2 deletions packages/vchart/src/series/waterfall/waterfall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class WaterfallSeries<T extends IWaterfallSeriesSpec = IWaterfallSeriesSp

static readonly mark: SeriesMarkMap = waterfallSeriesMark;

protected _stack: boolean = true;
protected _stack: boolean = false;

protected declare _theme: Maybe<IWaterfallSeriesTheme>;

Expand All @@ -68,7 +68,8 @@ export class WaterfallSeries<T extends IWaterfallSeriesSpec = IWaterfallSeriesSp

setAttrFromSpec() {
super.setAttrFromSpec();
this._stack = false;
// waterfall data stack data
this.setValueFieldToStack();
// 不支持多维度;
this._fieldX = [this._fieldX[0]];
this._fieldY = [this._fieldY[0]];
Expand Down

0 comments on commit 72a887b

Please sign in to comment.