tags:

views:

115

answers:

1

Hi,

i'm trying to generate the following diagram using Image_GraphViz for PEAR. However It only shows a top-level node (with the text "0") and childnodes "1", "2", "3" and "4" directly under the top-node. Am I missing something?

This is the code:

    $gv = new Image_GraphViz(true);

    $gv->addEdge(array('1', '2'));
    $gv->addEdge(array('2', '3'));
    $gv->addEdge(array('2', '4'));
    $gv->addEdge(array('3', '5'));
    $gv->addEdge(array('3', '6'));
    $gv->addEdge(array('3', '7'));
    $gv->addEdge(array('4', '5'));

    echo $gv->fetch('svg');

I tried the following, but this is obviously wrong :).

    $gv->addEdge(array('1', '2'));
    $gv->addEdge(array('1', '2', '3'));
    $gv->addEdge(array('1', '2', '4'));
    $gv->addEdge(array('1', '2', '3', '5'));
    $gv->addEdge(array('1', '2', '3', '6'));
    $gv->addEdge(array('1', '2', '3', '7'));
    $gv->addEdge(array('1', '2', '4', '5'));

I understand there are two ways to get to 5. Through (1, 2, 3, 5) and/or (1, 2, 4, 5).

The image should just show two lines going to 5. I'm very confused, any suggestions?

+1  A: 

From the documentation it seems you need associative arrays. Can you try this instead?

$gv = new Image_GraphViz(true);

// Notice the use of =>
$gv->addEdge(array('1' => '2'));
$gv->addEdge(array('2' => '3'));
$gv->addEdge(array('2' => '4'));
$gv->addEdge(array('3' => '5'));
$gv->addEdge(array('3' => '6'));
$gv->addEdge(array('3' => '7'));
$gv->addEdge(array('4' => '5'));

echo $gv->fetch('svg');
JP
I already figured that out and got it working. Thanks for the answer though!
Ropstah