antvis/G6






The issue has been closed
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