1. Ralph Bean
  2. tw2.protovis.hierarchies

Commits

Ralph Bean  committed 4f53e16

initial commit...

  • Participants
  • Parent commits c0da72e
  • Branches default

Comments (0)

Files changed (12)

File MANIFEST.in

View file
  • Ignore whitespace
+include README.rst
+recursive-include tw2/protovis/hierarchies/templates *
+recursive-include tw2/protovis/hierarchies/static *

File README.rst

View file
  • Ignore whitespace
+tw2.protovis.hierarchies
+===================
+
+:Author: Ralph Bean <ralph.bean@gmail.com>
+
+.. comment: split here
+
+.. _toscawidgets2 (tw2): http://toscawidgets.org/documentation/tw2.core/
+.. _protovis: http://vis.stanford.edu/protovis/
+
+tw2.protovis.hierarchies is a `toscawidgets2 (tw2)`_ wrapper for `protovis`_.
+
+Live Demo
+---------
+
+Peep the `live demonstration <http://craftsman.rc.rit.edu/module?module=tw2.protovis.hierarchies>`_.
+
+Links
+-----
+
+You can `get the source from github <http://github.com/ralphbean/tw2.protovis.hierarchies>`_,
+check out `the PyPI page <http://pypi.python.org/pypi/tw2.protovis.hierarchies>`_, and
+report or look into `bugs <http://github.com/ralphbean/tw2.protovis.hierarchies/issues/>`_.
+
+Description
+-----------
+
+`toscawidgets2 (tw2)`_ aims to be a practical and useful widgets framework
+that helps people build interactive websites with compelling features, faster
+and easier. Widgets are re-usable web components that can include a template,
+server-side code and JavaScripts/CSS resources. The library aims to be:
+flexible, reliable, documented, performant, and as simple as possible.
+
+`protovis`_ composes hierarchies views of data with simple marks such as bars and dots. Unlike low-level graphics libraries that quickly become tedious for visualization, Protovis defines marks through dynamic properties that encode data, allowing inheritance, scales and layouts to simplify construction.
+
+This module, tw2.protovis.hierarchies, provides `toscawidgets2 (tw2)`_ widgets that render `protovis`_ data visualizations.
+
+
+Sampling tw2.protovis.hierarchies in the WidgetBrowser
+-------------------------------------
+
+The best way to scope out ``tw2.protovis.hierarchies`` is to load its widgets in the 
+``tw2.devtools`` WidgetBrowser.  To see the source code that configures them,
+check out ``tw2.protovis.hierarchies/samples.py``
+
+To give it a try you'll need git, mercurial, python, and virtualenv.  Run:
+
+    ``git clone git://github.com/ralphbean/tw2.protovis.hierarchies.git``
+
+    ``cd tw2.protovis.hierarchies``
+
+The following script will set up all the necessary tw2 dependencies in a
+python virtualenv:
+
+    ``./develop-tw2-destroy-and-setup.sh``
+
+The following will enter the virtualenv and start up ``paster tw2.browser``:
+
+    ``./develop-tw2-start.sh``
+
+...and browse to http://localhost:8000/ to check it out.
+
+
+

File development-deps/develop-tw2-destroy-and-setup.sh

View file
  • Ignore whitespace
+#!/bin/bash -e
+
+devbase=development-deps
+venv=$devbase/virtualenv-tw2.jit
+$(
+    rm -rf $venv
+) || echo "Did not destroy $venv"
+
+virtualenv $venv --no-site-packages
+
+source $venv/bin/activate
+
+pip install genshi
+
+pushd $devbase
+hg clone http://bitbucket.org/paj/tw2core || echo "tw2core exists."
+hg clone http://bitbucket.org/paj/tw2devtools || echo "tw2devtools exists."
+git clone http://github.com/ralphbean/tw2.protovis.core.git || echo "tw2.protovis.core exists."
+pushd tw2core;hg pull;python setup.py develop;popd
+pushd tw2devtools;hg pull;python setup.py develop;popd
+pushd tw2.protovis.core;git pull;python setup.py develop;popd
+popd
+

File development-deps/develop-tw2-start.sh

View file
  • Ignore whitespace
+#!/bin/bash
+
+devbase=development-deps
+venv=$devbase/virtualenv-tw2.jit
+source $venv/bin/activate
+
+python setup.py develop && paster tw2.browser
+

File setup.py

View file
  • Ignore whitespace
+from setuptools import setup, find_packages
+
+f = open('README.rst')
+long_description = f.read().strip()
+long_description = long_description.split('split here', 1)[1]
+f.close()
+
+setup(
+    name='tw2.protovis.hierarchies',
+    version='0.1.a1',
+    description='toscawidgets2 wrapper for the stanford protovis toolkit',
+    long_description=long_description,
+    author='Ralph Bean',
+    author_email='ralph.bean@gmail.com',
+    url='',
+    install_requires=[
+        "tw2.core",
+        "tw2.protovis.core",
+        ],
+    packages=find_packages(exclude=['ez_setup']),
+    namespace_packages = ['tw2'],
+    zip_safe=False,
+    include_package_data=True,
+    entry_points="""
+        [tw2.widgets]
+        # Register your widgets so they can be listed in the WidgetBrowser
+        tw2.protovis.hierarchies = tw2.protovis.hierarchies
+    """,
+    keywords = [
+        'toscawidgets.widgets',
+    ],
+    classifiers = [
+        'Development Status :: 3 - Alpha',
+        'Environment :: Web Environment',
+        'Environment :: Web Environment :: ToscaWidgets',
+        'Topic :: Software Development :: Libraries :: Python Modules',
+        'Topic :: Software Development :: Widget Sets',
+        'Intended Audience :: Developers',
+        'Operating System :: OS Independent',
+        'Programming Language :: Python',
+        'Programming Language :: JavaScript',
+    ],
+)

File tests/__init__.py

  • Ignore whitespace
Empty file added.

File tests/test_widgets.py

View file
  • Ignore whitespace
+from webob import Request
+from webob.multidict import NestedMultiDict
+from tw2.core.testbase import assert_in_xml, assert_eq_xml, WidgetTest
+from nose.tools import raises
+from cStringIO import StringIO
+from tw2.core import EmptyField, IntValidator, ValidationError
+from cgi import FieldStorage
+import formencode
+
+import webob
+if hasattr(webob, 'NestedMultiDict'):
+    from webob import NestedMultiDict
+else:
+    from webob.multidict import NestedMultiDict
+
+import tw2.protovis.widgets as w
+
+# TODO -- test 'em all!

File tw2/__init__.py

View file
  • Ignore whitespace
+__import__('pkg_resources').declare_namespace(__name__)

File tw2/protovis/__init__.py

View file
  • Ignore whitespace
+__import__('pkg_resources').declare_namespace(__name__)

File tw2/protovis/hierarchies/__init__.py

View file
  • Ignore whitespace
+"""
+A bunch of cool widgets from protovis (under the 'custom' heading in their
+examples page).
+
+Get this source from http://github.com/ralphbean/tw2.protovis.custom
+
+Protovis itself can be found here:  http://vis.stanford.edu/protovis/
+"""
+
+from widgets import *

File tw2/protovis/hierarchies/samples.py

View file
  • Ignore whitespace
+""" 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
+
+from widgets import js
+from tw2.core import JSSymbol
+
+import math
+import random
+import os
+def build_tree(root, depth=0):
+    result = {}
+    if depth > 3 or 'development-deps' in root:
+        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:
+        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 = 25
+    p_depth = 60
+    def prepare(self):
+        self.p_data = build_tree('.')
+        super(DemoNodeLinkTree, self).prepare()
+

File tw2/protovis/hierarchies/widgets.py

View file
  • Ignore whitespace
+"""
+TODO
+"""
+
+import tw2.core as twc
+import tw2.protovis.core as twp
+from tw2.protovis.core import pv
+
+class js(twc.JSSymbol):
+    def __init__(self, src):
+        super(js, self).__init__(src=src)
+        
+class NodeLinkTree(twp.PVWidget):
+    p_orient = twc.Param('orientation parameter', default="radial")
+    p_breadth = twc.Param(default=10)
+    p_depth = twc.Param(default=10)
+
+    def prepare(self):
+        self.init_js = js('var data = %s;' % self.p_data)
+
+        self.setupRootPanel()
+
+        tree = self.add(pv.Layout.Tree)\
+            .nodes(js('pv.dom(data).root().nodes()'))\
+            .depth(self.p_depth)\
+            .breadth(self.p_breadth)\
+            .orient(self.p_orient)
+
+        tree.link.add(pv.Line)
+
+        tree.node.add(pv.Dot)\
+            .fillStyle(js('function(n) n.firstChild ? "#aec7e8" : "#ff7f0e"'))
+
+        tree.label.add(pv.Label)
+