2017 © Pedro Peláez
 

library graphviz

Graphviz abstraction

image

innmind/graphviz

Graphviz abstraction

  • Monday, April 23, 2018
  • by Baptouuuu
  • Repository
  • 1 Watchers
  • 0 Stars
  • 462 Installations
  • PHP
  • 3 Dependents
  • 1 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 25 % Grown

The README.md

Graphviz

Build Status codecov Type Coverage, (*1)

Graphviz model to help build graphs. This model goal is to express the possibilities offered by Graphviz (though note that all features are not implemented)., (*2)

All objects of this package are immutable., (*3)

Important: you must use vimeo/psalm to make sure you use this library correctly., (*4)

Installation

composer require innmind/graphviz

Usage

use Innmind\Graphviz\{
    Layout\Dot,
    Graph,
    Node,
    Node\Shape,
};
use Innmind\Url\Url;
use Innmind\Colour\Colour;
use Innmind\OperatingSystem\Factory;
use Innmind\Server\Control\Server\Command;

$dot = Dot::of();
$clusterOne = Graph::directed('one')
    ->target(Url::of('http://example.com'))
    ->displayAs('One')
    ->fillWithColor(Colour::blue->toRGBA())
    ->add($one = Node::named('one'));
$clusterTwo = Graph::directed('two')
    ->fillWithColor(Colour::red->toRGBA())
    ->add($two = Node::named('two'));
$clusterThree = Graph::directed('three')
    ->add($three = Node::named('three'));

$root = Node::named('root')
    ->shaped(Shape::house())
    ->linkedTo($one->name())
    ->linkedTo($two->name());

$graph = Graph::directed()
    ->add($root)
    ->add($one->linkedTo($three->name()))
    ->add($two->linkedTo($three->name()))
    ->cluster($clusterOne)
    ->cluster($clusterTwo)
    ->cluster($clusterThree);

$output = $dot($graph);

Factory::build()
    ->control()
    ->processes()
    ->execute(
        Command::foreground('dot')
            ->withShortOption('Tsvg')
            ->withShortOption('o', 'graph.svg')
            ->withInput($output),
    )
    ->wait();

This example will produce the given svg file: (source), (*5)

, (*6)

The Versions