antvis / antvis/G6

[Bug]: 5.0.49版本点击事件回调没有被触发、框选节点控制台报错

Open
#7,264 2 comments 0 reactions 0 assignees View on GitHub
waiting for maintainer
Dominant language
TypeScript
Stars
12.3k
Forks
1.6k
PR merge metrics
No merged PRs in 30d

Description

### Describe the bug / 问题描述

测试代码如下:
```



G6 事件测试


#container {
width: 800px;
height: 600px;
border: 2px solid red;
margin: 20px;
}

G6 事件测试 (v5.0.48)



// 验证库加载
console.log("G6 版本:", G6.version);
console.log("Graph 类:", typeof G6.Graph);

// 创建简单数据
const data = {
nodes: [
{ id: 'node1', x: 100, y: 100 },
{ id: 'node2', x: 300, y: 100 }
],
edges: [
{ source: 'node1', target: 'node2' }
]
};

// 创建图实例
const graph = new G6.Graph({
container: 'container',
width: 800,
height: 600,
node: {
type: 'circle',
style: {
r: 30,
fill: '#9EC9FF',
stroke: '#5B8FF9',
lineWidth: 2
}
},
layout: { type: 'grid' },
behaviors: [{
key: 'brush-select',
type: 'brush-select',
enable: true,
animation: false,
immediately: true,
mode: 'default', // union intersect diff default
state: 'selected', // 'active', 'selected', 'inactive', ...
trigger: [], // ['Shift', 'Alt', 'Control', 'Drag', 'Meta', ...]
style: {},
onSelect: (states) => {
console.log(states)
}
}]
});

// 添加事件监听
graph.on('node:click', (e) => {
console.log('节点点击事件:', e.item.id);
alert(`点击了节点: ${e.item.id}`);
});

graph.on('canvas:click', (e) => {
console.log('画布点击事件');
alert('点击了画布空白处');
});

// 加载数据并渲染
graph.setData(data);
graph.render();

```

框选报错如下
g6.min.js:89 Uncaught (in promise) Error: [G6 v5.0.49] Unknown element type of id: undefined
at MU.getElementType (g6.min.js:89:27558)
at DU.getElementType (g6.min.js:89:59784)
at g6.min.js:89:69054
at Array.forEach ()
at DU. (g6.min.js:89:69023)
at Generator.next ()
at g6.min.js:1:33414
at new Promise ()
at ze (g6.min.js:1:33162)
at DU.setElementState (g6.min.js:89:68859)

### Reproduction link / 复现链接

_No response_

### Steps to Reproduce the Bug or Issue / 重现步骤

_No response_

### Version / 版本

Please select / 请选择

### OS / 操作系统

- [ ] macOS
- [ ] Windows
- [ ] Linux
- [x] Others / 其他

### Browser / 浏览器

- [x] Chrome
- [ ] Edge
- [ ] Firefox
- [ ] Safari (Limited support / 有限支持)
- [ ] IE (Nonsupport / 不支持)
- [ ] Others / 其他

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the issue with the provided CDN example using G6 5.0.49, focusing on graph.on callbacks and the brush-select behavior. Start from the reported g6.min.js stack at DU.setElementState and verify that node and canvas clicks fire while brush selection no longer produces the unknown element type error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
data-visualization, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.