Commits

Ralph Bean committed 021f36f Merge

Merge branch 'release/2.0.0'

Comments (0)

Files changed (10)

 tw2.jit
 =======
 
-:Author: Ralph Bean <ralph.bean@gmail.com>
+:Author: Ralph Bean <rbean@redhat.com>
 
 .. figure:: tw2.jit/raw/master/doc/images/screenshot1.png
     :alt: An examle of the RadialGraph widget
-    :target: http://github.com/ralphbean/tw2.jit
+    :target: http://github.com/toscawidgets/tw2.jit
     :align: center
 
     A screenshot of the ``tw2.jit.widgets.RadialGraph`` widget in action.
 ---------
 
 Peep the `live demonstration <http://tw2-demos.threebean.org/module?module=tw2.jit>`_ and
-`screenshots <http://github.com/ralphbean/tw2.jit/raw/master/doc/images/screenshot1.png>`_.
+`screenshots <http://github.com/toscawidgets/tw2.jit/raw/master/doc/images/screenshot1.png>`_.
 
 Links
 -----
 
-You can `get the source from github <http://github.com/ralphbean/tw2.jit>`_,
+You can `get the source from github <http://github.com/toscawidgets/tw2.jit>`_,
 check out `the PyPI page <http://pypi.python.org/pypi/tw2.jit>`_, and
-report or look into `bugs <http://github.com/ralphbean/tw2.jit/issues/>`_.
+report or look into `bugs <http://github.com/toscawidgets/tw2.jit/issues/>`_.
 
 Description
 -----------
 
 This module, tw2.jit, provides `toscawidgets2 (tw2)`_ widgets that render `thejit`_ data visualizations.
 
-
 Sampling tw2.jit in the WidgetBrowser
 -------------------------------------
 
 The best way to scope out ``tw2.jit`` is to load its widgets in the
 ``tw2.devtools`` WidgetBrowser.  To see the source code that configures them,
-check out ``tw2/jit/samples.py``
+check out ``tw2.jit/tw2/jit/samples.py``
 
-To give it a try you'll need git, mercurial, python, and virtualenv.  Run::
+To give it a try you'll need git, python, and `virtualenvwrapper
+<http://pypi.python.org/pypi/virtualenvwrapper>`_.  Run::
 
-    $ git clone git://github.com/ralphbean/tw2.jit.git
+    $ git clone git://github.com/toscawidgets/tw2.jit.git
     $ cd tw2.jit
-
-Setup a virtualenv with all the necessary tw2 dependencies::
-
-    $ mkvirtualenv --no-site-packages tw2.jit
-    $ python setup.py develop
-    $ pip install tw2.devtools
-
-Start up the tw2 development server::
-
-    $ paster tw2.browser
+    $ mkvirtualenv tw2.jit
+    (tw2.jit) $ pip install tw2.devtools
+    (tw2.jit) $ python setup.py develop
+    (tw2.jit) $ paster tw2.browser
 
 ...and browse to http://localhost:8000/ to check it out.
-
-
-
 
 setup(
     name='tw2.jit',
-    version='0.3.06',
+    version='2.0.0',
     description='toscawidgets2 wrapper for the javascript infovis toolkit(jit)',
     long_description=long_description,
     author='Ralph Bean',
-    author_email='ralph.bean@gmail.com',
-    url='',
+    author_email='rbean@redhat.com',
+    url='http://github.com/toscawidgets/tw2.jit',
     install_requires=[
-        "tw2.core",
+        "tw2.core>=2.0.0",
         "tw2.jquery",
         "genshi",
         "mako",

tests/test_widgets.py

File contents unchanged.

tw2/jit/__init__.py

 """
 This package contains the basic jit widgets.
 
-Get this source from http://github.com/ralphbean/tw2.jit
+Get this source from http://github.com/toscawidgets/tw2.jit
 """
 
 #TODO -- this is *not* the right way to do this.
 jit_base = "static/Jit-2.0.1"
 
-from widgets import (AreaChart, BarChart, PieChart,
-                     TreeMap, ForceDirectedGraph, RadialGraph,
-                     Sunburst, Icicle, SpaceTree, HyperTree)
+from widgets import (
+    AreaChart,
+    BarChart,
+    PieChart,
+    TreeMap,
+    ForceDirectedGraph,
+    RadialGraph,
+    Sunburst,
+    Icicle,
+    SpaceTree,
+    HyperTree,
+)
 
 from widgets import AjaxRadialGraph
 

tw2/jit/resources.py

-""" Special tw2.jit resource types """
-
-import weakref
-import types
-
-import tw2.core as twc
-
-from tw2.core.resources import JSSource
-
-class CompoundJSSource(JSSource):
-    """ Takes multiple JSSource/JSFuncCall params and displays them
-    all within the same <script> tag and javascript scope.
-
-    Used by tw2.jit to separate the namespaces of different widgets on the
-    same page.  widget variable names (like ``var jitwidget``) can be shared
-    between different calls of a certain widget, but not come into conflict
-    with other widgets.
-    """
-
-    children = twc.Param('An iterable of twc.JSSource objects')
-    exec_delay = twc.Param('Value in milliseconds to delay execution',default=0)
-    src = None
-    location = 'bodybottom'
-
-    @classmethod
-    def post_define(cls):
-        """
-        1) Check children are valid
-        2) Disable their 'display' method
-        3) Update them to have a parent link.
-        """
-
-        cls._sub_compound = not getattr(cls, 'id', None)
-        if not hasattr(cls, 'children'):
-            return
-        joined_cld = []
-        for c in cls.children:
-            if not isinstance(c, type) or not issubclass(c, JSSource):
-                raise twc.ParameterError("Children must be JSSources")
-            # Override children's display method so they don't go
-            #  rendering on their own.  We want to aggregate their
-            #  sources into our own wrapped js call.
-            class DisabledJSSource(c):
-                def display(self, displays_on):
-                    return ''
-            joined_cld.append(DisabledJSSource(parent=cls))
-        ids = set()
-        for c in cls.children_deep():
-            if getattr(c, 'id', None):
-                if c.id in ids:
-                    raise twc.WidgetError("Duplicate id %s" % c.id)
-                ids.add(c.id)
-
-        cls.children = twc.widgets.WidgetBunch(joined_cld)
-
-    def __init__(self, **kw):
-        super(CompoundJSSource, self).__init__(**kw)
-        self.children = twc.widgets.WidgetBunch(
-            c.req(parent=weakref.proxy(self)) for c in self.children)
-
-    @classmethod
-    def children_deep(cls):
-        if getattr(cls, 'id', None):
-            yield cls
-        else:
-            for c in getattr(cls, 'children', []):
-                for cc in c.children_deep():
-                    yield cc
-
-    def prepare(self):
-        if not self.src:
-            for c in self.children:
-                c.prepare()
-            self.src = """
-            window.setTimeout(
-                (function(){
-                    %s
-                }), %i);""" % (
-                    ';\n'.join(c.src for c in self.children),
-                    self.exec_delay)
-        super(CompoundJSSource, self).prepare()
-

tw2/jit/samples/chart.py

File contents unchanged.

tw2/jit/samples/samples_data.py

          {
            "children": [],
            "data": {
-             "description": "$jit namespace and $jit() for append vis to Global\n    \n    Example:\n    \n    new $jit.Hypertree({\n      'injectInto': 'myvisContainer'\n    });",
+             "description": "",
              "$angularWidth": 7490,
              "days": 111,
              "$color": "#FCD9A1",
          {
            "children": [],
            "data": {
-             "description": "$jit namespace and $jit() for append vis to Global\n    \n    Example:\n    \n    new $jit.Hypertree({\n      'injectInto': 'myvisContainer'\n    });",
+             "description": "",
              "$angularWidth": 5838,
              "days": 111,
              "$color": "#FCD9A1",
          {
            "children": [],
            "data": {
-             "description": "(Re)-Implemented nodeTypes using node/edgeHelpers\n    \n    Code is cleaner and NodeTypes are now easier to implement.",
+             "description": "(Re)-Implemented nodeTypes",
              "$angularWidth": 6947,
              "days": 32,
              "$color": "#ECCFB3",
          {
            "children": [],
            "data": {
-             "description": "$jit namespace and $jit() for append vis to Global\n    \n    Example:\n    \n    new $jit.Hypertree({\n      'injectInto': 'myvisContainer'\n    });",
+             "description": "$jit namespace",
              "$angularWidth": 4064,
              "days": 111,
              "$color": "#FCD9A1",
          {
            "children": [],
            "data": {
-             "description": "$jit namespace and $jit() for append vis to Global\n    \n    Example:\n    \n    new $jit.Hypertree({\n      'injectInto': 'myvisContainer'\n    });",
+             "description": "$jit namespace",
              "$angularWidth": 4372,
              "days": 111,
              "$color": "#FCD9A1",
          {
            "children": [],
            "data": {
-             "description": "$jit namespace and $jit() for append vis to Global\n    \n    Example:\n    \n    new $jit.Hypertree({\n      'injectInto': 'myvisContainer'\n    });",
+             "description": "$jit namespace",
              "$angularWidth": 6696,
              "days": 111,
              "$color": "#FCD9A1",
          {
            "children": [],
            "data": {
-             "description": "Add label types in Label configuration object.\n    \n    Add calls to getLabelData in plotLabel.",
+             "description": "Add label types",
              "$angularWidth": 392,
              "days": 26,
              "$color": "#E0C7C0",
          {
            "children": [],
            "data": {
-             "description": "Added raw Canvas options + and animations\n    \n    Added the CanvasStyles object in Node/Edge properties to define raw\n    canvas properties before plotting a node or edge. For example\n    \n          Node: {\n            overridable: true,\n            dim: 4,\n            color: \"#fff\",\n            CanvasStyles: {\n              shadowBlur: 10,\n              shadowColor: '#ccc',\n              shadowOffsetY: 5,\n              shadowOffsetX: 5\n            }\n          }\n    \n    These properties can also be animated and accessed just like dataset\n    properties.\n    \n    Also there are new APIs for setting multiple properties at the same\n    time. setDataset and setCanvasStyles have been added and can be used\n    like this:\n    \n         node.setCanvasStyle('shadowBlur', 100, 'end');\n    \n         //will perform various node.setCanvasStyle\n         node.setCanvasStyles(['current', 'end'], {\n           'shadowBlur': [100, 5],\n           'shadowOffsetX': [200, 3]\n         });\n    \n         node.setData('width', 100, 'end');\n    \n         //will perform various node.setData\n         node.setDataset('end', {\n           'width': 100,\n           'color: '#ccc'\n         });\n    \n    For more information take a look at test1.js for the ForceDirected\n    visualization.",
+             "description": "Added raw Canvas options ",
              "$angularWidth": 1475,
              "days": 31,
              "$color": "#EACDB5",
          {
            "children": [],
            "data": {
-             "description": "$jit namespace and $jit() for append vis to Global\n    \n    Example:\n    \n    new $jit.Hypertree({\n      'injectInto': 'myvisContainer'\n    });",
+             "description": "$jit namespace",
              "$angularWidth": 749,
              "days": 111,
              "$color": "#FCD9A1",
          {
            "children": [],
            "data": {
-             "description": "Revisiting Extras.js Redesigning MouseEventManager and registered\n    classes to automatically use DOM elements via event delegation or canvas\n    based events.",
+             "description": "Revisiting Extras.js",
              "$angularWidth": 530,
              "days": 25,
              "$color": "#DEC6C2",
          {
            "children": [],
            "data": {
-             "description": "Add label types in Label configuration object.\n    \n    Add calls to getLabelData in plotLabel.",
+             "description": "Add label types",
              "$angularWidth": 203,
              "days": 26,
              "$color": "#E0C7C0",
          {
            "children": [],
            "data": {
-             "description": "* Ignore panning if Options.Navigation.panning = false\n     * Add 'avoid nodes' panning option for panning only when the cursor does not match a nodes position",
+             "description": "* Ignore panning",
              "$angularWidth": 137,
              "days": 1,
              "$color": "#AEA9F8",
          {
            "children": [],
            "data": {
-             "description": "Added raw Canvas options + and animations\n    \n    Added the CanvasStyles object in Node/Edge properties to define raw\n    canvas properties before plotting a node or edge. For example\n    \n          Node: {\n            overridable: true,\n            dim: 4,\n            color: \"#fff\",\n            CanvasStyles: {\n              shadowBlur: 10,\n              shadowColor: '#ccc',\n              shadowOffsetY: 5,\n              shadowOffsetX: 5\n            }\n          }\n    \n    These properties can also be animated and accessed just like dataset\n    properties.\n    \n    Also there are new APIs for setting multiple properties at the same\n    time. setDataset and setCanvasStyles have been added and can be used\n    like this:\n    \n         node.setCanvasStyle('shadowBlur', 100, 'end');\n    \n         //will perform various node.setCanvasStyle\n         node.setCanvasStyles(['current', 'end'], {\n           'shadowBlur': [100, 5],\n           'shadowOffsetX': [200, 3]\n         });\n    \n         node.setData('width', 100, 'end');\n    \n         //will perform various node.setData\n         node.setDataset('end', {\n           'width': 100,\n           'color: '#ccc'\n         });\n    \n    For more information take a look at test1.js for the ForceDirected\n    visualization.",
+             "description": "Added raw Canvas options",
              "$angularWidth": 2083,
              "days": 31,
              "$color": "#EACDB5",
          {
            "children": [],
            "data": {
-             "description": "Revisiting Extras.js Redesigning MouseEventManager and registered\n    classes to automatically use DOM elements via event delegation or canvas\n    based events.",
+             "description": "Revisiting Extras.js RedesigningMouseEventManager",
              "$angularWidth": 1120,
              "days": 25,
              "$color": "#DEC6C2",

tw2/jit/samples/sqla.py

File contents unchanged.

tw2/jit/samples/tree.py

 
     onCreateLabel = JSSymbol(src="""
     (function(domElement, node){
-       var labels = jitwidget.config.Label.type;
+       var labels = $$jitwidget.config.Label.type;
        var aw = node.getData('angularWidth');  
        if (labels === 'HTML' && (node._depth < 2 || aw > 2000)) {  
          domElement.innerHTML = node.name;  
      })""")
     onPlaceLabel = JSSymbol(src="""
         (function(domElement, node){  
-            var labels = jitwidget.config.Label.type;  
+            var labels = $$jitwidget.config.Label.type;  
             if (labels === 'SVG') {  
                 var fch = domElement.firstChild;  
                 var style = fch.style;  

tw2/jit/widgets/core.py

 """
 
 import tw2.core as twc
-from tw2.core.resources import JSLink, CSSLink
-from tw2.core.resources import JSSymbol, JSFuncCall
-from tw2.core.resources import JSSource
-from tw2.core.resources import encoder
+
+from tw2.core import js_callback, js_function, js_symbol
+
 from tw2.core.widgets import WidgetMeta
 from tw2.core.widgets import Widget
 
 from tw2.jit import jit_base
-from tw2.jit.resources import CompoundJSSource
 
 import tw2.jquery
 
 modname = "tw2.jit"
 
 # TODO -- what's the right way to choose minified or not in tw2?
-jit_yc_js = JSLink(modname=modname, filename="%s/jit-yc.js" % jit_base)
-jit_js = JSLink(modname=modname, filename="%s/jit.js" % jit_base)
-jit_glue_js = JSLink(modname=modname, filename="static/js/tw2.jit.glue.js")
-jit_css = CSSLink(modname=modname, filename="static/css/jit_base.css")
+jit_yc_js = twc.JSLink(modname=modname, filename="%s/jit-yc.js" % jit_base)
+jit_js = twc.JSLink(modname=modname, filename="%s/jit.js" % jit_base)
+jit_glue_js = twc.JSLink(modname=modname, filename="static/js/tw2.jit.glue.js")
+jit_css = twc.CSSLink(modname=modname, filename="static/css/jit_base.css")
 
 # TODO -- redo all of these with mako so we have examples of that and genshi
 class JitWidget(twc.Widget):
     """ Baseclass for all other tw2.jit.widgets
 
     Provides a set of parameters common to widgets in the library.
-
-    Uses tw2.jit.resources.CompoundJSSource for client-side initialization
     """
 
     # Hide docs from the widget browser.  They're very verbose.
 
     postInitJSCallback = twc.Param(
         'javascript to run after client-side initialization of the widget',
-        default=JSSymbol(src='(function(jitwidget){})'), attribute=True)
+        default=js_callback("(function(node) {})"), attribute=True)
 
     data = twc.Param('python data to be jsonified and passed to the widget',
                     default=None, attribute=True)
         All the possible transitions are listed here:
             http://thejit.org/static/v20/Docs/files/Options/Options-Fx-js.html#Options.Fx
         """,
-        default=JSSymbol(src="$jit.Trans.Quart.easeOut"), attribute=True)
+        default=js_callback("$jit.Trans.Quart.easeOut"), attribute=True)
 
     duration = twc.Param(
         '(number) Duration of the animation in milliseconds.',
             '$$jitwidget': lambda s:'window._jitwidgets["%s"]' % s.compound_id,
             '$$deep_linking': lambda s: s.deep_linking,
             '$$duration': lambda s: s.duration,
-            '$$transition': lambda s: s.transition.src,
+            '$$transition': lambda s: str(s.transition),
         }
     )
     # End twc attrs
             raise ValueError, msg
 
         if not self.data and not self.base_url:
-            msg = "%s requires 'data' or 'base_url' param." % self.__class__.__name__
+            msg = "%s requires 'data' or 'base_url' param." % \
+                    self.__class__.__name__
             raise ValueError, msg
 
         self.url = self.base_url
             q_str = urllib.urlencode(self.url_kw)
             self.url += '?' + q_str
 
+        # TODO -- this should be overhauled to not use JSSymbol
         for k, v in self.attrs.iteritems():
-            if type(v) in [JSSymbol]:
+            if type(v) in [twc.JSSymbol]:
                 for var, fun in self.jsVariables.iteritems():
                     if not var in v.src:
                         continue
                     res = fun(self)
                     if not isinstance(res, basestring):
-                        res = encoder.encode(res)
+                        res = twc.encoder.encode(res)
 
-                    self.attrs[k] = JSSymbol(
+                    self.attrs[k] = twc.JSSymbol(
                         src=self.attrs[k].src.replace(var, res))
 
-        setupcall = JSFuncCall(
-            function='var jitwidget = setupTW2JitWidget',
-            args=[
-                self.jitClassName,
-                self.jitSecondaryClassName,
-                self.compound_id,
-                self.attrs
-            ])
+        setupcall = js_function('setupTW2JitWidget')(
+            self.jitClassName,
+            self.jitSecondaryClassName,
+            self.compound_id,
+            self.attrs
+        )
         if self.data:
             # For normal loading
-            loadcall = JSFuncCall(
-                function='jitwidget.loadJSON',
-                args=[self.data],)
-            postcall = JSSource(
-                src=self.attrs['postInitJSCallback'].src+'(jitwidget)')
+            loadcall = js_function(
+                self._jit_js_ident() + '.loadJSON'
+            )(self.data)
+            postcall = js_function(self.attrs['postInitJSCallback'])(
+                js_symbol(self._jit_js_ident()))
         else:
             # For asynchronous loading
             self.resources.append(tw2.jquery.jquery_js)
             loadcall = None
-            postcall = JSSource(src="""
-                                $.getJSON(
-                                    '%s',
-                                    function (data) {
-                                        // load data when we get it
-                                        jitwidget.loadJSON(data);
-                                        // Do post-init stuff
-                                        %s(jitwidget);
-                                    }
-                               );""" % (self.url,
-                                        self.attrs['postInitJSCallback'].src))
+            postcall = js_function('$.getJSON')(
+                self.url,
+                js_callback(
+                    """function(data) {
+                        // load data when we get it
+                        %s.loadJSON(data);
+                        // Do post-init stuff
+                        (%s)(%s);
+                    }
+                    """ % (
+                        self._jit_js_ident(),
+                        self.attrs['postInitJSCallback'],
+                        self._jit_js_ident(),
+                    )
+                ))
+        self.add_delayed_call(setupcall)
+        self.add_delayed_call(loadcall)
+        self.add_delayed_call(postcall)
 
-        composite_js_call = CompoundJSSource(
-            exec_delay=self.init_delay,
-            setupcall=setupcall,
-            loadcall=loadcall,
-            postcall=postcall)
+    def _jit_js_ident(self):
+        return self.jsVariables['$$jitwidget'](self)
 
-        self.resources.append(composite_js_call)
+    def add_delayed_call(self, call):
+        if not call:
+            return
+        self.add_call(js_function('setTimeout')(
+            js_callback(call),
+            self.init_delay
+        ))
+
 
 
 class JitTreeOrGraphWidget(JitWidget):
         "(javascript) This method is called right before performing all " +
         "computations and animations.  The selected Graph.Node " +
         "is passed as parameter.",
-        default=JSSymbol(src="(function(node) {})"), attribute=True)
+        default=js_callback("(function(node) {})"), attribute=True)
 
     onAfterCompute = twc.Param(
         "(javascript) This method is triggered after all animations " +
         "or computations ended.",
-        default=JSSymbol(src="(function(node) {})"), attribute=True)
+        default=js_callback("(function(node) {})"), attribute=True)
 
     onCreateLabel = twc.Param(
         "(javascript) This method receives a new label DIV element as " +
         "parameter.  This method will only be called once for each label.  " +
         "This method is useful when adding events or styles to the labels " +
         "used by the JIT.",
-        default=JSSymbol(src="(function(node) {})"), attribute=True)
+        default=js_callback("(function(node) {})"), attribute=True)
 
     onPlaceLabel = twc.Param(
         "(javascript) This method receives a label DIV element as first " +
         "the labels positions.  That means that, for example, the left and " +
         "top css properties are already updated to match the nodes " +
         "positions.  Width and height properties are not set however.",
-        default=JSSymbol(src="(function(node) {})"), attribute=True)
+        default=js_callback("(function(node) {})"), attribute=True)
 
     onBeforePlotNode = twc.Param(
         "(javascript) This method is triggered right before plotting " +
         "each Graph.Node.  This method is useful for changing a node " +
         "style right before plotting it.",
-        default=JSSymbol(src="(function(node) {})"), attribute=True)
+        default=js_callback("(function(node) {})"), attribute=True)
 
     onAfterPlotNode = twc.Param(
         "(javascript) This method is triggered right after plotting " +
         "each Graph.Node.",
-        default=JSSymbol(src="(function(node) {})"), attribute=True)
+        default=js_callback("(function(node) {})"), attribute=True)
 
     onBeforePlotLine = twc.Param(
         "(javascript) This method is triggered right before plotting " +
         "a Graph.Adjacence.  This method is useful for adding some " +
         "styles to a particular edge before being plotted.",
-        default=JSSymbol(src="(function(node) {})"), attribute=True)
+        default=js_callback("(function(node) {})"), attribute=True)
 
     onAfterPlotLine = twc.Param(
         "(javascript) This method is triggered right after plotting " +
         "a Graph.Adjacence.",
-        default=JSSymbol(src="(function(node) {})"), attribute=True)
+        default=js_callback("(function(node) {})"), attribute=True)