From 4b687819e8945dbd4d8b5dae2633558aa6cb5988 Mon Sep 17 00:00:00 2001 From: "yilin.qyl" Date: Tue, 26 Mar 2019 18:43:44 +0800 Subject: [PATCH] fix(minimap): fix minimap view error when bbox.minX || bbox.minY < 0 --- plugins/minimap/index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/plugins/minimap/index.js b/plugins/minimap/index.js index 1c1b98525a..3338a16757 100644 --- a/plugins/minimap/index.js +++ b/plugins/minimap/index.js @@ -161,6 +161,10 @@ class Minimap extends Base { const pixelRatio = canvas.get('pixelRatio'); const ratio = Math.min(size[0] / width, size[1] / height); canvas.resetMatrix(); + // 如果bbox为负,先平移到左上角 + const minX = -(bbox.minX > 0 ? 0 : bbox.minX); + const minY = -(bbox.minY > 0 ? 0 : bbox.minY); + canvas.translate(minX, minY); canvas.scale(ratio * pixelRatio, ratio * pixelRatio); // 缩放到适合视口后, 平移到画布中心 const dx = (size[0] - width * ratio) / 2; @@ -168,14 +172,18 @@ class Minimap extends Base { canvas.translate(dx * pixelRatio, dy * pixelRatio); canvas.draw(); // 更新minimap视口 - this._updateViewport(ratio, dx, dy); + this._updateViewport(ratio, dx + minX * ratio, dy + minY * ratio); } // 仅在minimap上绘制keyShape // FIXME 如果用户自定义绘制了其他内容,minimap上就无法画出 _updateKeyShapes() { const graph = this._cfgs.graph; const canvas = this.get('canvas'); - const group = canvas.get('children')[0] || canvas.addGroup(); + let group = canvas.get('children')[0]; + if (!group) { + group = canvas.addGroup(); + group.setMatrix(graph.get('group').getMatrix()); + } const nodes = graph.getNodes(); group.clear(); this._getGraphEdgeKeyShape(group);