From 007a5f2815a96b4e2655d79bc2c1ac4852c066c5 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: Mon, 9 Sep 2024 17:47:17 +0800 Subject: [PATCH] =?UTF-8?q?Feat=EF=BC=9A=E7=BB=84=E7=BB=87=E7=BB=93?= =?UTF-8?q?=E6=9E=84=E5=9B=BE=E6=94=AF=E6=8C=81=E6=9B=B2=E7=BA=BF=E8=BF=9E?= =?UTF-8?q?=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/layouts/Base.js | 30 ++++++++--- .../src/layouts/OrganizationStructure.js | 54 ++++++++++++++++++- web/src/config/constant.js | 10 +++- 3 files changed, 82 insertions(+), 12 deletions(-) diff --git a/simple-mind-map/src/layouts/Base.js b/simple-mind-map/src/layouts/Base.js index e8943ce9..6e2084dc 100644 --- a/simple-mind-map/src/layouts/Base.js +++ b/simple-mind-map/src/layouts/Base.js @@ -375,18 +375,32 @@ class Base { } // 二次贝塞尔曲线 - quadraticCurvePath(x1, y1, x2, y2) { - let cx = x1 + (x2 - x1) * 0.2 - let cy = y1 + (y2 - y1) * 0.8 + quadraticCurvePath(x1, y1, x2, y2, v = false) { + let cx, cy + if (v) { + cx = x1 + (x2 - x1) * 0.8 + cy = y1 + (y2 - y1) * 0.2 + } else { + cx = x1 + (x2 - x1) * 0.2 + cy = y1 + (y2 - y1) * 0.8 + } return `M ${x1},${y1} Q ${cx},${cy} ${x2},${y2}` } // 三次贝塞尔曲线 - cubicBezierPath(x1, y1, x2, y2) { - let cx1 = x1 + (x2 - x1) / 2 - let cy1 = y1 - let cx2 = cx1 - let cy2 = y2 + cubicBezierPath(x1, y1, x2, y2, v = false) { + let cx1, cy1, cx2, cy2 + if (v) { + cx1 = x1 + cy1 = y1 + (y2 - y1) / 2 + cx2 = x2 + cy2 = cy1 + } else { + cx1 = x1 + (x2 - x1) / 2 + cy1 = y1 + cx2 = cx1 + cy2 = y2 + } return `M ${x1},${y1} C ${cx1},${cy1} ${cx2},${cy2} ${x2},${y2}` } diff --git a/simple-mind-map/src/layouts/OrganizationStructure.js b/simple-mind-map/src/layouts/OrganizationStructure.js index 475bf7c6..ff5d0730 100644 --- a/simple-mind-map/src/layouts/OrganizationStructure.js +++ b/simple-mind-map/src/layouts/OrganizationStructure.js @@ -34,7 +34,14 @@ class OrganizationStructure extends Base { this.renderer.renderTree, null, (cur, parent, isRoot, layerIndex, index, ancestors) => { - let newNode = this.createNode(cur, parent, isRoot, layerIndex, index, ancestors) + let newNode = this.createNode( + cur, + parent, + isRoot, + layerIndex, + index, + ancestors + ) // 根节点定位在画布中心位置 if (isRoot) { this.setNodeCenter(newNode) @@ -148,13 +155,56 @@ class OrganizationStructure extends Base { // 绘制连线,连接该节点到其子节点 renderLine(node, lines, style, lineStyle) { - if (lineStyle === 'direct') { + if (lineStyle === 'curve') { + this.renderLineCurve(node, lines, style) + } else if (lineStyle === 'direct') { this.renderLineDirect(node, lines, style) } else { this.renderLineStraight(node, lines, style) } } + // 曲线风格连线 + renderLineCurve(node, lines, style) { + if (node.children.length <= 0) { + return [] + } + let { left, top, width, height, expandBtnSize } = node + const { alwaysShowExpandBtn, notShowExpandBtn } = this.mindMap.opt + if (!alwaysShowExpandBtn || notShowExpandBtn) { + expandBtnSize = 0 + } + const { + nodeUseLineStyle, + rootLineStartPositionKeepSameInCurve, + rootLineKeepSameInCurve + } = this.mindMap.themeConfig + node.children.forEach((item, index) => { + if (node.layerIndex === 0) { + expandBtnSize = 0 + } + let x1 = left + width / 2 + let y1 = + node.layerIndex === 0 && !rootLineStartPositionKeepSameInCurve + ? top + height / 2 + : top + height + expandBtnSize + let x2 = item.left + item.width / 2 + let y2 = item.top + let path = '' + // 节点使用横线风格,需要额外渲染横线 + let nodeUseLineStylePath = nodeUseLineStyle + ? ` L ${item.left},${y2} L ${item.left + item.width},${y2}` + : '' + if (node.isRoot && !rootLineKeepSameInCurve) { + path = + this.quadraticCurvePath(x1, y1, x2, y2, true) + nodeUseLineStylePath + } else { + path = this.cubicBezierPath(x1, y1, x2, y2, true) + nodeUseLineStylePath + } + this.setLineStyle(style, lines[index], path, item) + }) + } + // 直连风格 renderLineDirect(node, lines, style) { if (node.children.length <= 0) { diff --git a/web/src/config/constant.js b/web/src/config/constant.js index 3189e33a..d85420f7 100644 --- a/web/src/config/constant.js +++ b/web/src/config/constant.js @@ -85,12 +85,14 @@ export const formulaList = [ '\\begin{cases}3x + 5y + z \\\\7x - 2y + 4z \\\\-6x + 3y + 2z\\end{cases}' ] +// 支持某种连线类型的结构 export const supportLineStyleLayoutsMap = { curve: [ 'logicalStructure', 'logicalStructureLeft', 'mindMap', - 'verticalTimeline' + 'verticalTimeline', + 'organizationStructure' ], direct: [ 'logicalStructure', @@ -101,6 +103,7 @@ export const supportLineStyleLayoutsMap = { ] } +// 直线模式支持设置圆角的结构 export const supportLineRadiusLayouts = [ 'logicalStructure', 'logicalStructureLeft', @@ -108,6 +111,7 @@ export const supportLineRadiusLayouts = [ 'verticalTimeline' ] +// 支持只显示底边直线风格的结构 export const supportNodeUseLineStyleLayouts = [ 'logicalStructure', 'logicalStructureLeft', @@ -116,10 +120,12 @@ export const supportNodeUseLineStyleLayouts = [ 'organizationStructure' ] +// 支持曲线模式下,根节点样式和其他节点样式保持一致的结构 export const supportRootLineKeepSameInCurveLayouts = [ 'logicalStructure', 'logicalStructureLeft', - 'mindMap' + 'mindMap', + 'organizationStructure' ] // 彩虹线条配置