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,可否提供一个更好的方式实现 #4442

Open
Caaalabash opened this issue Sep 13, 2024 · 6 comments
Open

Comments

@Caaalabash
Copy link

功能描述

在参考了一众issue后,勉强可以实现自定义id了

#3011
#3002
#2789
#2634
#1547

改动了如下内容,粗看没问题,也算能用,但其实非常hack

复制的处理

  graph.bindKey(["meta+v", "ctrl+v"], () => {
    if (!graph.isClipboardEmpty()) {
      const cells = graph.paste({ offset: 32 });
      const newCells = cells.map((cell) => graph.updateCellId(cell, idGenerator[cell.shape]()));
      graph.cleanSelection();
      graph.select(newCells);
    }
    return false;
  });

dnd插件的处理

    new Dnd({
      getDragNode: (node) => node.clone({ keepId: true }),
      getDropNode: (node) => node.clone({ keepId: true }),
      ...
    });

边的处理

connecting: {
   createEdge() {
      return this.createEdge({ id: idGenerator.edge() });
    }
}

dnd拖拽的处理

    const startDrag = (target: any, e: any) => {
      const node = graph.value.createNode({
        id: idGenerator[target.shape](),
        shape: target.shape,
        width: target.width,
        height: target.height,
      });
      dnd.value.start(node, e);
    };

期望解决方案

提供一个配置项,在创建id前调用,例如

const id = props.id || DONT_KNOW_WHERE.genId(一些上下文信息,比如shape) || StringExt.uuid()
@x6-bot
Copy link
Contributor

x6-bot bot commented Sep 13, 2024

👋 @Caaalabash

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.

Caaalabash added a commit to Caaalabash/X6 that referenced this issue Sep 14, 2024
@zlecheng
Copy link

其实你可以不用自己处理id的问题,完全可以把节点自带的uuid传给后端,让后端帮你转成真实的id返回给你

@Caaalabash
Copy link
Author

其实你可以不用自己处理id的问题,完全可以把节点自带的uuid传给后端,让后端帮你转成真实的id返回给你

理论上都可以,保存前自己转换也可以,麻烦后端去转换也可以,创建了节点/边后再去修改id也可以

但是都麻烦、都不稳妥、都不是最佳做法,直接在创建id这一步能够自定义才最方便

@zlecheng
Copy link

zlecheng commented Sep 14, 2024 via email

@zlecheng
Copy link

zlecheng commented Sep 14, 2024 via email

@Caaalabash
Copy link
Author

不管麻不麻烦得先把功能搞出来再说

---- 回复的原邮件 ---- | 发件人 | @.> | | 发送日期 | 2024年09月14日 13:23 | | 收件人 | antvis/X6 @.> | | 抄送人 | zlecheng @.>, Comment @.> | | 主题 | Re: [antvis/X6] 关于自定义节点/边的id,可否提供一个更好的方式实现 (Issue #4442) | 其实你可以不用自己处理id的问题,完全可以把节点自带的uuid传给后端,让后端帮你转成真实的id返回给你 理论上都可以,保存前自己转换也可以,麻烦后端去转换也可以,创建了节点/边后再去修改id也可以 但是都麻烦、都不稳妥、都不是最佳做法,直接在创建id这一步能够自定义才最方便 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

嗯,全局唯一id不是难事,已经提了一个pr看看能不能合并,本地可以先用pnpm patch的方式改x6对应部分源码实现功能

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

2 participants