Giter Club home page Giter Club logo

nodesoup's Introduction

Graph untangling

Force-directed graph layout simulates forces to give motion to vertices and arrange them in a way that is visually pleasing and/or reveals structure. The Fruchterman-Reingold algorithm assigns a repelling force to vertices pair of the graph, effectively pushing apart vertices so they don't overlap, and a attraction force between each adjacent vertices pair, thus dragging closer connected vertices. The forces attenuate when the vertices get respectively further apart or closer, and a global temperature also serves as a simulated annealing, capping the maximum vertex displacement at each iteration. As the forces between each component and the temperature gradually diminish, the layout stabilizes.

Another method, the Kamada Kawai algorithm, relies on the simulation of springs between each vertex, which strength is determined by the length of the shortest path between both vertices. The potential energy of each vertex, ie the sum of the energy of all its springs, is then computed. The goal being to reduce the global energy of the layout, each vertex is moved step-by-step until its potential energy is considered low-enough, using a Newton-Raphson algorithm.

Implementation

This implementation of Fruchterman-Reingold starts by positioning all vertices on a circle as this appears to favor "unmangling" compared to random positions. The radius of the circle is alway 1.0, and all further computations are performed with floating point values, without knowledge of the canvas dimensions. In consequence, contrary to the original Fruchterman-Reingold algorithm, no bound checking is performed, and the layout can spread constraint-free. The final result is then scaled to fit into the canvas dimensions.

A Kamada-Kawai algorithm is also provided, mostly for comparison purpose. Its complexity makes it rather unsuitable for larger graphs.

Results

Click for full-scale image

K6 graph

Fruchterman-Reingold Kamada-Kawai Graphviz
x.xxs x.xxs x.xxs

DOT file from graphs.grevian.org

Small dense graph

Fruchterman-Reingold Kamada-Kawai Graphviz
x.xxs x.xxs x.xxs

DOT file from graphs.grevian.org

Binary tree

Fruchterman-Reingold Kamada-Kawai Graphviz
x.xxs x.xxs x.xxs

Quad tree

Fruchterman-Reingold Kamada-Kawai Graphviz
x.xxs x.xxs x.xxs

Large graph with disconnected components

Fruchterman-Reingold Graphviz
x.xxs x.xxs

GML file from gephi based on dataset by M. E. J. Newman

It might take some twiddling with the k parameter (a constant used to compute attractive and repulsive forces between vertices), as well as of the number of iterations, in order to get a layout perfectly free of edge-crossing. A better solution could be to introduce a "fine-tuning" phase during which we slightly raise again the temperature (and possibly the k value?) so as to shake the layout a bit before cooling it down again.

nodesoup's People

Contributors

globberwops avatar olvb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

nodesoup's Issues

Instructions on building the library

I am trying to build and install the library but I would require some more instructions on how to do that.

Can this be added to the README, please?

Citation

Hi,

I'd like to mention your repository on a paper.

Is there a name I can mention?
Is the official library name "nodesoup" or "NodeSoup"?

Thanks,

Not an issue. Feed a CSV instead

Hi there,

I am new here and wasn't sure how to reach out to you. I ported your code over to python (trying Fruchterman Reingold). Now I want to try the input based on a CSV (instead of dot file). If you don't mind, could you please give me some guidance on how to proceed? Thanks.

CSV input structure:
ID,FROM,TO
100,K,C
101,J,H
102,D,K
103,E,F
104,E,G
105,K,Z
106,D,J
107,C,X
108,B,I
109,H,C
110,I,E
111,K,B
112,J,K
113,I,C
114,H,K
115,E,A

Also what is the collection item here (g_[v_id])?

// line 40 of /src/fruchterman_reingold.cpp
// Attraction force between edges
        for (vertex_id_t adj_id : g_[v_id]) {
            if (adj_id > v_id) {
                continue;
            }

            Vector2D delta = positions[v_id] - positions[adj_id];
            double distance = delta.norm();
            double attraction = distance * distance / k_;

            mvmts_[v_id] -= delta / distance * attraction;
            mvmts_[adj_id] += delta / distance * attraction;
        }

You could send me the instruction in sample words or python or cpp, however it you feel comfortable and saves you time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.