Cookbook Draw App Logo
May 23, 2020 at 8:39 AMIn this example, we will learn how to personalize render, to draw the Application Logo.
use Bartlett\GraphUml;
use Bartlett\GraphPlantUml\PlantUmlGenerator;
use Graphp\Graph\Graph;
$generator = new PlantUmlGenerator();
$generator->setExecutable('vendor/bin/plantuml');
$graph = new Graph();
$builder = new GraphUml\ClassDiagramBuilder(
$generator,
$graph,
[
'label_format' => 'default',
]
);
$builder->createVertexClass(PlantUmlGenerator::class);
// personalize render
$graph->setAttribute($generator->getPrefix() . 'graph.bgcolor', 'transparent');
$graph->setAttribute($generator->getPrefix() . 'cluster.Bartlett\\GraphPlantUml.graph.bgcolor', 'LightSteelBlue');
$graph->setAttribute($generator->getPrefix() . 'cluster.Bartlett\\GraphUml\\Generator.graph.bgcolor', 'limegreen');
// show UML diagram statements
echo $generator->createScript($graph);
// default format is PNG
echo $generator->createImageFile($graph) . ' file generated' . PHP_EOL;
NOTE Usage of getPrefix() is not necessary here. We keep it, in case you’ll have custom generator rather than the default one.
- We specify a transparent background color with
graph.bgcolorattribute - We specify the background color of
Bartlett\GraphPlantUmlnamespace withcluster.Bartlett\\GraphPlantUml.graph.bgcolorattribute - We specify the background color of
Bartlett\GraphUml\Generatornamespace withcluster.Bartlett\\GraphUml.graph.bgcolorattribute
All colors are defined at https://plantuml.com/en/color
Namespace separator character is escaped in the attribute name, while cluster identify a subgraph