def get_data(self): result = {} ctx = rpc.get_session().context.copy() res = super(PieChart, self).get_graph_data() if len(res) > 1: values = res[0] domain = res[1] model = res[2] label_x = res[3] axis = res[4] else: return res dataset = result.setdefault('dataset', []) value = values.values()[0] url = [] for dom in domain: u = url_plus('/openerp/form/find', _terp_view_type='tree', _terp_view_mode=ustr(self.view_mode), _terp_domain=ustr(dom), _terp_model=self.model, _terp_context=ustr(ctx)) url.append(u) allvalues = [] total_val = 0 for i, x in enumerate(label_x): total_val += value[i] for i, x in enumerate(label_x): val = {'value': value[i], 'text': x, 'label': x} if not ctx.get('report_id', False): val['on-click'] = "function(){onChartClick('" + url[i] + "')}" # completely randomly selected epsilon if abs(total_val) > .0001: field_key = (100 * value[i])/total_val field_key = '%.2f' % (field_key) val["tip"] = x + ' (' + field_key + ' %)' else: val["tip"] = x allvalues.append(val) ChartColors = choice_colors(len(allvalues)) dataset.append({'type': 'pie', "colours": ChartColors, "animate": "true", "gradient-fill": 'true', "no-labels": 'true', "values": allvalues}) result = {"legend": {"bg_colour": "#FFFFFF", "border": 'true', "position": "top", "shadow": 'true', "visible": 'true' }, "elements": [d for d in dataset], "bg_colour": "#FFFFFF"} return result
def get_data(self): result = {} ctx = rpc.get_session().context.copy() ctx.update(self.context) res = super(BarChart, self).get_graph_data() if len(res) > 1: values = res[0] domain = res[1] model = res[2] label_x = res[3] axis = res[4] axis_group = res[5] stack_list = res[6] stack_labels = res[7] axis_data = res[8] stack_id_list = res[9] else: return res def minmx_ticks(values): x_data = [] for st in stack_list: range = 0 for s in st: range = range + s x_data.append(range) mx = 0 mn = 0 if values: values.sort() if x_data: x_data.sort() mx = x_data[-1] else: mn = 0 mx = values[-1] if mx != 0: if mx < 0: mx = mx - (10 + mx % 10) else: mx = mx + (10 - (mx % 10)) total = mx + mn tk = round(total/10) return {'y_max': mx, 'y_min': mn, 'y_steps': tk} temp_lbl = [] stack_labels = [] dataset = result.setdefault('dataset', []) for i in label_x: i = re.sub(ur'[êéèë]', 'e', i) i = re.sub(ur'[ïî]', 'i', i) i = re.sub(ur'[àâáâãä]', 'a', i) i = re.sub(ur'[ç]', 'c', i) i = re.sub(ur'[òóôõö]', 'o', i) i = re.sub(ur'[ýÿ]', 'y', i) i = re.sub(ur'[ñ]', 'n', i) i = re.sub(ur'[ÁÂÃÄ]', 'A', i) i = re.sub(ur'[ÈÉÊË]', 'E', i) i = re.sub(ur'[ÌÍÎÏ]', 'I', i) i = re.sub(ur'[ÒÓÔÕÖ]', 'O', i) i = re.sub(ur'[ÙÚÛÜ]', 'U', i) i = re.sub(ur'[Ý]', 'Y', i) i = re.sub(ur'[Ñ]', 'N', i) lbl = {'text': i, 'colour': "#432BAF"} if len(axis_group) > 1: stack_labels.append(lbl) else: temp_lbl.append(lbl) url = [] for x in axis[1:]: if len(axis_group) > 1: for st in stack_id_list: for s in st: if s.find('/') != -1: ids = s.split('/')[1] ids = eval(ids) dom = [('id', 'in', ids)] u = url_plus('/openerp/form/find', _terp_view_type='tree', _terp_view_mode=ustr(self.view_mode), _terp_domain=ustr(dom), _terp_model=self.model, _terp_context=ustr(ctx)) url.append(u) else: for dom in domain: u = url_plus('/openerp/form/find', _terp_view_type='tree', _terp_view_mode=ustr(self.view_mode), _terp_domain=ustr(dom), _terp_model=self.model, _terp_context=ustr(ctx)) url.append(u) allvalues = [] ChartColors = choice_colors(len(axis)) for i, x in enumerate(axis[1:]): data = values[x] for j, d in enumerate(data): allvalues.append(d) yopts = minmx_ticks(allvalues) y_grid_color = True if yopts['y_steps'] == 0.0: yopts['y_steps'] = 1 yopts['y_max'] = 9 yopts['y_min'] = 0 y_grid_color = False if y_grid_color: axis_y = {"steps": yopts['y_steps'], "max": yopts['y_max'], "min": yopts['y_min'], "stroke": 2 , "grid-colour": "#F0EEEE"} else: axis_y = {"steps": yopts['y_steps'], "max": yopts['y_max'], "min": yopts['y_min'], 'stroke': 2 , "grid-colour": "#F0EEEE"} if len(axis_group) > 1: ChartColors = choice_colors(len(axis_group)) all_keys = [] for i, x in enumerate(axis_group): data = {'text': x, 'colour': ChartColors[i], 'font-size': 12} all_keys.append(data) stack_val = [] cnt = 0 for j, stk in enumerate(stack_list): sval = [] for x, s in enumerate(stk): stack = {'val': s} if s != 0.0 and not ctx.get('report_id', False) and url: stack["on-click"]= "function(){onChartClick('" + url[cnt] + "')}" cnt += 1 stack['tip'] = s sval.append(stack) stack_val.append(sval) result = { "elements": [{"type": "bar_stack", "colours": ChartColors, "values": [s for s in stack_val], "keys": [key for key in all_keys]}], "x_axis": {"colour": "#909090", "labels": { "labels": [ lbl for lbl in stack_labels ], "rotate": "diagonal", "colour": "#ff0000"}, "3d": 3, "grid-colour": "#F0EEEE"}, "y_axis": axis_y, "bg_colour": "#FFFFFF", "tooltip": {"mouse": 2 }} else: for i, x in enumerate(axis[1:]): datas = [] data = values[x] for j, d in enumerate(data): dt = {} if not ctx.get('report_id', False): dt["on-click"]= "function(){onChartClick('" + url[j] + "')}" dt['top'] = d datas.append(dt) allvalues.append(d) dataset.append({"text": axis_data[x]['string'], "type": "bar_3d", "colour": ChartColors[i], "values": datas, "font-size": 10}) result = {"y_axis": axis_y, "title": {"text": ""}, "elements": [i for i in dataset], "bg_colour": "#FFFFFF", "x_axis": {"colour": "#909090", "stroke": 1, "tick-height": 5, "steps": 1, "labels": { "rotate": "diagonal", "colour": "#ff0000", "labels": [l for l in temp_lbl]}, "3d": 3, "grid-colour": "#F0EEEE" } } return result