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

复制粘贴插件——自定义粘贴节点id #3736

Closed
JackyChen02 opened this issue Jul 5, 2023 · 7 comments
Closed

复制粘贴插件——自定义粘贴节点id #3736

JackyChen02 opened this issue Jul 5, 2023 · 7 comments
Labels
type: feature 新功能 Feature/enhancement requests

Comments

@JackyChen02
Copy link
Contributor

JackyChen02 commented Jul 5, 2023

功能描述

场景中需要对节点的id进行定制,如节点id为 base_123 ,不包含 -
希望在粘贴节点的时候可以自定义节点id,从而进行分类或满足节点id要求,如粘贴的节点id为base_456

期望解决方案

graph.paste({
id: 'base_456'
offset: {
dx: 200,
dy: 0,
},
});

@x6-bot
Copy link
Contributor

x6-bot bot commented Jul 5, 2023

👋 @JackyChen02

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.

@NewByVector NewByVector added the type: feature 新功能 Feature/enhancement requests label Jul 10, 2023
@NewByVector
Copy link
Contributor

自定义粘贴节点会涉及到以下内容变更:

  1. 粘贴选项增加 resetCellId 方法
  2. 序列化 cells 后遍历,如果 id 发生变化,需要重新 clone 一份新的 cell
  3. 如果该 cell 是边的话,需要更新 cells 中起始节点和终止节点
  4. 如果该 cell 有 parent、children 在 cells 中,也需要将他们的相关属性重置

@ShirlyKong
Copy link

自定义粘贴节点会涉及到以下内容变更:

  1. 粘贴选项增加 resetCellId 方法
  2. 序列化 cells 后遍历,如果 id 发生变化,需要重新 clone 一份新的 cell
  3. 如果该 cell 是边的话,需要更新 cells 中起始节点和终止节点
  4. 如果该 cell 有 parent、children 在 cells 中,也需要将他们的相关属性重置

目前使用插件,复制选中内容(包括节点和边)后获取粘贴板中的元素没有边,但实际粘贴效果显示会出现边。粘贴时需要获取边,来更新节点连接关系,目前没有办法实现。

@NewByVector
Copy link
Contributor

@ShirlyKong 粘贴板中是可以获取到边的,如果没有获取的话,提供一个可以复现的 demo 看下。

@ShirlyKong
Copy link

@ShirlyKong 粘贴板中是可以获取到边的,如果没有获取的话,提供一个可以复现的 demo 看下。

感谢回答,已找到问题原因。 通过graph.getCellsInClipboard()获取元素确实包括了边,之前是直接通过graph.getSelectedCells()获取的待粘贴元素是不包含edge的,而且框选中也确实不会选中边即使设置了showEdgeSelectionBox: true。

@martSforever
Copy link

可以考虑这么搞,监听 node:added 事件,检测到新添加节点的时候检查这个节点的id,如果id的格式不是你要的(那就是x6自动生成的),那么就调用undo撤销这个复制的节点,复制这个节点数据并且设置id为你自己的id生成方式,然后graph.addNode添加你自己这个新的node数据

@JackyChen02
Copy link
Contributor Author

可以考虑这么搞,监听 node:added 事件,检测到新添加节点的时候检查这个节点的id,如果id的格式不是你要的(那就是x6自动生成的),那么就调用undo撤销这个复制的节点,复制这个节点数据并且设置id为你自己的id生成方式,然后graph.addNode添加你自己这个新的node数据

嗯嗯。也可以监听node:added后直接调用updateCellId去更新ID😋

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature 新功能 Feature/enhancement requests
Projects
None yet
Development

No branches or pull requests

4 participants