Source

tw2.protovis.hierarchies / tw2 / protovis / hierarchies / samples.py

""" Samples of how to use tw2.protovis.hierarchies

Each class exposed in the widgets submodule has an accompanying Demo<class>
widget here with some parameters filled out.

The demos implemented here are what is displayed in the tw2.devtools
WidgetBrowser.
"""
from widgets import NodeLinkTree, CirclePackingWidget

from widgets import js
from tw2.core import JSSymbol

import math
import random
import os

tw2core_location = "/".join(
    __import__('tw2.core', fromlist=['core']).__file__.split('/')[:-1])

def build_tree(root=tw2core_location, depth=0):
    result = {}
    if depth > 3:
        return result
    tups = os.walk(root)
    d, dirs, files = [e for e in tups][0]
    for dir in dirs:
        result[dir] = build_tree("%s/%s" % (d, dir), depth=depth+1)
    for file in files:
        if file.endswith('.pyc') or file.endswith('.pyo'):
            continue
        result[file] = int(os.path.getsize("%s/%s" % (d, file))) + 1
    return result

class DemoNodeLinkTree(NodeLinkTree):
    p_height = 500
    p_width = 500
    p_orient = 'radial'
    p_breadth = 29 
    p_depth = 100
    def prepare(self):
        self.p_data = build_tree() # of tw2.core
        super(DemoNodeLinkTree, self).prepare()

class DemoCirclePackingWidget(CirclePackingWidget):
    p_height = 500
    p_width = 500
    p_data = build_tree() # Builds a tree of the filesizes of tw2.core
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.