Comments (6)
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.
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() // ...
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.
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.
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.
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()
// ...
from g6.
nodeGroup.cfg.children.splice(i, 1)
三克油 我再检查检查
from g6.
Related Issues (20)
- 【v5】5.07版本 zoom-canvas behavior 配置 zoomRange 失效
- 在pad端不适应 HOT 1
- 自定义节点G6.registerNode,在draw函数中打印cfg.x和cfg.y,值是undefined HOT 1
- V5 版本官网中Combo 的流程图 拖拽Combo的时候出现虚影的线条 HOT 3
- 如何恢复被批量更新的自定义节点的样式 HOT 2
- 树图删除中间的某个节点并保留他的子节点 HOT 2
- 5.0版本动态添加元素边,拖拽和缩放画布之后边错位,如果在新增边也是错位的 HOT 1
- Custom React Node with zoom-canvas and drag-canvas displaces the node. HOT 4
- 树图TreeGraph首次render时先触发了afterrender事件 HOT 1
- [v5] Calling render while an existing render is happening causes force layout to flash HOT 1
- gForce 布局,没有设置 preset 依然显示 HOT 1
- Cannot read properties of undefined (reading 'Graph') HOT 2
- Method not implemented. 报错。 HOT 4
- [V5] label 使用padding并且折行的情况下,background宽度不能覆盖全部文字内容 HOT 1
- 【5.x】边选中有偏差 HOT 1
- 【V5】5.0.9 combo updateComboData 更新 icon/badge 等不生效
- cursor 状态不会自动变化
- dagre布局下的combo,如何设置固定宽度,高度由内容自动撑开,或者有api实现节点换行吗
- V5.0.9 自定义节点展开 收缩有问题 HOT 2
- 【V5】树布局中,节点高度不固定的情况下,getHeight按节点实际高度设置,会出现节点布局重叠问题
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from g6.