File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed
Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -7,4 +7,9 @@ require_once __DIR__ . '/../vendor/autoload.php';
77$ dir = isset ($ argv [1 ]) ? $ argv [1 ] : '. ' ;
88
99$ graph = new Clue \GraphComposer ($ dir );
10- $ graph ->displayGraph ();
10+
11+ if (isset ($ argv [2 ])) {
12+ $ graph ->exportGraph ($ argv [2 ]);
13+ } else {
14+ $ graph ->displayGraph ();
15+ }
Original file line number Diff line number Diff line change @@ -87,4 +87,27 @@ public function displayGraph()
8787 $ graphviz ->setFormat ('svg ' );
8888 $ graphviz ->display ();
8989 }
90+
91+ public function exportGraph ($ target )
92+ {
93+ $ graph = $ this ->createGraph ();
94+
95+ if (is_dir ($ target )) {
96+ $ target = rtrim ($ target , '/ ' ) . '/graph-composer.svg ' ;
97+ }
98+
99+ $ filename = basename ($ target );
100+ $ format = 'svg ' ;
101+ $ pos = strrpos ($ filename , '. ' );
102+ if ($ pos !== false && isset ($ filename [$ pos + 1 ])) {
103+ // extension found and not empty
104+ $ format = substr ($ filename , $ pos + 1 );
105+ }
106+
107+ $ graphviz = new GraphViz ($ graph );
108+ $ graphviz ->setFormat ($ format );
109+ $ temp = $ graphviz ->createImageFile ();
110+
111+ rename ($ temp , $ target );
112+ }
90113}
You can’t perform that action at this time.
0 commit comments