Skip to content

fix(dodge): 当分组 数据为一组时,当前的 intervalPadding dodgePadding 计算 position 不满足 #17

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
55 changes: 29 additions & 26 deletions src/adjusts/dodge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default class Dodge extends Adjust {
const { customOffset } = this;
const map = this.getDistribution(dim);
const groupData = this.groupData(data, dim); // 根据值分组

_.each(groupData, (group, key) => {
let range: Range;

Expand Down Expand Up @@ -99,38 +99,41 @@ export default class Dodge extends Adjust {
marginRatio,
intervalPadding,
dodgePadding,
groupNum,
} = this;
const { pre, next } = range;

const tickLength = next - pre;
let position;
// 分多种输入情况
if (!_.isNil(intervalPadding) && _.isNil(dodgePadding) && intervalPadding >= 0) {
// 仅配置intervalPadding
const offset = this.getIntervalOnlyOffset(len, idx);
position = pre + offset;
} else if (!_.isNil(dodgePadding) && _.isNil(intervalPadding) && dodgePadding >= 0) {
// 仅配置dodgePadding
const offset = this.getDodgeOnlyOffset(len, idx);
position = pre + offset;
} else if (
!_.isNil(intervalPadding) &&
!_.isNil(dodgePadding) &&
intervalPadding >= 0 &&
dodgePadding >= 0
) {
// 同时配置intervalPadding和dodgePadding
const offset = this.getIntervalAndDodgeOffset(len, idx);
position = pre + offset;
if (groupNum > 1) {
// 分多种输入情况
if (!_.isNil(intervalPadding) && _.isNil(dodgePadding) && intervalPadding >= 0) {
// 仅配置intervalPadding
const offset = this.getIntervalOnlyOffset(len, idx);
position = pre + offset;
} else if (!_.isNil(dodgePadding) && _.isNil(intervalPadding) && dodgePadding >= 0) {
// 仅配置dodgePadding
const offset = this.getDodgeOnlyOffset(len, idx);
position = pre + offset;
} else if (
!_.isNil(intervalPadding) &&
!_.isNil(dodgePadding) &&
intervalPadding >= 0 &&
dodgePadding >= 0
) {
// 同时配置intervalPadding和dodgePadding
const offset = this.getIntervalAndDodgeOffset(len, idx);
position = pre + offset;
}
} else {
// 默认情况
const width = (tickLength * dodgeRatio) / len;
const margin = marginRatio * width;
const offset =
(1 / 2) * (tickLength - len * width - (len - 1) * margin) +
((idx + 1) * width + idx * margin) -
(1 / 2) * width -
(1 / 2) * tickLength;
(1 / 2) * (tickLength - len * width - (len - 1) * margin) +
((idx + 1) * width + idx * margin) -
(1 / 2) * width -
(1 / 2) * tickLength;
position = (pre + next) / 2 + offset;
}
return position;
Expand Down Expand Up @@ -165,7 +168,7 @@ export default class Dodge extends Adjust {
normalizedDodgePadding = ((1 - (groupNum - 1) * normalizedIntervalPadding) / groupNum - len * geomWidth) / (len - 1);
const offset =
((1 / 2 + idx) * geomWidth + idx * normalizedDodgePadding +
(1 / 2) * normalizedIntervalPadding) * groupNum -
(1 / 2) * normalizedIntervalPadding) * groupNum -
normalizedIntervalPadding / 2;
return offset;
}
Expand Down Expand Up @@ -199,7 +202,7 @@ export default class Dodge extends Adjust {
normalizedIntervalPadding = (1 - (geomWidth * len + normalizedDodgePadding * (len - 1)) * groupNum) / (groupNum - 1);
const offset =
((1 / 2 + idx) * geomWidth + idx * normalizedDodgePadding +
(1 / 2) * normalizedIntervalPadding) * groupNum -
(1 / 2) * normalizedIntervalPadding) * groupNum -
normalizedIntervalPadding / 2;
return offset;
}
Expand All @@ -216,7 +219,7 @@ export default class Dodge extends Adjust {
const geomWidth = ((1 - normalizedIntervalPadding * (groupNum - 1)) / groupNum - normalizedDodgePadding * (len - 1)) / len;
const offset =
((1 / 2 + idx) * geomWidth + idx * normalizedDodgePadding +
(1 / 2) * normalizedIntervalPadding) * groupNum -
(1 / 2) * normalizedIntervalPadding) * groupNum -
normalizedIntervalPadding / 2;
return offset;
}
Expand Down