Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: 修复 roseSeries 在非堆叠场景里 innerRadius 不生效的问题\n\n",
"type": "none",
"packageName": "@visactor/vchart"
}
],
"packageName": "@visactor/vchart",
"email": "just_star@qq.com"
}
55 changes: 55 additions & 0 deletions packages/vchart/__tests__/unit/series/rose.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { DataSet, DataView } from '@visactor/vdataset';
import { get } from '@visactor/vutils';
import type { ISeriesOption } from '../../../src/series/interface';
import { initChartDataSet, seriesOption } from '../../util/context';
import { RoseSeries, type IRoseSeriesSpec } from '../../../src';

const dataSet = new DataSet();
initChartDataSet(dataSet);

let ctx: ISeriesOption;

class TestRoseSeries extends RoseSeries<IRoseSeriesSpec> {
protected _computeLayoutRadius() {
return 100;
}
}

describe('[Domain-Series-Rose] Rose Series', () => {
beforeEach(() => {
ctx = seriesOption({ dataSet });
});

test('non-stacked rose respects innerRadius', () => {
const dataView = new DataView(dataSet);
dataView.parse(
[
{ type: 'A', group: 'g1', value: 10 },
{ type: 'B', group: 'g2', value: 20 }
],
{
type: 'array'
}
);

const rose = new TestRoseSeries(
{
type: 'rose',
data: dataView,
categoryField: ['type', 'group'],
valueField: 'value',
seriesField: 'group',
stack: false,
innerRadius: 0.6
},
ctx
);
rose.created();
rose.init({});

const roseMark = rose.getMarks().find(mark => mark.name === 'rose');
const innerRadiusStyle = get(roseMark?.stateStyle.normal, 'innerRadius.style');

expect(innerRadiusStyle({ value: 10 })).toBe(60);
});
});
8 changes: 3 additions & 5 deletions packages/vchart/src/series/rose/rose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,13 @@ export class RoseSeries<T extends IRoseSeriesSpec = IRoseSeriesSpec> extends Ros
),
innerRadius: (datum: Datum) => {
if (!this.getStack()) {
return 0;
return this._computeLayoutRadius() * this._innerRadius;
}
const stackStart = valueInScaleRange(
this.radiusAxisHelper.dataToPosition([datum[this._innerRadiusField[0]]]),
this.radiusAxisHelper.getScale(0)
);
return stackStart <= Number.MIN_VALUE
? this._computeLayoutRadius() * (this._spec.innerRadius ?? 0)
: stackStart;
return stackStart <= Number.MIN_VALUE ? this._computeLayoutRadius() * this._innerRadius : stackStart;
}
});
}
Expand Down Expand Up @@ -141,7 +139,7 @@ export class RoseSeries<T extends IRoseSeriesSpec = IRoseSeriesSpec> extends Ros

if (this._roseMark) {
const animationParams: IRoseAnimationParams = {
innerRadius: () => this._computeLayoutRadius() * (this._spec.innerRadius ?? 0)
innerRadius: () => this._computeLayoutRadius() * this._innerRadius
};
this._roseMark.setAnimationConfig(
animationConfig(
Expand Down
Loading