web/views/plots.py
changeset 3451 6b46d73823f5
parent 3408 c92170fca813
child 3720 5376aaadd16b
equal deleted inserted replaced
3448:495862266785 3451:6b46d73823f5
   126     __select__ = at_least_two_columns() & all_columns_are_numbers()
   126     __select__ = at_least_two_columns() & all_columns_are_numbers()
   127     timemode = False
   127     timemode = False
   128 
   128 
   129     def call(self, width=500, height=400):
   129     def call(self, width=500, height=400):
   130         # prepare data
   130         # prepare data
   131         rqlst = self.rset.syntax_tree()
   131         rqlst = self.cw_rset.syntax_tree()
   132         # XXX try to make it work with unions
   132         # XXX try to make it work with unions
   133         varnames = [var.name for var in rqlst.children[0].get_selected_variables()][1:]
   133         varnames = [var.name for var in rqlst.children[0].get_selected_variables()][1:]
   134         abscissa = [row[0] for row in self.rset]
   134         abscissa = [row[0] for row in self.cw_rset]
   135         plots = []
   135         plots = []
   136         nbcols = len(self.rset.rows[0])
   136         nbcols = len(self.cw_rset.rows[0])
   137         for col in xrange(1, nbcols):
   137         for col in xrange(1, nbcols):
   138             data = [row[col] for row in self.rset]
   138             data = [row[col] for row in self.cw_rset]
   139             plots.append(filterout_nulls(abscissa, data))
   139             plots.append(filterout_nulls(abscissa, data))
   140         plotwidget = FlotPlotWidget(varnames, plots, timemode=self.timemode)
   140         plotwidget = FlotPlotWidget(varnames, plots, timemode=self.timemode)
   141         plotwidget.render(self.req, width, height, w=self.w)
   141         plotwidget.render(self._cw, width, height, w=self.w)
   142 
   142 
   143 
   143 
   144 class TimeSeriePlotView(PlotView):
   144 class TimeSeriePlotView(PlotView):
   145     __select__ = at_least_two_columns() & columns_are_date_then_numbers()
   145     __select__ = at_least_two_columns() & columns_are_date_then_numbers()
   146     timemode = True
   146     timemode = True
   174         pieclass = Pie
   174         pieclass = Pie
   175 
   175 
   176         __select__ = at_least_two_columns() & second_column_is_number()
   176         __select__ = at_least_two_columns() & second_column_is_number()
   177 
   177 
   178         def _guess_vid(self, row):
   178         def _guess_vid(self, row):
   179             etype = self.rset.description[row][0]
   179             etype = self.cw_rset.description[row][0]
   180             if self.schema.eschema(etype).is_final():
   180             if self._cw.schema.eschema(etype).is_final():
   181                 return 'final'
   181                 return 'final'
   182             return 'textincontext'
   182             return 'textincontext'
   183 
   183 
   184         def call(self, title=None, width=None, height=None):
   184         def call(self, title=None, width=None, height=None):
   185             labels = []
   185             labels = []
   186             values = []
   186             values = []
   187             for rowidx, (_, value) in enumerate(self.rset):
   187             for rowidx, (_, value) in enumerate(self.cw_rset):
   188                 if value is not None:
   188                 if value is not None:
   189                     vid = self._guess_vid(rowidx)
   189                     vid = self._guess_vid(rowidx)
   190                     label = '%s: %s' % (self.view(vid, self.rset, row=rowidx, col=0),
   190                     label = '%s: %s' % (self.view(vid, self.cw_rset, row=rowidx, col=0),
   191                                         value)
   191                                         value)
   192                     labels.append(label.encode(self.req.encoding))
   192                     labels.append(label.encode(self._cw.encoding))
   193                     values.append(value)
   193                     values.append(value)
   194             pie = PieChartWidget(labels, values, pieclass=self.pieclass,
   194             pie = PieChartWidget(labels, values, pieclass=self.pieclass,
   195                                  title=title)
   195                                  title=title)
   196             if width is not None:
   196             if width is not None:
   197                 height = height or width
   197                 height = height or width