Git Product home page Git Product logo

Comments (6)

LeaveZzz avatar LeaveZzz commented on July 19, 2024 1

1、在graph.render()之后调用
const newGroup = graph.getGroup().addGroup({
id: 'newGroup',
name: 'newGroup'
// 其他配置省略
}) 创建新分组
2、创建新分组后const nodeGroup = graph.getGroup().find(i => i.cfg.id === '-node')获取到节点分组,将节点分组里你需要的元素(nodeGroup.cfg.children)移动到新分组,最后调用newGroup.toBack()置底新分组

from g6.

TabCrazy avatar TabCrazy commented on July 19, 2024 1

1、在graph.render()之后调用 const newGroup = graph.getGroup().addGroup({ id: 'newGroup', name: 'newGroup' // 其他配置省略 }) 创建新分组 2、创建新分组后const nodeGroup = graph.getGroup().find(i => i.cfg.id === '-node')获取到节点分组,将节点分组里你需要的元素(nodeGroup.cfg.children)移动到新分组,最后调用newGroup.toBack()置底新分组

// ...
graph.render()
const newGroup = graph.getGroup().addGroup({ id: 'newGroup', name: 'newGroup'})
const nodeGroup = graph.get('nodeGroup')
const cloneNodeGroup = cloneDeep(nodeGroup)
cloneNodeGroup.cfg.children.forEach((groupItem) => {
    if(groupItem.cfg.name === 'key') {
       newGroup.cfg.children.push(groupItem)
       nodeGroup.removeChild(groupItem)
    }
})
graph.get('comboGroup').set('zIndex', 0)
newGroup.set('zIndex', 1)
graph.get('edgeGroup').set('zIndex', 2)
nodeGroup.set('zIndex', 3)
graph.get('group').sort()
// ...

做了如下的验证,感觉好像通过 push 直接移到新创建的分组, 再操作排序。发现好像并没有搞定

你检查一下循环里push和remove操作的结果是否符合预期,我改了一下代码,是可以实现功能的。

 // ...
 graph.render()
 const newGroup = graph.getGroup().addGroup({ id: 'newGroup', name: 'newGroup' })
 const nodeGroup = graph.get('nodeGroup')
 for (let i = nodeGroup.cfg.children.length - 1; i >= 0; i--) {
   if (nodeGroup.cfg.children[i].cfg.item.getModel().type === 'site') {
     newGroup.cfg.children.push(nodeGroup.cfg.children[i])
     nodeGroup.cfg.children.splice(i, 1)
   }
 }
 graph.get('comboGroup').set('zIndex', 0)
 newGroup.set('zIndex', 1)
 graph.get('edgeGroup').set('zIndex', 2)
 nodeGroup.set('zIndex', 3)
 graph.get('group').sort()
 // ...

demo

for (let i = nodeGroup.cfg.children.length - 1; i >= 0; i--) {
   if (nodeGroup.cfg.children[i].cfg.item.getModel().type === 'site') {
     newGroup.cfg.children.push(nodeGroup.cfg.children[i])
      nodeGroup.cfg.children.splice(i, 1)
   }
}

用nodeGroup.cfg.children.splice 移除元素搞定,已经达到预期。非常感谢!

from g6.

TabCrazy avatar TabCrazy commented on July 19, 2024

1、在graph.render()之后调用 const newGroup = graph.getGroup().addGroup({ id: 'newGroup', name: 'newGroup' // 其他配置省略 }) 创建新分组 2、创建新分组后const nodeGroup = graph.getGroup().find(i => i.cfg.id === '-node')获取到节点分组,将节点分组里你需要的元素(nodeGroup.cfg.children)移动到新分组,最后调用newGroup.toBack()置底新分组

谢谢!我去试试

from g6.

TabCrazy avatar TabCrazy commented on July 19, 2024

1、在graph.render()之后调用 const newGroup = graph.getGroup().addGroup({ id: 'newGroup', name: 'newGroup' // 其他配置省略 }) 创建新分组 2、创建新分组后const nodeGroup = graph.getGroup().find(i => i.cfg.id === '-node')获取到节点分组,将节点分组里你需要的元素(nodeGroup.cfg.children)移动到新分组,最后调用newGroup.toBack()置底新分组

// ...
graph.render()
const newGroup = graph.getGroup().addGroup({ id: 'newGroup', name: 'newGroup'})
const nodeGroup = graph.get('nodeGroup')
const cloneNodeGroup = cloneDeep(nodeGroup)
cloneNodeGroup.cfg.children.forEach((groupItem) => {
    if(groupItem.cfg.name === 'key') {
       newGroup.cfg.children.push(groupItem)
       nodeGroup.removeChild(groupItem)
    }
})
graph.get('comboGroup').set('zIndex', 0)
newGroup.set('zIndex', 1)
graph.get('edgeGroup').set('zIndex', 2)
nodeGroup.set('zIndex', 3)
graph.get('group').sort()
// ...

做了如下的验证,感觉好像通过 push 直接移到新创建的分组, 再操作排序。发现好像并没有搞定

from g6.

LeaveZzz avatar LeaveZzz commented on July 19, 2024

1、在graph.render()之后调用 const newGroup = graph.getGroup().addGroup({ id: 'newGroup', name: 'newGroup' // 其他配置省略 }) 创建新分组 2、创建新分组后const nodeGroup = graph.getGroup().find(i => i.cfg.id === '-node')获取到节点分组,将节点分组里你需要的元素(nodeGroup.cfg.children)移动到新分组,最后调用newGroup.toBack()置底新分组

// ...
graph.render()
const newGroup = graph.getGroup().addGroup({ id: 'newGroup', name: 'newGroup'})
const nodeGroup = graph.get('nodeGroup')
const cloneNodeGroup = cloneDeep(nodeGroup)
cloneNodeGroup.cfg.children.forEach((groupItem) => {
    if(groupItem.cfg.name === 'key') {
       newGroup.cfg.children.push(groupItem)
       nodeGroup.removeChild(groupItem)
    }
})
graph.get('comboGroup').set('zIndex', 0)
newGroup.set('zIndex', 1)
graph.get('edgeGroup').set('zIndex', 2)
nodeGroup.set('zIndex', 3)
graph.get('group').sort()
// ...

做了如下的验证,感觉好像通过 push 直接移到新创建的分组, 再操作排序。发现好像并没有搞定

你检查一下循环里push和remove操作的结果是否符合预期,我改了一下代码,是可以实现功能的。

 // ...
 graph.render()
 const newGroup = graph.getGroup().addGroup({ id: 'newGroup', name: 'newGroup' })
 const nodeGroup = graph.get('nodeGroup')
 for (let i = nodeGroup.cfg.children.length - 1; i >= 0; i--) {
   if (nodeGroup.cfg.children[i].cfg.item.getModel().type === 'site') {
     newGroup.cfg.children.push(nodeGroup.cfg.children[i])
     nodeGroup.cfg.children.splice(i, 1)
   }
 }
 graph.get('comboGroup').set('zIndex', 0)
 newGroup.set('zIndex', 1)
 graph.get('edgeGroup').set('zIndex', 2)
 nodeGroup.set('zIndex', 3)
 graph.get('group').sort()
 // ...

demo

from g6.

TabCrazy avatar TabCrazy commented on July 19, 2024

nodeGroup.cfg.children.splice(i, 1)

三克油 我再检查检查

from g6.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.