代码优化:读取和设置节点的nodeData.data改为通过setData和getData方法
This commit is contained in:
parent
5079ad2190
commit
74a000723b
@ -448,7 +448,7 @@ class Render {
|
|||||||
this.root,
|
this.root,
|
||||||
null,
|
null,
|
||||||
node => {
|
node => {
|
||||||
if (!node.nodeData.data.isActive) {
|
if (!node.getData('isActive')) {
|
||||||
this.addNodeToActiveList(node)
|
this.addNodeToActiveList(node)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -625,7 +625,9 @@ class Render {
|
|||||||
}
|
}
|
||||||
node.nodeData.children.push(newNode)
|
node.nodeData.children.push(newNode)
|
||||||
// 插入子节点时自动展开子节点
|
// 插入子节点时自动展开子节点
|
||||||
node.nodeData.data.expand = true
|
node.setData({
|
||||||
|
expand: true
|
||||||
|
})
|
||||||
})
|
})
|
||||||
// 如果同时对多个节点插入子节点,需要清除原来激活的节点
|
// 如果同时对多个节点插入子节点,需要清除原来激活的节点
|
||||||
if (handleMultiNodes || !openEdit) {
|
if (handleMultiNodes || !openEdit) {
|
||||||
@ -661,7 +663,9 @@ class Render {
|
|||||||
childList = createUidForAppointNodes(childList, true)
|
childList = createUidForAppointNodes(childList, true)
|
||||||
node.nodeData.children.push(...childList)
|
node.nodeData.children.push(...childList)
|
||||||
// 插入子节点时自动展开子节点
|
// 插入子节点时自动展开子节点
|
||||||
node.nodeData.data.expand = true
|
node.setData({
|
||||||
|
expand: true
|
||||||
|
})
|
||||||
})
|
})
|
||||||
this.clearActiveNodeList()
|
this.clearActiveNodeList()
|
||||||
this.mindMap.render()
|
this.mindMap.render()
|
||||||
@ -961,7 +965,9 @@ class Render {
|
|||||||
(node.layerIndex === 1 && toNode.layerIndex !== 1) ||
|
(node.layerIndex === 1 && toNode.layerIndex !== 1) ||
|
||||||
(node.layerIndex !== 1 && toNode.layerIndex === 1)
|
(node.layerIndex !== 1 && toNode.layerIndex === 1)
|
||||||
if (nodeLayerChanged) {
|
if (nodeLayerChanged) {
|
||||||
node.nodeData.data.resetRichText = true
|
node.setData({
|
||||||
|
resetRichText: true
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1331,7 +1337,7 @@ class Render {
|
|||||||
this.mindMap.execCommand(
|
this.mindMap.execCommand(
|
||||||
'SET_NODE_EXPAND',
|
'SET_NODE_EXPAND',
|
||||||
node,
|
node,
|
||||||
!node.nodeData.data.expand
|
!node.getData('expand')
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1410,7 +1416,7 @@ class Render {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.activeNodeList.forEach(node => {
|
this.activeNodeList.forEach(node => {
|
||||||
if (node.nodeData.data.generalization || node.isRoot) {
|
if (node.getData('generalization') || node.isRoot) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.mindMap.execCommand('SET_NODE_DATA', node, {
|
this.mindMap.execCommand('SET_NODE_DATA', node, {
|
||||||
@ -1429,7 +1435,7 @@ class Render {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.activeNodeList.forEach(node => {
|
this.activeNodeList.forEach(node => {
|
||||||
if (!node.nodeData.data.generalization) {
|
if (!node.getData('generalization')) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.mindMap.execCommand('SET_NODE_DATA', node, {
|
this.mindMap.execCommand('SET_NODE_DATA', node, {
|
||||||
@ -1485,7 +1491,7 @@ class Render {
|
|||||||
|
|
||||||
// 定位到指定节点
|
// 定位到指定节点
|
||||||
goTargetNode(node, callback = () => {}) {
|
goTargetNode(node, callback = () => {}) {
|
||||||
let uid = typeof node === 'string' ? node : node.nodeData.data.uid
|
let uid = typeof node === 'string' ? node : node.getData('uid')
|
||||||
if (!uid) return
|
if (!uid) return
|
||||||
this.expandToNodeUid(uid, () => {
|
this.expandToNodeUid(uid, () => {
|
||||||
let targetNode = this.findNodeByUid(uid)
|
let targetNode = this.findNodeByUid(uid)
|
||||||
@ -1571,7 +1577,7 @@ class Render {
|
|||||||
findNodeByUid(uid) {
|
findNodeByUid(uid) {
|
||||||
let res = null
|
let res = null
|
||||||
walk(this.root, null, node => {
|
walk(this.root, null, node => {
|
||||||
if (node.nodeData.data.uid === uid) {
|
if (node.getData('uid') === uid) {
|
||||||
res = node
|
res = node
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@ -173,7 +173,7 @@ export default class TextEdit {
|
|||||||
let scale = this.mindMap.view.scale
|
let scale = this.mindMap.view.scale
|
||||||
let lineHeight = node.style.merge('lineHeight')
|
let lineHeight = node.style.merge('lineHeight')
|
||||||
let fontSize = node.style.merge('fontSize')
|
let fontSize = node.style.merge('fontSize')
|
||||||
let textLines = (this.cacheEditingText || node.nodeData.data.text)
|
let textLines = (this.cacheEditingText || node.getData('text'))
|
||||||
.split(/\n/gim)
|
.split(/\n/gim)
|
||||||
.map(item => {
|
.map(item => {
|
||||||
return htmlEscape(item)
|
return htmlEscape(item)
|
||||||
|
|||||||
@ -430,7 +430,7 @@ class Node {
|
|||||||
// 多选和取消多选
|
// 多选和取消多选
|
||||||
if (e.ctrlKey && enableCtrlKeyNodeSelection) {
|
if (e.ctrlKey && enableCtrlKeyNodeSelection) {
|
||||||
this.isMultipleChoice = true
|
this.isMultipleChoice = true
|
||||||
let isActive = this.nodeData.data.isActive
|
let isActive = this.getData('isActive')
|
||||||
if (!isActive)
|
if (!isActive)
|
||||||
this.mindMap.emit(
|
this.mindMap.emit(
|
||||||
'before_node_active',
|
'before_node_active',
|
||||||
@ -493,7 +493,7 @@ class Node {
|
|||||||
// 如果有且只有当前节点激活了,那么不需要重新激活
|
// 如果有且只有当前节点激活了,那么不需要重新激活
|
||||||
if (
|
if (
|
||||||
!(
|
!(
|
||||||
this.nodeData.data.isActive &&
|
this.getData('isActive') &&
|
||||||
this.renderer.activeNodeList.length === 1
|
this.renderer.activeNodeList.length === 1
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
@ -510,7 +510,7 @@ class Node {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
e && e.stopPropagation()
|
e && e.stopPropagation()
|
||||||
if (this.nodeData.data.isActive) {
|
if (this.getData('isActive')) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.mindMap.emit('before_node_active', this, this.renderer.activeNodeList)
|
this.mindMap.emit('before_node_active', this, this.renderer.activeNodeList)
|
||||||
@ -535,7 +535,7 @@ class Node {
|
|||||||
this.renderExpandBtn()
|
this.renderExpandBtn()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let { isActive, expand } = this.nodeData.data
|
let { isActive, expand } = this.getData()
|
||||||
// 展开状态且非激活状态,且当前鼠标不在它上面,才隐藏
|
// 展开状态且非激活状态,且当前鼠标不在它上面,才隐藏
|
||||||
if (expand && !isActive && !this._isMouseenter) {
|
if (expand && !isActive && !this._isMouseenter) {
|
||||||
this.hideExpandBtn()
|
this.hideExpandBtn()
|
||||||
@ -602,7 +602,7 @@ class Node {
|
|||||||
// 更新节点激活状态
|
// 更新节点激活状态
|
||||||
updateNodeActive() {
|
updateNodeActive() {
|
||||||
if (!this.group) return
|
if (!this.group) return
|
||||||
const isActive = this.nodeData.data.isActive
|
const isActive = this.getData('isActive')
|
||||||
this.group[isActive ? 'addClass' : 'removeClass']('active')
|
this.group[isActive ? 'addClass' : 'removeClass']('active')
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -635,7 +635,7 @@ class Node {
|
|||||||
if (
|
if (
|
||||||
this.children &&
|
this.children &&
|
||||||
this.children.length &&
|
this.children.length &&
|
||||||
this.nodeData.data.expand !== false
|
this.getData('expand') !== false
|
||||||
) {
|
) {
|
||||||
let index = 0
|
let index = 0
|
||||||
this.children.forEach(item => {
|
this.children.forEach(item => {
|
||||||
@ -780,7 +780,7 @@ class Node {
|
|||||||
|
|
||||||
// 连线
|
// 连线
|
||||||
renderLine(deep = false) {
|
renderLine(deep = false) {
|
||||||
if (this.nodeData.data.expand === false) {
|
if (this.getData('expand') === false) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let childrenLen = this.nodeData.children.length
|
let childrenLen = this.nodeData.children.length
|
||||||
@ -902,7 +902,7 @@ class Node {
|
|||||||
|
|
||||||
// 获取padding值
|
// 获取padding值
|
||||||
getPaddingVale() {
|
getPaddingVale() {
|
||||||
let { isActive } = this.nodeData.data
|
let { isActive } = this.getData()
|
||||||
return {
|
return {
|
||||||
paddingX: this.getStyle('paddingX', true, isActive),
|
paddingX: this.getStyle('paddingX', true, isActive),
|
||||||
paddingY: this.getStyle('paddingY', true, isActive)
|
paddingY: this.getStyle('paddingY', true, isActive)
|
||||||
@ -945,7 +945,7 @@ class Node {
|
|||||||
|
|
||||||
// 获取数据
|
// 获取数据
|
||||||
getData(key) {
|
getData(key) {
|
||||||
return key ? this.nodeData.data[key] || '' : this.nodeData.data
|
return key ? this.nodeData.data[key] : this.nodeData.data
|
||||||
}
|
}
|
||||||
|
|
||||||
// 是否存在自定义样式
|
// 是否存在自定义样式
|
||||||
|
|||||||
@ -88,7 +88,7 @@ class Style {
|
|||||||
|
|
||||||
// 获取自身自定义样式
|
// 获取自身自定义样式
|
||||||
getSelfStyle(prop) {
|
getSelfStyle(prop) {
|
||||||
return this.ctx.nodeData.data[prop]
|
return this.ctx.getData(prop)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 矩形
|
// 矩形
|
||||||
@ -107,7 +107,7 @@ class Style {
|
|||||||
// !this.ctx.isRoot &&
|
// !this.ctx.isRoot &&
|
||||||
// !this.ctx.isGeneralization &&
|
// !this.ctx.isGeneralization &&
|
||||||
// this.ctx.mindMap.themeConfig.nodeUseLineStyle &&
|
// this.ctx.mindMap.themeConfig.nodeUseLineStyle &&
|
||||||
// !this.ctx.nodeData.data.isActive
|
// !this.ctx.getData('isActive')
|
||||||
// ) {
|
// ) {
|
||||||
// return
|
// return
|
||||||
// }
|
// }
|
||||||
@ -225,7 +225,7 @@ class Style {
|
|||||||
// 是否设置了自定义的样式
|
// 是否设置了自定义的样式
|
||||||
hasCustomStyle() {
|
hasCustomStyle() {
|
||||||
let res = false
|
let res = false
|
||||||
Object.keys(this.ctx.nodeData.data).forEach(item => {
|
Object.keys(this.ctx.getData()).forEach(item => {
|
||||||
if (checkIsNodeStyleDataKey(item)) {
|
if (checkIsNodeStyleDataKey(item)) {
|
||||||
res = true
|
res = true
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,14 +12,14 @@ import { CONSTANTS, commonCaches } from '../../../constants/constant'
|
|||||||
|
|
||||||
// 创建图片节点
|
// 创建图片节点
|
||||||
function createImgNode() {
|
function createImgNode() {
|
||||||
let img = this.nodeData.data.image
|
let img = this.getData('image')
|
||||||
if (!img) {
|
if (!img) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let imgSize = this.getImgShowSize()
|
let imgSize = this.getImgShowSize()
|
||||||
let node = new Image().load(img).size(...imgSize)
|
let node = new Image().load(img).size(...imgSize)
|
||||||
if (this.nodeData.data.imageTitle) {
|
if (this.getData('imageTitle')) {
|
||||||
node.attr('title', this.nodeData.data.imageTitle)
|
node.attr('title', this.getData('imageTitle'))
|
||||||
}
|
}
|
||||||
node.on('dblclick', e => {
|
node.on('dblclick', e => {
|
||||||
this.mindMap.emit('node_img_dblclick', this, e)
|
this.mindMap.emit('node_img_dblclick', this, e)
|
||||||
@ -42,7 +42,7 @@ function createImgNode() {
|
|||||||
|
|
||||||
// 获取图片显示宽高
|
// 获取图片显示宽高
|
||||||
function getImgShowSize() {
|
function getImgShowSize() {
|
||||||
const { custom, width, height } = this.nodeData.data.imageSize
|
const { custom, width, height } = this.getData('imageSize')
|
||||||
// 如果是自定义了图片的宽高,那么不受最大宽高限制
|
// 如果是自定义了图片的宽高,那么不受最大宽高限制
|
||||||
if (custom) return [width, height]
|
if (custom) return [width, height]
|
||||||
return resizeImgSize(
|
return resizeImgSize(
|
||||||
@ -55,7 +55,7 @@ function getImgShowSize() {
|
|||||||
|
|
||||||
// 创建icon节点
|
// 创建icon节点
|
||||||
function createIconNode() {
|
function createIconNode() {
|
||||||
let _data = this.nodeData.data
|
let _data = this.getData()
|
||||||
if (!_data.icon || _data.icon.length <= 0) {
|
if (!_data.icon || _data.icon.length <= 0) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
@ -91,7 +91,7 @@ function createRichTextNode() {
|
|||||||
let g = new G()
|
let g = new G()
|
||||||
// 重新设置富文本节点内容
|
// 重新设置富文本节点内容
|
||||||
let recoverText = false
|
let recoverText = false
|
||||||
if (this.nodeData.data.resetRichText) {
|
if (this.getData('resetRichText')) {
|
||||||
delete this.nodeData.data.resetRichText
|
delete this.nodeData.data.resetRichText
|
||||||
recoverText = true
|
recoverText = true
|
||||||
}
|
}
|
||||||
@ -102,7 +102,7 @@ function createRichTextNode() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (recoverText) {
|
if (recoverText) {
|
||||||
let text = this.nodeData.data.text
|
let text = this.getData('text')
|
||||||
// 判断节点内容是否是富文本
|
// 判断节点内容是否是富文本
|
||||||
let isRichText = checkIsRichText(text)
|
let isRichText = checkIsRichText(text)
|
||||||
// 样式字符串
|
// 样式字符串
|
||||||
@ -116,9 +116,11 @@ function createRichTextNode() {
|
|||||||
// 非富文本
|
// 非富文本
|
||||||
text = `<p><span style="${style}">${text}</span></p>`
|
text = `<p><span style="${style}">${text}</span></p>`
|
||||||
}
|
}
|
||||||
this.nodeData.data.text = text
|
this.setData({
|
||||||
|
text: text
|
||||||
|
})
|
||||||
}
|
}
|
||||||
let html = `<div>${this.nodeData.data.text}</div>`
|
let html = `<div>${this.getData('text')}</div>`
|
||||||
if (!commonCaches.measureRichtextNodeTextSizeEl) {
|
if (!commonCaches.measureRichtextNodeTextSizeEl) {
|
||||||
commonCaches.measureRichtextNodeTextSizeEl = document.createElement('div')
|
commonCaches.measureRichtextNodeTextSizeEl = document.createElement('div')
|
||||||
commonCaches.measureRichtextNodeTextSizeEl.style.position = 'fixed'
|
commonCaches.measureRichtextNodeTextSizeEl.style.position = 'fixed'
|
||||||
@ -157,7 +159,7 @@ function createRichTextNode() {
|
|||||||
|
|
||||||
// 创建文本节点
|
// 创建文本节点
|
||||||
function createTextNode() {
|
function createTextNode() {
|
||||||
if (this.nodeData.data.richText) {
|
if (this.getData('richText')) {
|
||||||
return this.createRichTextNode()
|
return this.createRichTextNode()
|
||||||
}
|
}
|
||||||
let g = new G()
|
let g = new G()
|
||||||
@ -166,8 +168,8 @@ function createTextNode() {
|
|||||||
// 文本超长自动换行
|
// 文本超长自动换行
|
||||||
let textStyle = this.style.getTextFontStyle()
|
let textStyle = this.style.getTextFontStyle()
|
||||||
let textArr = []
|
let textArr = []
|
||||||
if (!isUndef(this.nodeData.data.text)) {
|
if (!isUndef(this.getData('text'))) {
|
||||||
textArr = String(this.nodeData.data.text).split(/\n/gim)
|
textArr = String(this.getData('text')).split(/\n/gim)
|
||||||
}
|
}
|
||||||
let maxWidth = this.mindMap.opt.textAutoWrapWidth
|
let maxWidth = this.mindMap.opt.textAutoWrapWidth
|
||||||
let isMultiLine = false
|
let isMultiLine = false
|
||||||
@ -215,7 +217,7 @@ function createTextNode() {
|
|||||||
|
|
||||||
// 创建超链接节点
|
// 创建超链接节点
|
||||||
function createHyperlinkNode() {
|
function createHyperlinkNode() {
|
||||||
let { hyperlink, hyperlinkTitle } = this.nodeData.data
|
let { hyperlink, hyperlinkTitle } = this.getData()
|
||||||
if (!hyperlink) {
|
if (!hyperlink) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -245,7 +247,7 @@ function createHyperlinkNode() {
|
|||||||
|
|
||||||
// 创建标签节点
|
// 创建标签节点
|
||||||
function createTagNode() {
|
function createTagNode() {
|
||||||
let tagData = this.nodeData.data.tag
|
let tagData = this.getData('tag')
|
||||||
if (!tagData || tagData.length <= 0) {
|
if (!tagData || tagData.length <= 0) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
@ -274,7 +276,7 @@ function createTagNode() {
|
|||||||
|
|
||||||
// 创建备注节点
|
// 创建备注节点
|
||||||
function createNoteNode() {
|
function createNoteNode() {
|
||||||
if (!this.nodeData.data.note) {
|
if (!this.getData('note')) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
let iconSize = this.mindMap.themeConfig.iconSize
|
let iconSize = this.mindMap.themeConfig.iconSize
|
||||||
@ -302,7 +304,7 @@ function createNoteNode() {
|
|||||||
this.mindMap.opt.customInnerElsAppendTo || document.body
|
this.mindMap.opt.customInnerElsAppendTo || document.body
|
||||||
targetNode.appendChild(this.noteEl)
|
targetNode.appendChild(this.noteEl)
|
||||||
}
|
}
|
||||||
this.noteEl.innerText = this.nodeData.data.note
|
this.noteEl.innerText = this.getData('note')
|
||||||
}
|
}
|
||||||
node.on('mouseover', () => {
|
node.on('mouseover', () => {
|
||||||
let { left, top } = node.node.getBoundingClientRect()
|
let { left, top } = node.node.getBoundingClientRect()
|
||||||
@ -312,7 +314,7 @@ function createNoteNode() {
|
|||||||
this.noteEl.style.display = 'block'
|
this.noteEl.style.display = 'block'
|
||||||
} else {
|
} else {
|
||||||
this.mindMap.opt.customNoteContentShow.show(
|
this.mindMap.opt.customNoteContentShow.show(
|
||||||
this.nodeData.data.note,
|
this.getData('note'),
|
||||||
left,
|
left,
|
||||||
top + iconSize
|
top + iconSize
|
||||||
)
|
)
|
||||||
|
|||||||
@ -52,7 +52,7 @@ function sumNode(data = []) {
|
|||||||
}
|
}
|
||||||
// 创建或更新展开收缩按钮内容
|
// 创建或更新展开收缩按钮内容
|
||||||
function updateExpandBtnNode() {
|
function updateExpandBtnNode() {
|
||||||
let { expand } = this.nodeData.data
|
let { expand } = this.getData()
|
||||||
// 如果本次和上次的展开状态一样则返回
|
// 如果本次和上次的展开状态一样则返回
|
||||||
if (expand === this._lastExpandBtnType) return
|
if (expand === this._lastExpandBtnType) return
|
||||||
if (this._expandBtn) {
|
if (this._expandBtn) {
|
||||||
@ -129,7 +129,7 @@ function renderExpandBtn() {
|
|||||||
this.mindMap.execCommand(
|
this.mindMap.execCommand(
|
||||||
'SET_NODE_EXPAND',
|
'SET_NODE_EXPAND',
|
||||||
this,
|
this,
|
||||||
!this.nodeData.data.expand
|
!this.getData('expand')
|
||||||
)
|
)
|
||||||
this.mindMap.emit('expand_btn_click', this)
|
this.mindMap.emit('expand_btn_click', this)
|
||||||
})
|
})
|
||||||
@ -164,7 +164,7 @@ function showExpandBtn() {
|
|||||||
function hideExpandBtn() {
|
function hideExpandBtn() {
|
||||||
if (this.mindMap.opt.alwaysShowExpandBtn || this._isMouseenter) return
|
if (this.mindMap.opt.alwaysShowExpandBtn || this._isMouseenter) return
|
||||||
// 非激活状态且展开状态鼠标移出才隐藏按钮
|
// 非激活状态且展开状态鼠标移出才隐藏按钮
|
||||||
let { isActive, expand } = this.nodeData.data
|
let { isActive, expand } = this.getData()
|
||||||
if (!isActive && expand) {
|
if (!isActive && expand) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.removeExpandBtn()
|
this.removeExpandBtn()
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { createUid } from '../../../utils/index'
|
|||||||
|
|
||||||
// 检查是否存在概要
|
// 检查是否存在概要
|
||||||
function checkHasGeneralization() {
|
function checkHasGeneralization() {
|
||||||
return !!this.nodeData.data.generalization
|
return !!this.getData('generalization')
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建概要节点
|
// 创建概要节点
|
||||||
@ -17,7 +17,7 @@ function createGeneralizationNode() {
|
|||||||
if (!this._generalizationNode) {
|
if (!this._generalizationNode) {
|
||||||
this._generalizationNode = new Node({
|
this._generalizationNode = new Node({
|
||||||
data: {
|
data: {
|
||||||
data: this.nodeData.data.generalization
|
data: this.getData('generalization')
|
||||||
},
|
},
|
||||||
uid: createUid(),
|
uid: createUid(),
|
||||||
renderer: this.renderer,
|
renderer: this.renderer,
|
||||||
@ -27,7 +27,7 @@ function createGeneralizationNode() {
|
|||||||
this._generalizationNodeWidth = this._generalizationNode.width
|
this._generalizationNodeWidth = this._generalizationNode.width
|
||||||
this._generalizationNodeHeight = this._generalizationNode.height
|
this._generalizationNodeHeight = this._generalizationNode.height
|
||||||
this._generalizationNode.generalizationBelongNode = this
|
this._generalizationNode.generalizationBelongNode = this
|
||||||
if (this.nodeData.data.generalization.isActive) {
|
if (this.getData('generalization').isActive) {
|
||||||
this.renderer.addNodeToActiveList(this._generalizationNode)
|
this.renderer.addNodeToActiveList(this._generalizationNode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ function renderGeneralization() {
|
|||||||
this._generalizationNodeHeight = 0
|
this._generalizationNodeHeight = 0
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (this.nodeData.data.expand === false) {
|
if (this.getData('expand') === false) {
|
||||||
this.removeGeneralization()
|
this.removeGeneralization()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -91,7 +91,7 @@ class Base {
|
|||||||
// 数据上没有保存节点引用,但是通过uid找到了缓存的节点,也可以复用
|
// 数据上没有保存节点引用,但是通过uid找到了缓存的节点,也可以复用
|
||||||
newNode = this.lru.get(data.data.uid)
|
newNode = this.lru.get(data.data.uid)
|
||||||
// 保存该节点上一次的数据
|
// 保存该节点上一次的数据
|
||||||
let lastData = JSON.stringify(newNode.nodeData.data)
|
let lastData = JSON.stringify(newNode.getData())
|
||||||
let isLayerTypeChange = this.checkIsLayerTypeChange(
|
let isLayerTypeChange = this.checkIsLayerTypeChange(
|
||||||
newNode.layerIndex,
|
newNode.layerIndex,
|
||||||
layerIndex
|
layerIndex
|
||||||
@ -132,7 +132,9 @@ class Base {
|
|||||||
}
|
}
|
||||||
// 如果当前节点在激活节点列表里,那么添加上激活的状态
|
// 如果当前节点在激活节点列表里,那么添加上激活的状态
|
||||||
if (this.mindMap.renderer.findActiveNodeIndex(newNode) !== -1) {
|
if (this.mindMap.renderer.findActiveNodeIndex(newNode) !== -1) {
|
||||||
newNode.nodeData.data.isActive = true
|
newNode.setData({
|
||||||
|
isActive: true
|
||||||
|
})
|
||||||
}
|
}
|
||||||
// 根节点
|
// 根节点
|
||||||
if (isRoot) {
|
if (isRoot) {
|
||||||
@ -298,12 +300,12 @@ class Base {
|
|||||||
let { left, right, top, bottom } = walk(child)
|
let { left, right, top, bottom } = walk(child)
|
||||||
// 概要内容的宽度
|
// 概要内容的宽度
|
||||||
let generalizationWidth =
|
let generalizationWidth =
|
||||||
child.checkHasGeneralization() && child.nodeData.data.expand
|
child.checkHasGeneralization() && child.getData('expand')
|
||||||
? child._generalizationNodeWidth + generalizationNodeMargin
|
? child._generalizationNodeWidth + generalizationNodeMargin
|
||||||
: 0
|
: 0
|
||||||
// 概要内容的高度
|
// 概要内容的高度
|
||||||
let generalizationHeight =
|
let generalizationHeight =
|
||||||
child.checkHasGeneralization() && child.nodeData.data.expand
|
child.checkHasGeneralization() && child.getData('expand')
|
||||||
? child._generalizationNodeHeight + generalizationNodeMargin
|
? child._generalizationNodeHeight + generalizationNodeMargin
|
||||||
: 0
|
: 0
|
||||||
if (left - (dir === 'h' ? generalizationWidth : 0) < _left) {
|
if (left - (dir === 'h' ? generalizationWidth : 0) < _left) {
|
||||||
|
|||||||
@ -73,7 +73,7 @@ class CatalogOrganization extends Base {
|
|||||||
null,
|
null,
|
||||||
(node, parent, isRoot, layerIndex) => {
|
(node, parent, isRoot, layerIndex) => {
|
||||||
if (
|
if (
|
||||||
node.nodeData.data.expand &&
|
node.getData('expand') &&
|
||||||
node.children &&
|
node.children &&
|
||||||
node.children.length
|
node.children.length
|
||||||
) {
|
) {
|
||||||
@ -114,7 +114,7 @@ class CatalogOrganization extends Base {
|
|||||||
this.root,
|
this.root,
|
||||||
null,
|
null,
|
||||||
(node, parent, isRoot, layerIndex) => {
|
(node, parent, isRoot, layerIndex) => {
|
||||||
if (!node.nodeData.data.expand) {
|
if (!node.getData('expand')) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 调整left
|
// 调整left
|
||||||
|
|||||||
@ -112,7 +112,7 @@ class Fishbone extends Base {
|
|||||||
this.root,
|
this.root,
|
||||||
null,
|
null,
|
||||||
(node, parent, isRoot, layerIndex) => {
|
(node, parent, isRoot, layerIndex) => {
|
||||||
if (!node.nodeData.data.expand) {
|
if (!node.getData('expand')) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let params = { node, parent, layerIndex, ctx: this }
|
let params = { node, parent, layerIndex, ctx: this }
|
||||||
|
|||||||
@ -127,7 +127,7 @@ class Fishbone extends Base {
|
|||||||
this.root,
|
this.root,
|
||||||
null,
|
null,
|
||||||
(node, parent, isRoot, layerIndex) => {
|
(node, parent, isRoot, layerIndex) => {
|
||||||
if (!node.nodeData.data.expand) {
|
if (!node.getData('expand')) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 调整top
|
// 调整top
|
||||||
|
|||||||
@ -110,7 +110,7 @@ class Fishbone extends Base {
|
|||||||
this.root,
|
this.root,
|
||||||
null,
|
null,
|
||||||
(node, parent, isRoot, layerIndex) => {
|
(node, parent, isRoot, layerIndex) => {
|
||||||
if (!node.nodeData.data.expand) {
|
if (!node.getData('expand')) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 调整top
|
// 调整top
|
||||||
|
|||||||
@ -78,7 +78,7 @@ class LogicalStructure extends Base {
|
|||||||
null,
|
null,
|
||||||
(node, parent, isRoot, layerIndex) => {
|
(node, parent, isRoot, layerIndex) => {
|
||||||
if (
|
if (
|
||||||
node.nodeData.data.expand &&
|
node.getData('expand') &&
|
||||||
node.children &&
|
node.children &&
|
||||||
node.children.length
|
node.children.length
|
||||||
) {
|
) {
|
||||||
@ -103,7 +103,7 @@ class LogicalStructure extends Base {
|
|||||||
this.root,
|
this.root,
|
||||||
null,
|
null,
|
||||||
(node, parent, isRoot, layerIndex) => {
|
(node, parent, isRoot, layerIndex) => {
|
||||||
if (!node.nodeData.data.expand) {
|
if (!node.getData('expand')) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 判断子节点所占的高度之和是否大于该节点自身,大于则需要调整位置
|
// 判断子节点所占的高度之和是否大于该节点自身,大于则需要调整位置
|
||||||
|
|||||||
@ -117,7 +117,7 @@ class MindMap extends Base {
|
|||||||
null,
|
null,
|
||||||
(node, parent, isRoot, layerIndex) => {
|
(node, parent, isRoot, layerIndex) => {
|
||||||
if (
|
if (
|
||||||
node.nodeData.data.expand &&
|
node.getData('expand') &&
|
||||||
node.children &&
|
node.children &&
|
||||||
node.children.length
|
node.children.length
|
||||||
) {
|
) {
|
||||||
@ -148,7 +148,7 @@ class MindMap extends Base {
|
|||||||
this.root,
|
this.root,
|
||||||
null,
|
null,
|
||||||
(node, parent, isRoot, layerIndex) => {
|
(node, parent, isRoot, layerIndex) => {
|
||||||
if (!node.nodeData.data.expand) {
|
if (!node.getData('expand')) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 判断子节点所占的高度之和是否大于该节点自身,大于则需要调整位置
|
// 判断子节点所占的高度之和是否大于该节点自身,大于则需要调整位置
|
||||||
|
|||||||
@ -79,7 +79,7 @@ class OrganizationStructure extends Base {
|
|||||||
null,
|
null,
|
||||||
(node, parent, isRoot, layerIndex) => {
|
(node, parent, isRoot, layerIndex) => {
|
||||||
if (
|
if (
|
||||||
node.nodeData.data.expand &&
|
node.getData('expand') &&
|
||||||
node.children &&
|
node.children &&
|
||||||
node.children.length
|
node.children.length
|
||||||
) {
|
) {
|
||||||
@ -104,7 +104,7 @@ class OrganizationStructure extends Base {
|
|||||||
this.root,
|
this.root,
|
||||||
null,
|
null,
|
||||||
(node, parent, isRoot, layerIndex) => {
|
(node, parent, isRoot, layerIndex) => {
|
||||||
if (!node.nodeData.data.expand) {
|
if (!node.getData('expand')) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 判断子节点所占的宽度之和是否大于该节点自身,大于则需要调整位置
|
// 判断子节点所占的宽度之和是否大于该节点自身,大于则需要调整位置
|
||||||
|
|||||||
@ -81,7 +81,7 @@ class Timeline extends Base {
|
|||||||
null,
|
null,
|
||||||
(node, parent, isRoot, layerIndex, index) => {
|
(node, parent, isRoot, layerIndex, index) => {
|
||||||
if (
|
if (
|
||||||
node.nodeData.data.expand &&
|
node.getData('expand') &&
|
||||||
node.children &&
|
node.children &&
|
||||||
node.children.length
|
node.children.length
|
||||||
) {
|
) {
|
||||||
@ -122,7 +122,7 @@ class Timeline extends Base {
|
|||||||
this.root,
|
this.root,
|
||||||
null,
|
null,
|
||||||
(node, parent, isRoot, layerIndex) => {
|
(node, parent, isRoot, layerIndex) => {
|
||||||
if (!node.nodeData.data.expand) {
|
if (!node.getData('expand')) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 调整left
|
// 调整left
|
||||||
|
|||||||
@ -98,7 +98,7 @@ class VerticalTimeline extends Base {
|
|||||||
null,
|
null,
|
||||||
(node, parent, isRoot, layerIndex, index) => {
|
(node, parent, isRoot, layerIndex, index) => {
|
||||||
if (
|
if (
|
||||||
node.nodeData.data.expand &&
|
node.getData('expand') &&
|
||||||
node.children &&
|
node.children &&
|
||||||
node.children.length
|
node.children.length
|
||||||
) {
|
) {
|
||||||
@ -135,7 +135,7 @@ class VerticalTimeline extends Base {
|
|||||||
this.root,
|
this.root,
|
||||||
null,
|
null,
|
||||||
(node, parent, isRoot, layerIndex) => {
|
(node, parent, isRoot, layerIndex) => {
|
||||||
if (!node.nodeData.data.expand) {
|
if (!node.getData('expand')) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (isRoot) return
|
if (isRoot) return
|
||||||
|
|||||||
@ -142,7 +142,7 @@ class AssociativeLine {
|
|||||||
null,
|
null,
|
||||||
cur => {
|
cur => {
|
||||||
if (!cur) return
|
if (!cur) return
|
||||||
let data = cur.nodeData.data
|
let data = cur.getData()
|
||||||
if (
|
if (
|
||||||
data.associativeLineTargets &&
|
data.associativeLineTargets &&
|
||||||
data.associativeLineTargets.length > 0
|
data.associativeLineTargets.length > 0
|
||||||
@ -161,7 +161,7 @@ class AssociativeLine {
|
|||||||
ids.forEach((uid, index) => {
|
ids.forEach((uid, index) => {
|
||||||
let toNode = idToNode.get(uid)
|
let toNode = idToNode.get(uid)
|
||||||
if (!node || !toNode) return
|
if (!node || !toNode) return
|
||||||
const associativeLinePoint = (node.nodeData.data.associativeLinePoint ||
|
const associativeLinePoint = (node.getData('associativeLinePoint') ||
|
||||||
[])[index]
|
[])[index]
|
||||||
// 切换结构和布局,都会更新坐标
|
// 切换结构和布局,都会更新坐标
|
||||||
const [startPoint, endPoint] = this.updateAllLinesPos(
|
const [startPoint, endPoint] = this.updateAllLinesPos(
|
||||||
@ -364,7 +364,7 @@ class AssociativeLine {
|
|||||||
checkOverlapNode(x, y) {
|
checkOverlapNode(x, y) {
|
||||||
this.overlapNode = null
|
this.overlapNode = null
|
||||||
bfsWalk(this.mindMap.renderer.root, node => {
|
bfsWalk(this.mindMap.renderer.root, node => {
|
||||||
if (node.nodeData.data.isActive) {
|
if (node.getData('isActive')) {
|
||||||
this.mindMap.execCommand('SET_NODE_ACTIVE', node, false)
|
this.mindMap.execCommand('SET_NODE_ACTIVE', node, false)
|
||||||
}
|
}
|
||||||
if (node.uid === this.creatingStartNode.uid || this.overlapNode) {
|
if (node.uid === this.creatingStartNode.uid || this.overlapNode) {
|
||||||
@ -377,7 +377,7 @@ class AssociativeLine {
|
|||||||
this.overlapNode = node
|
this.overlapNode = node
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (this.overlapNode && !this.overlapNode.nodeData.data.isActive) {
|
if (this.overlapNode && !this.overlapNode.getData('isActive')) {
|
||||||
this.mindMap.execCommand('SET_NODE_ACTIVE', this.overlapNode, true)
|
this.mindMap.execCommand('SET_NODE_ACTIVE', this.overlapNode, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -386,7 +386,7 @@ class AssociativeLine {
|
|||||||
completeCreateLine(node) {
|
completeCreateLine(node) {
|
||||||
if (this.creatingStartNode.uid === node.uid) return
|
if (this.creatingStartNode.uid === node.uid) return
|
||||||
this.addLine(this.creatingStartNode, node)
|
this.addLine(this.creatingStartNode, node)
|
||||||
if (this.overlapNode && this.overlapNode.nodeData.data.isActive) {
|
if (this.overlapNode && this.overlapNode.getData('isActive')) {
|
||||||
this.mindMap.execCommand('SET_NODE_ACTIVE', this.overlapNode, false)
|
this.mindMap.execCommand('SET_NODE_ACTIVE', this.overlapNode, false)
|
||||||
}
|
}
|
||||||
this.isCreatingLine = false
|
this.isCreatingLine = false
|
||||||
@ -401,7 +401,7 @@ class AssociativeLine {
|
|||||||
addLine(fromNode, toNode) {
|
addLine(fromNode, toNode) {
|
||||||
if (!fromNode || !toNode) return
|
if (!fromNode || !toNode) return
|
||||||
// 目标节点如果没有id,则生成一个id
|
// 目标节点如果没有id,则生成一个id
|
||||||
let uid = toNode.nodeData.data.uid
|
let uid = toNode.getData('uid')
|
||||||
if (!uid) {
|
if (!uid) {
|
||||||
uid = uuid()
|
uid = uuid()
|
||||||
this.mindMap.execCommand('SET_NODE_DATA', toNode, {
|
this.mindMap.execCommand('SET_NODE_DATA', toNode, {
|
||||||
@ -409,7 +409,7 @@ class AssociativeLine {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
// 将目标节点id保存起来
|
// 将目标节点id保存起来
|
||||||
let list = fromNode.nodeData.data.associativeLineTargets || []
|
let list = fromNode.getData('associativeLineTargets') || []
|
||||||
// 连线节点是否存在相同的id,存在则阻止添加关联线
|
// 连线节点是否存在相同的id,存在则阻止添加关联线
|
||||||
const sameLine = list.some(item => item === uid)
|
const sameLine = list.some(item => item === uid)
|
||||||
if (sameLine) {
|
if (sameLine) {
|
||||||
@ -425,7 +425,7 @@ class AssociativeLine {
|
|||||||
endPoint.y
|
endPoint.y
|
||||||
)
|
)
|
||||||
let offsetList =
|
let offsetList =
|
||||||
fromNode.nodeData.data.associativeLineTargetControlOffsets || []
|
fromNode.getData('associativeLineTargetControlOffsets') || []
|
||||||
// 保存的实际是控制点和端点的差值,否则当节点位置改变了,控制点还是原来的位置,连线就不对了
|
// 保存的实际是控制点和端点的差值,否则当节点位置改变了,控制点还是原来的位置,连线就不对了
|
||||||
offsetList[list.length - 1] = [
|
offsetList[list.length - 1] = [
|
||||||
{
|
{
|
||||||
@ -437,7 +437,7 @@ class AssociativeLine {
|
|||||||
y: controlPoints[1].y - endPoint.y
|
y: controlPoints[1].y - endPoint.y
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
let associativeLinePoint = fromNode.nodeData.data.associativeLinePoint || []
|
let associativeLinePoint = fromNode.getData('associativeLinePoint') || []
|
||||||
// 记录关联的起始|结束坐标
|
// 记录关联的起始|结束坐标
|
||||||
associativeLinePoint[list.length - 1] = { startPoint, endPoint }
|
associativeLinePoint[list.length - 1] = { startPoint, endPoint }
|
||||||
this.mindMap.execCommand('SET_NODE_DATA', fromNode, {
|
this.mindMap.execCommand('SET_NODE_DATA', fromNode, {
|
||||||
@ -457,14 +457,14 @@ class AssociativeLine {
|
|||||||
associativeLinePoint,
|
associativeLinePoint,
|
||||||
associativeLineTargetControlOffsets,
|
associativeLineTargetControlOffsets,
|
||||||
associativeLineText
|
associativeLineText
|
||||||
} = node.nodeData.data
|
} = node.getData()
|
||||||
associativeLinePoint = associativeLinePoint || []
|
associativeLinePoint = associativeLinePoint || []
|
||||||
let targetIndex = getAssociativeLineTargetIndex(node, toNode)
|
let targetIndex = getAssociativeLineTargetIndex(node, toNode)
|
||||||
// 更新关联线文本数据
|
// 更新关联线文本数据
|
||||||
let newAssociativeLineText = {}
|
let newAssociativeLineText = {}
|
||||||
if (associativeLineText) {
|
if (associativeLineText) {
|
||||||
Object.keys(associativeLineText).forEach(item => {
|
Object.keys(associativeLineText).forEach(item => {
|
||||||
if (item !== toNode.nodeData.data.uid) {
|
if (item !== toNode.getData('uid')) {
|
||||||
newAssociativeLineText[item] = associativeLineText[item]
|
newAssociativeLineText[item] = associativeLineText[item]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@ -109,10 +109,10 @@ class Drag extends Base {
|
|||||||
})
|
})
|
||||||
this.removeCloneNode()
|
this.removeCloneNode()
|
||||||
let overlapNodeUid = this.overlapNode
|
let overlapNodeUid = this.overlapNode
|
||||||
? this.overlapNode.nodeData.data.uid
|
? this.overlapNode.getData('uid')
|
||||||
: ''
|
: ''
|
||||||
let prevNodeUid = this.prevNode ? this.prevNode.nodeData.data.uid : ''
|
let prevNodeUid = this.prevNode ? this.prevNode.getData('uid') : ''
|
||||||
let nextNodeUid = this.nextNode ? this.nextNode.nodeData.data.uid : ''
|
let nextNodeUid = this.nextNode ? this.nextNode.getData('uid') : ''
|
||||||
// 存在重叠子节点,则移动作为其子节点
|
// 存在重叠子节点,则移动作为其子节点
|
||||||
if (this.overlapNode) {
|
if (this.overlapNode) {
|
||||||
this.mindMap.execCommand('SET_NODE_ACTIVE', this.overlapNode, false)
|
this.mindMap.execCommand('SET_NODE_ACTIVE', this.overlapNode, false)
|
||||||
@ -205,7 +205,7 @@ class Drag extends Base {
|
|||||||
this.offsetX = this.mouseDownX - (node.left * scaleX + translateX)
|
this.offsetX = this.mouseDownX - (node.left * scaleX + translateX)
|
||||||
this.offsetY = this.mouseDownY - (node.top * scaleY + translateY)
|
this.offsetY = this.mouseDownY - (node.top * scaleY + translateY)
|
||||||
// 如果鼠标按下的节点是激活节点,那么保存当前所有激活的节点
|
// 如果鼠标按下的节点是激活节点,那么保存当前所有激活的节点
|
||||||
if (node.nodeData.data.isActive) {
|
if (node.getData('isActive')) {
|
||||||
// 找出这些激活节点中的最顶层节点
|
// 找出这些激活节点中的最顶层节点
|
||||||
this.beingDragNodeList = getTopAncestorsFomNodeList(
|
this.beingDragNodeList = getTopAncestorsFomNodeList(
|
||||||
// 过滤掉根节点和概要节点
|
// 过滤掉根节点和概要节点
|
||||||
@ -317,7 +317,7 @@ class Drag extends Base {
|
|||||||
this.nextNode = null
|
this.nextNode = null
|
||||||
this.placeholder.size(0, 0)
|
this.placeholder.size(0, 0)
|
||||||
this.nodeList.forEach(node => {
|
this.nodeList.forEach(node => {
|
||||||
if (node.nodeData.data.isActive) {
|
if (node.getData('isActive')) {
|
||||||
this.mindMap.execCommand('SET_NODE_ACTIVE', node, false)
|
this.mindMap.execCommand('SET_NODE_ACTIVE', node, false)
|
||||||
}
|
}
|
||||||
if (this.overlapNode || (this.prevNode && this.nextNode)) {
|
if (this.overlapNode || (this.prevNode && this.nextNode)) {
|
||||||
|
|||||||
@ -205,7 +205,7 @@ class NodeImgAdjust {
|
|||||||
// 隐藏节点实际图片
|
// 隐藏节点实际图片
|
||||||
this.hideNodeImage()
|
this.hideNodeImage()
|
||||||
// 将节点图片渲染到自定义元素上
|
// 将节点图片渲染到自定义元素上
|
||||||
this.handleEl.style.backgroundImage = `url(${this.node.nodeData.data.image})`
|
this.handleEl.style.backgroundImage = `url(${this.node.getData('image')})`
|
||||||
}
|
}
|
||||||
|
|
||||||
// 鼠标移动
|
// 鼠标移动
|
||||||
@ -214,7 +214,7 @@ class NodeImgAdjust {
|
|||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
// 计算当前拖拽位置对应的图片的实时大小
|
// 计算当前拖拽位置对应的图片的实时大小
|
||||||
let { width: imageOriginWidth, height: imageOriginHeight } =
|
let { width: imageOriginWidth, height: imageOriginHeight } =
|
||||||
this.node.nodeData.data.imageSize
|
this.node.getData('imageSize')
|
||||||
let newWidth = e.clientX - this.rect.x
|
let newWidth = e.clientX - this.rect.x
|
||||||
let newHeight = e.clientY - this.rect.y
|
let newHeight = e.clientY - this.rect.y
|
||||||
if (newWidth <= 0 || newHeight <= 0) return
|
if (newWidth <= 0 || newHeight <= 0) return
|
||||||
@ -237,7 +237,7 @@ class NodeImgAdjust {
|
|||||||
// 隐藏自定义元素
|
// 隐藏自定义元素
|
||||||
this.hideHandleEl()
|
this.hideHandleEl()
|
||||||
// 更新节点图片为新的大小
|
// 更新节点图片为新的大小
|
||||||
let { image, imageTitle } = this.node.nodeData.data
|
let { image, imageTitle } = this.node.getData()
|
||||||
let { scaleX, scaleY } = this.mindMap.draw.transform()
|
let { scaleX, scaleY } = this.mindMap.draw.transform()
|
||||||
this.mindMap.execCommand('SET_NODE_IMAGE', this.node, {
|
this.mindMap.execCommand('SET_NODE_IMAGE', this.node, {
|
||||||
url: image,
|
url: image,
|
||||||
|
|||||||
@ -53,7 +53,7 @@ class Painter {
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
const style = {}
|
const style = {}
|
||||||
const painterNodeData = this.painterNode.nodeData.data
|
const painterNodeData = this.painterNode.getData()
|
||||||
Object.keys(painterNodeData).forEach(key => {
|
Object.keys(painterNodeData).forEach(key => {
|
||||||
if (checkIsNodeStyleDataKey(key)) {
|
if (checkIsNodeStyleDataKey(key)) {
|
||||||
style[key] = painterNodeData[key]
|
style[key] = painterNodeData[key]
|
||||||
|
|||||||
@ -236,17 +236,17 @@ class RichText {
|
|||||||
this.textEditNode.style.borderRadius = (node.height || 50) + 'px'
|
this.textEditNode.style.borderRadius = (node.height || 50) + 'px'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!node.nodeData.data.richText) {
|
if (!node.getData('richText')) {
|
||||||
// 还不是富文本的情况
|
// 还不是富文本的情况
|
||||||
let text = ''
|
let text = ''
|
||||||
if (!isUndef(node.nodeData.data.text)) {
|
if (!isUndef(node.getData('text'))) {
|
||||||
text = String(node.nodeData.data.text).split(/\n/gim).join('<br>')
|
text = String(node.getData('text')).split(/\n/gim).join('<br>')
|
||||||
}
|
}
|
||||||
let html = `<p>${text}</p>`
|
let html = `<p>${text}</p>`
|
||||||
this.textEditNode.innerHTML = this.cacheEditingText || html
|
this.textEditNode.innerHTML = this.cacheEditingText || html
|
||||||
} else {
|
} else {
|
||||||
this.textEditNode.innerHTML =
|
this.textEditNode.innerHTML =
|
||||||
this.cacheEditingText || node.nodeData.data.text
|
this.cacheEditingText || node.getData('text')
|
||||||
}
|
}
|
||||||
this.initQuillEditor()
|
this.initQuillEditor()
|
||||||
document.querySelector('.ql-editor').style.minHeight = originHeight + 'px'
|
document.querySelector('.ql-editor').style.minHeight = originHeight + 'px'
|
||||||
@ -256,7 +256,7 @@ class RichText {
|
|||||||
this.focus(
|
this.focus(
|
||||||
isInserting || (selectTextOnEnterEditText && !isFromKeyDown) ? 0 : null
|
isInserting || (selectTextOnEnterEditText && !isFromKeyDown) ? 0 : null
|
||||||
)
|
)
|
||||||
if (!node.nodeData.data.richText) {
|
if (!node.getData('richText')) {
|
||||||
// 如果是非富文本的情况,需要手动应用文本样式
|
// 如果是非富文本的情况,需要手动应用文本样式
|
||||||
this.setTextStyleIfNotRichText(node)
|
this.setTextStyleIfNotRichText(node)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -73,7 +73,7 @@ class Search {
|
|||||||
this.matchNodeList = []
|
this.matchNodeList = []
|
||||||
this.currentIndex = -1
|
this.currentIndex = -1
|
||||||
bfsWalk(this.mindMap.renderer.root, node => {
|
bfsWalk(this.mindMap.renderer.root, node => {
|
||||||
let { richText, text } = node.nodeData.data
|
let { richText, text } = node.getData()
|
||||||
if (richText) {
|
if (richText) {
|
||||||
text = getTextFromHtml(text)
|
text = getTextFromHtml(text)
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ class Search {
|
|||||||
if (!currentNode) return
|
if (!currentNode) return
|
||||||
let text = this.getReplacedText(currentNode, this.searchText, replaceText)
|
let text = this.getReplacedText(currentNode, this.searchText, replaceText)
|
||||||
this.notResetSearchText = true
|
this.notResetSearchText = true
|
||||||
currentNode.setText(text, currentNode.nodeData.data.richText, true)
|
currentNode.setText(text, currentNode.getData('richText'), true)
|
||||||
this.matchNodeList = this.matchNodeList.filter(node => {
|
this.matchNodeList = this.matchNodeList.filter(node => {
|
||||||
return currentNode !== node
|
return currentNode !== node
|
||||||
})
|
})
|
||||||
@ -143,7 +143,7 @@ class Search {
|
|||||||
node,
|
node,
|
||||||
{
|
{
|
||||||
text,
|
text,
|
||||||
resetRichText: !!node.nodeData.data.richText
|
resetRichText: !!node.getData('richText')
|
||||||
},
|
},
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
@ -155,7 +155,7 @@ class Search {
|
|||||||
|
|
||||||
// 获取某个节点替换后的文本
|
// 获取某个节点替换后的文本
|
||||||
getReplacedText(node, searchText, replaceText) {
|
getReplacedText(node, searchText, replaceText) {
|
||||||
let { richText, text } = node.nodeData.data
|
let { richText, text } = node.getData()
|
||||||
if (richText) {
|
if (richText) {
|
||||||
return replaceHtmlText(text, searchText, replaceText)
|
return replaceHtmlText(text, searchText, replaceText)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -124,7 +124,7 @@ class Select {
|
|||||||
let cur = this.cacheActiveList[i]
|
let cur = this.cacheActiveList[i]
|
||||||
if (
|
if (
|
||||||
!this.mindMap.renderer.activeNodeList.find(item => {
|
!this.mindMap.renderer.activeNodeList.find(item => {
|
||||||
return item.nodeData.data.uid === cur.nodeData.data.uid
|
return item.getData('uid') === cur.getData('uid')
|
||||||
})
|
})
|
||||||
) {
|
) {
|
||||||
isNodeChange = true
|
isNodeChange = true
|
||||||
@ -218,12 +218,12 @@ class Select {
|
|||||||
if (
|
if (
|
||||||
checkTwoRectIsOverlap(minx, maxx, miny, maxy, left, right, top, bottom)
|
checkTwoRectIsOverlap(minx, maxx, miny, maxy, left, right, top, bottom)
|
||||||
) {
|
) {
|
||||||
if (node.nodeData.data.isActive) {
|
if (node.getData('isActive')) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.mindMap.renderer.addNodeToActiveList(node)
|
this.mindMap.renderer.addNodeToActiveList(node)
|
||||||
} else if (node.nodeData.data.isActive) {
|
} else if (node.getData('isActive')) {
|
||||||
if (!node.nodeData.data.isActive) {
|
if (!node.getData('isActive')) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.mindMap.renderer.removeNodeFromActiveList(node)
|
this.mindMap.renderer.removeNodeFromActiveList(node)
|
||||||
|
|||||||
@ -64,7 +64,7 @@ function onControlPointMousemove(e) {
|
|||||||
let [, , , node, toNode] = this.activeLine
|
let [, , , node, toNode] = this.activeLine
|
||||||
let targetIndex = getAssociativeLineTargetIndex(node, toNode)
|
let targetIndex = getAssociativeLineTargetIndex(node, toNode)
|
||||||
let { associativeLinePoint, associativeLineTargetControlOffsets } =
|
let { associativeLinePoint, associativeLineTargetControlOffsets } =
|
||||||
node.nodeData.data
|
node.getData()
|
||||||
associativeLinePoint = associativeLinePoint || []
|
associativeLinePoint = associativeLinePoint || []
|
||||||
const nodePos = this.getNodePos(node)
|
const nodePos = this.getNodePos(node)
|
||||||
const toNodePos = this.getNodePos(toNode)
|
const toNodePos = this.getNodePos(toNode)
|
||||||
@ -160,7 +160,7 @@ function onControlPointMouseup(e) {
|
|||||||
let [, , , node] = this.activeLine
|
let [, , , node] = this.activeLine
|
||||||
let offsetList = []
|
let offsetList = []
|
||||||
let { associativeLinePoint, associativeLineTargetControlOffsets } =
|
let { associativeLinePoint, associativeLineTargetControlOffsets } =
|
||||||
node.nodeData.data
|
node.getData()
|
||||||
if (!associativeLinePoint) {
|
if (!associativeLinePoint) {
|
||||||
associativeLinePoint = []
|
associativeLinePoint = []
|
||||||
}
|
}
|
||||||
|
|||||||
@ -110,8 +110,8 @@ function hideEditTextBox() {
|
|||||||
str = isDefaultText ? '' : str
|
str = isDefaultText ? '' : str
|
||||||
this.mindMap.execCommand('SET_NODE_DATA', node, {
|
this.mindMap.execCommand('SET_NODE_DATA', node, {
|
||||||
associativeLineText: {
|
associativeLineText: {
|
||||||
...(node.nodeData.data.associativeLineText || {}),
|
...(node.getData('associativeLineText') || {}),
|
||||||
[toNode.nodeData.data.uid]: str
|
[toNode.getData('uid')]: str
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
this.textEditNode.style.display = 'none'
|
this.textEditNode.style.display = 'none'
|
||||||
@ -123,11 +123,11 @@ function hideEditTextBox() {
|
|||||||
|
|
||||||
// 获取某根关联线的文字
|
// 获取某根关联线的文字
|
||||||
function getText(node, toNode) {
|
function getText(node, toNode) {
|
||||||
let obj = node.nodeData.data.associativeLineText
|
let obj = node.getData('associativeLineText')
|
||||||
if (!obj) {
|
if (!obj) {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
return obj[toNode.nodeData.data.uid] || ''
|
return obj[toNode.getData('uid')] || ''
|
||||||
}
|
}
|
||||||
|
|
||||||
// 渲染关联线文字
|
// 渲染关联线文字
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
// 获取目标节点在起始节点的目标数组中的索引
|
// 获取目标节点在起始节点的目标数组中的索引
|
||||||
export const getAssociativeLineTargetIndex = (node, toNode) => {
|
export const getAssociativeLineTargetIndex = (node, toNode) => {
|
||||||
return node.nodeData.data.associativeLineTargets.findIndex(item => {
|
return node.getData('associativeLineTargets').findIndex(item => {
|
||||||
return item === toNode.nodeData.data.uid
|
return item === toNode.getData('uid')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,7 +231,7 @@ export const getNodeLinePath = (startPoint, endPoint, node, toNode) => {
|
|||||||
// 控制点
|
// 控制点
|
||||||
let controlPoints = []
|
let controlPoints = []
|
||||||
let associativeLineTargetControlOffsets =
|
let associativeLineTargetControlOffsets =
|
||||||
node.nodeData.data.associativeLineTargetControlOffsets
|
node.getData('associativeLineTargetControlOffsets')
|
||||||
if (
|
if (
|
||||||
associativeLineTargetControlOffsets &&
|
associativeLineTargetControlOffsets &&
|
||||||
associativeLineTargetControlOffsets[targetIndex]
|
associativeLineTargetControlOffsets[targetIndex]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user