antvis/G6

Do you want to work on this issue?

You can request for a bounty in order to promote it!

[Bug]: v5 version Misalignment of connections between edges using custom node edge type: 'polyline' #6876

jisaz posted onGitHub

Describe the bug / 问题描述

import { DatabaseFilled } from '@ant-design/icons';
import { ExtensionCategory, Graph, register } from '@antv/g6';
import { ReactNode } from '@antv/g6-extension-react';
import { Badge, Flex, Input, Tag, Typography } from 'antd';
import { useEffect, useRef } from 'react';
import { createRoot } from 'react-dom/client';

const { Text } = Typography;

register(ExtensionCategory.NODE, 'react', ReactNode);

const Node = ({ data, onChange }) => {
  const { status, type } = data.data;

  return (
    <Flex
      style={{
        width: '100%',
        height: '100%',
        background: '#fff',
        padding: 10,
        borderRadius: 5,
        border: '1px solid gray',
      }}
      vertical
    >
      <Flex align="center" justify="space-between">
        <Text>
          <DatabaseFilled />
          Server
          <Tag>{type}</Tag>
        </Text>
        <Badge status={status} />
      </Flex>
      <Text type="secondary">{data.id}</Text>
      <Flex align="center">
        <Text style={{ flexShrink: 0 }}>
          <Text type="danger">*</Text>URL:
        </Text>
        <Input
          style={{ borderRadius: 0, borderBottom: '1px solid #d9d9d9' }}
          variant="borderless"
          value={data.data?.url}
          onChange={(event) => {
            const url = event.target.value;
            onChange?.(url);
          }}
        />
      </Flex>
    </Flex>
  );
};

export const ReactNodeDemo = () => {
  const containerRef = useRef();

  useEffect(() => {
    const graph = new Graph({
      container: containerRef.current,
      data: {
        nodes: [
          {
            id: 'local-server-1',
            data: { status: 'success', type: 'local', url: 'http://localhost:3000' },
            style: { x: 50, y: 50 },
          },
          {
            id: 'remote-server-1',
            data: { status: 'warning', type: 'remote' },
            style: { x: 350, y: 50 },
          },
        ],
        edges: [{ source: 'local-server-1', target: 'remote-server-1' }],
      },
      node: {
        type: 'react',
        style: {
          size: [240, 100],
          component: (data) => <Node data={data} />,
        },
      }, 
      edge: {
        type: 'polyline'
      },     
      layout: {
       type: 'antv-dagre',
        rankdir: 'LR',
        align: 'UL',
        controlPoints: true,
        nodesep: 50,
        ranksep: 50,
      },
      behaviors: ['drag-element', 'zoom-canvas', 'drag-canvas'],
    });

    graph.render();
  }, []);

  return <div style={{ width: '100%', height: '100%' }} ref={containerRef}></div>;
};

const root = createRoot(document.getElementById('container'));
root.render(<ReactNodeDemo />);

Image

No response

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

No response

Version / 版本

🆕 5.x

OS / 操作系统

  • macOS
  • Windows
  • Linux
  • Others / 其他

Browser / 浏览器

  • Chrome
  • Edge
  • Firefox
  • Safari (Limited support / 有限支持)
  • IE (Nonsupport / 不支持)
  • Others / 其他

感谢您提供详细的代码和描述。根据您描述的问题,您在使用 antvis/g6 v5 版本时遇到了自定义节点和 polyline 类型边之间的连接错位问题。

在查看您的代码后,以下是一些可能的解决方案和建议:

  1. 检查布局设置: 您使用了 antv-dagre 布局,并设置了 controlPoints: true。这意味着边的控制点会被自动计算。可以尝试将 controlPoints 设置为 false,看看是否能解决连接错位的问题。

  2. 边的样式设置: 确保边的样式设置正确,尤其是 polyline 类型的边,可能需要调整边的样式或控制点。

  3. 节点位置: 确保节点的位置设置正确,尤其是在使用自定义节点时,可能需要手动调整节点的位置以确保边的连接正确。

  4. 更新 G6 版本: 确保您使用的是最新的 G6 版本,因为新版本可能会修复一些已知的问题。

如果以上建议没有解决您的问题,您可以提供更多的细节或尝试创建一个最小可复现的示例,以便更好地帮助您解决问题。

如果您需要进一步的帮助,请随时告诉我。

<details> <summary>🪧 Tips</summary> For further assistance, please describe your question in the comments and @petercat-assistant to start a conversation with me. </details>

posted by petercat-assistant[bot] about 1 month ago

Fund this Issue

$0.00
Funded
Only logged in users can fund an issue

Pull requests