-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Labels
waiting for maintainerTriage or intervention needed from a maintainer.Triage or intervention needed from a maintainer.
Description
Describe the bug / 问题描述
测试代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>G6 事件测试</title>
<script src="https://unpkg.com/@antv/[email protected]/dist/g6.min.js"></script>
<style>
#container {
width: 800px;
height: 600px;
border: 2px solid red;
margin: 20px;
}
</style>
</head>
<body>
<h1>G6 事件测试 (v5.0.48)</h1>
<div id="container"></div>
<script>
// 验证库加载
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();
</script>
</body>
</html>
框选报错如下
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
- Others / 其他
Browser / 浏览器
- Chrome
- Edge
- Firefox
- Safari (Limited support / 有限支持)
- IE (Nonsupport / 不支持)
- Others / 其他
Metadata
Metadata
Assignees
Labels
waiting for maintainerTriage or intervention needed from a maintainer.Triage or intervention needed from a maintainer.