Commits

Ralph Bean committed 6cc888e

Added circle packing widget.

Comments (0)

Files changed (3)

 
 setup(
     name='tw2.protovis.hierarchies',
-    version='0.1.a1',
+    version='0.1.a2',
     description='toscawidgets2 wrapper for the stanford protovis toolkit',
     long_description=long_description,
     author='Ralph Bean',

tw2/protovis/hierarchies/samples.py

 The demos implemented here are what is displayed in the tw2.devtools
 WidgetBrowser.
 """
-from widgets import NodeLinkTree
+from widgets import NodeLinkTree, CirclePackingWidget
 
 from widgets import js
 from tw2.core import JSSymbol
         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
+

tw2/protovis/hierarchies/widgets.py

 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)
 
         tree.label.add(pv.Label)
 
+class CirclePackingWidget(twp.PVWidget):
+
+    def prepare(self):
+        self.init_js = js(
+            """
+            var format = pv.Format.number();
+            var data = %s;
+            """ % self.p_data
+        )
+
+        self.setupRootPanel()
+
+        pack = self.add(pv.Layout.Pack)\
+                .nodes(js('pv.dom(data).root("flare").nodes()'))\
+                .size(js('function(d) d.nodeValue'))
+
+        pack.node.add(pv.Dot)\
+                .fillStyle(js(
+        'function(d) d.firstChild ? "rgba(31, 119, 180, .25)" : "#ff7f0e"'
+                ))\
+                .title(js(
+        'function(d) d.nodeName + (d.firstChild ? "" : ": " + format(d.nodeValue))'
+                ))\
+                .lineWidth(1)
+        pack.label.add(pv.Label)\
+                .visible(js('function(d) !d.firstChild'))\
+                .text(js(
+        'function(d) d.nodeName.substring(0, Math.sqrt(d.nodeValue) / 20)'
+                ))