From 5f663914282694787ccc4514888abc828fe2747d Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Sun, 29 Mar 2026 21:48:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D`Legend`=E7=9A=84`Background`?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E5=9C=A8`Horizonal`=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E4=B8=8B=E4=B8=8D=E5=AF=B9=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Documentation~/zh/changelog.md | 1 + Runtime/Component/Legend/LegendHelper.cs | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Documentation~/zh/changelog.md b/Documentation~/zh/changelog.md index 9047891f..fe7d4a34 100644 --- a/Documentation~/zh/changelog.md +++ b/Documentation~/zh/changelog.md @@ -81,6 +81,7 @@ slug: /changelog ## master +* (2026.03.29) 修复`Legend`的`Background`区域在`Horizonal`模式下不对的问题 * (2026.03.25) 增加`Chart`的`Json`导出导入 * (2026.03.10) 增加`Sankey`的线条tooltip触发显示 * (2026.03.10) 增加`UITable`的排序功能支持 diff --git a/Runtime/Component/Legend/LegendHelper.cs b/Runtime/Component/Legend/LegendHelper.cs index f5293a32..9604006b 100644 --- a/Runtime/Component/Legend/LegendHelper.cs +++ b/Runtime/Component/Legend/LegendHelper.cs @@ -198,11 +198,14 @@ namespace XCharts.Runtime legend.context.eachHeight = 0; if (legend.orient == Orient.Horizonal) { + var maxRowWidth = 0f; foreach (var kv in legend.context.buttonList) { if (width + kv.Value.width > maxWidth) { realWidth = width - legend.itemGap; + if (realWidth > maxRowWidth) + maxRowWidth = realWidth; realHeight += height + legend.itemGap; if (legend.context.eachHeight < height + legend.itemGap) { @@ -216,8 +219,10 @@ namespace XCharts.Runtime height = kv.Value.height; } width -= legend.itemGap; + if (width > maxRowWidth) + maxRowWidth = width; legend.context.height = realHeight + height; - legend.context.width = realWidth > 0 ? realWidth : width; + legend.context.width = maxRowWidth; } else {