Two fundamental graph visualizing ideas are implemented in this code.
https://www.sciencedirect.com/science/article/abs/pii/0020019089901026
An optimal euclidean distance between two nodes is calculated based on the corresponding graph distance. Then, an energy function based on the variance of node distances and the optimal distances is optimized with Newton's method.
We also implemented a simple clustering and unclustering algorithm, that allows Kamada-Kawai to be run on bigger graphs, but this is not currently used. Instead, we just use the ForceAtlas2 algorithm on big graphs.
Similar to https://github.com/visjs/vis-network
https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0098679
A force-based layout algortihm.
The forces are calculated with the fast multipole algorithm. Also includes an own quadtree implementation.
https://cpsc.yale.edu/sites/default/files/files/tr533.pdf
Layouts for components are computed separately. For smaller components we use Kamada-Kawai and for bigger components ForceAtlas2. Then we construct a new graph consisting of the components as vertices, and calculate a Kamada-Kawai layout on the result, to place the components.
To build and run the code, you can use your local g++ compiler or Docker's official gcc:13 image. To draw the calculated layout, you can use your local python3 interpreter or Docker's official python:3 image.
Examples are given for the sample graph sample/2011_05_19.gml.
To build the executable, run:
g++ -Ofast main.cpp forces.cpp quadtree.cpp layout.cpp block_visual.cpp cluster.cpp -o calc_layout.exeor on macOS with Homebrew's gcc@13:
/opt/homebrew/bin/g++-13 -Ofast main.cpp forces.cpp quadtree.cpp layout.cpp block_visual.cpp cluster.cpp -o calc_layout.exeor use Docker's official gcc:13 image to build the executable:
docker run -it --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp gcc:13 g++ -Ofast main.cpp forces.cpp quadtree.cpp layout.cpp block_visual.cpp cluster.cpp -o calc_layout.exeTo run the built executable, run
./calc_layout.exeon the command line to calculate a layout
or use Docker's official gcc:13 image to do so:
docker run -it --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp gcc:13 ./calc_layout.exeYou should see something like this:
Reading file sample/2011_05_19.gml.
Calculating fa2 layout for graph with 14867 vertices:
...
Ran through in: 33.7754 seconds...You should see a new file sample/2011_05_19_out.txt being created.
Adjust sample/visual_settings.txt to define the input and output files.
To draw the calculated layout, run
make -C sample reiniton the command line
- to build a Docker image with all necessary Python dependencies,
- to run the Docker image to draw the calculated layout.
Alternatively, execute sample/gen_img_from_lay.py directly.
You should see a new file sample/2011_05_19_pic.png being created.
Adjust sample/gen_img_from_lay.py to define the input and output files.