antvis/G6

linkCenter为false情况下,处理平行边时候,边两边会出现相交情况 #5298

helanya posted onGitHub

G6 版本

4.x

问题描述

linkCenter为false情况下,处理平行边时候,如果方向不一样的边两边会出现相交情况,因为其他需求,linkCenter 需要设置为false

重现链接

重现链接

重现步骤

官网例子 为例: 设置 linkCenter 为false,并创建两条边,两条边的方向一条像左,一条向右

import G6 from "@antv/g6";

const data = {
  nodes: [
    { id: "node1", x: 350, y: 200 },
    { id: "node2", x: 350, y: 250 },
    { id: "node3", x: 100, y: 200 },
  ],
  edges: [
    { id: "edge2", target: "node2", source: "node1", type: "quadratic" },
    { id: "edge1", target: "node1", source: "node2", type: "quadratic" },
  ],
};
const descriptionDiv = document.createElement("div");
descriptionDiv.innerHTML =
  "Drag from a source node to a target node to create a new edge. Note that in trigger: 'drag' mode cannot create a self-loop edge";
const container = document.getElementById("container");
container.appendChild(descriptionDiv);

const width = container.scrollWidth;
const height = (container.scrollHeight || 500) - 20;
const graph = new G6.Graph({
  container: "container",
  width,
  height,
  linkCenter: false,
  modes: {
    default: [
      {
        type: "create-edge",
        trigger: "drag", // 'click' by default. options: 'drag', 'click'
      },
    ],
  },
  defaultEdge: {
    style: {
      stroke: "#F6BD16",
      lineWidth: 2,
    },
  },
});

graph.data(data);
graph.render();

graph.on("aftercreateedge", (e) => {
  const edges = graph.save().edges;
  G6.Util.processParallelEdges(edges);
  graph.getEdges().forEach((edge, i) => {
    graph.updateItem(edge, {
      curveOffset: edges[i].curveOffset,
      curvePosition: edges[i].curvePosition,
    });
  });
});

if (typeof window !== "undefined")
  window.onresize = () => {
    if (!graph || graph.get("destroyed")) return;
    if (!container || !container.scrollWidth || !container.scrollHeight) return;
    graph.changeSize(container.scrollWidth, container.scrollHeight - 20);
  };

预期行为

处理平行边时是否能够控制边的两头端点在一个点

平台

  • 操作系统: [macOS]
  • 网页浏览器: [Google Chrome]
  • G6 版本: [4.8.23 ... ]

屏幕截图或视频(可选)

<img width="429" alt="image" src="https://github.com/antvis/G6/assets/20741045/eb61d685-d578-46ba-a25e-343fd1ef220b">

补充说明(可选)

No response


hi @helanya, welcome!

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

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

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

Hi @helanya, Please star this repo if you find it useful! Thanks :star:! 你好 @helanya。如果该仓库对你有用,可以在仓库右上角 star 一下,感谢你的 :star:!

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

通过重写 processParallelEdges 处理可以解决

posted by helanya over 1 year ago

通过重写 processParallelEdges 处理可以解决

请问是怎么重写or处理这个的,我也遇到了这个问题

posted by DIVADING about 1 year ago

通过重写 processParallelEdges 处理可以解决

请问是怎么重写or处理这个的,我也遇到了这个问题

我的大致思路是,先将不同方向的连线分个类排个序,然后再设置连线的 curveOffset; 比如: A、B 节点连线有5条: [a->b, b->a, a->b, a->b, b->a], 然后排个序:[a->b, a->b, a ->b, b->a, b->a],将相同方向连线放在一起,最后根据这个排序后的连线设置他的 curveOffset 即可。

posted by helanya about 1 year ago

Fund this Issue

$0.00
Funded

Pull requests