The issue has been closed

posted by lovelyGFR almost 2 years ago 
用state管理不可以吗
后来才发现到。 但,想问如何可以拿到别的shape? 因为我要改的是background,不是keyshape . 这个是我随便试试的

posted by neolee6053 almost 2 years ago
posted by lovelyGFR almost 2 years ago 
用state管理不可以吗
后来才发现到。 但,想问如何可以拿到别的shape? 因为我要改的是background,不是keyshape . 这个是我随便试试的 
是不是可以直接在节点定义的时候就设置stateStyles,别的shape有自己的name直接用name当key值就可以吧 https://g6.antv.antgroup.com/manual/middle/states/state
啊,你是说这样? 试了,不可以
group.addShape("circle", {
attrs: {
x: 0,
y: 0,
r: size[0] / 2 + 2,
...(backgroundConfig as object),
stateStyles: {
selected: {
fill: "red",
stroke: "red"
}
}
},
name: "circle-shape"
});
posted by neolee6053 almost 2 years ago
posted by Yanyan-Wang almost 2 years ago 
posted by neolee6053 almost 2 years ago 
找到答案了
https://g6.antv.antgroup.com/manual/middle/elements/nodes/custom-node
G6.registerNode(
'custom',
{
// 响应状态变化
setState(name, value, item) {
const group = item.getContainer();
const shape = group.get('children')[0]; // 顺序根据 draw 时确定
if (name === 'selected') {
if (value) {
shape.attr('fill', 'red');
} else {
shape.attr('fill', 'white');
}
}
},
},
'rect',
);

posted by neolee6053 almost 2 years ago
posted by wSh-zm over 1 year ago