antvis/G6

V5.0.0-beta.27 sourceAnchor 设置后不生效 #5209

America-first-melon posted onGitHub

问题描述

使用 v5 连线demo测试 sourceAnchor 与 targetAnchor 是否可以正常连接。

按文档所理解, sourceAnchor 为 输入数据 或 内部数据, 在 data 传入后, 并不是按照 anchorPoint 进行的连线

image

import { Graph, Extensions, extend } from '@antv/g6';

const data = {
  nodes: [

    {
      id: 'node2',
      data: {
        x: 550,
        y: 250,
      },
    },
    {
      id: 'node4',
      data: {
        x: 340,
        y: 130,
      },
    },
    {
      id: 'node5',
      data: {
        x: 100,
        y: 350,
      },
    },

    {
      id: 'enhanced-node',
      data: {
        x: 400,
        y: 130,
        preventPolylineEdgeOverlap: true,
        label: 'Enhanced Node',
      },
    },
    {
      id: 'normal-node',
      data: {
        x: 300,
        y: 300,
        label: 'Normal Node',
      },
    },
  ],
  edges: [
    {
      id: 'edge1',
      source: 'node4',
      target: 'node2',
      data: {
        color: 'red',
        label: 'test',
        sourceAnchor: 0,
        targetAnchor: 1
      },
    },
  ],
};

const container = document.getElementById('container');
const width = container.scrollWidth;
const height = container.scrollHeight || 500;

const ExtGraph = extend(Graph, {
  edges: {
    'polyline-edge': Extensions.PolylineEdge,
  },
});

const graph = new ExtGraph({
  container: 'container',
  width,
  height,
  modes: {
    default: ['zoom-canvas', 'drag-canvas', 'drag-node', 'click-select'],
  },
  plugins: [
    {
      // lod-controller will be automatically assigned to graph with `disableLod: false` to graph if it is not configured as following
      type: 'lod-controller',
      disableLod: true,
    },
  ],
  data,
  node: {
    type: 'rect-node',
    labelShape: {
      text: {
        fields: ['label'],
        formatter: (model) => model.data.label,
      },
      position: 'bottom',
      maxLines: 4,
    },
    anchorShapes: [
        {
          position: [0, 0.5],
        },
        {
          position: [0.5, 0],
        },
        {
          position: [0.5, 1],
        },
        {
          position: [1, 0.5],
        },
      ]
  },
  // edge: {
  //   type: 'polyline-edge',
  //   keyShape: {
  //     endArrow: true,
  //     routeCfg: {
  //       /**
  //        * 目前支持正交路由 'orth' 和地铁路由 'er'
  //        */
  //       // name: 'er',
  //       /**
  //        * 是否开启自动避障,默认为 false
  //        * Whether to enable automatic obstacle avoidance, default is false
  //        */
  //       enableObstacleAvoidance: true,
  //     },
  //     /**
  //      * 拐弯处的圆角弧度,默认为直角,值为 0
  //      * The radius of the corner rounding, defaults to a right angle
  //      */
  //     // radius: 20,
  //     /**
  //      * 拐弯处距离节点最小距离, 默认为 2
  //      * Minimum distance from the node at the corner, default is 5.
  //      */
  //     // offset: 0,
  //     /**
  //      * 控制点数组,不指定时根据 A* 算法自动生成折线。若指定了,则按照 controlPoints 指定的位置进行弯折
  //      * An array of control points that, when not specified, automatically generates the bends according to the A* algorithm. If specified, bends are made at the position specified by controlPoints.
  //      */
  //     // controlPoints: [],
  //   },
  // },
});

if (typeof window !== 'undefined')
  window.onresize = () => {
    if (!graph || graph.destroyed) return;
    if (!container || !container.scrollWidth || !container.scrollHeight) return;
    graph.setSize([container.scrollWidth, container.scrollHeight]);
  };

重现链接

https://g6-next.antv.antgroup.com/zh/examples/item/defaultEdges/#polyline3

平台

  • 操作系统: [macOS, Windows, Linux, React Native ...]
  • 网页浏览器: [Google Chrome, Safari, Firefox]
  • G6 版本: [5.0.0-beta.27 ]

Hi @America-first-melon, Please star this repo if you find it useful! Thanks :star:! 你好 @America-first-melon。如果该仓库对你有用,可以 star 一下,感谢你的 :star:!

posted by github-actions[bot] over 1 year ago

另外, combo 设置 anchorShapes 不生效, 不支持这个属性吗? image

另外,anchorPoints 好像也没什么用, image

posted by America-first-melon over 1 year ago

另外, combo 设置 anchorShapes 不生效, 不支持这个属性吗? image

beta.28也有相同的问题;另外anchorPoints和anchorShapes有啥区别啊

posted by zzjjbbaa about 1 year ago

刚试了一下(5.0.0-beta.28),要想让targetAnchor和sourceAnchor生效,需要同时设置node或combo的anchorShapesanchorPoints image

posted by zzjjbbaa about 1 year ago

刚试了一下(5.0.0-beta.28),要想让targetAnchor和sourceAnchor生效,需要同时设置node或combo的anchorShapesanchorPoints image

更新下,line类型的edge有效;polyline类型的edge的targetAnchor和sourceAnchor也无效

posted by zzjjbbaa about 1 year ago

等正式版吧

posted by America-first-melon about 1 year ago

正式版现在通过 sourcePort 和 targetPort 来指定连接到节点上的连接桩,其是一个字符串类型,对于节点上定一个 ports

posted by Aarebecca 11 months ago

Fund this Issue

$0.00
Funded

Pull requests