Coder Social home page Coder Social logo

graph-composer's Introduction

clue/graph-composer

CI status downloads on GitHub installs on Packagist

Graph visualization for your project's composer.json and its dependencies:

dependency graph for clue/graph-composer

Table of contents

Usage

Once clue/graph-composer is installed, you can use it via command line like this.

graph-composer show

The show command creates a dependency graph for the given project path and opens the default desktop image viewer for you:

$ php graph-composer.phar show ~/path/to/your/project
  • It accepts an optional argument which is the path to your project directory or composer.json file (defaults to checking the current directory for a composer.json file).

  • You may optionally pass an --format=[svg/svgz/png/jpeg/...] option to set the image type (defaults to svg).

graph-composer export

The export command works very much like the show command, but instead of opening your default image viewer, it will write the resulting graph to STDOUT or into an image file:

$ php graph-composer.phar export ~/path/to/your/project
  • It accepts an optional argument which is the path to your project directory or composer.json file (defaults to checking the current directory for a composer.json file).

  • It accepts an additional optional argument which is the path to write the resulting image to. Its file extension also sets the image format (unless you also explicitly pass the --format option). Example call:

    $ php graph-composer.phar export ~/path/to/your/project export.png

    If this argument is not given, it defaults to writing to STDOUT, which may be useful for scripting purposes:

    $ php graph-composer.phar export ~/path/to/your/project | base64
  • You may optionally pass an --format=[svg/svgz/png/jpeg/...] option to set the image type (defaults to svg).

Install

You can grab a copy of clue/graph-composer in either of the following ways.

This project aims to run on any platform and thus does not require any PHP extensions and supports running on legacy PHP 5.3 through current PHP 8+. It's highly recommended to use the latest supported PHP version for this project.

The graph drawing feature is powered by the excellent GraphViz software. This means you'll have to install GraphViz (dot executable). The Graphviz homepage includes complete installation instructions for most common platforms, users of Debian/Ubuntu-based distributions may simply invoke:

$ sudo apt install graphviz

As a phar (recommended)

Once you have PHP and GraphViz installed, you can simply download a pre-packaged and ready-to-use version of this project as a Phar to any directory. You can simply download the latest graph-composer.phar file from our releases page. The latest release can always be downloaded like this:

$ curl -JOL https://clue.engineering/graph-composer-latest.phar

That's it already. Once downloaded, you can verify everything works by running this:

$ cd ~/Downloads
$ php graph-composer.phar --version

If you prefer a global (system-wide) installation without having to type the .phar extension each time, you may simply invoke:

$ chmod +x graph-composer.phar
$ sudo mv graph-composer.phar /usr/local/bin/graph-composer

You can verify everything works by running:

$ graph-composer --version

There's no separate update procedure, simply download the latest release again and overwrite the existing phar.

Installation using Composer

Alternatively, you can also install clue/graph-composer as part of your development dependencies. You will likely want to use the require-dev section to exclude clue/graph-composer in your production environment.

This method also requires PHP 5.3+, GraphViz and, of course, Composer.

You can either modify your composer.json manually or run the following command to include the latest tagged release:

$ composer require --dev clue/graph-composer

Now you should be able to invoke the following command in your project root:

$ ./vendor/bin/graph-composer show

Alternatively, you can install this globally for your user by running:

$ composer global require clue/graph-composer

Now, assuming you have ~/.composer/vendor/bin in your path, you can invoke the following command:

$ graph-composer show ~/path/to/your/project

Note: You should only invoke and rely on the main graph-composer bin file. Installing this project as a non-dev dependency in order to use its source code as a library is not supported.

To update to the latest release, just run composer update clue/graph-composer. If you installed it globally via composer you can run composer global update clue/graph-composer instead.

Development

clue/graph-composer is an open-source project and encourages everybody to participate in its development. You're interested in checking out how clue/graph-composer works under the hood and/or want to contribute to the development of clue/graph-composer? Then this section is for you!

The recommended way to install clue/graph-composer is to clone (or download) this repository and use Composer to download its dependencies. Therefore you'll need PHP, Composer, GraphViz, git and curl installed. For example, on a recent Ubuntu/debian system, simply run:

$ sudo apt install php7.2-cli git curl graphviz

$ git clone https://github.com/clue/graph-composer.git
$ cd graph-composer

$ curl -s https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer

$ composer install

You can now verify everything works by running clue/graph-composer like this:

$ php bin/graph-composer show

If you want to distribute clue/graph-composer as a single standalone release file, you may compile the project into a single graph-composer.phar file like this:

$ composer build

Note that compiling will temporarily install a copy of this project to the local build/ directory and install all non-development dependencies for distribution. This should only take a second or two if you've previously installed its dependencies already. The build script optionally accepts the version number (VERSION env) and an output file name or will otherwise try to look up the last release tag, such as graph-composer-1.0.0.phar.

You can now verify the resulting graph-composer.phar file works by running it like this:

$ ./graph-composer.phar --version

To update your development version to the latest version, just run this:

$ git pull
$ php composer.phar install

Made some changes to your local development version?

Make sure to let the world know! :shipit: We welcome PRs and would love to hear from you!

Happy hacking!

Tests

To run the test suite, you first need to clone this repo and then install all dependencies through Composer:

$ composer install

To run the test suite, go to the project root and run:

$ php vendor/bin/phpunit

License

This project is released under the permissive MIT license.

Did you know that I offer custom development services and issuing invoices for sponsorships of releases and for contributions? Contact me (@clue) for details.

graph-composer's People

Contributors

clue avatar elkuku avatar keradus avatar nubs avatar paulrotmann avatar simonfrings avatar xavismeh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

graph-composer's Issues

Add warning when GraphViz is not installed

Currently, generating a graph image just fails if GraphViz (dot executable) is not installed. Instead, we should check for the existence and fail gracefully with a concise, readable error message. On Debian-based systems, we could perhaps also offer to install it via sudo apt-get install graphviz.

add dockerfile/example to ease usage

I created the following dockerfile to test this project

FROM alpine:3.13

RUN apk add --no-cache curl

WORKDIR /app

RUN curl -o graph-composer -L https://clue.engineering/graph-composer-latest.phar && chmod +x graph-composer

FROM php:8.0-cli-alpine

COPY --from=0 /app/graph-composer /usr/local/bin/graph-composer

RUN sed -i '/edge/s/^#//' /etc/apk/repositories \
    && apk add --no-cache graphviz

WORKDIR /app

ENTRYPOINT ["/usr/local/bin/graph-composer"]

Would you be interested in connecting it to your project in any way ? It can of course be modified.

Release 1.0.0 is missing version

wget https://github.com/clue/graph-composer/releases/download/v1.0.0/graph-composer.phar
php graph-composer.phar --version

Output:

graph-composer version @git_tag@

Expected:

graph-composer version 1.0.0

show command requires xdg-open

the requirement is one issue .. but the fact it gives no information if the command is not available is the bigger issue.

What about left to right direction? (horizontal layout)

The default exported image is from up to down. So, when the dependence packages go large, the width of the image goes wide.
I think it would be better to make it left to right (Or you can do an option), at least as a tree, the depth wouldn't go so far. It is more convenience to scroll from up to down than scroll left to right...
( :) a lot of directions may not confuse you )

Add GraphML export for manual positioning

Actually exporting to GraphML should be implemented in graphp/graph#3.

This ticket serves both as a valid use case for its implementation and as a reminder to add the necessary glue code to take advantage of it within this project.

Unable to invoke "dot" to create image file (code 127)

I get this error:

Unable to invoke "dot" to create image file (code 127)

I have installed the graphviz, I have tried to reinstall it again, but I still get the same error.

Using Yii2, controller action:

public function actionGraph()
{
    $dir = Yii::getAlias('@app') . '/vendor';
    $graphComposer = new \Clue\GraphComposer\Graph\GraphComposer($dir);
    $graph = $graphComposer->createGraph();

    $graphviz = new \Graphp\GraphViz\GraphViz();
    $graphviz->setFormat('svg');
    $svg = $graphviz->createImageFile($graph);
    return $this->render('graph', ['svg' => $svg]);
}

and view:

<?php

/**
 * @var $this yii\web\View
 * @var $svg string
 */

var_dump($svg);
use yii\helpers\Html;

$this->title = 'Dependency Graph';
$this->params['breadcrumbs'][] = $this->title;

?>

<div class="site-dependency-graph">
    <h1><?= Html::encode($this->title) ?></h1><br />

    <div id="graph-placeholder">
        <!-- place here the svg file -->
        <?= $svg ?>
    </div>
</div>

composer install doesn't work

Ran this to install:

composer require --dev clue/graph-composer

Tried this but there is no vendor/bin folder even:
./vendor/bin/graph-composer show

Tried this but get error message:
./vendor/clue/graph-composer/bin/graph-composer show

sh: dot: command not found

  [Fhaculty\Graph\Exception\UnexpectedValueException]
  Unable to invoke "dot" to create image file (code 127)

Need to update installation directions to require dot even if installing via composer.
Also fix or update installation directions for the vendor/bin problem.

Add option to limit depth of the graph

Some projects have many dependencies and the graphs can get too large (#11). One option would be to add a --depth option in order to limit the depth of the resulting graph.

For example, the following could be used to display only direct dependencies (i.e. no sub-dependencies):

$ graph-composer show --depth=1

Special care may have to be taken with regards to loops/circles in the graph.

How to tweak the layout?

I just played around with your phar and created a graph of my project (phundament/app).

bildschirmfoto 2013-10-21 um 19 58 16

How could I stretch or expand the nodes so that the connections become more clearly visible?
Or adjust the layout so that the nodes are distributed more into a vertical direction.

PHP 8+ support

The following deprecation notices are generated when I run the latest release on PHP 8.1

php graph-composer-1.1.0.phar export ./
[12-Sep-2022 07:56:11 UTC] PHP Deprecated:  Return type of Symfony\Component\Console\Helper\HelperSet::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///mnt/files/local_mount/build/graph-composer-1.1.0.phar/vendor/symfony/console/Symfony/Component/Console/Helper/HelperSet.php on line 104

Deprecated: Return type of Symfony\Component\Console\Helper\HelperSet::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///mnt/files/local_mount/build/graph-composer-1.1.0.phar/vendor/symfony/console/Symfony/Component/Console/Helper/HelperSet.php on line 104
[12-Sep-2022 07:56:11 UTC] PHP Deprecated:  Return type of Fhaculty\Graph\Set\Vertices::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///mnt/files/local_mount/build/graph-composer-1.1.0.phar/vendor/clue/graph/src/Set/Vertices.php on line 414

Deprecated: Return type of Fhaculty\Graph\Set\Vertices::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///mnt/files/local_mount/build/graph-composer-1.1.0.phar/vendor/clue/graph/src/Set/Vertices.php on line 414
[12-Sep-2022 07:56:11 UTC] PHP Deprecated:  Return type of Fhaculty\Graph\Set\Vertices::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///mnt/files/local_mount/build/graph-composer-1.1.0.phar/vendor/clue/graph/src/Set/Vertices.php on line 451

Deprecated: Return type of Fhaculty\Graph\Set\Vertices::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///mnt/files/local_mount/build/graph-composer-1.1.0.phar/vendor/clue/graph/src/Set/Vertices.php on line 451
[12-Sep-2022 07:56:11 UTC] PHP Deprecated:  Return type of Fhaculty\Graph\Set\Edges::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///mnt/files/local_mount/build/graph-composer-1.1.0.phar/vendor/clue/graph/src/Set/Edges.php on line 386

Deprecated: Return type of Fhaculty\Graph\Set\Edges::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///mnt/files/local_mount/build/graph-composer-1.1.0.phar/vendor/clue/graph/src/Set/Edges.php on line 386
[12-Sep-2022 07:56:11 UTC] PHP Deprecated:  Return type of Fhaculty\Graph\Set\Edges::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///mnt/files/local_mount/build/graph-composer-1.1.0.phar/vendor/clue/graph/src/Set/Edges.php on line 412

Deprecated: Return type of Fhaculty\Graph\Set\Edges::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///mnt/files/local_mount/build/graph-composer-1.1.0.phar/vendor/clue/graph/src/Set/Edges.php on line 412

Compatibility with composer v2

Looks like composer build is not compatible with composer v2.

$ composer build

[1/1] Creating phar graph-composer-1.1.0-5-g25ea081.phar
  - Adding main package "clue/graph-composer"
  - Adding composer base files

Catchable fatal error: Argument 1 passed to Clue\PharComposer\Package\Package::__construct() must be of the type array, boolean given, called in /root/graph-composer/vendor/clue/phar-composer/src/Clue/PharComposer/Phar/PharComposer.php on line 136 and defined in /root/graph-composer/vendor/clue/phar-composer/src/Clue/PharComposer/Package/Package.php on line 21
Script @php build.php handling the build event returned with error code 255

Build still works fine however in composer v1 (now deprecated). I noticed this when attempting to containerize this (see https://github.com/patricknelson/graph-composer-docker).
Step to reproduce:

# Get graph-composer-docker repository and work from the 'composer-2' branch
git clone [email protected]:patricknelson/graph-composer-docker.git
cd graph-composer-docker
git checkout composer-2

# Tries to build container, but will fail
docker-compose up -d --build

Basically, what the Dockerfile does:

EDIT: You can see the diff in Dockerfile now in this PR: patricknelson/graph-composer-docker#1

Build/deploy graph-composer.phar automatically

The current steps to build and deploy a new graph-composer.phar are:

  1. Install project and dependencies as per README.md
  2. Install box.phar as per its readme
  3. Run php box.phar build to generate a new graph-composer-{version}.phar
  4. Upload the phar to any hosting service and get its URL
  5. Update README.md to reflect new download URL

Obviously, this should be automated. Possible solutions:

  • Perhaps using some external cloud service? I suppose we're not the first to run into this?
  • Perhaps using something like bintray to host the phar archives (could automatic steps 4 and 5)
  • Any suggestions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.