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

增加 hideLables() API?addTools({ name: edge-editor 保存后如何隐藏这个文字? #3799

Open
hylerrix opened this issue Jul 24, 2023 · 2 comments
Labels
type: feature 新功能 Feature/enhancement requests

Comments

@hylerrix
Copy link
Contributor

功能描述

https://x6.antv.vision/en/examples/node/tool#editable 里创建的边上的文字如何隐藏?

例子中能看出来 edge-editor 编辑框是通过 addTools 函数增加的,一个绝对定位在 svg 画布外的编辑框。
因此 hideTools() 隐藏不了编辑框保存后生成的 labels 数组。

  • 问题:如何隐藏边上的文字 Labels?

目前能看到 Edge 上提供的 Lable 相关的函数只有如下:

appendLabel, getDefaultLabel, getLabelAt, getLabels, insertLabel, labels, onLabelsChanged, parseLabel, removeLabelAt, setLabelAt, setLabels

期望解决方案

新增 hideLables() API

@hylerrix hylerrix changed the title 增加 hideLables() API?addTools 增加的 edge-editor 如何隐藏? 增加 hideLables() API?addTools({ name: edge-editor 保存后如何隐藏这个文字? Jul 24, 2023
@cnyballk
Copy link
Contributor

这样hack怎么样?

    function hideLabels(edge: Edge) {
      const data = cloneDeep(edge.getLabels())
      data.forEach((label: any) => {
        label.attrs.label.hideBeforeFontSize = label.attrs.label.fontSize
        label.attrs.label.fontSize = 0
      })
      edge.setLabels(data, {
        overWrite: true,
      })
    }
    function showLabels(edge: Edge) {
      const data = cloneDeep(edge.getLabels())
      data.forEach((label: any) => {
        label.attrs.label.fontSize = label.attrs.label.hideBeforeFontSize
      })
      edge.setLabels(data, {
        overWrite: true,
      })
    }

@hylerrix
Copy link
Contributor Author

这样hack怎么样?

感谢,很有帮助。但目前我这边用这个方法隐藏后,合并边的多个线段场景下,每个线段都依然会意外保留一个不被隐藏 (就这个的 fontSize 打印的时候是和别的一样被变成 0 了,但是进入到 node_modules/@antv/x6/es/model/edge.js 中的 setLabels 后 labels 变量中每个线段都会有一个 fontSize 并没有赋值成功)。目前不知道是我自己的原因还是 x6 的什么原因,还需要继续排查。

CleanShot 2023-07-25 at 17 48 08

@NewByVector NewByVector added the type: feature 新功能 Feature/enhancement requests label Oct 11, 2023
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

3 participants