Skip to content
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

fix: 处理自定义mini图显示柱状图时,全为正值&全为零值 展示异常问题 #2826

Merged
merged 1 commit into from
Jul 23, 2024
Merged
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
25 changes: 19 additions & 6 deletions packages/s2-core/src/utils/g-mini-charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,26 @@ export const scale = (chartData: BaseChartData, cell: S2CellType) => {
positionY = baseLinePositionY;
}
} else {
baseLinePositionY = minMeasure < 0 ? yStart : yEnd;
// 有三种情况:全为正数 / 全为负数 / 全为零值
// baseLinePositionY = minMeasure < 0 ? yStart : yEnd;
measureRange = max([Math.abs(maxMeasure), Math.abs(minMeasure)])!;
barHeight =
measureRange === 0
? heightRange
: (Math.abs(item?.y - 0) / measureRange) * heightRange;
positionY = baseLinePositionY;

if (measureRange === 0 && minMeasure === 0 && maxMeasure === 0) {
// 全为零值: 没有bar
barHeight = 0;
} else {
// 全为非零值: 有bar 高度相同
barHeight =
measureRange === 0
? heightRange
: (Math.abs(item?.y - 0) / measureRange) * heightRange;
}

if (minMeasure < 0) {
positionY = yStart;
} else {
positionY = yEnd - barHeight;
}
}

const barWidth = intervalX - intervalPadding;
Expand Down
Loading