mirror of
https://github.com/wanglin2/mind-map.git
synced 2026-02-21 10:27:44 +08:00
Feat:walk方法增加祖先列表回调参数
This commit is contained in:
parent
13a1f989c3
commit
1620a013ba
@ -32,8 +32,8 @@ class CatalogOrganization extends Base {
|
||||
walk(
|
||||
this.renderer.renderTree,
|
||||
null,
|
||||
(cur, parent, isRoot, layerIndex) => {
|
||||
let newNode = this.createNode(cur, parent, isRoot, layerIndex)
|
||||
(cur, parent, isRoot, layerIndex, index, ancestors) => {
|
||||
let newNode = this.createNode(cur, parent, isRoot, layerIndex, index, ancestors)
|
||||
// 根节点定位在画布中心位置
|
||||
if (isRoot) {
|
||||
this.setNodeCenter(newNode)
|
||||
|
||||
@ -36,9 +36,9 @@ class Fishbone extends Base {
|
||||
walk(
|
||||
this.renderer.renderTree,
|
||||
null,
|
||||
(node, parent, isRoot, layerIndex, index) => {
|
||||
(node, parent, isRoot, layerIndex, index, ancestors) => {
|
||||
// 创建节点
|
||||
let newNode = this.createNode(node, parent, isRoot, layerIndex)
|
||||
let newNode = this.createNode(node, parent, isRoot, layerIndex, index, ancestors)
|
||||
// 根节点定位在画布中心位置
|
||||
if (isRoot) {
|
||||
this.setNodeCenter(newNode)
|
||||
|
||||
@ -35,8 +35,8 @@ class LogicalStructure extends Base {
|
||||
walk(
|
||||
this.renderer.renderTree,
|
||||
null,
|
||||
(cur, parent, isRoot, layerIndex) => {
|
||||
let newNode = this.createNode(cur, parent, isRoot, layerIndex)
|
||||
(cur, parent, isRoot, layerIndex, index, ancestors) => {
|
||||
let newNode = this.createNode(cur, parent, isRoot, layerIndex, index, ancestors)
|
||||
newNode.sortIndex = sortIndex
|
||||
sortIndex++
|
||||
// 根节点定位在画布中心位置
|
||||
|
||||
@ -34,8 +34,8 @@ class MindMap extends Base {
|
||||
walk(
|
||||
this.renderer.renderTree,
|
||||
null,
|
||||
(cur, parent, isRoot, layerIndex, index) => {
|
||||
let newNode = this.createNode(cur, parent, isRoot, layerIndex)
|
||||
(cur, parent, isRoot, layerIndex, index, ancestors) => {
|
||||
let newNode = this.createNode(cur, parent, isRoot, layerIndex, index, ancestors)
|
||||
// 根节点定位在画布中心位置
|
||||
if (isRoot) {
|
||||
this.setNodeCenter(newNode)
|
||||
|
||||
@ -33,8 +33,8 @@ class OrganizationStructure extends Base {
|
||||
walk(
|
||||
this.renderer.renderTree,
|
||||
null,
|
||||
(cur, parent, isRoot, layerIndex) => {
|
||||
let newNode = this.createNode(cur, parent, isRoot, layerIndex)
|
||||
(cur, parent, isRoot, layerIndex, index, ancestors) => {
|
||||
let newNode = this.createNode(cur, parent, isRoot, layerIndex, index, ancestors)
|
||||
// 根节点定位在画布中心位置
|
||||
if (isRoot) {
|
||||
this.setNodeCenter(newNode)
|
||||
|
||||
@ -34,8 +34,8 @@ class Timeline extends Base {
|
||||
walk(
|
||||
this.renderer.renderTree,
|
||||
null,
|
||||
(cur, parent, isRoot, layerIndex, index) => {
|
||||
let newNode = this.createNode(cur, parent, isRoot, layerIndex)
|
||||
(cur, parent, isRoot, layerIndex, index, ancestors) => {
|
||||
let newNode = this.createNode(cur, parent, isRoot, layerIndex, index, ancestors)
|
||||
// 根节点定位在画布中心位置
|
||||
if (isRoot) {
|
||||
this.setNodeCenter(newNode)
|
||||
|
||||
@ -34,8 +34,8 @@ class VerticalTimeline extends Base {
|
||||
walk(
|
||||
this.renderer.renderTree,
|
||||
null,
|
||||
(cur, parent, isRoot, layerIndex, index) => {
|
||||
let newNode = this.createNode(cur, parent, isRoot, layerIndex)
|
||||
(cur, parent, isRoot, layerIndex, index, ancestors) => {
|
||||
let newNode = this.createNode(cur, parent, isRoot, layerIndex, index, ancestors)
|
||||
// 根节点定位在画布中心位置
|
||||
if (isRoot) {
|
||||
this.setNodeCenter(newNode)
|
||||
|
||||
@ -14,11 +14,12 @@ export const walk = (
|
||||
afterCallback,
|
||||
isRoot,
|
||||
layerIndex = 0,
|
||||
index = 0
|
||||
index = 0,
|
||||
ancestors = []
|
||||
) => {
|
||||
let stop = false
|
||||
if (beforeCallback) {
|
||||
stop = beforeCallback(root, parent, isRoot, layerIndex, index)
|
||||
stop = beforeCallback(root, parent, isRoot, layerIndex, index, ancestors)
|
||||
}
|
||||
if (!stop && root.children && root.children.length > 0) {
|
||||
let _layerIndex = layerIndex + 1
|
||||
@ -30,11 +31,13 @@ export const walk = (
|
||||
afterCallback,
|
||||
false,
|
||||
_layerIndex,
|
||||
nodeIndex
|
||||
nodeIndex,
|
||||
[...ancestors, root]
|
||||
)
|
||||
})
|
||||
}
|
||||
afterCallback && afterCallback(root, parent, isRoot, layerIndex, index)
|
||||
afterCallback &&
|
||||
afterCallback(root, parent, isRoot, layerIndex, index, ancestors)
|
||||
}
|
||||
|
||||
// 广度优先遍历树
|
||||
@ -948,7 +951,11 @@ export const addDataToAppointNodes = (appointNodes, data = {}) => {
|
||||
|
||||
// 给指定的节点列表树数据添加uid,会修改原数据
|
||||
// createNewId默认为false,即如果节点不存在uid的话,会创建新的uid。如果传true,那么无论节点数据原来是否存在uid,都会创建新的uid
|
||||
export const createUidForAppointNodes = (appointNodes, createNewId = false, handle = null) => {
|
||||
export const createUidForAppointNodes = (
|
||||
appointNodes,
|
||||
createNewId = false,
|
||||
handle = null
|
||||
) => {
|
||||
const walk = list => {
|
||||
list.forEach(node => {
|
||||
if (!node.data) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user