Friday, December 23, 2011

The Code Christmas Tree



The Code Christmas Tree is a technique used to visualize the quality of your code. It is based on a treemap which is an information visualization technique to display hierarchical or tree-structured data as a set of nested rectangles. Branches are represented by rectangles and sub branches are represented by smaller rectangles and so on. The leaf node’s rectangle has an area and color proportional to a specified dimension of data. In the case of the Code Christmas Tree these can be lines of code, cyclomatic complexity, and test code coverage. The different colors and sizes make it easy to see patterns that would be difficult to spot in other ways. Looking at the tree you can quickly identify which code areas are clean and which ones need more tests or major refactoring.



The chart examples shown here were generated by Michael Kaiser and Guy Royse using a utility that displays Big Visible Metrics (BVM). It takes XML metrics generated by Sonar and parses the data and converts it to CSV data that is then consumable using the Microsoft Treemapper and Excell Add-in to generate these colorful charts. The size of the rectangle represents lines of code. The color represents cyclomatic complexity or test coverage. The large red rectangles are the code targets that need to be refactored or need increased code coverage. BVM is on GitHub and you can find out more about it here.


Adapted from The Code Christmas Tree @Agile2011