Commits

Ralph Bean committed 6ff7d22

initial commit

Comments (0)

Files changed (13)

+build
+tw2.jit.egg-info
+*.pyc
+*.swp
+virtualenv-tw2.jit
+tw2core
+tw2devtools
+README.pdf
+dist
+*.egg
+*.egg*
+include README.rst
+recursive-include tw2/protovis/conventional/templates *
+recursive-include tw2/protovis/conventional/static *
+tw2.protovis.conventional
+=========================
+
+: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.conventional is a `toscawidgets2 (tw2)`_ wrapper for `protovis`_.
+
+Live Demo
+---------
+
+Peep the `live demonstration <http://craftsman.rc.rit.edu/module?module=tw2.protovis.conventional>`_.
+
+Links
+-----
+
+You can `get the source from github <http://github.com/ralphbean/tw2.protovis.conventional>`_,
+check out `the PyPI page <http://pypi.python.org/pypi/tw2.protovis.conventional>`_, and
+report or look into `bugs <http://github.com/ralphbean/tw2.protovis.conventional/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 custom 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.conventional, provides `toscawidgets2 (tw2)`_ widgets that render `protovis`_ data visualizations.
+
+
+Sampling tw2.protovis.conventional in the WidgetBrowser
+-------------------------------------
+
+The best way to scope out ``tw2.protovis.conventional`` is to load its widgets in the 
+``tw2.devtools`` WidgetBrowser.  To see the source code that configures them,
+check out ``tw2.protovis.conventional/samples.py``
+
+To give it a try you'll need git, mercurial, python, and virtualenv.  Run:
+
+    ``git clone git://github.com/ralphbean/tw2.protovis.conventional.git``
+
+    ``cd tw2.protovis.conventional``
+
+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.
+
+
+

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

+#!/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
+pushd $devbase
+hg clone http://bitbucket.org/paj/tw2core || echo "tw2core exists."
+hg clone http://bitbucket.org/paj/tw2devtools || echo "tw2devtools exists."
+pushd tw2core;hg pull;python setup.py develop;popd
+pushd tw2devtools;hg pull;python setup.py develop;popd
+popd
+

development-deps/develop-tw2-start.sh

+#!/bin/bash
+
+devbase=development-deps
+venv=$devbase/virtualenv-tw2.jit
+source $venv/bin/activate
+
+python setup.py develop && paster tw2.browser
+
+
+
+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.conventional',
+    version='0.1.a0',
+    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",
+        "genshi",
+        "mako",
+        ],
+    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.conventional = tw2.protovis.conventional
+    """,
+    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',
+    ],
+)

tests/__init__.py

Empty file added.

tests/test_widgets.py

+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!
+__import__('pkg_resources').declare_namespace(__name__)

tw2/protovis/__init__.py

+__import__('pkg_resources').declare_namespace(__name__)

tw2/protovis/conventional/__init__.py

+"""
+This package contains the basic core protovis resources to be
+used by the widgets packaged in the following:
+
+    - tw2.protovis.conventional
+    - tw2.protovis.custom
+    - tw2.protovis.interaction
+    - tw2.protovis.hierarchies
+    - tw2.protovis.networks
+    - tw2.protovis.maps
+    - tw2.protovis.stats
+    - tw2.protovis.art
+
+Get this source from http://github.com/ralphbean/tw2.protovis.core
+
+Protovis itself can be found here:  http://vis.stanford.edu/protovis/
+"""
+
+from widgets import *

tw2/protovis/conventional/samples.py

+""" Samples of how to use tw2.jit
+
+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 AreaChart
+from tw2.core import JSSymbol
+
+import math
+import random
+
+class DemoAreaChart(AreaChart):
+    py_data = [{'x': i, 'y' : math.sin(i) + random.random() * .5 + 2}
+                for i in map(lambda x : x / 10.0, range(100))]

tw2/protovis/conventional/widgets.py

+"""
+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 AreaChart(twp.PVPanel):
+    p_data = twc.Param('(list) data for the chart')
+    p_width = twc.Param('TODO', default=400)
+    p_height = twc.Param('TODO', default=200)
+    p_bottom = twc.Param('TODO', default=20)
+    p_top = twc.Param('TODO', default=5)
+    p_left = twc.Param('TODO', default=20)
+    p_right = twc.Param('TODO', default=10)
+    p_color = twc.Param('TODO', default='rgb(121,173,210)')
+
+    def prepare(self):
+        super(AreaChart, self).prepare()
+        self.init_js = twc.JSSymbol(
+            src="""
+            var data = %s,
+                w = %i,
+                h = %i,
+                x = pv.Scale.linear(data, function(d) d.x).range(0, w),
+                y = pv.Scale.linear(0, 5).range(0, h);
+            """ % (self.py_data, self.p_width, self.p_height))
+                          
+        self.init().width(self.p_width).height(self.p_height) \
+                .bottom(self.p_bottom).top(self.p_top) \
+                .left(self.p_left).right(self.p_right)
+
+        self.add(pv.Area) \
+                .data(self.py_data) \
+                .bottom(1) \
+                .left(js('function(d) x(d.x)')) \
+                .height(twc.JSSymbol(src='function(d) y(d.y)')) \
+                .fillStyle(self.p_color) \
+                .anchor('top').add(pv.Line).lineWidth(3)