From e36e238c2f0e81f1c6b6d5a4d6e6c8c1c9550159 Mon Sep 17 00:00:00 2001 From: wanglin2 <1013335014@qq.com> Date: Mon, 28 Aug 2023 08:49:45 +0800 Subject: [PATCH] =?UTF-8?q?Fix=EF=BC=9A=E4=BF=AE=E5=A4=8D=E5=A4=A7?= =?UTF-8?q?=E8=BE=B9=E6=A1=86=E5=B0=BA=E5=AF=B8=E7=9A=84=E6=B8=B2=E6=9F=93?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E5=8C=85=E6=8B=AC=E9=87=8D=E5=8F=A0?= =?UTF-8?q?=EF=BC=8C=E5=86=85=E5=AE=B9=E4=B8=8D=E5=B1=85=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/core/render/node/Shape.js | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/simple-mind-map/src/core/render/node/Shape.js b/simple-mind-map/src/core/render/node/Shape.js index a9ff7816..217a8ae6 100644 --- a/simple-mind-map/src/core/render/node/Shape.js +++ b/simple-mind-map/src/core/render/node/Shape.js @@ -62,14 +62,9 @@ export default class Shape { // 创建形状节点 createShape() { const shape = this.node.getShape() - const borderWidth = this.node.getBorderWidth() - let { width, height } = this.node - width -= borderWidth - height -= borderWidth let node = null // 矩形 if (shape === CONSTANTS.SHAPE.RECTANGLE) { - // node = new Rect().size(width, height) node = this.createRect() } else if (shape === CONSTANTS.SHAPE.DIAMOND) { // 菱形 @@ -99,9 +94,21 @@ export default class Shape { return node } - // 创建矩形TODO - createRect() { + // 获取节点减去边框宽度的尺寸 + getNodeSize() { + const borderWidth = this.node.getBorderWidth() let { width, height } = this.node + width -= borderWidth + height -= borderWidth + return { + width, + height + } + } + + // 创建矩形 + createRect() { + let { width, height } = this.getNodeSize() let borderRadius = this.node.style.merge('borderRadius') return new Path().plot(` M${borderRadius},0 @@ -121,7 +128,7 @@ export default class Shape { // 创建菱形 createDiamond() { - let { width, height } = this.node + let { width, height } = this.getNodeSize() let halfWidth = width / 2 let halfHeight = height / 2 let topX = halfWidth @@ -144,7 +151,7 @@ export default class Shape { createParallelogram() { let { paddingX } = this.node.getPaddingVale() paddingX = paddingX || this.node.shapePadding.paddingX - let { width, height } = this.node + let { width, height } = this.getNodeSize() return new Polygon().plot([ [paddingX, 0], [width, 0], @@ -155,7 +162,7 @@ export default class Shape { // 创建圆角矩形 createRoundedRectangle() { - let { width, height } = this.node + let { width, height } = this.getNodeSize() let halfHeight = height / 2 return new Path().plot(` M${halfHeight},0 @@ -169,7 +176,7 @@ export default class Shape { // 创建八角矩形 createOctagonalRectangle() { let w = 5 - let { width, height } = this.node + let { width, height } = this.getNodeSize() return new Polygon().plot([ [0, w], [w, 0], @@ -186,7 +193,7 @@ export default class Shape { createOuterTriangularRectangle() { let { paddingX } = this.node.getPaddingVale() paddingX = paddingX || this.node.shapePadding.paddingX - let { width, height } = this.node + let { width, height } = this.getNodeSize() return new Polygon().plot([ [paddingX, 0], [width - paddingX, 0], @@ -201,7 +208,7 @@ export default class Shape { createInnerTriangularRectangle() { let { paddingX } = this.node.getPaddingVale() paddingX = paddingX || this.node.shapePadding.paddingX - let { width, height } = this.node + let { width, height } = this.getNodeSize() return new Polygon().plot([ [0, 0], [width, 0], @@ -214,7 +221,7 @@ export default class Shape { // 创建椭圆 createEllipse() { - let { width, height } = this.node + let { width, height } = this.getNodeSize() let halfWidth = width / 2 let halfHeight = height / 2 return new Path().plot(` @@ -227,7 +234,7 @@ export default class Shape { // 创建圆 createCircle() { - let { width, height } = this.node + let { width, height } = this.getNodeSize() let halfWidth = width / 2 let halfHeight = height / 2 return new Path().plot(`