antvis/G2
The issue has been closed
关于Shape children更新的问题 #2626
baweiji posted onGitHub
- G2 Version: 4.0.12
- Platform: Windows/Mac
- Mini Showcase(like screenshots):
参考帮助文档(https://g2.antv.vision/zh/examples/gallery/line#line8), 在写自己的一个多颜色段的line shape。发现如果数据更新时,往数据源里添加新的数据,效果就不对了,新添加的折线会空白显示。
以下是我的自己写shape
registerShape('line', 'split-line', {
draw(cfg, container) {
const path = [];
const lines = buildLines()
lines.map(line=>{
container.addShape('path',{
attrs:{
path: line.path,
stroke: line.color,
lineWidth: 2
}
}
})
return container;
}
});
看了下源代码,问题应该是在更新shape时,有关更新shape信息的相关代码syncShapeStyle
没有和最新的shape同步。
for (let i = 0; i < children.length; i++) {
this.syncShapeStyle(children[i], newChildren[i], state, animateCfg, index + i);
}
这里是根据原来shape的children在更新,如果newChildren里的数量大于原来children,那么最新的shape属性是更新不上去的。