Ralph Bean committed 1b2062d

Better attempt at truncating text in circlepacking widget.

Comments (0)

Files changed (2)

-    version='0.1.a3',
+    version='0.1.a4',
     description='toscawidgets2 wrapper for the stanford protovis toolkit',
     author='Ralph Bean',


     root_title = twc.Param("Root title", default="root title")
+    def find_bounds(self, data, _min=1000000000000, _max=0):
+        for key, value in data.iteritems():
+            if isinstance(value, dict):
+                _min, _max = self.find_bounds(value, _min, _max)
+            else:
+                if value < _min:
+                    _min = value
+                if value > _max:
+                    _max = value
+        return _min, _max
     def prepare(self):
+        _min, _max = self.find_bounds(self.p_data)
         self.init_js = js(
             var format = pv.Format.number();
             var data = %s;
             var title = "%s";
-            """ % (self.p_data, self.root_title)
+            var min = %f;
+            var max = %f;
+            """ % (self.p_data, self.root_title, _min, _max)
                 .visible(js('function(d) !d.firstChild'))\
-        'function(d) d.nodeName.substring(0, Math.sqrt(d.nodeValue) / 20)'
+        'function(d) d.nodeName.substring(0, 25*(d.nodeValue - min)/(max - min))'
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.