From 17ab977efbd8df1dbc0fa44854b1bf80de069576 Mon Sep 17 00:00:00 2001 From: wanglin2 <1013335014@qq.com> Date: Wed, 22 Mar 2023 13:42:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=85=B3=E8=81=94=E7=BA=BF?= =?UTF-8?q?=E7=9A=84=E7=82=B9=E5=87=BB=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/AssociativeLine.js | 49 ++++++++++++++++++++------ 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/simple-mind-map/src/AssociativeLine.js b/simple-mind-map/src/AssociativeLine.js index 153feb68..599a973b 100644 --- a/simple-mind-map/src/AssociativeLine.js +++ b/simple-mind-map/src/AssociativeLine.js @@ -106,9 +106,16 @@ class AssociativeLine { // 绘制连接线 drawLine(startPoint, endPoint, node, toNode) { - let { associativeLineWidth, associativeLineColor, associativeLineActiveWidth, associativeLineActiveColor } = this.mindMap.themeConfig + let { + associativeLineWidth, + associativeLineColor, + associativeLineActiveWidth, + associativeLineActiveColor + } = this.mindMap.themeConfig // 箭头 - this.markerPath.stroke({ color: associativeLineColor }).fill({ color: associativeLineColor }) + this.markerPath + .stroke({ color: associativeLineColor }) + .fill({ color: associativeLineColor }) // 路径 let pathStr = this.cubicBezierPath( startPoint.x, @@ -119,21 +126,36 @@ class AssociativeLine { // 虚线 let path = this.draw.path() path - .stroke({ width: associativeLineWidth, color: associativeLineColor, dasharray: [6, 4] }) + .stroke({ + width: associativeLineWidth, + color: associativeLineColor, + dasharray: [6, 4] + }) .fill({ color: 'none' }) path.plot(pathStr) path.marker('end', this.marker) // 不可见的点击线 let clickPath = this.draw.path() - clickPath.stroke({ width: associativeLineActiveWidth, color: 'transparent' }).fill({ color: 'none' }) + clickPath + .stroke({ width: associativeLineActiveWidth, color: 'transparent' }) + .fill({ color: 'none' }) clickPath.plot(pathStr) clickPath.click(e => { e.stopPropagation() - this.clearActiveNodes() - this.clearActiveLine() - this.activeLine = [path, clickPath, node, toNode] - clickPath.stroke({ color: associativeLineActiveColor }) - this.mindMap.emit('associative_line_click', path, clickPath, node, toNode) + if (this.mindMap.renderer.activeNodeList.length > 0) { + this.clearActiveNodes() + } else { + this.clearActiveLine() + this.activeLine = [path, clickPath, node, toNode] + clickPath.stroke({ color: associativeLineActiveColor }) + this.mindMap.emit( + 'associative_line_click', + path, + clickPath, + node, + toNode + ) + } }) this.lineList.push([path, clickPath, node, toNode]) } @@ -156,13 +178,18 @@ class AssociativeLine { // 创建连接线 createLine(fromNode) { - let { associativeLineWidth, associativeLineColor } = this.mindMap.themeConfig + let { associativeLineWidth, associativeLineColor } = + this.mindMap.themeConfig if (this.isCreatingLine || !fromNode) return this.isCreatingLine = true this.creatingStartNode = fromNode this.creatingLine = this.draw.path() this.creatingLine - .stroke({ width: associativeLineWidth, color: associativeLineColor, dasharray: [6, 4] }) + .stroke({ + width: associativeLineWidth, + color: associativeLineColor, + dasharray: [6, 4] + }) .fill({ color: 'none' }) this.creatingLine.marker('end', this.marker) }