Feat:1.优化概要渲染,减少不必要的重新渲染;2.修复同时选中概要节点和其所属节点,设置节点样式后概要节点会失去激活状态的问题

This commit is contained in:
街角小林 2024-08-15 15:19:26 +08:00
parent 161d9dd715
commit 2c8b96582a
2 changed files with 33 additions and 3 deletions

View File

@ -239,7 +239,8 @@ class Node {
getSize() {
this.customLeft = this.getData('customLeft') || undefined
this.customTop = this.getData('customTop') || undefined
this.updateGeneralization()
// 这里不要更新概要,不然即使概要没修改,每次也会重新渲染
// this.updateGeneralization()
this.createNodeData()
let { width, height } = this.getNodeRect()
// 判断节点尺寸是否有变化

View File

@ -122,7 +122,10 @@ class Base {
// 判断编号是否改变
let isNumberChange = false
if (hasNumberPlugin) {
isNumberChange = this.mindMap.numbers.updateNumber(newNode, newNumberStr)
isNumberChange = this.mindMap.numbers.updateNumber(
newNode,
newNumberStr
)
}
// 主题或主题配置改变了、节点层级改变了,需要重新渲染节点文本等情况需要重新计算节点大小和布局
if (
@ -134,6 +137,7 @@ class Base {
newNode.getSize()
newNode.needLayout = true
}
this.checkGetGeneralizationChange(newNode)
} else if (
(this.lru.has(uid) || this.renderer.lastNodeCache[uid]) &&
!this.renderer.reRender
@ -167,7 +171,10 @@ class Base {
// 判断编号是否改变
let isNumberChange = false
if (hasNumberPlugin) {
isNumberChange = this.mindMap.numbers.updateNumber(newNode, newNumberStr)
isNumberChange = this.mindMap.numbers.updateNumber(
newNode,
newNumberStr
)
}
if (
isResizeSource ||
@ -179,6 +186,7 @@ class Base {
newNode.getSize()
newNode.needLayout = true
}
this.checkGetGeneralizationChange(newNode)
} else {
// 创建新节点
const newUid = uid || createUid()
@ -219,6 +227,27 @@ class Base {
return newNode
}
// 检查概要节点是否需要更新
checkGetGeneralizationChange(node) {
const generalizationList = node.getData('generalization')
if (
generalizationList &&
node._generalizationList &&
node._generalizationList.length > 0
) {
node._generalizationList.forEach((item, index) => {
const gNode = item.generalizationNode
const oldData = gNode.getData()
const newData = generalizationList[index]
if (newData && JSON.stringify(oldData) !== JSON.stringify(newData)) {
gNode.nodeData.data = newData
gNode.getSize()
gNode.needLayout = true
}
})
}
}
// 格式化节点位置
formatPosition(value, size, nodeSize) {
if (typeof value === 'number') {