Skip to content

Commit

Permalink
fix: 处理自定义mini图显示柱状图时,全为正值&全为零值 展示异常问题 (#2826)
Browse files Browse the repository at this point in the history
  • Loading branch information
duganlx authored Jul 23, 2024
1 parent 36b681e commit 81def62
Showing 1 changed file with 19 additions and 6 deletions.
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

0 comments on commit 81def62

Please sign in to comment.