[views][plot] piechart view now accepts either final or non final entities in the first column
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Wed, 27 May 2009 08:39:16 +0200
changeset 1956 9865daa96cd7
parent 1938 bf27b4190739
child 1962 45af1e015683
[views][plot] piechart view now accepts either final or non final entities in the first column
web/views/plots.py
--- a/web/views/plots.py	Tue May 26 09:31:44 2009 +0200
+++ b/web/views/plots.py	Wed May 27 08:39:16 2009 +0200
@@ -177,10 +177,22 @@
 
         __select__ = at_least_two_columns() & second_column_is_number()
 
+        def _guess_vid(self, row):
+            etype = self.rset.description[row][0]
+            if self.schema.eschema(etype).is_final():
+                return 'final'
+            return 'textincontext'
+
         def call(self, title=None, width=None, height=None):
-            labels = ['%s: %s' % (row[0].encode(self.req.encoding), row[1])
-                      for row in self.rset]
-            values = [(row[1] or 0) for row in self.rset]
+            labels = []
+            values = []
+            for rowidx, (_, value) in enumerate(self.rset):
+                if value is not None:
+                    vid = self._guess_vid(rowidx)
+                    label = '%s: %s' % (self.view(vid, self.rset, row=rowidx, col=0),
+                                        value)
+                    labels.append(label.encode(self.req.encoding))
+                    values.append(value)
             pie = PieChartWidget(labels, values, pieclass=self.pieclass,
                                  title=title)
             if width is not None: