[Bug]: 仅启用drag-canvas禁用drag-element时,点击到node节点时无法触发drag-canvas行为 #7407
Replies: 3 comments 1 reply
-
|
@bertonwalker-cn 您好!以下是关于您问题的自动回复: 感谢您的反馈和详细描述! 问题分析在 G6 v5.x 中, 如果未启用 目前的行为是设计如此
解决建议
示例:自定义 drag-canvas 行为(简易版) import { Graph, registerBehavior } from '@antv/g6';
// 注册自定义行为
registerBehavior('custom-drag-canvas', {
getEvents() {
return {
'mousedown': 'onMouseDown',
'mousemove': 'onMouseMove',
'mouseup': 'onMouseUp',
};
},
onMouseDown(e) {
this.origin = { x: e.x, y: e.y };
this.dragging = true;
},
onMouseMove(e) {
if (this.dragging) {
const dx = e.x - this.origin.x;
const dy = e.y - this.origin.y;
this.graph.translate(dx, dy);
this.origin = { x: e.x, y: e.y };
}
},
onMouseUp() {
this.dragging = false;
}
});
// 使用自定义行为
const graph = new Graph({
// ... 其它配置
behaviors: [
{ type: 'custom-drag-canvas' }
],
});
总结如需进一步帮助或有其他需求,欢迎补充说明! 此回复由 AI 助手自动生成。如有任何问题,我们的团队会尽快跟进。 |
Beta Was this translation helpful? Give feedback.
-
配置到哪里? |
Beta Was this translation helpful? Give feedback.
-
|
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the bug / 问题描述
const graph = new G6.Graph({
container: 'container',
width: 800,
height: 600,
behaviors: [
{
type: 'drag-canvas',
enable: (event) => true, // 不管点在什么上,都允许拖动画布
},
],
});
Reproduction link / 复现链接
No response
Steps to Reproduce the Bug or Issue / 重现步骤
No response
Version / 版本
🆕 5.x
OS / 操作系统
Browser / 浏览器
Beta Was this translation helpful? Give feedback.
All reactions