示例#1
1
文件: Image.php 项目: graphp/graphviz
 public function __construct(GraphViz $graphviz = null)
 {
     if ($graphviz === null) {
         $graphviz = new GraphViz();
         $graphviz->setFormat('png');
     }
     $this->graphviz = $graphviz;
 }
示例#2
1
 /**
  * @return string
  */
 private static function getGroupLayoutScript()
 {
     $script = '';
     foreach (self::$groupLayout as $attr => $val) {
         $script .= self::EOL . $attr . '=' . parent::escape($val) . ';';
     }
     return $script;
 }
示例#3
1
require_once __DIR__ . '/vendor/autoload.php';
use Example\Order\Process\Postpayment;
use Example\Order\Process\Prepayment;
use Metabor\NamedCollection;
use Metabor\Statemachine\Graph\GraphBuilder;
use Fhaculty\Graph\Graph;
use Graphp\GraphViz\GraphViz;
try {
    $processes = new NamedCollection();
    $processes->add(new Prepayment());
    $processes->add(new Postpayment());
    if (isset($_GET['process'])) {
        $processName = strtolower($_GET['process']);
        if ($processes->has($processName)) {
            $process = $processes->get($processName);
        }
    }
    if (!isset($process)) {
        $processNames = $processes->getNames();
        $processName = reset($processNames);
        $process = $processes->get($processName);
    }
    $graph = new Graph();
    $builder = new GraphBuilder($graph);
    $builder->addStateCollection($process);
    $viz = new GraphViz();
    $viz->setFormat('svg');
    echo file_get_contents($viz->createImageFile($graph));
} catch (Exception $e) {
    echo $e->getMessage();
}
示例#4
1
 public function setFormat($format)
 {
     $this->graphviz->setFormat($format);
     return $this;
 }
示例#5
-1
    public function testEscaping()
    {
        $graph = new Graph();
        $graph->createVertex('a');
        $graph->createVertex('b¹²³ is; ok\\ay, "right"?');
        $graph->createVertex(3);
        $graph->createVertex(4)->setAttribute('graphviz.label', 'normal');
        $graph->createVertex(5)->setAttribute('graphviz.label', GraphViz::raw('<raw>'));
        $expected = <<<VIZ
graph G {
  "a"
  "b¹²³ is; ok\\\\ay, &quot;right&quot;?"
  3
  4 [label="normal"]
  5 [label=<raw>]
}

VIZ;
        $this->assertEquals($expected, $this->graphViz->createScript($graph));
    }