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

toJSON({ diff: true })没有达到预期效果 #4297

Open
Lmangoxx opened this issue May 10, 2024 · 4 comments
Open

toJSON({ diff: true })没有达到预期效果 #4297

Lmangoxx opened this issue May 10, 2024 · 4 comments

Comments

@Lmangoxx
Copy link

Lmangoxx commented May 10, 2024

Describe the bug

官方文档里diff功能说明:是否返回与默认值相比具有差异的那些数据。

画布初始化fromJSON数据后,修改node位置或者新增node后,执行toJSON({ diff: true })并没有返回差异数据,返回的是完整的画布数据,是我哪里使用的不对吗?还是有什么条件限制

Your Example Website or App

https://stackblitz.com/edit/vitejs-vite-fhnajx?file=src%2FApp.jsx

Steps to Reproduce the Bug or Issue

  1. 初始化graph并fromJSON默认数据
  2. 点击底部"新增node”按钮,或者修改画布中node位置
  3. 点击底部“查看差异”按钮,console.log(graph.toJSON({ diff: true })),返回的并不是差异数据,而是整个画布数据

Expected behavior

期望返回修改的差异数据

Screenshots or Videos

No response

Platform

  • OS: macOS
  • Browser: Chrome
  • Version: 124.0.6367.92

Additional context

No response

@x6-bot
Copy link
Contributor

x6-bot bot commented May 10, 2024

👋 @Lmangoxx

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.

@qiufeihong2018
Copy link
Contributor

qiufeihong2018 commented May 12, 2024

@Lmangoxx 是返回了剔除默认属性的数据,这句“是否返回与默认值相比具有差异的那些数据”这句话模棱两可
可以见代码

      if (key !== 'attrs' && key !== 'shape' && diff) {
        const preset = defaults[key]
        if (ObjectExt.isEqual(val, preset)) {
          delete props[key]
        }
      }

比如默认值
image

@qiufeihong2018
Copy link
Contributor

左边是graph?.toJSON({ diff: true })打印的数据吗,右边是graph?.toJSON()打印的数据,可以看到一些属性是被剔除了
image

@qiufeihong2018
Copy link
Contributor

qiufeihong2018 commented May 12, 2024

  1. 当前如果符合预期的话,更改文案,改成“是否返回与默认值相比具有差异的那些数据(还是会导出整个画布的数据)”
  2. 当前不符合预期,希望功能应该返回与默认状态相比有差异的数据

我觉得toJSON(...)这里想表达的是1吧,因为有说“将节点/边的结构化数据转换为 JSON 数据,以便做持久化存储(通常我们通过调用 graph.toJSON 来导出整个画布的数据)。”

qiufeihong2018 added a commit to qiufeihong2018/X6 that referenced this issue May 12, 2024
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