From 78179da0cdd2951efb4fef8840d42ea42d0dba13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=B7=E5=B8=83=E7=BD=97=E7=85=9C?= <1056317718@qq.com> Date: Mon, 8 Jul 2024 15:07:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B5=AE=E7=82=B9=E6=95=B0=E7=B2=BE?= =?UTF-8?q?=E5=BA=A6=E4=B8=A2=E5=A4=B1=E5=AF=BC=E8=87=B4=E7=94=BB=E5=B8=83?= =?UTF-8?q?=E7=BC=A9=E6=94=BE=E5=8D=A1=E6=AD=BB=20(#4356)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 浮点数精度丢失导致画布缩放卡死 * chore: 移除多余的代码 --- packages/x6/src/graph/mousewheel.ts | 13 +++++++------ pnpm-lock.yaml | 6 +++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/x6/src/graph/mousewheel.ts b/packages/x6/src/graph/mousewheel.ts index 9f3760815ba..ddfe827a512 100644 --- a/packages/x6/src/graph/mousewheel.ts +++ b/packages/x6/src/graph/mousewheel.ts @@ -81,9 +81,9 @@ export class MouseWheel extends Base { // webkit and to avoid rounding errors for zoom steps this.cumulatedFactor = Math.round(this.currentScale * factor * 20) / 20 / this.currentScale - if (this.cumulatedFactor === 1) { - this.cumulatedFactor = 1.05 - } + } + if (this.cumulatedFactor <= 1) { + this.cumulatedFactor = 1.05 } } else { // zoomout @@ -98,9 +98,9 @@ export class MouseWheel extends Base { Math.round(this.currentScale * (1 / factor) * 20) / 20 / this.currentScale - if (this.cumulatedFactor === 1) { - this.cumulatedFactor = 0.95 - } + } + if (this.cumulatedFactor >= 1) { + this.cumulatedFactor = 0.95 } } @@ -114,6 +114,7 @@ export class MouseWheel extends Base { let targetScale = this.graph.transform.clampScale( currentScale * this.cumulatedFactor, ) + const minScale = this.widgetOptions.minScale || Number.MIN_SAFE_INTEGER const maxScale = this.widgetOptions.maxScale || Number.MAX_SAFE_INTEGER targetScale = NumberExt.clamp(targetScale, minScale, maxScale) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7d490311a42..4a38bc3c5f1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -597,7 +597,7 @@ importers: version: 1.0.0-rc.1(vue@3.2.47) vue-demi: specifier: latest - version: 0.14.6(@vue/composition-api@1.0.0-rc.1)(vue@3.2.47) + version: 0.14.8(@vue/composition-api@1.0.0-rc.1)(vue@3.2.47) devDependencies: '@antv/x6': specifier: ^2.x @@ -46436,10 +46436,10 @@ packages: engines: { node: '>=0.10.0' } dev: false - /vue-demi@0.14.6(@vue/composition-api@1.0.0-rc.1)(vue@3.2.47): + /vue-demi@0.14.8(@vue/composition-api@1.0.0-rc.1)(vue@3.2.47): resolution: { - integrity: sha512-8QA7wrYSHKaYgUxDA5ZC24w+eHm3sYCbp0EzcDwKqN3p6HqtTCGR/GVsPyZW92unff4UlcSh++lmqDWN3ZIq4w==, + integrity: sha512-Uuqnk9YE9SsWeReYqK2alDI5YzciATE0r2SkA6iMAtuXvNTMNACJLJEXNXaEy94ECuBe4Sk6RzRU80kjdbIo1Q==, } engines: { node: '>=12' } hasBin: true