Created
February 26, 2014 14:09
-
-
Save asavin/9230056 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| buildTreeChart = (tags) -> | |
| tag-index = {} | |
| # Build tag index | |
| for tag in tags | |
| if tag-index[tag] | |
| tag-index[tag] += 1 | |
| else | |
| tag-index[tag] = 1 | |
| # Sort index | |
| sortable = [] | |
| for tag of tag-index | |
| sortable.push [tag, tag-index[tag]] | |
| sortable.sort (a, b) -> | |
| b[1] - a[1] | |
| tree-chart = [] | |
| limit = void | |
| if sortable.length > 10 | |
| limit = 9 | |
| else | |
| limit = sortable.length - 1 | |
| # Construct proper object for D3 tree chart | |
| for tag in sortable[0 to limit] | |
| tree-chart.push {name: tag[0], size: tag[1]} | |
| tree-chart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment