2 /* jshint undef: false */
6 var QWeb = openerp.web.qweb;
7 var _lt = openerp.web._lt;
8 var _t = openerp.web._t;
10 nv.dev = false; // sets nvd3 library in production mode
12 openerp.web_graph.Graph = openerp.web.Widget.extend({
13 template: 'GraphWidget',
15 // ----------------------------------------------------------------------
17 // ----------------------------------------------------------------------
18 init: function(parent, model, domain, options) {
22 this.mode = options.mode || 'pivot'; // pivot, bar, pie, line
23 this.visible_ui = options.visible_ui || true;
24 this.bar_ui = options.bar_ui || 'group';
25 this.graph_view = options.graph_view || null;
26 this.pivot_options = options;
27 this.title = options.title || 'Data';
28 this.$buttons = options.$buttons;
33 this.table = $('<table>');
34 this.$('.graph_main_content').append(this.table);
36 this.$buttons.find('.oe-pivot-mode').click(function () {
37 self.set_mode.bind(self)('pivot');
39 this.$measure_list = this.$buttons.find('.oe-measure-list');
41 this.$buttons.find('.oe-bar-mode').click(function () {
42 self.set_mode.bind(self)('bar');
44 this.$buttons.find('.oe-line-mode').click(function () {
45 self.set_mode.bind(self)('line');
47 this.$buttons.find('.oe-pie-mode').click(function () {
48 self.set_mode.bind(self)('pie');
50 this.$buttons.find('.fa-expand').click(this.swap_axis.bind(this));
51 this.$buttons.find('.fa-arrows-alt').click(function () {
52 self.pivot.expand_all().then(self.proxy('display_data'));
54 this.$buttons.find('.fa-download').click(this.export_xls.bind(this));
56 var indexes = {'pivot': 0, 'bar': 1, 'line': 2, 'chart': 3};
57 this.$('.graph_mode_selection label').eq(indexes[this.mode]).addClass('selected');
59 if (this.mode !== 'pivot') {
60 this.$('.graph_heatmap label').addClass('disabled');
61 this.$('.graph_main_content').addClass('graph_chart_mode');
63 this.$('.graph_main_content').addClass('graph_pivot_mode');
66 var parent = this.getParent();
67 while (!(parent instanceof openerp.web.ViewManager)) {
68 parent = parent.getParent();
70 this.search_view = parent.searchview;
72 openerp.session.rpc('/web_graph/check_xlwt').then(function (result) {
73 self.$('.graph_options_selection label').last().toggle(result);
76 this.$buttons.find('button').tooltip();
78 return this.model.call('fields_get', []).then(function (f) {
80 self.fields.__count = {field:'__count', type: 'integer', string:_t('Count')};
81 self.groupby_fields = self.get_groupby_fields();
82 self.measure_list = self.get_measures();
83 self.add_measures_to_options();
84 self.pivot_options.row_groupby = self.create_field_values(self.pivot_options.row_groupby || []);
85 self.pivot_options.col_groupby = self.create_field_values(self.pivot_options.col_groupby || []);
86 self.pivot_options.measures = self.create_field_values(self.pivot_options.measures || [{field:'__count', type: 'integer', string:'Count'}]);
87 self.pivot = new openerp.web_graph.PivotTable(self.model, self.domain, self.fields, self.pivot_options);
88 self.pivot.update_data().then(function () {
90 if (self.graph_view) {
91 self.graph_view.register_groupby(self.pivot.rows.groupby, self.pivot.cols.groupby);
94 openerp.web.bus.on('click', self, function (event) {
96 self.$row_clicked = $(event.target).closest('tr');
97 self.dropdown.remove();
101 self.put_measure_checkmarks();
105 get_groupby_fields: function () {
106 var search_fields = this.get_search_fields(),
107 search_field_names = _.pluck(search_fields, 'field'),
109 groupable_types = ['many2one', 'char', 'boolean', 'selection', 'date', 'datetime'];
111 _.each(this.fields, function (val, key) {
112 if (!_.contains(search_field_names, key) &&
113 _.contains(groupable_types, val.type) &&
114 val.store === true) {
121 return search_fields.concat(other_fields);
124 // this method gets the fields that appear in the search view, under the
126 get_search_fields: function () {
127 // this method is disabled for now. This requires extensive changes because the
128 // search view works quite differently: But the graph view is going to be split
129 // soon in pivot view and graph view. The pivot view will then properly handle
134 var groupbygroups = _(this.search_view.drawer.inputs).select(function (g) {
135 return g instanceof openerp.web.search.GroupbyGroup;
138 var filters = _.flatten(_.pluck(groupbygroups, 'filters'), true),
139 groupbys = _.flatten(_.map(filters, function (filter) {
140 var groupby = py.eval(filter.attrs.context).group_by;
141 if (!(groupby instanceof Array)) { groupby = [groupby]; }
142 return _.map(groupby, function(g) {
143 return {field: g, filter: filter};
147 return _.uniq(_.map(groupbys, function (groupby) {
148 var field = groupby.field,
149 filter = groupby.filter,
150 raw_field = field.split(':')[0],
151 string = (field === raw_field) ? filter.attrs.string : self.fields[raw_field].string;
153 filter = (field === raw_field) ? filter : undefined;
155 return { field: raw_field, string: string, filter: filter };
156 }), false, function (filter) {return filter.field;});
159 // Extracts the integer/float fields which are not 'id'
160 get_measures: function() {
161 return _.compact(_.map(this.fields, function (f, id) {
162 if (((f.type === 'integer') || (f.type === 'float')) &&
164 (f.store !== false)) {
165 return {field:id, type: f.type, string: f.string};
170 add_measures_to_options: function() {
171 this.$measure_list.append(
172 _.map(this.measure_list, function (measure) {
173 return $('<li>').append($('<a>').attr('data-choice', measure.field)
175 .text(measure.string));
177 this.$measure_list.find('li').click(this.measure_selection.bind(this));
180 // ----------------------------------------------------------------------
181 // Configuration methods
182 // ----------------------------------------------------------------------
183 set: function (domain, row_groupby, col_groupby, measures_groupby) {
185 this.pivot_options.domain = domain;
186 this.pivot_options.row_groupby = row_groupby;
187 this.pivot_options.col_groupby = col_groupby;
188 this.pivot_options.measures_groupby = measures_groupby;
191 var row_gbs = this.create_field_values(row_groupby),
192 col_gbs = this.create_field_values(col_groupby),
193 measures_gbs = this.create_field_values(measures_groupby),
194 dom_changed = !_.isEqual(this.pivot.domain, domain),
195 row_gb_changed = !_.isEqual(row_gbs, this.pivot.rows.groupby),
196 col_gb_changed = !_.isEqual(col_gbs, this.pivot.cols.groupby),
197 measures_gb_changed = !_.isEqual(measures_gbs, this.pivot.measures),
198 row_reduced = is_strict_beginning_of(row_gbs, this.pivot.rows.groupby),
199 col_reduced = is_strict_beginning_of(col_gbs, this.pivot.cols.groupby),
200 measures_reduced = is_strict_beginning_of(measures_gbs, this.pivot.measures);
202 if (!dom_changed && row_reduced && !col_gb_changed && !measures_gb_changed) {
203 this.pivot.fold_with_depth(this.pivot.rows, row_gbs.length);
207 if (!dom_changed && col_reduced && !row_gb_changed && !measures_gb_changed) {
208 this.pivot.fold_with_depth(this.pivot.cols, col_gbs.length);
213 if (!dom_changed && col_reduced && row_reduced && !measures_gb_changed) {
214 this.pivot.fold_with_depth(this.pivot.rows, row_gbs.length);
215 this.pivot.fold_with_depth(this.pivot.cols, col_gbs.length);
220 if (dom_changed || row_gb_changed || col_gb_changed || measures_gb_changed) {
221 this.pivot.set(domain, row_gbs, col_gbs, measures_gbs).then(this.proxy('display_data'));
224 if (measures_gb_changed) {
225 this.put_measure_checkmarks();
229 set_mode: function (mode) {
232 if (mode === 'pivot') {
233 this.$('.graph_heatmap label').removeClass('disabled');
234 this.$('.graph_main_content').removeClass('graph_chart_mode').addClass('graph_pivot_mode');
236 this.$('.graph_heatmap label').addClass('disabled');
237 this.$('.graph_main_content').removeClass('graph_pivot_mode').addClass('graph_chart_mode');
242 create_field_value: function (f) {
243 var field = (_.contains(f, ':')) ? f.split(':')[0] : f,
244 groupby_field = _.findWhere(this.groupby_fields, {field:field}),
245 string = groupby_field ? groupby_field.string : this.fields[field].string,
246 result = {field: f, string: string, type: this.fields[field].type };
249 result.filter = groupby_field.filter;
255 create_field_values: function (field_ids) {
256 return _.map(field_ids, this.proxy('create_field_value'));
260 get_col_groupbys: function () {
261 return _.pluck(this.pivot.cols.groupby, 'field');
264 get_current_measures: function () {
265 return _.pluck(this.pivot.measures, 'field');
268 // ----------------------------------------------------------------------
270 // ----------------------------------------------------------------------
272 'click .graph_mode_selection label' : 'mode_selection',
273 'click .graph_measure_selection li' : 'measure_selection',
274 'click .graph_options_selection label' : 'option_selection',
275 'click .graph_heatmap label' : 'heatmap_mode_selection',
276 'click .web_graph_click' : 'header_cell_clicked',
277 'click a.field-selection' : 'field_selection',
280 mode_selection: function (event) {
281 event.preventDefault();
282 var mode = event.currentTarget.getAttribute('data-mode');
286 measure_selection: function (event) {
287 event.preventDefault();
288 event.stopPropagation();
289 var measure_field = event.target.getAttribute('data-choice');
291 field: measure_field,
292 type: this.fields[measure_field].type,
293 string: this.fields[measure_field].string
296 this.pivot.toggle_measure(measure).then(this.proxy('display_data'));
297 this.put_measure_checkmarks();
300 put_measure_checkmarks: function () {
302 measures_li = this.$measure_list.find('li');
303 measures_li.removeClass('selected');
304 _.each(this.measure_list, function (measure, index) {
305 if (_.findWhere(self.pivot.measures, measure)) {
306 measures_li.eq(index).addClass('selected');
312 option_selection: function (event) {
313 event.preventDefault();
314 switch (event.currentTarget.getAttribute('data-choice')) {
319 this.pivot.expand_all().then(this.proxy('display_data'));
321 case 'update_values':
322 this.pivot.update_data().then(this.proxy('display_data'));
330 header_cell_clicked: function (event) {
331 event.preventDefault();
332 event.stopPropagation();
333 var id = event.target.getAttribute('data-id'),
334 header = this.pivot.get_header(id),
337 if (header.expanded) {
338 if (header.root === this.pivot.rows) {
339 this.fold_row(header, event);
341 this.fold_col(header);
345 if (header.path.length < header.root.groupby.length) {
346 this.$row_clicked = $(event.target).closest('tr');
350 if (!this.groupby_fields.length) {
354 var fields = _.map(this.groupby_fields, function (field) {
355 return {id: field.field, value: field.string, type:self.fields[field.field.split(':')[0]].type};
358 this.dropdown.remove();
360 this.dropdown = $(QWeb.render('field_selection', {fields:fields, header_id:id}));
361 $(event.target).after(this.dropdown);
364 left:event.originalEvent.layerX,
366 this.$('.field-selection').next('.dropdown-menu').first().toggle();
369 field_selection: function (event) {
370 var id = event.target.getAttribute('data-id'),
371 field_id = event.target.getAttribute('data-field-id'),
373 groupby = this.create_field_value(field_id);
374 event.preventDefault();
375 if (this.fields[field_id].type === 'date' || this.fields[field_id].type === 'datetime') {
376 interval = event.target.getAttribute('data-interval');
377 groupby.field = groupby.field + ':' + interval;
379 this.expand(id, groupby);
382 // ----------------------------------------------------------------------
383 // Pivot Table integration
384 // ----------------------------------------------------------------------
385 expand: function (header_id, groupby) {
387 header = this.pivot.get_header(header_id),
388 update_groupby = !!groupby;
390 groupby = groupby || header.root.groupby[header.path.length];
392 this.pivot.expand(header_id, groupby).then(function () {
393 if (header.root === self.pivot.rows) {
394 // expanding rows can be done by only inserting in the dom
395 // console.log(event.target);
396 var rows = self.build_rows(header.children);
397 var doc_fragment = $(document.createDocumentFragment());
398 rows.map(function (row) {
399 doc_fragment.append(self.draw_row(row, 0));
401 self.$row_clicked.after(doc_fragment);
403 // expanding cols will redraw the full table
406 if (update_groupby && self.graph_view) {
407 self.graph_view.register_groupby(self.pivot.rows.groupby, self.pivot.cols.groupby);
413 fold_row: function (header, event) {
414 var rows_before = this.pivot.rows.headers.length,
415 update_groupby = this.pivot.fold(header),
416 rows_after = this.pivot.rows.headers.length,
417 rows_removed = rows_before - rows_after;
419 if (rows_after === 1) {
420 // probably faster to redraw the unique row instead of removing everything
423 var $row = $(event.target).parent().parent();
424 $row.nextAll().slice(0,rows_removed).remove();
426 if (update_groupby && this.graph_view) {
427 this.graph_view.register_groupby(this.pivot.rows.groupby, this.pivot.cols.groupby);
431 fold_col: function (header) {
432 var update_groupby = this.pivot.fold(header);
435 if (update_groupby && this.graph_view) {
436 this.graph_view.register_groupby(this.pivot.rows.groupby, this.pivot.cols.groupby);
440 swap_axis: function () {
441 this.pivot.swap_axis();
443 this.graph_view.register_groupby(this.pivot.rows.groupby, this.pivot.cols.groupby);
446 // ----------------------------------------------------------------------
447 // Convert Pivot data structure into table structure :
448 // compute rows, cols, colors, cell width, cell height, ...
449 // ----------------------------------------------------------------------
450 build_table: function(raw) {
452 headers: this.build_headers(),
453 measure_row: this.build_measure_row(),
454 rows: this.build_rows(this.pivot.rows.headers,raw),
455 nbr_measures: this.pivot.measures.length,
460 build_headers: function () {
461 var pivot = this.pivot,
462 nbr_measures = pivot.measures.length,
463 height = _.max(_.map(pivot.cols.headers, function(g) {return g.path.length;})) + 1,
466 _.each(pivot.cols.headers, function (col) {
467 var cell_width = nbr_measures * (col.expanded ? pivot.get_ancestor_leaves(col).length : 1),
468 cell_height = col.expanded ? 1 : height - col.path.length,
469 cell = {width: cell_width, height: cell_height, title: col.title, id: col.id, expanded: col.expanded};
470 if (rows[col.path.length]) {
471 rows[col.path.length].push(cell);
473 rows[col.path.length] = [cell];
477 if (pivot.get_cols_leaves().length > 1) {
478 rows[0].push({width: nbr_measures, height: height, title: ' ', id: pivot.main_col().id });
480 if (pivot.cols.headers.length === 1) {
481 rows = [[{width: nbr_measures, height: 1, title: _t('Total'), id: pivot.main_col().id, expanded: false}]];
486 build_measure_row: function () {
487 var nbr_leaves = this.pivot.get_cols_leaves().length,
488 nbr_cols = nbr_leaves + ((nbr_leaves > 1) ? 1 : 0),
490 add_total = this.pivot.get_cols_leaves().length > 1,
492 for (i = 0; i < nbr_cols; i++) {
493 for (m = 0; m < this.pivot.measures.length; m++) {
495 text:this.pivot.measures[m].string,
496 is_bold: add_total && (i === nbr_cols - 1)
503 make_cell: function (row, col, value, index, raw) {
504 var formatted_value = raw && !_.isUndefined(value) ? value : openerp.web.format_value(value, {type:this.pivot.measures[index].type}),
505 cell = {value:formatted_value};
510 build_rows: function (headers, raw) {
513 m, i, j, k, cell, row;
516 var cells, pivot_cells, values;
518 var nbr_of_rows = headers.length;
519 var col_headers = pivot.get_cols_leaves();
521 for (i = 0; i < nbr_of_rows; i++) {
525 for (j = 0; j < pivot.cells.length; j++) {
526 if (pivot.cells[j].x == row.id || pivot.cells[j].y == row.id) {
527 pivot_cells.push(pivot.cells[j]);
531 for (j = 0; j < col_headers.length; j++) {
533 for (k = 0; k < pivot_cells.length; k++) {
534 if (pivot_cells[k].x == col_headers[j].id || pivot_cells[k].y == col_headers[j].id) {
535 values = pivot_cells[k].values;
539 if (!values) { values = new Array(pivot.measures.length);}
540 for (m = 0; m < pivot.measures.length; m++) {
541 cells.push(self.make_cell(row,col_headers[j],values[m], m, raw));
544 if (col_headers.length > 1) {
545 var totals = pivot.get_total(row);
546 for (m = 0; m < pivot.measures.length; m++) {
547 cell = self.make_cell(row, pivot.cols.headers[0], totals[m], m, raw);
548 cell.is_bold = 'true';
554 indent: row.path.length,
556 expanded: row.expanded,
564 // ----------------------------------------------------------------------
565 // Main display method
566 // ----------------------------------------------------------------------
567 display_data: function () {
568 var scroll = $(window).scrollTop();
569 this.$('.graph_main_content svg').remove();
570 this.$('.graph_main_content div').remove();
572 this.$('.graph_options_selection label').last().toggleClass('disabled', this.pivot.no_data);
573 this.width = this.$el.width();
574 this.height = Math.min(Math.max(document.documentElement.clientHeight - 116 - 60, 250), Math.round(0.8*this.$el.width()));
576 this.$('.graph_header').toggle(this.visible_ui);
577 if (this.pivot.no_data) {
578 this.$('.graph_main_content').append($(QWeb.render('graph_no_data')));
580 if (this.mode === 'pivot') {
582 $(window).scrollTop(scroll);
584 this.$('.graph_main_content').append($('<div><svg>'));
585 this.svg = this.$('.graph_main_content svg')[0];
591 // ----------------------------------------------------------------------
593 // ----------------------------------------------------------------------
594 draw_table: function () {
595 var custom_gbs = this.graph_view.get_custom_filter_groupbys(),
596 frozen_rows = custom_gbs.groupby.length,
597 frozen_cols = custom_gbs.col_groupby.length;
599 var table = this.build_table();
600 var doc_fragment = $(document.createDocumentFragment());
601 this.draw_headers(table.headers, doc_fragment, frozen_cols);
602 this.draw_measure_row(table.measure_row, doc_fragment);
603 this.draw_rows(table.rows, doc_fragment, frozen_rows);
604 this.table.append(doc_fragment);
607 make_header_cell: function (header, frozen) {
608 var cell = (_.has(header, 'cells') ? $('<td>') : $('<th>'))
609 .addClass('graph_border')
610 .attr('rowspan', header.height)
611 .attr('colspan', header.width);
612 var $content = $('<span>').attr('href','#')
613 .text(' ' + (header.title || _t('Undefined')))
614 .css('margin-left', header.indent*30 + 'px')
615 .attr('data-id', header.id);
616 if (_.has(header, 'expanded')) {
617 if (('indent' in header) && header.indent >= frozen) {
618 $content.addClass(header.expanded ? 'fa fa-minus-square' : 'fa fa-plus-square');
619 $content.addClass('web_graph_click');
621 if (!('indent' in header) && header.lvl >= frozen) {
622 $content.addClass(header.expanded ? 'fa fa-minus-square' : 'fa fa-plus-square');
623 $content.addClass('web_graph_click');
626 $content.css('font-weight', 'bold');
628 return cell.append($content);
631 draw_headers: function (headers, doc_fragment, frozen_cols) {
632 var make_cell = this.make_header_cell,
633 $empty_cell = $('<th>').attr('rowspan', headers.length),
634 $thead = $('<thead>');
636 _.each(headers, function (row, lvl) {
637 var $row = $('<tr>');
638 _.each(row, function (header) {
640 $row.append(make_cell(header, frozen_cols));
644 $thead.children(':first').prepend($empty_cell);
645 doc_fragment.append($thead);
646 this.$thead = $thead;
649 draw_measure_row: function (measure_row) {
650 var $row = $('<tr>').append('<th>');
651 _.each(measure_row, function (cell) {
652 var $cell = $('<th>').addClass('measure_row').text(cell.text);
653 if (cell.is_bold) {$cell.css('font-weight', 'bold');}
656 this.$thead.append($row);
659 draw_row: function (row, frozen_rows) {
661 .attr('data-indent', row.indent)
662 .append(this.make_header_cell(row, frozen_rows));
664 var cells_length = row.cells.length;
668 for (var j = 0; j < cells_length; j++) {
671 if (cell.is_bold || cell.color) {
673 if (cell.is_bold) hcell += 'font-weight: bold;';
674 if (cell.color) hcell += 'background-color:' + $.Color(255, cell.color, cell.color) + ';';
677 hcell += '>' + cell.value + '</td>';
678 cells_list[j] = hcell;
680 return $row.append(cells_list.join(''));
683 draw_rows: function (rows, doc_fragment, frozen_rows) {
684 var rows_length = rows.length,
685 $tbody = $('<tbody>');
687 doc_fragment.append($tbody);
688 for (var i = 0; i < rows_length; i++) {
689 $tbody.append(this.draw_row(rows[i], frozen_rows));
693 // ----------------------------------------------------------------------
694 // Drawing charts code
695 // ----------------------------------------------------------------------
698 dim_x = this.pivot.rows.groupby.length,
699 dim_y = this.pivot.cols.groupby.length,
700 show_controls = (this.width > 400 && this.height > 300 && dim_x + dim_y >=2),
704 if ((dim_x === 0) && (dim_y === 0)) {
705 data = [{key: _t('Total'), values:[{
707 y: this.pivot.get_total()[0],
709 // Only column groupbys
710 } else if ((dim_x === 0) && (dim_y >= 1)){
711 data = _.map(this.pivot.get_cols_with_depth(1), function (header) {
714 values: [{x:header.title, y: self.pivot.get_total(header)[0]}]
717 // Just 1 row groupby
718 } else if ((dim_x === 1) && (dim_y === 0)) {
719 data = _.map(this.pivot.main_row().children, function (pt) {
720 var value = self.pivot.get_total(pt)[0],
721 title = (pt.title !== undefined) ? pt.title : _t('Undefined');
722 return {x: title, y: value};
724 data = [{key: self.pivot.measures[0].string, values:data}];
725 // 1 row groupby and some col groupbys
726 } else if ((dim_x === 1) && (dim_y >= 1)) {
727 data = _.map(this.pivot.get_cols_with_depth(1), function (colhdr) {
728 var values = _.map(self.pivot.get_rows_with_depth(1), function (header) {
730 x: header.title || _t('Undefined'),
731 y: self.pivot.get_values(header.id, colhdr.id)[0] || 0
734 return {key: colhdr.title || _t('Undefined'), values: values};
736 // At least two row groupby
738 var keys = _.uniq(_.map(this.pivot.get_rows_with_depth(2), function (hdr) {
739 return hdr.title || _t('Undefined');
741 data = _.map(keys, function (key) {
742 var values = _.map(self.pivot.get_rows_with_depth(1), function (hdr) {
743 var subhdr = _.find(hdr.children, function (child) {
744 return ((child.title === key) || ((child.title === undefined) && (key === _t('Undefined'))));
747 x: hdr.title || _t('Undefined'),
748 y: (subhdr) ? self.pivot.get_total(subhdr)[0] : 0
751 return {key:key, values: values};
755 nv.addGraph(function () {
756 var chart = nv.models.multiBarChart()
758 .stacked(self.bar_ui === 'stack')
759 .showControls(show_controls);
761 if (self.width / data[0].values.length < 80) {
762 chart.rotateLabels(-15);
763 chart.reduceXTicks(true);
764 chart.margin({bottom:40});
769 .attr('width', self.width)
770 .attr('height', self.height)
773 nv.utils.windowResize(chart.update);
781 dim_x = this.pivot.rows.groupby.length,
782 dim_y = this.pivot.cols.groupby.length;
784 var rows = this.pivot.get_rows_with_depth(dim_x),
785 labels = _.pluck(rows, 'title');
787 var data = _.map(this.pivot.get_cols_leaves(), function (col) {
788 var values = _.map(rows, function (row, index) {
789 return {x: index, y: self.pivot.get_values(row.id,col.id)[0] || 0};
791 var title = _.map(col.path, function (p) {
792 return p || _t('Undefined');
795 title = self.pivot.measures[0].string;
797 return {values: values, key: title};
800 nv.addGraph(function () {
801 var chart = nv.models.lineChart()
802 .x(function (d,u) { return u; });
804 chart.xAxis.tickFormat(function (d,u) {return labels[d];});
807 .attr('width', self.width)
808 .attr('height', self.height)
818 dim_x = this.pivot.rows.groupby.length;
819 var data = _.map(this.pivot.get_rows_leaves(), function (row) {
820 var title = _.map(row.path, function (p) {
821 return p || _t('Undefined');
824 title = self.measure_label;
826 return {x: title, y: self.pivot.get_total(row)[0]};
829 nv.addGraph(function () {
830 var chart = nv.models.pieChart()
833 .color(d3.scale.category10().range());
837 .transition().duration(1200)
838 .attr('width', self.width)
839 .attr('height', self.height)
842 nv.utils.windowResize(chart.update);
847 // ----------------------------------------------------------------------
848 // Controller stuff...
849 // ----------------------------------------------------------------------
850 export_xls: function() {
851 var c = openerp.webclient.crashmanager;
852 openerp.web.blockUI();
853 this.session.get_file({
854 url: '/web_graph/export_xls',
855 data: {data: JSON.stringify(this.build_table(true))},
856 complete: openerp.web.unblockUI,
857 error: c.rpc_error.bind(c)
863 // Utility function: returns true if the beginning of array2 is array1 and
864 // if array1 is not array2
865 function is_strict_beginning_of (array1, array2) {
866 if (array1.length >= array2.length) { return false; }
868 for (var i = 0; i < array1.length; i++) {
869 if (!_.isEqual(array1[i], array2[i])) { return false;}