Feature:默认改为鼠标移上节点才显示展开收起按钮
This commit is contained in:
parent
65151f4b0a
commit
e1b4146171
@ -103,7 +103,9 @@ const defaultOpt = {
|
|||||||
// 是否在点击了画布外的区域时结束节点文本的编辑状态
|
// 是否在点击了画布外的区域时结束节点文本的编辑状态
|
||||||
isEndNodeTextEditOnClickOuter: true,
|
isEndNodeTextEditOnClickOuter: true,
|
||||||
// 最大历史记录数
|
// 最大历史记录数
|
||||||
maxHistoryCount: 1000
|
maxHistoryCount: 1000,
|
||||||
|
// 是否一直显示节点的展开收起按钮,默认为鼠标移上去和激活时才显示
|
||||||
|
alwaysShowExpandBtn: false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 思维导图
|
// 思维导图
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import Style from './Style'
|
import Style from './Style'
|
||||||
import Shape from './Shape'
|
import Shape from './Shape'
|
||||||
import { asyncRun } from './utils'
|
import { asyncRun } from './utils'
|
||||||
import { G } from '@svgdotjs/svg.js'
|
import { G, Rect } from '@svgdotjs/svg.js'
|
||||||
import nodeGeneralizationMethods from './utils/nodeGeneralization'
|
import nodeGeneralizationMethods from './utils/nodeGeneralization'
|
||||||
import nodeExpandBtnMethods from './utils/nodeExpandBtn'
|
import nodeExpandBtnMethods from './utils/nodeExpandBtn'
|
||||||
import nodeCommandWrapsMethods from './utils/nodeCommandWraps'
|
import nodeCommandWrapsMethods from './utils/nodeCommandWraps'
|
||||||
@ -74,6 +74,7 @@ class Node {
|
|||||||
this._lines = []
|
this._lines = []
|
||||||
this._generalizationLine = null
|
this._generalizationLine = null
|
||||||
this._generalizationNode = null
|
this._generalizationNode = null
|
||||||
|
this._unVisibleRectRegionNode = null
|
||||||
// 尺寸信息
|
// 尺寸信息
|
||||||
this._rectInfo = {
|
this._rectInfo = {
|
||||||
imgContentWidth: 0,
|
imgContentWidth: 0,
|
||||||
@ -242,13 +243,23 @@ class Node {
|
|||||||
layout() {
|
layout() {
|
||||||
// 清除之前的内容
|
// 清除之前的内容
|
||||||
this.group.clear()
|
this.group.clear()
|
||||||
let { width, textContentItemMargin } = this
|
let { width, height, textContentItemMargin } = this
|
||||||
let { paddingY } = this.getPaddingVale()
|
let { paddingY } = this.getPaddingVale()
|
||||||
paddingY += this.shapePadding.paddingY
|
paddingY += this.shapePadding.paddingY
|
||||||
// 节点形状
|
// 节点形状
|
||||||
this.shapeNode = this.shapeInstance.createShape()
|
this.shapeNode = this.shapeInstance.createShape()
|
||||||
this.group.add(this.shapeNode)
|
this.group.add(this.shapeNode)
|
||||||
this.updateNodeShape()
|
this.updateNodeShape()
|
||||||
|
// 渲染一个隐藏的矩形区域,用来触发展开收起按钮的显示
|
||||||
|
if (!this.mindMap.opt.alwaysShowExpandBtn) {
|
||||||
|
if (!this._unVisibleRectRegionNode) {
|
||||||
|
this._unVisibleRectRegionNode = new Rect()
|
||||||
|
}
|
||||||
|
this._unVisibleRectRegionNode.fill({
|
||||||
|
color: 'transparent'
|
||||||
|
}).size(this.expandBtnSize, height).x(width).y(0)
|
||||||
|
this.group.add(this._unVisibleRectRegionNode)
|
||||||
|
}
|
||||||
// 概要节点添加一个带所属节点id的类名
|
// 概要节点添加一个带所属节点id的类名
|
||||||
if (this.isGeneralization && this.generalizationBelongNode) {
|
if (this.isGeneralization && this.generalizationBelongNode) {
|
||||||
this.group.addClass('generalization_' + this.generalizationBelongNode.uid)
|
this.group.addClass('generalization_' + this.generalizationBelongNode.uid)
|
||||||
@ -374,9 +385,12 @@ class Node {
|
|||||||
this.mindMap.emit('node_mouseup', this, e)
|
this.mindMap.emit('node_mouseup', this, e)
|
||||||
})
|
})
|
||||||
this.group.on('mouseenter', e => {
|
this.group.on('mouseenter', e => {
|
||||||
|
// 显示展开收起按钮
|
||||||
|
this.showExpandBtn()
|
||||||
this.mindMap.emit('node_mouseenter', this, e)
|
this.mindMap.emit('node_mouseenter', this, e)
|
||||||
})
|
})
|
||||||
this.group.on('mouseleave', e => {
|
this.group.on('mouseleave', e => {
|
||||||
|
this.hideExpandBtn()
|
||||||
this.mindMap.emit('node_mouseleave', this, e)
|
this.mindMap.emit('node_mouseleave', this, e)
|
||||||
})
|
})
|
||||||
// 双击事件
|
// 双击事件
|
||||||
@ -424,14 +438,21 @@ class Node {
|
|||||||
if (!this.group) {
|
if (!this.group) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let { enableNodeTransitionMove, nodeTransitionMoveDuration } =
|
let { enableNodeTransitionMove, nodeTransitionMoveDuration, alwaysShowExpandBtn } =
|
||||||
this.mindMap.opt
|
this.mindMap.opt
|
||||||
// 需要移除展开收缩按钮
|
if (alwaysShowExpandBtn) {
|
||||||
if (this._expandBtn && this.nodeData.children.length <= 0) {
|
// 需要移除展开收缩按钮
|
||||||
this.removeExpandBtn()
|
if (this._expandBtn && this.nodeData.children.length <= 0) {
|
||||||
|
this.removeExpandBtn()
|
||||||
|
} else {
|
||||||
|
// 更新展开收起按钮
|
||||||
|
this.renderExpandBtn()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// 更新展开收起按钮
|
// 如果是收起状态,那么显示展开收起按钮
|
||||||
this.renderExpandBtn()
|
if (!this.nodeData.data.expand) {
|
||||||
|
this.showExpandBtn()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 更新概要
|
// 更新概要
|
||||||
this.renderGeneralization()
|
this.renderGeneralization()
|
||||||
@ -730,9 +751,10 @@ class Node {
|
|||||||
|
|
||||||
// 获取padding值
|
// 获取padding值
|
||||||
getPaddingVale() {
|
getPaddingVale() {
|
||||||
|
let { isActive }= this.nodeData.data
|
||||||
return {
|
return {
|
||||||
paddingX: this.getStyle('paddingX', true, this.nodeData.data.isActive),
|
paddingX: this.getStyle('paddingX', true, isActive),
|
||||||
paddingY: this.getStyle('paddingY', true, this.nodeData.data.isActive)
|
paddingY: this.getStyle('paddingY', true, isActive)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -366,6 +366,8 @@ class Render {
|
|||||||
if (!node.nodeData.data.isActive) {
|
if (!node.nodeData.data.isActive) {
|
||||||
node.nodeData.data.isActive = true
|
node.nodeData.data.isActive = true
|
||||||
this.addActiveNode(node)
|
this.addActiveNode(node)
|
||||||
|
// 激活节点需要显示展开收起按钮
|
||||||
|
node.showExpandBtn()
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
node.updateNodeShape()
|
node.updateNodeShape()
|
||||||
}, 0)
|
}, 0)
|
||||||
@ -735,6 +737,12 @@ class Render {
|
|||||||
this.setNodeData(node, {
|
this.setNodeData(node, {
|
||||||
isActive: active
|
isActive: active
|
||||||
})
|
})
|
||||||
|
// 切换激活状态,需要切换展开收起按钮的显隐
|
||||||
|
if (active) {
|
||||||
|
node.showExpandBtn()
|
||||||
|
} else {
|
||||||
|
node.hideExpandBtn()
|
||||||
|
}
|
||||||
node.updateNodeShape()
|
node.updateNodeShape()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -199,6 +199,9 @@ class CatalogOrganization extends Base {
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
let { left, top, width, height, expandBtnSize } = node
|
let { left, top, width, height, expandBtnSize } = node
|
||||||
|
if (!this.mindMap.opt.alwaysShowExpandBtn) {
|
||||||
|
expandBtnSize = 0
|
||||||
|
}
|
||||||
let len = node.children.length
|
let len = node.children.length
|
||||||
let marginX = this.getMarginX(node.layerIndex + 1)
|
let marginX = this.getMarginX(node.layerIndex + 1)
|
||||||
if (node.isRoot) {
|
if (node.isRoot) {
|
||||||
|
|||||||
@ -231,6 +231,9 @@ class Fishbone extends Base {
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
let { top, height, expandBtnSize } = node
|
let { top, height, expandBtnSize } = node
|
||||||
|
if (!this.mindMap.opt.alwaysShowExpandBtn) {
|
||||||
|
expandBtnSize = 0
|
||||||
|
}
|
||||||
let len = node.children.length
|
let len = node.children.length
|
||||||
if (node.isRoot) {
|
if (node.isRoot) {
|
||||||
// 当前节点是根节点
|
// 当前节点是根节点
|
||||||
|
|||||||
@ -159,6 +159,9 @@ class LogicalStructure extends Base {
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
let { left, top, width, height, expandBtnSize } = node
|
let { left, top, width, height, expandBtnSize } = node
|
||||||
|
if (!this.mindMap.opt.alwaysShowExpandBtn) {
|
||||||
|
expandBtnSize = 0
|
||||||
|
}
|
||||||
let marginX = this.getMarginX(node.layerIndex + 1)
|
let marginX = this.getMarginX(node.layerIndex + 1)
|
||||||
let s1 = (marginX - expandBtnSize) * 0.6
|
let s1 = (marginX - expandBtnSize) * 0.6
|
||||||
let nodeUseLineStyle = this.mindMap.themeConfig.nodeUseLineStyle
|
let nodeUseLineStyle = this.mindMap.themeConfig.nodeUseLineStyle
|
||||||
@ -188,6 +191,9 @@ class LogicalStructure extends Base {
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
let { left, top, width, height, expandBtnSize } = node
|
let { left, top, width, height, expandBtnSize } = node
|
||||||
|
if (!this.mindMap.opt.alwaysShowExpandBtn) {
|
||||||
|
expandBtnSize = 0
|
||||||
|
}
|
||||||
let nodeUseLineStyle = this.mindMap.themeConfig.nodeUseLineStyle
|
let nodeUseLineStyle = this.mindMap.themeConfig.nodeUseLineStyle
|
||||||
node.children.forEach((item, index) => {
|
node.children.forEach((item, index) => {
|
||||||
let x1 =
|
let x1 =
|
||||||
@ -213,6 +219,9 @@ class LogicalStructure extends Base {
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
let { left, top, width, height, expandBtnSize } = node
|
let { left, top, width, height, expandBtnSize } = node
|
||||||
|
if (!this.mindMap.opt.alwaysShowExpandBtn) {
|
||||||
|
expandBtnSize = 0
|
||||||
|
}
|
||||||
let nodeUseLineStyle = this.mindMap.themeConfig.nodeUseLineStyle
|
let nodeUseLineStyle = this.mindMap.themeConfig.nodeUseLineStyle
|
||||||
node.children.forEach((item, index) => {
|
node.children.forEach((item, index) => {
|
||||||
let x1 =
|
let x1 =
|
||||||
|
|||||||
@ -198,6 +198,9 @@ class MindMap extends Base {
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
let { left, top, width, height, expandBtnSize } = node
|
let { left, top, width, height, expandBtnSize } = node
|
||||||
|
if (!this.mindMap.opt.alwaysShowExpandBtn) {
|
||||||
|
expandBtnSize = 0
|
||||||
|
}
|
||||||
let marginX = this.getMarginX(node.layerIndex + 1)
|
let marginX = this.getMarginX(node.layerIndex + 1)
|
||||||
let s1 = (marginX - expandBtnSize) * 0.6
|
let s1 = (marginX - expandBtnSize) * 0.6
|
||||||
let nodeUseLineStyle = this.mindMap.themeConfig.nodeUseLineStyle
|
let nodeUseLineStyle = this.mindMap.themeConfig.nodeUseLineStyle
|
||||||
@ -235,6 +238,9 @@ class MindMap extends Base {
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
let { left, top, width, height, expandBtnSize } = node
|
let { left, top, width, height, expandBtnSize } = node
|
||||||
|
if (!this.mindMap.opt.alwaysShowExpandBtn) {
|
||||||
|
expandBtnSize = 0
|
||||||
|
}
|
||||||
let nodeUseLineStyle = this.mindMap.themeConfig.nodeUseLineStyle
|
let nodeUseLineStyle = this.mindMap.themeConfig.nodeUseLineStyle
|
||||||
node.children.forEach((item, index) => {
|
node.children.forEach((item, index) => {
|
||||||
let x1 =
|
let x1 =
|
||||||
@ -269,6 +275,9 @@ class MindMap extends Base {
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
let { left, top, width, height, expandBtnSize } = node
|
let { left, top, width, height, expandBtnSize } = node
|
||||||
|
if (!this.mindMap.opt.alwaysShowExpandBtn) {
|
||||||
|
expandBtnSize = 0
|
||||||
|
}
|
||||||
let nodeUseLineStyle = this.mindMap.themeConfig.nodeUseLineStyle
|
let nodeUseLineStyle = this.mindMap.themeConfig.nodeUseLineStyle
|
||||||
node.children.forEach((item, index) => {
|
node.children.forEach((item, index) => {
|
||||||
let x1 =
|
let x1 =
|
||||||
@ -276,7 +285,7 @@ class MindMap extends Base {
|
|||||||
? left + width / 2
|
? left + width / 2
|
||||||
: item.dir === 'left'
|
: item.dir === 'left'
|
||||||
? left - expandBtnSize
|
? left - expandBtnSize
|
||||||
: left + width + 20
|
: left + width + expandBtnSize
|
||||||
let y1 = top + height / 2
|
let y1 = top + height / 2
|
||||||
let x2 = item.dir === 'left' ? item.left + item.width : item.left
|
let x2 = item.dir === 'left' ? item.left + item.width : item.left
|
||||||
let y2 = item.top + item.height / 2
|
let y2 = item.top + item.height / 2
|
||||||
|
|||||||
@ -179,6 +179,9 @@ class OrganizationStructure extends Base {
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
let { left, top, width, height, expandBtnSize, isRoot } = node
|
let { left, top, width, height, expandBtnSize, isRoot } = node
|
||||||
|
if (!this.mindMap.opt.alwaysShowExpandBtn) {
|
||||||
|
expandBtnSize = 0
|
||||||
|
}
|
||||||
let x1 = left + width / 2
|
let x1 = left + width / 2
|
||||||
let y1 = top + height
|
let y1 = top + height
|
||||||
let marginX = this.getMarginX(node.layerIndex + 1)
|
let marginX = this.getMarginX(node.layerIndex + 1)
|
||||||
|
|||||||
@ -238,6 +238,9 @@ class Timeline extends Base {
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
let { left, top, width, height, expandBtnSize } = node
|
let { left, top, width, height, expandBtnSize } = node
|
||||||
|
if (!this.mindMap.opt.alwaysShowExpandBtn) {
|
||||||
|
expandBtnSize = 0
|
||||||
|
}
|
||||||
let len = node.children.length
|
let len = node.children.length
|
||||||
if (node.isRoot) {
|
if (node.isRoot) {
|
||||||
// 当前节点是根节点
|
// 当前节点是根节点
|
||||||
|
|||||||
@ -32,14 +32,15 @@ function createExpandNodeContent() {
|
|||||||
|
|
||||||
// 创建或更新展开收缩按钮内容
|
// 创建或更新展开收缩按钮内容
|
||||||
function updateExpandBtnNode() {
|
function updateExpandBtnNode() {
|
||||||
|
let { expand } = this.nodeData.data
|
||||||
// 如果本次和上次的展开状态一样则返回
|
// 如果本次和上次的展开状态一样则返回
|
||||||
if (this.nodeData.data.expand === this._lastExpandBtnType) return
|
if (expand === this._lastExpandBtnType) return
|
||||||
if (this._expandBtn) {
|
if (this._expandBtn) {
|
||||||
this._expandBtn.clear()
|
this._expandBtn.clear()
|
||||||
}
|
}
|
||||||
this.createExpandNodeContent()
|
this.createExpandNodeContent()
|
||||||
let node
|
let node
|
||||||
if (this.nodeData.data.expand === false) {
|
if (expand === false) {
|
||||||
node = this._openExpandNode
|
node = this._openExpandNode
|
||||||
this._lastExpandBtnType = false
|
this._lastExpandBtnType = false
|
||||||
} else {
|
} else {
|
||||||
@ -108,10 +109,32 @@ function removeExpandBtn() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 显示展开收起按钮
|
||||||
|
function showExpandBtn() {
|
||||||
|
if (this.mindMap.opt.alwaysShowExpandBtn) return
|
||||||
|
setTimeout(() => {
|
||||||
|
this.renderExpandBtn()
|
||||||
|
}, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 隐藏展开收起按钮
|
||||||
|
function hideExpandBtn() {
|
||||||
|
if (this.mindMap.opt.alwaysShowExpandBtn) return
|
||||||
|
// 非激活状态且展开状态鼠标移出才隐藏按钮
|
||||||
|
let { isActive, expand } = this.nodeData.data
|
||||||
|
if (!isActive && expand) {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.removeExpandBtn()
|
||||||
|
}, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
createExpandNodeContent,
|
createExpandNodeContent,
|
||||||
updateExpandBtnNode,
|
updateExpandBtnNode,
|
||||||
updateExpandBtnPos,
|
updateExpandBtnPos,
|
||||||
renderExpandBtn,
|
renderExpandBtn,
|
||||||
removeExpandBtn
|
removeExpandBtn,
|
||||||
|
showExpandBtn,
|
||||||
|
hideExpandBtn
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user