Commits

Ralph Bean committed 7f5c370

Added configurable width to SparkBar.

Comments (0)

Files changed (3)

development-deps/develop-tw2-start.sh

 venv=$devbase/virtualenv-tw2.jit
 source $venv/bin/activate
 
+pip install decorator
+
 python setup.py develop && paster tw2.browser
 
 
 setup(
     name='tw2.protovis.custom',
-    version='0.1.a4',
+    version='0.1.a5',
     description='toscawidgets2 wrapper for the stanford protovis toolkit',
     long_description=long_description,
     author='Ralph Bean',

tw2/protovis/custom/widgets.py

 import tw2.protovis.core as twp
 from tw2.protovis.core import pv
 
+import math
+
 class js(twc.JSSymbol):
     def __init__(self, src):
         super(js, self).__init__(src=src)
 
 class SparkBar(twp.PVWidget):
     """ A sparkbar is just like a sparkline, but,... you know. """
+    p_width = 80
+    p_margin = twc.Param("Integer margin between bars.", default=1)
+
     def prepare(self):
+        outer_dw = math.floor(self.p_width / len(self.p_data))
+        inner_dw = outer_dw - self.p_margin
+
         self.init_js = js(
             """
             var data = %s;
 
         self.add(pv.Bar) \
           .data(js('data'))\
-          .width(4)\
-          .left(js('function() 5 * this.index'))\
+          .width(inner_dw)\
+          .left(js('function() %i * this.index' % outer_dw))\
           .height(js('function(d) Math.round(h * d)'))\
           .bottom(0)