[Gammaray-interest] Graph library

Christian Gagneraud chgans at gmail.com
Tue May 21 17:46:39 CEST 2019


Hi there,

I've been working on implementing a Qt/C++ wrapper library for
GraphViz's libcgraph/libgvc. Surprisingly, I couldn't find anything
re-usable and flexible.

Are you interested?

If so, then i would like to submit the first part: libcgraph.
These wrappers allows to create, manipulate and "walk" graphs. These
are value class that encapsulate underlying C pointers (and hide the
cgraph crazy/messy API). My value class based approach is IMHO very
efficient, but has few drawbacks. I'm happy to discuss and rework it.

Next stage would be the wrapper for the layout and the rendering, I've
already implemented the layout wrappers and a "hot-pluggable" render
plugin  that renders a layed out graph into a QGraphicsScene. It's
surprisingly very lightweight and was easy too. This is IMHO way
better than invoking "dot" from the command line to display an SVG.
This will allow to access the full layed out graph structure,
including clusters, sub-graph, etc...

After that, i would like to propose "attributes" handling, which i'm
still working on.
The attributes allows you to configure the layout algorithms (dot,
neato, ...)  and tweak a few geometric/visual things at
graph/node/edge level. So far, i've taken the path of wrapping the
whole graphviz string pairs attribute zoo [1] behind a carefully
selected and named sub-set implemented as enums/qvariant, I think the
pain was worth the effort.

Finally, there will be a need for export in dot/xdot files, and a
proper "GraphWidget" UI. I am confident with handling this too, see
eg. [2].

But then, ... We'll need some real usage within gammaray! :)

Chris

[1] https://www.graphviz.org/doc/info/attrs.html
[2] https://gitlab.com/chgans/le-ipc2581-viewer/raw/master/Screenshot_20170109_135029.png

PS: Demo time!
using namespace graphviz;
void test3()
{
    auto rootGraph = Graph("root", DirectedGraph);
    auto graph1 = rootGraph.addSubgraph("cluster_1");
    graph1.setLabel("Cluster#1");

    auto node1 = graph1.addNode("1 circle/solid");
    node1.setShape("circle");
    node1.setStyle("solid");
     ...
}
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    auto l = new Layout();
    auto w = new QMainWindow();
    w->showMaximized();
    auto s = new QGraphicsScene(w);
    auto r = new Render(s);
    auto v = new QGraphicsView();
    v->setScene(s);
    v->scale(1.0, -1.0); // Y down
    w->setCentralWidget(v);
    auto g = test3();
    l->render(r, g, HierarchicalLayout);
    return a.exec();
}

and the result: https://i.imgur.com/MInEFJX.png


More information about the Gammaray-interest mailing list