Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No output #10

Closed
Sophivorus opened this issue May 12, 2015 · 5 comments
Closed

No output #10

Sophivorus opened this issue May 12, 2015 · 5 comments
Labels

Comments

@Sophivorus
Copy link

I installed the latest Graph and Graphviz using Composer in a server with CentOS 6.5 and PHP 5.4.13. I also installed dot using yum install graphviz, it's now available at /usr/bin/dot
I then created a test.php file with the quickstart code, or to be perfectly precise:

<?php

ini_set( 'display_errors', 1 );
error_reporting( E_ALL );

include 'vendor/autoload.php';

$graph = new Fhaculty\Graph\Graph();

$blue = $graph->createVertex('blue');
$blue->setAttribute('graphviz.color', 'blue');

$red = $graph->createVertex('red');
$red->setAttribute('graphviz.color', 'red');

$edge = $blue->createEdgeTo($red);
$edge->setAttribute('graphviz.color', 'grey');

$graphviz = new Graphp\GraphViz\GraphViz();
$graphviz->display($graph);

Then I opened the test.php file in my browser and nothing. No graph, no errors on the screen or log, just nothing. The path /usr/bin/dot is allowed by open_basedir and I tried the latest Chrome and Firefox. The lack of symptoms prevents me from diagnosing, but maybe someone here is more experienced. What can I be missing? Thanks!

@clue
Copy link
Member

clue commented May 13, 2015

@lfschenone Documentation is one of the areas that could use some improvements :)

The display() method can be used to launch an image viewer with the resulting graph image and as such only makes sense in CLI or desktop applications. If you're accessing this page through a browser, you would most likely want to output the image data, which can be accessed via createImageData().

@Sophivorus
Copy link
Author

Thanks clue, I'm on my way. For the curious, and in case you want to add it to the documentation, the minimal code to output a PNG image in the browser is:

<?php

include 'vendor/autoload.php';

$graph = new Fhaculty\Graph\Graph();

$blue = $graph->createVertex( 'blue' );
$blue->setAttribute( 'graphviz.color', 'blue' );

$red = $graph->createVertex( 'red' );
$red->setAttribute( 'graphviz.color', 'red' );

$edge = $blue->createEdgeTo( $red );
$edge->setAttribute( 'graphviz.color', 'grey' );

$graphviz = new Graphp\GraphViz\GraphViz();
$data = $graphviz->createImageData( $graph );
$image = imagecreatefromstring( $data );
header( 'Content-Type: image/png' );
imagepng( $image );
imagedestroy( $image );

@clue
Copy link
Member

clue commented May 14, 2015

Thanks for sharing your findings!

Afaict the following code should have the same effect (untested):

$graphviz->setFormat('png');

header('Content-Type: image/png');
echo $graphviz->createImageData($graph);

Either way, if you want to contribute to the documentation, PRs are very much appreciated! :)

@Sophivorus
Copy link
Author

Ok clue! I'm still getting started and having some difficulty to do basic things, but when I have some code going, I'll be happy to contribute with documentation. Cheers!

@clue
Copy link
Member

clue commented May 19, 2015

Awesome, keep me posted! :)

having some difficulty to do basic things

These are exactly the kind of things that should be covered in our documentation (eventually…) :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants