Skip to content
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

使用layout布局后,不会触发 added 事件 #4113

Open
byk04712 opened this issue Dec 21, 2023 · 3 comments
Open

使用layout布局后,不会触发 added 事件 #4113

byk04712 opened this issue Dec 21, 2023 · 3 comments

Comments

@byk04712
Copy link

byk04712 commented Dec 21, 2023

Describe the bug

使用 GridLayoutCircularLayout 或其他布局 进行布局后,没有触发 graph.on('node:added') 事件

import { Graph, Model } from '@antv/x6'
import { GridLayout } from '@antv/layout'

const data: Model.FromJSONData = {
  nodes: [],
}

for (let i = 1; i <= 16; i++) {
  data.nodes!.push({
    id: `${i}`,
    shape: 'rect',
    width: 20,
    height: 20,
    label: `${i}`,
    attrs: {
      body: {
        stroke: 'transparent',
        fill: '#5F95FF',
      },
      label: {
        fill: '#fff',
      },
    },
  })
}

const graph = new Graph({
  container: document.getElementById('container')!,
})

graph.on('node:added', (arg) => {
  console.log('node:added', arg)
})

// 使用 graph.addNode 会触发 node:added
// data.nodes.forEach(n => {
//   graph.addNode(n)
// })

// 使用 GridLayout 或 CircularLayout 等布局不会触发 node:added 事件
const circularLayout = new GridLayout({
  type: 'circular',
  center: [500, 500],
})
const model = circularLayout.layout(data)
graph.fromJSON(model, { silent: false })

根据文档查阅到 fromJSON,将 options.silent 设置为 false 也没有触发 added

Your Example Website or App

Steps to Reproduce the Bug or Issue

详情见描述

Expected behavior

不管通过哪种方式添加到 graph 上,都应该触发 added 事件吧

Screenshots or Videos

No response

Platform

  • OS: [ Windows,]
  • Browser: [Chrome]
  • Version: ["@antv/x6": "^2.16.1", "@antv/layout": "0.3.25 ]

Additional context

No response

@x6-bot
Copy link
Contributor

x6-bot bot commented Dec 21, 2023

👋 @byk04712

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.

@kingyue737
Copy link
Contributor

遇到了相同的问题,fromJSON无法进入 @antv/x6-plugin-history的栈中

@XueMeijing
Copy link
Contributor

这个issue #509 说fromJSON有问题
可以直接遍历 fromJSON 的data,然后调用 addCell 方法 添加到画布,就能触发事件了

const cells = graph.parseJSON(currentProcess);
cells.forEach((cell) => graph.addCell(cell));

但是我没想到两三年升到v2了还没解决

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants