CodeFlower Source code visualization

This experiment visualizes source repositories using an interactive tree. Each disc represents a file, with a radius proportional to the number of lines of code (loc). All rendering is done client-side, in JavaScript. Try hovering on nodes to see the loc number, clicking on directory nodes to fold them, dragging nodes to rearrange the layout, and changing project to see different tree structures. Built with d3.js. Inspired by Code Swarm and Gource.

Purpose

CodeFlowers tries to answer these needs. Also, it tries to make code look beautiful, but that's another story.

Usage

To create a CodeFlower, include the CodeFlower.js file together with d3.js, just like in this page. Create a new CodeFlower instance using a CSS selector (of the div where the flower should be inserted), and the width and height of the desired visualization. Then, bind JSON data to the flower using CodeFlower.update(), and you're done.

var myFlower = new CodeFlower("#visualization", 300, 200);
myflower.update(jsonData);
        

Input data format

The jsonData format taken as input to update() is extremely simple. It's a JavaScript object representing a file tree structure. Each node must have a name (the file or directory name), leaf nodes must have a size (the number of lines of code or the file), and directory nodes must have a children property containing an array of nodes. As an example, here is the input for the currently displayed CodeFlower. You can modify it at will and click the update button to see the effect of your changes on the CodeFlower.

Generating JSON for a project

It's easy to generate loc metrics for any project, whatever the language. You can use wc, but this method requires cleaning the output and counts comments and blanks together with actual lines of code. Alternatively, you can use cloc (http://cloc.sourceforge.net/), which is open-source and makes the difference between real source code and comments. Here are three examples using GitHub as a source.

# Using curl and cloc (fast, accurate)
$ curl https://nodeload.github.com/symfony/symfony/tar.gz/master | tar xvz
$ cloc symfony-master --csv --by-file --report-file=symfony.cloc

# Using git clone and cloc (slow, accurate)
$ git clone git://github.com/symfony/symfony.git
$ cloc symfony --csv --by-file --report-file=symfony.cloc

# Using git clone and wc (slow, inaccurate)
$ git clone git://github.com/symfony/symfony.git
$ cd symfony
$ git ls-files | xargs wc -l > symfony.wc
        

Once you have a loc metrics file, paste its content below and click on the convert button. This will update the CodeFlower and the JSON textarea, to let you save data for your own CodeFlowers.

Sharing your CodeFlowers

The best way to share your CodeFlowers is to use GitHub Pages, just like this very page. So just fork the fzaninotto/CodeFlower repository, add your own JSON data under the data directory, update the options of the dropdown list in the index.html file accordingly, commit the code, and push to the gh-pages branch. GitHub will publish the result for you.

Licence

All this work is open-source, published by François Zaninotto under the MIT license. That means that nothing prevents you from growing as many CodeFlowers as you want!

Fork me on GitHub
Tip: If you like the CodeFlower, you may also like another visualization I made with d3.js called DependencyWheel.