antvis/G6

The issue has been closed
自定义节点时,坐标系与原生节点坐标系不一致 #5300
Alessandro-Pang posted onGitHub
G6 版本
4.x
问题描述
自定义的节点坐标系与原生节点坐标系不一致。 同样的 x , y 渲染位置偏差很大
我也看了一下 #3922 这个问题,尝试使用 cfg.x - width / 2
使节点以中心点为起始坐标,但是并没有解决问题
G6.registerNode('my-node', {
draw(cfg, group) {
const [width = 420, height = 200] = cfg.size;
return group.addShape('rect', {
attrs: {
width: width,
height: height,
x: (cfg.x || 0) - width / 2,
y: (cfg.y || 0) - height / 2,
// x: (cfg.x || 0),
// y: (cfg.y || 0),
stroke: 'rgba(64,159,253,0.5)',
fill: 'rgba(64,159,253,0.04)',
},
draggable: false,
name: 'node-keyShape',
})
}
})
重现链接
重现步骤
进入页面即可看到实际渲染偏差
预期行为
预期自定义节点与原生节点渲染位置一致
平台
- 操作系统: [macOS, Windows, Linux, React Native ...]
- 网页浏览器: [Google Chrome, Safari, Firefox]
- G6 版本: [4.8.7]
屏幕截图或视频(可选)
No response
补充说明(可选)
No response