From 8d57a2ce8fb3ad67a9f6b5934021585d8ec6a85c Mon Sep 17 00:00:00 2001 From: tangying1027 <33517362+tangying1027@users.noreply.github.com> Date: Tue, 2 Jan 2024 15:27:43 +0800 Subject: [PATCH] fix: legend resize (#1912) Co-authored-by: xuying.xu --- .../f2/src/components/legend/withLegend.tsx | 1 + ...-tsx-canvas-chart-resize-legend-1-snap.png | Bin 0 -> 5973 bytes .../f2/test/components/canvas/canvas.test.tsx | 45 +++++++++++++++++- 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 packages/f2/test/components/canvas/__image_snapshots__/canvas-test-tsx-canvas-chart-resize-legend-1-snap.png diff --git a/packages/f2/src/components/legend/withLegend.tsx b/packages/f2/src/components/legend/withLegend.tsx index 61927aa37..bda0044fe 100644 --- a/packages/f2/src/components/legend/withLegend.tsx +++ b/packages/f2/src/components/legend/withLegend.tsx @@ -223,6 +223,7 @@ export default (View) => { willUpdate(): void { const items = this.getItems(); if (!items || !items.length) return; + this._init(); this.updateCoord(); } diff --git a/packages/f2/test/components/canvas/__image_snapshots__/canvas-test-tsx-canvas-chart-resize-legend-1-snap.png b/packages/f2/test/components/canvas/__image_snapshots__/canvas-test-tsx-canvas-chart-resize-legend-1-snap.png new file mode 100644 index 0000000000000000000000000000000000000000..1a93a672a85aebcae714b132d3fa17271c296cfc GIT binary patch literal 5973 zcmb7oXIzs_@NEc1KoJs(RE;6@-a%T>2q6^d9YhIL=}np@q8OwjEtJr!5D=+SUzI?l zNtcd-pcFw+kRtvc?!CYJ`Q8tC@?m#pcV}kLIWw^)#(FHwyv!gFh(#ZbG6Vkm&VGyx zz_-SROag%}@#~{>EFL&*<+1n)Oa%A-3w6~rP-KJNm&7y0EKvkK2A<*5KB*dyfjk%e8>c!Sjsm&HnBYN!vx;@tN* z{fs2Lp6v%Eu9DXZHK^fj+gqIzB=zD~dNUE*tz8kP+YdL})_6V4z!+yVSa({KMo3nX zhLaHf49XpYV@A#2V5&flpG!lkg0DS(vRu|Ge;rA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SdZDyuGRT~vzZF~Qf2E;Ga6oR1njnTIyJeCM_S+!{{36V0y^Wh%Wxog{ydex zMe!wP>AInG;%63PZ6sDA{?)N}#{!n_GR7~?_8Vwv zO5)LieKb=$zZ!O;{+jKf?e1HuZ#)BvnDJW*<4_?JJ^(>x{3guwm}ofrM8BiGb-e*U zc)hbU5D)^OtGGn4k*D!0VE*agGU>{Yq}yCgInBK>e>*P?x*}%mr%O-6d1Xn)<91#^ z6Vyz-$!=Hl>@ZPXS$^M0+=>EiTcw(s#gDAPzcH{>WEt7Ft70_f_kcriU}@N|Frj1) zya%}Q1XW04Fsv$XTrdIlEUfb^t7anzCns!8Su$6-Q>t3iS4Y;;k!FDB5MsrRPC{&# z{&zBLTg;nKteb~aHmaP+TorWJ*$Cpv>-nPC0WcxZzepI { await delay(1000); expect(context).toMatchImageSnapshot(); }); + + it('chart resize legend', async () => { + const chartRef = { current: null }; + const context = createContext('chart resize legend'); + const width = 300; + const height = 300; + const { type, props } = ( + + + + + + + ); + + const canvas = new Canvas(props); + await canvas.render(); + + await delay(1000); + await canvas.resize(200, 200); + await delay(1000); + expect(context).toMatchImageSnapshot(); + }); });