-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from alexandresalome/comments
Comments
- Loading branch information
Showing
15 changed files
with
387 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
--- | ||
title: Add comments | ||
--- | ||
|
||
Adding comments | ||
=============== | ||
|
||
<p style="padding: .2rem .5rem; border: 1px solid #8888ff; background-color: #ddeeff; color: #0033aa; font-weight: bold;"> | ||
Available from the version 2.1 | ||
</p> | ||
|
||
Add comments into the graph | ||
--------------------------- | ||
|
||
### Single line comments | ||
|
||
You can add a comment inside your graph by using the method ``commentLine``: | ||
|
||
```php | ||
$graph = new Graphviz\Digraph(); | ||
$graph->commentLine('Empty graph'); | ||
echo $graph->render(); | ||
|
||
# digraph G { | ||
# // Empty graph | ||
# } | ||
``` | ||
|
||
Note that if you pass multiple lines to this method, it will add multiple lines: | ||
|
||
```php | ||
$graph = new Graphviz\Digraph(); | ||
$graph->commentLine("Line 1\nLine 2"); | ||
echo $graph->render(); | ||
|
||
# digraph G { | ||
# // Line 1 | ||
# // Line 2 | ||
# } | ||
``` | ||
|
||
You can also remove the initial space prefix by passing ``false`` as a second | ||
argument: | ||
|
||
```php | ||
$graph = new Graphviz\Digraph(); | ||
$graph->commentLine('-- ASCII MASTER --//', false); | ||
echo $graph->render(); | ||
|
||
# digraph G { | ||
# //-- ASCII MASTER --// | ||
# } | ||
``` | ||
|
||
And for C++ style arguments (``#`` instead of ``//``), pass ``true`` as a third | ||
argument: | ||
|
||
```php | ||
$graph = new Graphviz\Digraph(); | ||
$graph->commentLine('C++ style', true, false); | ||
echo $graph->render(); | ||
|
||
# digraph G { | ||
# # C++ style | ||
# } | ||
``` | ||
|
||
### Block comments | ||
|
||
You can add block comments by using the ``commentBlock`` function: | ||
|
||
```php | ||
$graph = new Graphviz\Digraph(); | ||
$graph->commentBlock('My block comment'); | ||
echo $graph->render(); | ||
|
||
# digraph G { | ||
# /* | ||
# * My block comment | ||
# */ | ||
# } | ||
``` | ||
|
||
Multiple lines is also supported: | ||
|
||
```php | ||
$graph = new Graphviz\Digraph(); | ||
$graph->commentBlock("My block comment\non multiple lines"); | ||
echo $graph->render(); | ||
|
||
# digraph G { | ||
# /* | ||
# * My block comment | ||
# * on multiple lines | ||
# */ | ||
# } | ||
``` | ||
|
||
|
||
|
||
You can disable new lines and spacing and new line indent by providing ``false`` | ||
as a second argument: | ||
|
||
```php | ||
$graph = new Graphviz\Digraph(); | ||
$graph->commentBlock("** ASCII fan\nNew line\n**", false); | ||
echo $graph->render(); | ||
|
||
# digraph G { | ||
# /*** ASCII fan | ||
# New line\n | ||
# ***/ | ||
# } | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
parameters: | ||
level: 6 | ||
level: 7 | ||
paths: | ||
- src | ||
- src_dev | ||
- tests | ||
bootstrapFiles: | ||
- vendor/autoload.php | ||
includes: | ||
- vendor/phpstan/phpstan-phpunit/extension.neon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/* | ||
* This file is part of PHP Graphviz. | ||
* (c) Alexandre Salomé <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Graphviz; | ||
|
||
/** | ||
* Comment. | ||
* | ||
* @author Alexandre Salomé <[email protected]> | ||
*/ | ||
class Comment implements InstructionInterface | ||
{ | ||
/** @var string Content of the comment */ | ||
protected string $content; | ||
|
||
/** @var bool Indent the comment on rendering */ | ||
protected bool $indented; | ||
|
||
/** | ||
* Creates a new comment. | ||
* | ||
* @param string $content Comment content, with delimiters | ||
* @param bool $indented Indicates if the content must be rendered indented | ||
*/ | ||
public function __construct(string $content, bool $indented = true) | ||
{ | ||
$this->content = $content; | ||
$this->indented = $indented; | ||
} | ||
|
||
public function getContent(): string | ||
{ | ||
return $this->content; | ||
} | ||
|
||
public function isIndented(): bool | ||
{ | ||
return $this->indented; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.