From d412ae8cce98fa8d4899d5d9fe9d2f8bc7b52896 Mon Sep 17 00:00:00 2001 From: wanglin2 <1013335014@qq.com> Date: Tue, 28 Mar 2023 19:15:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E5=AE=9E=E4=BE=8B=E3=80=81=E6=A0=B7=E5=BC=8F=E5=AE=9E=E4=BE=8B?= =?UTF-8?q?=E4=B8=8D=E5=86=8D=E4=BF=9D=E5=AD=98=E4=B8=BB=E9=A2=98=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=EF=BC=8C=E7=9B=B4=E6=8E=A5=E4=BB=8EmindMap=E5=AE=9E?= =?UTF-8?q?=E4=BE=8B=E4=B8=8A=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/Node.js | 29 +++++++++-------------------- simple-mind-map/src/Style.js | 22 ++++++++-------------- 2 files changed, 17 insertions(+), 34 deletions(-) diff --git a/simple-mind-map/src/Node.js b/simple-mind-map/src/Node.js index 386e9a71..9947826f 100644 --- a/simple-mind-map/src/Node.js +++ b/simple-mind-map/src/Node.js @@ -21,10 +21,8 @@ class Node { this.renderer = opt.renderer // 渲染器 this.draw = opt.draw || null - // 主题配置 - this.themeConfig = this.mindMap.themeConfig // 样式实例 - this.style = new Style(this, this.themeConfig) + this.style = new Style(this) // 形状实例 this.shapeInstance = new Shape(this) this.shapePadding = { @@ -110,15 +108,6 @@ class Node { this._top = val } - // 更新主题配置 - - updateThemeConfig() { - // 主题配置 - this.themeConfig = this.mindMap.themeConfig - // 样式实例 - this.style.updateThemeConfig(this.themeConfig) - } - // 复位部分布局时会重新设置的数据 reset() { @@ -342,8 +331,8 @@ class Node { return resizeImgSize( this.nodeData.data.imageSize.width, this.nodeData.data.imageSize.height, - this.themeConfig.imgMaxWidth, - this.themeConfig.imgMaxHeight + this.mindMap.themeConfig.imgMaxWidth, + this.mindMap.themeConfig.imgMaxHeight ) } @@ -354,7 +343,7 @@ class Node { if (!_data.icon || _data.icon.length <= 0) { return [] } - let iconSize = this.themeConfig.iconSize + let iconSize = this.mindMap.themeConfig.iconSize return _data.icon.map(item => { return { node: SVG(iconsSvg.getNodeIconListIcon(item)).size(iconSize, iconSize), @@ -458,7 +447,7 @@ class Node { if (!hyperlink) { return } - let iconSize = this.themeConfig.iconSize + let iconSize = this.mindMap.themeConfig.iconSize let node = new SVG() // 超链接节点 let a = new A().to(hyperlink).target('_blank') @@ -515,7 +504,7 @@ class Node { if (!this.nodeData.data.note) { return null } - let iconSize = this.themeConfig.iconSize + let iconSize = this.mindMap.themeConfig.iconSize let node = new SVG().attr('cursor', 'pointer') // 透明的层,用来作为鼠标区域 node.add(new Rect().size(iconSize, iconSize).fill({ color: 'transparent' })) @@ -571,7 +560,7 @@ class Node { getShape() { // 节点使用功能横线风格的话不支持设置形状,直接使用默认的矩形 - return this.themeConfig.nodeUseLineStyle + return this.mindMap.themeConfig.nodeUseLineStyle ? 'rectangle' : this.style.getStyle('shape', false, false) } @@ -754,7 +743,7 @@ class Node { // 更新节点 - update(layout = false) { + update(isLayout = false) { if (!this.group) { return } @@ -769,7 +758,7 @@ class Node { } this.renderGeneralization() let t = this.group.transform() - if (!layout) { + if (!isLayout) { this.group .animate(300) .translate( diff --git a/simple-mind-map/src/Style.js b/simple-mind-map/src/Style.js index 083120b2..876782e6 100644 --- a/simple-mind-map/src/Style.js +++ b/simple-mind-map/src/Style.js @@ -21,34 +21,28 @@ class Style { // 构造函数 - constructor(ctx, themeConfig) { + constructor(ctx) { this.ctx = ctx - this.themeConfig = themeConfig - } - - // 更新主题配置 - - updateThemeConfig(themeConfig) { - this.themeConfig = themeConfig } // 合并样式 merge(prop, root, isActive) { + let themeConfig = this.ctx.mindMap.themeConfig // 三级及以下节点 - let defaultConfig = this.themeConfig.node + let defaultConfig = themeConfig.node if (root || rootProp.includes(prop)) { // 直接使用最外层样式 - defaultConfig = this.themeConfig + defaultConfig = themeConfig } else if (this.ctx.isGeneralization) { // 概要节点 - defaultConfig = this.themeConfig.generalization + defaultConfig = themeConfig.generalization } else if (this.ctx.layerIndex === 0) { // 根节点 - defaultConfig = this.themeConfig.root + defaultConfig = themeConfig.root } else if (this.ctx.layerIndex === 1) { // 二级节点 - defaultConfig = this.themeConfig.second + defaultConfig = themeConfig.second } // 激活状态 if (isActive !== undefined ? isActive : this.ctx.nodeData.data.isActive) { @@ -96,7 +90,7 @@ class Style { if ( !this.ctx.isRoot && !this.ctx.isGeneralization && - this.themeConfig.nodeUseLineStyle && + this.ctx.mindMap.themeConfig.nodeUseLineStyle && !this.ctx.nodeData.data.isActive ) { return