diff --git a/.gitignore b/.gitignore index 7e34aa12dc..1ebcadec42 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,4 @@ /file DOCUMENTATION/database/* -!DOCUMENTATION/database/diagram.pdf \ No newline at end of file +!DOCUMENTATION/database/database.pdf \ No newline at end of file diff --git a/DOCUMENTATION/database/database.pdf b/DOCUMENTATION/database/database.pdf new file mode 100644 index 0000000000..f92649aaa0 Binary files /dev/null and b/DOCUMENTATION/database/database.pdf differ diff --git a/DOCUMENTATION/database/diagram.pdf b/DOCUMENTATION/database/diagram.pdf deleted file mode 100644 index 2814d5ae11..0000000000 Binary files a/DOCUMENTATION/database/diagram.pdf and /dev/null differ diff --git a/bin/generate_entity_diagrams b/bin/generate_entity_diagrams index 3a85a06965..e22a772e83 100755 --- a/bin/generate_entity_diagrams +++ b/bin/generate_entity_diagrams @@ -11,30 +11,13 @@ use App\Util\HTML as H; use Functional as F; $template = ' -\documentclass{article} - -\paperheight=120cm -\paperwidth=100cm - -\usepackage[pdf]{graphviz} - -\title{GNU social database diagram} -\author{Hugo Sales} -\date{\today} - -\begin{document} - - \maketitle - - \neatograph{database}{ - node [shape=plaintext] +graph database { %tables% %edges% - } -\end{document} +} '; $files = glob(INSTALL_DIR . '/src/Entity/*.php'); @@ -76,11 +59,9 @@ foreach ($files as $file) { F\map($fields, $cell)), ]; - $tables[] = Common::indent("{$table} [label=<\n" . Common::indent(H::html($html)) . "\n>]"); + $tables[] = Common::indent("{$table} [shape=none, label=<\n" . Common::indent(H::html($html)) . "\n>]"); } -$outfile = INSTALL_DIR . '/DOCUMENTATION/database/diagram.tex'; - $replace = [ '/%tables%/' => Common::indent(implode("\n", $tables)), '/%edges%/' => Common::indent(implode("\n", $edges)), @@ -92,11 +73,11 @@ foreach ($replace as $from => $to) { $out = preg_replace($from, $to, $out); } -file_put_contents($outfile, $out); - $path = dirname(__DIR__) . '/DOCUMENTATION/database'; -system("cd {$path} && pdflatex diagram.tex > /dev/null"); +$outfile = $path . '/database.dot'; +file_put_contents($outfile, $out); + system("neato -Goverlap=false -Gsplines=true -Tpdf {$path}/database.dot -o {$path}/database.pdf"); echo "Generated database diagram. See {$path}/database.pdf\n"; diff --git a/src/Util/Common.php b/src/Util/Common.php index cb0408020e..2bbeac620a 100644 --- a/src/Util/Common.php +++ b/src/Util/Common.php @@ -131,4 +131,23 @@ abstract class Common { return implode('', F\map(preg_split('/[\b_]/', $str), self::arity('ucfirst', 1))); } + + /** + * Indent $in, a string or array, $level levels + * + * @param array|string $in + */ + public static function indent($in, int $level = 1, int $count = 2): string + { + if (is_string($in)) { + return self::indent(explode("\n", $in), $level, $count); + } elseif (is_array($in)) { + $indent = str_repeat(' ', $count * $level); + return implode("\n", F\map(F\select($in, + self::arity(function ($s) { return $s != ''; }, 1)), + function ($val) use ($indent) { + return F\concat($indent . $val); + })); + } + } }