Skip to content

Commit

Permalink
Add option to export graph into image file
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed May 15, 2013
1 parent 39cfb3f commit 3b7477f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
7 changes: 6 additions & 1 deletion bin/graph-composer
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ require_once __DIR__ . '/../vendor/autoload.php';
$dir = isset($argv[1]) ? $argv[1] : '.';

$graph = new Clue\GraphComposer($dir);
$graph->displayGraph();

if (isset($argv[2])) {
$graph->exportGraph($argv[2]);
} else {
$graph->displayGraph();
}
23 changes: 23 additions & 0 deletions src/Clue/GraphComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,27 @@ public function displayGraph()
$graphviz->setFormat('svg');
$graphviz->display();
}

public function exportGraph($target)
{
$graph = $this->createGraph();

if (is_dir($target)) {
$target = rtrim($target, '/') . '/graph-composer.svg';
}

$filename = basename($target);
$format = 'svg';
$pos = strrpos($filename, '.');
if ($pos !== false && isset($filename[$pos + 1])) {
// extension found and not empty
$format = substr($filename, $pos + 1);
}

$graphviz = new GraphViz($graph);
$graphviz->setFormat($format);
$temp = $graphviz->createImageFile();

rename($temp, $target);
}
}

0 comments on commit 3b7477f

Please sign in to comment.