innmind / graphviz
Graphviz 抽象
3.4.0
2023-10-22 14:23 UTC
Requires
- php: ~8.2
- innmind/colour: ~4.0
- innmind/filesystem: ~7.0
- innmind/immutable: ~4.0|~5.0
- innmind/url: ~4.0
Requires (Dev)
- innmind/black-box: ~5.5
- innmind/coding-standard: ~2.0
- phpunit/phpunit: ~10.2
- vimeo/psalm: ~5.12
README
Graphviz 模型帮助构建图。此模型的目标是表达 Graphviz 提供的可能性(尽管请注意,并非所有功能都已实现)。
此包中的所有对象都是不可变的。
重要:您必须使用 vimeo/psalm
来确保正确使用此库。
安装
composer require innmind/graphviz
使用
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();
此示例将生成指定的 svg 文件:(源代码)