Skip to content

fix:修复 玉珏图没有考虑isStack的情况 重新计算最大值 #2685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 8, 2021
Merged
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
41 changes: 40 additions & 1 deletion __tests__/unit/plots/radial-bar/utils-spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { getScaleMax } from '../../../../src/plots/radial-bar/utils';
import { getScaleMax, getScaleIsStackMax } from '../../../../src/plots/radial-bar/utils';
import { antvStar } from '../../../data/antv-star';
import { populationMovementData as popData } from '../../../data/chord-population';

const yField = 'star';

const popField = {
yField: 'value',
xField: 'source',
};

describe('utils of radial-bar', () => {
const starArr = antvStar.map((item) => item[yField]);
const maxValue = Math.max(...starArr);
Expand All @@ -21,4 +27,37 @@ describe('utils of radial-bar', () => {
it('getScaleMax: empty array', () => {
expect(getScaleMax(360, yField, [])).toBe(0);
});

const popArr = popData
.reduce((value, item) => {
const valueItem = value.find((v) => v[popField.xField] === item[popField.xField]);
if (valueItem) {
valueItem[popField.yField] += item[popField.yField];
} else {
value.push({ ...item });
}
return value;
}, [])
.map((item) => item[popField.yField]);

const isStackMaxValue = Math.max(...popArr);

it('getScaleIsStackMax: normal', () => {
expect(getScaleIsStackMax(360, popField.yField, popField.xField, popData)).toBe(isStackMaxValue);
expect(getScaleIsStackMax(-300, popField.yField, popField.xField, popData)).toBe((isStackMaxValue * 360) / 300);
expect(getScaleIsStackMax(660, popField.yField, popField.xField, popData)).toBe((isStackMaxValue * 360) / 300);
});

it('getScaleIsStackMax: existed nil value', () => {
expect(
getScaleIsStackMax(-300, popField.yField, popField.xField, [...popData, { source: 'c', value: undefined }])
).toBe((isStackMaxValue * 360) / 300);
expect(getScaleIsStackMax(-300, popField.yField, popField.xField, [...popData, { source: 'c', value: null }])).toBe(
(isStackMaxValue * 360) / 300
);
});

it('getScaleIsStackMax: empty array', () => {
expect(getScaleIsStackMax(360, popField.yField, popField.xField, [])).toBe(0);
});
});
10 changes: 6 additions & 4 deletions src/plots/radial-bar/adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { flow, deepAssign, findGeometry, transformLabel } from '../../utils';
import { interval, point } from '../../adaptor/geometries';
import { processIllegalData } from '../../utils';
import { RadialBarOptions } from './types';
import { getScaleMax } from './utils';
import { getScaleMax, getScaleIsStackMax } from './utils';

/**
* geometry 处理
Expand Down Expand Up @@ -49,14 +49,16 @@ function geometry(params: Params<RadialBarOptions>): Params<RadialBarOptions> {
*/
export function meta(params: Params<RadialBarOptions>): Params<RadialBarOptions> {
const { options } = params;
const { yField, maxAngle, data } = options;

const { yField, xField, data, isStack, isGroup, colorField, maxAngle } = options;
const processData = processIllegalData(data, yField);
return flow(
scale({
[yField]: {
min: 0,
max: getScaleMax(maxAngle, yField, processData),
max:
isStack && !isGroup && colorField
? getScaleIsStackMax(maxAngle, yField, xField, processData)
: getScaleMax(maxAngle, yField, processData),
},
})
)(params);
Expand Down
4 changes: 4 additions & 0 deletions src/plots/radial-bar/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ export interface RadialBarOptions extends Options, Pick<BarOptions, 'barBackgrou
readonly colorField?: string;
/** 类型 */
readonly type?: string;
/** 叠加 */
readonly isStack?: boolean;
/** 分组 */
readonly isGroup?: boolean;
}
14 changes: 14 additions & 0 deletions src/plots/radial-bar/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,17 @@ export function getScaleMax(maxAngle: number, yField: string, data: Data): numbe
}
return (maxValue * 360) / formatRadian;
}

// 获取isStack 下的最大值
export function getScaleIsStackMax(maxAngle: number, yField: string, xField: string, data: Data) {
const newData: Data = [];
data.forEach((item) => {
const valueItem = newData.find((v) => v[xField] === item[xField]);
if (valueItem) {
valueItem[yField] += item[yField];
} else {
newData.push({ ...item });
}
});
return getScaleMax(maxAngle, yField, newData);
}