antvis/G2


The issue has been closed
Morph 动画前需要判断节点是否存在 #6077
xiaoiver posted onGitHub
问题描述
使用自定义标注时报错:
<img width="663" alt="截屏2024-02-01 下午3 38 38" src="https://github.com/antvis/G2/assets/3608471/94667263-b327-48d6-9728-d25135e2af70">
原因是自定义图形在插入画布前 parentNode 是 null,执行如下代码就会报错:
// morphing.ts
function replaceChild(newChild: DisplayObject, oldChild: DisplayObject) {
// 这里需要判断 parentNode 是否存在
oldChild.parentNode.replaceChild(newChild, oldChild);
}
重现链接
ant-design-charts 复现链接:https://codesandbox.io/p/sandbox/admiring-wave-jx99yh?file=%2Fsrc%2FApp.js%3A87%2C23 关闭动画后正常。
但奇怪的是 G2 例子无法复现:https://codepen.io/xiaoiver/pen/gOEKpay
debug 了下 options 都是一致的: <img width="318" alt="截屏2024-02-05 上午11 11 14" src="https://github.com/antvis/G2/assets/3608471/e2558749-d386-4954-9348-d47a7b12451e">
重现步骤
No response
预期行为
No response
平台
- 操作系统: [macOS, Windows, Linux, React Native ...]
- 网页浏览器: [Google Chrome, Safari, Firefox]
屏幕截图或视频(可选)
No response
补充说明(可选)
No response