New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
请问如何导出或加载Graph的JSON数据? #57
Comments
渲染 JSON 数据 import { Graph } from '@antv/x6'
const container = document.getElementById('container')
const graph = new Graph(container)
graph.render({
nodes: [
{
id: 'node-0',
x: 60,
y: 60,
width: 80,
height: 30,
label: 'Hello',
},
{
id: 'node-1',
x: 240,
y: 240,
width: 80,
height: 30,
label: 'World',
},
],
edges: [
{
id: 'edge-0',
source: 'node-0',
target: 'node-1',
label: 'Edge Label',
},
],
}) 以上数据中的 id 由用户定义,在 x6 中,只会在渲染时用于搜索关联关系,其他时候不会使用到这个 id。 导出 JSON 数据需要自己处理,API 现在还不够简洁,可以先用下面的方式。 const parent = graph.getDefaultParent()
graph.model.filterDescendants(
cell => cell.getData() != null && graph.view.getState(cell) != null, // 过滤
parent,
)
.forEach(cell => {
// 这里可以拿到 cell 的相关数据
}) |
谢谢!之前这个方案试了一下,自己组合的确不太方便。请问直接导出graph data的API在roadmap中么? 我这里的使用场景是这样的,先通过x6来绘制基本图形得到graphData,一系列计算步骤后,增加其他结果数据到graphData中,然后再通过G6来渲染。 |
@loongmxbt 导出数据能力,我们还需要更多的思考,感觉这个 API 应该很不通用。 |
因为G6渲染是通过装载data实现的,所以如果先使用x6图编辑器绘制图形,再通过
|
嗯,我已经给自己开了 issue,导出数据的解构思考清楚了就会添加。 |
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
@bubkoo 请问如何拿到 edges 数据 此外是否有方便的方法能取到所有的edges?谢谢! |
This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread. |
Expected Behavior
原先gg-editor或G6项目中通过data定义nodes和edges的json数据,可以方便找到Data或导出json。
Current Behavior
目前通过 addNode 或 addEdge 添加元素后渲染,或是通过 graph.render(data)进行渲染。
如果绘图后这个data数据需要导出,请问在graph的哪个属性或函数里可以获取?
Possible Solution
Steps To Reproduce
Error Message & Stack Trace
Additional Context
Your Environment
The text was updated successfully, but these errors were encountered: