Answer the question
In order to leave comments, you need to log in
Help develop an algorithm or what library to take to visualize a graph?
Hello. The task is to visualize the information:
There is a graph that is generated randomly - just information appears about the existence of the graph vertex and about who its parents are and who in relation to it is a child vertex. Directed Graph: Any vertex has 1 or more parent vertices other than the initial few. (There may be no children). That is, any newly appeared vertex has a connection with 1 or several old ones.
Task: represent this as a sequential growth of the graph horizontally down from several initial vertices (Initially, the vertices are not connected, but in the process of growth, the separated graphs are necessarily combined).
Its height should be represented in such a way that the child vertices in the visual representation should be below their immediate parent. This condition does not apply to those vertices that do not have a direct connection. That is, figuratively speaking, the grandfather's brother may be lower than the grandson of this very grandfather for the sake of visual presentation.
There is one more condition: at arbitrary times, a connection may appear between two randomly selected vertices. Let this be called event A. When such a connection appears, one of the vertices becomes a parent, and the other becomes a child. UPD (Link can only be oriented in such a way that there is no closed loop between the vertices)
The visibility condition is as follows: as the graph grows, visualize it so that it has a minimum number of intersections between links (does not look confused). And when event A occurs, redraw the visual representation of the graph in such a way that the newly arisen connection is not too long, and the graph again has a minimum number of intersections of connections, and the above condition that all child vertices must be drawn below their immediate parents continues to work .
Please tell me if there are libraries for solving similar problems in Python or javascript (I didn’t decide whether to implement vertex coordinate calculations in the client browser or on the backend, but it is preferable to calculate them in the browser).
Or a graph drawing algorithm, or at least articles and tutorials that cover similar tasks.
Thanks to
Answer the question
In order to leave comments, you need to log in
Standard solution for static graphs: https://www.graphviz.org/ perhaps you can take code or logic for dynamics from this library.
If you write yourself, you can start searching for logic from here: alenacpp.blogspot.com/2006/03/blog-post_23.html
In general, it should be enough to represent graph arcs in the form of springs, followed by physics emulation.
I also recommend googling about topological sorting.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question