-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
如何禁止起始节点和终点之间的连接呢? #2353
Comments
Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. To help make it easier for us to investigate your issue, please follow the contributing guidelines. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can. |
见 Graph 配置 > const graph = new Graph({
connecting: {
allowLoop: false, // forbids self edges
}
}) |
我认为可以在你的起点和终端节点中将对应的code值,添加到自定义属性data中,然后在连线时拿到这个自定义的值做判断 |
我之前有这么想过,但是项目中是不被允许的,因为不确定哪个节点是起点,哪个节点是终点 |
这里猜测你想要这个图是一个无环图?也就说所有的 Edge 不能形成一个环路? 如果是的话,目前 X6 本身没有开箱即用的支持,但是可以通过为 Graph 配置中的 connecting 配置提供 这里有一个之前我使用过的用于这一目的的函数 (仅供参考,对时间/空间复杂度不作考虑) /**
* Check if the graph will have (or already has) a cycle if there
* had been an edge from source to target.
*
* @param graph The graph to check.
* @param source The originating node.
* @param target The node that is about to receive an incoming edge from source.
* @returns true if the resulting graph will have node, or false otherwise.
*/
export function willHaveCycle(graph: Graph, source: Node, target: Node): boolean {
const preorder: Set<Node> = new Set();
function dfs(origin: Node): boolean {
if (preorder.has(origin)) return true;
preorder.add(origin);
for (const incoming of graph.getIncomingEdges(origin) ?? []) {
const parent = incoming.getSourceNode();
if (!parent) continue;
if (dfs(parent)) return true;
}
preorder.delete(origin);
return false;
}
preorder.add(target);
return dfs(source);
} 也可以考虑 AntV 公共算法库 antvis/algorithm 的 关于环路检测的更多细节:https://www.geeksforgeeks.org/detect-cycle-in-a-graph/ https://www.baeldung.com/cs/detecting-cycles-in-directed-graph |
嗦嘎,原来是这样的,那可以看一下楼下tonywu6的逻辑 |
请问上面的回答有解决你的问题吗,为了高效沟通,我们暂时关闭这个 issue,如果有必要,请重新开一个新的 issue。 |
This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread. |
问题描述
我希望起点和终点不能相互连接,现在是可以连一条线
重现链接
0
重现步骤
0
预期行为
0
平台
0
屏幕截图或视频(可选)
No response
补充说明(可选)
No response
The text was updated successfully, but these errors were encountered: