2.18.1版本X6,根据官网示例,layout布局不生效
问题描述
我在学习x6,根据官网示例,下载x6和布局插件,执行代码,报错layout不生效,我在在线编辑器上也复现了,因为内网问题无法上传代码,现提供在线编辑器的贴图。和本地的代码
重现链接
无
重现步骤
import { Graph } from '@antv/x6'; import data from './formateData'; import { DagreLayout } from '@antv/layout';
const initGraph = (dom: HTMLDivElement) => { const graph = new Graph({ container: dom, autoResize: true, background: { color: '#F2F7FA', }, panning: true, mousewheel: true, grid: { visible: true, type: 'doubleMesh', args: [ { color: '#eee', // 主网格线颜色 thickness: 1, // 主网格线宽度 }, { color: '#ddd', // 次网格线颜色 thickness: 1, // 次网格线宽度 factor: 4, // 主次网格线间隔 }, ], }, }); const dagreLayout = new DagreLayout({ type: 'dagre', rankdir: 'LR', align: 'UR', ranksep: 35, nodesep: 15, }) const model = dagreLayout.layout(data) graph.fromJSON(model); graph.centerContent(); };
export { initGraph }; type:'dagre'提示对象字面量只能指定已知属性,并且“type”不在类型“Partial”中 dagreLayout.layout(data)提示:类型“DagreLayout”上不存在属性“layout” 不管提示,直接运行,浏览器控制台报错,layout方法不存在
预期行为
指出错误
平台
-windows11 antv/x6 2.18.1 node:20.13.1
屏幕截图或视频(可选)
No response
补充说明(可选)
👋 @liguoyan
Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. To help make it easier for us to investigate your issue, please follow the contributing guidelines. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.
使用版本0.3.5 "@antv/layout": "^0.3.5",
我也遇到了同样的问题,我猜你和我一样安装了@lastest版本1.2.14-beta.9。
实际上,最新版本的antv/layout已经弃用了layout()方法,改用execute()方法执行布局,demo里的示例代码是这样写的:
const graph = new Graph(data);
const dagre = new DagreLayout({
nodeSize: 20,
nodesep: 50,
ranksep: 70,
rankdir: 'TB',
align: 'UR',
});
(async () => {
const positions = await dagre.execute(graph);
})();
不过,改为这种方法依旧会报错:
graph.getAllNodes is not a function
X6的Graph实例里并没有getAllNodes()这个方法(顺便一提G6也没有),getAllNodes()出自X6和G6共同的下游图基础库@antv/graphlib,奇怪的是X6删除了这个方法,导致在X6里无法调用execute()方法。
我的解决方法是降低antv/layout的版本,我目前使用的版本是0.3.25,这个版本可以使用layout()方法。
我也遇到了同样的问题,我猜你和我一样安装了
@lastest版本1.2.14-beta.9。 实际上,最新版本的antv/layout已经弃用了layout()方法,改用execute()方法执行布局,demo里的示例代码是这样写的:const graph = new Graph(data);
const dagre = new DagreLayout({ nodeSize: 20, nodesep: 50, ranksep: 70, rankdir: 'TB', align: 'UR', }); (async () => { const positions = await dagre.execute(graph); })();不过,改为这种方法依旧会报错:
graph.getAllNodes is not a function X6的Graph实例里并没有
getAllNodes()这个方法(顺便一提G6也没有),getAllNodes()出自X6和G6共同的下游图基础库@antv/graphlib,奇怪的是X6删除了这个方法,导致在X6里无法调用execute()方法。我的解决方法是降低antv/layout的版本,我目前使用的版本是
0.3.25,这个版本可以使用layout()方法。
谢谢说明~