From d80ee1e7c8f0034bb95731f3ea46dd29ebf9f0b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=97=E8=A7=92=E5=B0=8F=E6=9E=97?= <1013335014@qq.com> Date: Thu, 21 Dec 2023 11:25:08 +0800 Subject: [PATCH] =?UTF-8?q?Fix=EF=BC=9A=E4=BF=AE=E5=A4=8D=E5=BD=93?= =?UTF-8?q?=E7=94=BB=E5=B8=83=E5=AE=B9=E5=99=A8=E8=B7=9D=E6=B5=8F=E8=A7=88?= =?UTF-8?q?=E5=99=A8=E7=AA=97=E5=8F=A3=E5=B7=A6=E4=B8=8A=E8=A7=92=E4=B8=8D?= =?UTF-8?q?=E4=B8=BA0=E6=97=B6=EF=BC=8Cfit=E6=96=B9=E6=B3=95=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E5=87=BA=E6=9D=A5=E7=9A=84=E4=BD=8D=E7=BD=AE=E6=9C=89?= =?UTF-8?q?=E8=AF=AF=E5=B7=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/core/view/View.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/simple-mind-map/src/core/view/View.js b/simple-mind-map/src/core/view/View.js index 5e89cd60..ee97470b 100644 --- a/simple-mind-map/src/core/view/View.js +++ b/simple-mind-map/src/core/view/View.js @@ -261,17 +261,17 @@ class View { // 适应画布大小 fit() { - let { fitPadding } = this.mindMap.opt - let draw = this.mindMap.draw - let origTransform = draw.transform() - let rect = draw.rbox() - let drawWidth = rect.width / origTransform.scaleX - let drawHeight = rect.height / origTransform.scaleY - let drawRatio = drawWidth / drawHeight + const { fitPadding } = this.mindMap.opt + const draw = this.mindMap.draw + const origTransform = draw.transform() + const rect = draw.rbox() + const drawWidth = rect.width / origTransform.scaleX + const drawHeight = rect.height / origTransform.scaleY + const drawRatio = drawWidth / drawHeight let { width: elWidth, height: elHeight } = this.mindMap.elRect elWidth = elWidth - fitPadding * 2 elHeight = elHeight - fitPadding * 2 - let elRatio = elWidth / elHeight + const elRatio = elWidth / elHeight let newScale = 0 let flag = '' if (drawWidth <= elWidth && drawHeight <= elHeight) { @@ -292,7 +292,10 @@ class View { newScale = newWidth / drawWidth } this.setScale(newScale) - let newRect = draw.rbox() + const newRect = draw.rbox() + // 需要考虑画布容器距浏览器窗口左上角的距离 + newRect.x -= this.mindMap.elRect.left + newRect.y -= this.mindMap.elRect.top let newX = 0 let newY = 0 if (flag === 1) {