antvis/G6

自定义节点中部分img不显示问题 #5327

donghuizhou posted onGitHub

G6 版本

4.x

问题描述

如下图所示,自定义节点中放置了用户头像,但是在页面初始化时,部分节点的头像不显示,需要对画布做一些操作(如移动画布),头像才会显示 image image 自定义节点中添加img方法

G6.registerNode('xxxxx', {
    draw (cfg, group) {
        // .......
        let img = new Image()
        img.src = '后端返回的img地址'
        group.addShape('image', {
            attrs: {
                x:  xx,
                y:  xx,
                width: xx,
                height: xx,
                img
            }
        })
        // ......
    }
})

重现链接

如上所示

重现步骤

如上所示

预期行为

画布初始化时,所有自定节点的头像img能正常显示,无需用户对画布做操作

平台

  • 操作系统: [macOS, Windows, Linux, React Native ...]
  • 网页浏览器: [Google Chrome, Safari, Firefox]
  • G6 版本: [4.5.1 ... ]

屏幕截图或视频(可选)

No response

补充说明(可选)

No response


Hi @donghuizhou, Please star this repo if you find it useful! Thanks :star:! 你好 @donghuizhou。如果该仓库对你有用,可以 star 一下,感谢你的 :star:!

posted by github-actions[bot] over 1 year ago

可以尝试以下列方式设置图片 url,这两种理论上是一样的。官网案例中并没有出现你描述的首次加载无法显示的问题。如果仍然无法解决,请提供线上可复现 demo

G6.registerNode('xxxxx', {
    draw (cfg, group) {
        // .......
        group.addShape('image', {
            attrs: {
                x:  xx,
                y:  xx,
                width: xx,
                height: xx,
                img: 'url'
            }
        })
        // ......
    }
})
posted by Aarebecca over 1 year ago

可以尝试以下列方式设置图片 url,这两种理论上是一样的。官网案例中并没有出现你描述的首次加载无法显示的问题。如果仍然无法解决,请提供线上可复现 demo

G6.registerNode('xxxxx', {
    draw (cfg, group) {
        // .......
        group.addShape('image', {
            attrs: {
                x:  xx,
                y:  xx,
                width: xx,
                height: xx,
                img: 'url'
            }
        })
        // ......
    }
})

用这种方式报跨域,我们的图片地址是钉钉的地址 image

posted by donghuizhou about 1 year ago

This issue has been closed because it has been outdate for a long time. Please open a new issue if you still need help.

这个 issue 已经被关闭,因为 它已经过期很久了。 如果你仍然需要帮助,请创建一个新的 issue。

posted by github-actions[bot] 6 months ago

Fund this Issue

$0.00
Funded

Pull requests