dependency_tree icon indicating copy to clipboard operation
dependency_tree copied to clipboard

Generate a dependency tree visualization for Composer data

Composer dependency tree visualization

This is a simple PHP library that will take a standard composer.json file and composer.lock file and generate a dependency tree, using the D3JS visualization known as the collapsible tree.

Contents

  • Demonstration
  • Simple tree
  • Complex tree
  • Basic usage
  • Similar libraries
  • Drupal integration

Demo

Full demo at https://dependency.markfullmer.com

Simple tree

Screenshot of dependency tree

Complex tree

Screenshot of complex dependency tree

Basic usage

  1. Require this library to your PHP project:
composer require markfullmer/dependency_tree
  1. Ensure the library is autoloaded in your PHP file:
use markfullmer\DependencyTree;
  1. Copy or reference the d3.dependencyTree.js file from this library into your project and load it into a web page, along with the underlying D3JS API library.
<script src='https://d3js.org/d3.v4.min.js'></script>
<script src='./js/d3.dependencyTree.js'></script>
  1. Supply the contents of composer.json and composer.lock files as arguments and generate the tree. (Change the third parameter to TRUE to print version information.)
  $data = DependencyTree::generateTree($root, $lock, FALSE);
  1. Render the resulting data via Javascript, supplying the data and an HTML target ID.
  echo '
    <script>
      dependencyTree('. $data .');
    </script>
  ';

Similar libraries

  • https://github.com/fzaninotto/DependencyWheel : "This experiment visualizes package dependencies using an interactive disc. Each disc section represents a dependency, and links between arcs materialize these dependencies."

  • https://github.com/clue/graph-composer : "Graph visualization for your project's composer.json and its dependencies"

Drupal integration

A Drupal module that provides this functionality to sites directly is available at https://drupal.org/project/composer_dependency_tree