Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Using addData for rendering, the result is a bit unclear every time #6658

Open
10 tasks
mxm-web-develop opened this issue Dec 20, 2024 · 1 comment
Open
10 tasks
Labels
bug Need Improvement Lack of information or incorrect format status: waiting for maintainer These issues have not yet been reviewed by a maintainer v5

Comments

@mxm-web-develop
Copy link

Describe the bug / 问题描述

屏幕截图 2024-12-20 154600

Reproduction link / 复现链接

No response

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

import {
Graph,
register,
ExtensionCategory,
AutoAdaptLabel,
DragCanvas,
ClickSelect,
ZoomCanvas,
DragElement,
} from '@antv/g6';
register(ExtensionCategory.BEHAVIOR, 'AutoAdaptLabel', AutoAdaptLabel);

const default_size = 48;
export const registerDefaultGraph = (
graph: Graph,
data: any,
data_type?: 'gitech_finance' | 'default'
) => {
if (!graph || !data) return;
const dataType = data_type || 'default';
const [width, height] = graph.getSize();
console.log(width, height, '11111111111');
const centerX = width / 2;
const centerY = height / 2;
// 先清空数据
graph.clear();
const processedNodes = data.nodes.map((node: any) => ({
...node,
size: default_size,
style: {
...node.style,
x: node?.x ?? centerX,
y: node?.y ?? centerY,
},
}));
// 设置默认布局
graph.setLayout({
type: 'force',
animation: false,
//animated: true, // 启用布局动画
// preventOverlap: true,
});
graph.addData({
nodes: processedNodes,
edges: data.edges,
});
// 设置行为
graph.setBehaviors((behaviors) => {
console.log(behaviors, '默认行为');
return [
...behaviors,
{ type: 'AutoAdaptLabel', enable: true },
{ type: 'zoom-canvas', enable: true },
{ type: 'drag-canvas', enable: true },
{ type: 'click-select', animation: true, multiple: true },
];
});
console.log(graph.getBehaviors(), '默认行为');
// 设置插件
graph.setPlugins((plugins) => {
console.log(plugins, '插件');
return [...plugins, { type: 'minimap' }];
});

// 添加数据前先打印检查
console.log('Processed Nodes:', data.nodes);
console.log('Processed Edges:', data.edges);

try {
graph.render();
setTimeout(() => {
// 确保图形完全布局后再进行视图调整
graph.fitCenter({
duration: 1530,
});
}, 2000);
graph.on('beforerender', function () {
console.log('-----------------------render开始-----------------', graph.getData());
});
graph.on('afterrender', function () {
console.log('-----------------------render用时-----------------', graph.getData());
});

let startTimeRender = 0;
graph.on('beforelayout', function () {
  startTimeRender = new Date().valueOf();
  console.log('-----------------------layout开始-----------------', graph.getData());
});
graph.on('afterlayout', function () {
  console.log(new Date().valueOf() - startTimeRender);
  console.log('-----------------------layout用时-----------------', graph.getData());
});

} catch (error) {
console.error('Graph update failed:', error);
console.error('Nodes:', data.nodes);
console.error('Edges:', data.edges);
throw error;
}
};

G6 Version / G6 版本

Please select / 请选择

OS / 操作系统

  • macOS
  • Windows
  • Linux
  • Others / 其他

Browser / 浏览器

  • Chrome
  • Edge
  • Firefox
  • Safari (Limited support / 有限支持)
  • IE (Nonsupport / 不支持)
  • Others / 其他
@mxm-web-develop mxm-web-develop added the status: waiting for maintainer These issues have not yet been reviewed by a maintainer label Dec 20, 2024
@github-actions github-actions bot changed the title [Bug]: 使用addData进行渲染,结果每次都有点出不来 [Bug]: Using addData for rendering, the result is a bit unclear every time Dec 20, 2024
@Aarebecca Aarebecca added bug v5 Need Improvement Lack of information or incorrect format labels Dec 20, 2024
Copy link

Please provide more information, or use the standard format, otherwise we will not process this issue.
Reference document:


请提供更多信息,或者使用规范的格式,否则我们不会处理这个 issue。
参考文档:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Need Improvement Lack of information or incorrect format status: waiting for maintainer These issues have not yet been reviewed by a maintainer v5
Projects
None yet
Development

No branches or pull requests

2 participants