From 34d293f4e850b850cd56e5ff3e11f40cdfc40d5e Mon Sep 17 00:00:00 2001 From: duganlx <840797783@qq.com> Date: Sat, 20 Jul 2024 16:31:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A4=84=E7=90=86=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89mini=E5=9B=BE=E6=98=BE=E7=A4=BA=E6=9F=B1=E7=8A=B6?= =?UTF-8?q?=E5=9B=BE=E6=97=B6=EF=BC=8C=E5=85=A8=E4=B8=BA=E6=AD=A3=E5=80=BC?= =?UTF-8?q?&=E5=85=A8=E4=B8=BA=E9=9B=B6=E5=80=BC=20=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/s2-core/src/utils/g-mini-charts.ts | 25 ++++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/s2-core/src/utils/g-mini-charts.ts b/packages/s2-core/src/utils/g-mini-charts.ts index 5eaed0490b..85386984b0 100644 --- a/packages/s2-core/src/utils/g-mini-charts.ts +++ b/packages/s2-core/src/utils/g-mini-charts.ts @@ -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;