antvis/G6














The issue has been closed
对node节点设置label标签不生效 #5370
yym4531416 posted onGitHub
问题描述
项目很旧,G6版本也很旧,但是这个应该是基础功能,贴代码:
createG6PluginObjFun: function (data) {
// 第二步:注册图形
G6.registNode('rect', {
// 设置锚点
getAnchorPoints: function () {
return [
[1, 0.5], // 右边边的中点
[0, 0.5] // 左边边的中点
];
}
});
// 第三步:进行布局
var Layout = G6.Layout;
var margin = 10;
var height = 600 - margin;
var width = 200 - margin;
var nodes = data.nodes;
var edges = data.edges;
var layout = new Layout.Flow({
nodes: nodes,
edges: edges
});
nodes = layout.getNodes();
nodes.map(function (node) {
var x = node.x * width + margin;
var y = node.y * height + margin;
node.x = y;
node.y = x;
});
// 第四步:初始化图
var net = new G6.Net({
id: "dataMap", // 此处替换容器id
height: 300, // 此处替换高度
fitView: 'autoZoom', // 自动缩放
});
// 第五步:载入数据
net.source(nodes, edges);
// 第六步:数据映射
net.node()
.style(function (obj) {
var attrs = {};
attrs.fillOpacity = 0.9;
return attrs;
})
.label(function (obj) {
console.log('kuaichulai')
return {
text: obj.name,
fill: 'black',
fontSize: 12
};
}).tooltip("name");
net.tooltip(true);
net.edge()
.size(2)
.shape('smooth')
.style({
stroke: "black",
strokeOpacity: 0.6,
arrow: true
});
// 第八步:渲染关系图
net.render();
}
node下的.label(function (obj) { console.log('kuaichulai') return { text: obj.name, fill: 'black', fontSize: 12 }; 控制台没有任何反应,将这段代码放到net.edge()后面能正常执行并生成label
重现链接
no
重现步骤
不涉及
预期行为
能够正常的在node上生成label
平台
- 操作系统: [ Windows]
- 网页浏览器: [Google Chrome, Safari, Firefox]
- G6 版本: [1.1.6]
屏幕截图或视频(可选)
No response
补充说明(可选)
No response