Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Library to Generate xdot Files From dot Files

Apologies in advance is I'm misusing terminology, and corrections are appreciated. I'm fascinated by directed graphs, but I never has the math/cs background to know what they're really about, I just like the tech because it makes useful diagrams.

I'm trying to create a web application feature that will render a dynamic directed graph to the browser. I recently discovered Canviz, which is a cavas based xdot renderer, which I'd like to use.

Canviz is awesome, but it renders xdot files, which (appear?) to contain all the complicated positioning logic

/* example xdot file */
digraph abstract {
    graph [size="6,6"];
    node [label="\N"];
    graph [bb="0,0,1250,612",
        _draw_="c 9 -#ffffffff C 9 -#ffffffff P 4 0 -1 0 612 1251 612 1251 -1 ",
        xdotversion="1.2"];
    S1 [pos="464,594", width="0.75", height="0.5", _draw_="c 9 -#000000ff e 464 594 27 18 ", _ldraw_="F 14.000000 11 -Times-Roman c 9 -#000000ff T 464 588 0 15 2 -S1 "];
    10 [pos="409,522", width="0.75", height="0.5", _draw_="c 9 -#000000ff e 409 522 27 18 ", _ldraw_="F 14.000000 11 -Times-Roman c 9 -#000000ff T 409 516 0 15 2 -10 "];

    S1 -> 10 [pos="e,421.43,538.27 451.52,577.66 444.49,568.46 435.57,556.78 427.71,546.5", _draw_="c 9 -#000000ff B 4 452 578 444 568 436 557 428 546 ", _hdraw_="S 5 -solid c 9 -#000000ff C 9 -#000000ff P 3 430 544 421 538 425 548 "];
}

The files I'm generating with my application are dot files, which contain none of this positioning logic

digraph g {

    ranksep=6
    node [
        fontsize = "16"
        shape = "rectangle"
        width =3
        height =.5
    ];
    edge [
    ];

    S1 -> 10
}    

I'm looking for a PHP library that can convert my dot file into an xdot file that can be consumed by Canviz. I realize that the command line program dot can do this, but this is for a redistributable PHP web application, and I'd prefer to avoid any binaries as dependencies.

My core problem: I'm generating dot files based on simple directed relationships, and I want to display the visual graph to end users in a browser. I'd like to do this without having to rely on the presence of a particular binary program on the server. I think the best solution for this is Canviz+PHP to generate xdot files. I'm looking for a PHP library that can do this. However, I'm more than open to other solutions.

like image 731
Alan Storm Avatar asked Nov 14 '22 03:11

Alan Storm


1 Answers

Have you looked at Image_GraphViz ? It's really just a wrapper for the binary, but from the look of things, I don't think you'll find something better and this at least keeps you from having to do direct command line calls from your PHP script.

 $dot_obj = new Image_GraphViz();
 $dot_obj -> load('path/to/graph.gv');
 $xdot = $dot_obj -> fetch('xdot');
like image 183
Anthony Avatar answered Dec 19 '22 23:12

Anthony