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 return this.model.call('fields_get', []).then(function (f) {
78 self.fields.__count = {field:'__count', type: 'integer', string:_t('Count')};
79 self.groupby_fields = self.get_groupby_fields();
80 self.measure_list = self.get_measures();
81 self.add_measures_to_options();
82 self.pivot_options.row_groupby = self.create_field_values(self.pivot_options.row_groupby || []);
83 self.pivot_options.col_groupby = self.create_field_values(self.pivot_options.col_groupby || []);
84 self.pivot_options.measures = self.create_field_values(self.pivot_options.measures || [{field:'__count', type: 'integer', string:'Count'}]);
85 self.pivot = new openerp.web_graph.PivotTable(self.model, self.domain, self.fields, self.pivot_options);
86 self.pivot.update_data().then(function () {
88 if (self.graph_view) {
89 self.graph_view.register_groupby(self.pivot.rows.groupby, self.pivot.cols.groupby);
92 openerp.web.bus.on('click', self, function (event) {
94 self.$row_clicked = $(event.target).closest('tr');
95 self.dropdown.remove();
99 self.put_measure_checkmarks();
103 get_groupby_fields: function () {
104 var search_fields = this.get_search_fields(),
105 search_field_names = _.pluck(search_fields, 'field'),
107 groupable_types = ['many2one', 'char', 'boolean', 'selection', 'date', 'datetime'];
109 _.each(this.fields, function (val, key) {
110 if (!_.contains(search_field_names, key) &&
111 _.contains(groupable_types, val.type) &&
112 val.store === true) {
119 return search_fields.concat(other_fields);
122 // this method gets the fields that appear in the search view, under the
124 get_search_fields: function () {
125 // this method is disabled for now. This requires extensive changes because the
126 // search view works quite differently: But the graph view is going to be split
127 // soon in pivot view and graph view. The pivot view will then properly handle
132 var groupbygroups = _(this.search_view.drawer.inputs).select(function (g) {
133 return g instanceof openerp.web.search.GroupbyGroup;
136 var filters = _.flatten(_.pluck(groupbygroups, 'filters'), true),
137 groupbys = _.flatten(_.map(filters, function (filter) {
138 var groupby = py.eval(filter.attrs.context).group_by;
139 if (!(groupby instanceof Array)) { groupby = [groupby]; }
140 return _.map(groupby, function(g) {
141 return {field: g, filter: filter};
145 return _.uniq(_.map(groupbys, function (groupby) {
146 var field = groupby.field,
147 filter = groupby.filter,
148 raw_field = field.split(':')[0],
149 string = (field === raw_field) ? filter.attrs.string : self.fields[raw_field].string;
151 filter = (field === raw_field) ? filter : undefined;
153 return { field: raw_field, string: string, filter: filter };
154 }), false, function (filter) {return filter.field;});
157 // Extracts the integer/float fields which are not 'id'
158 get_measures: function() {
159 return _.compact(_.map(this.fields, function (f, id) {
160 if (((f.type === 'integer') || (f.type === 'float')) &&
162 (f.store !== false)) {
163 return {field:id, type: f.type, string: f.string};
168 add_measures_to_options: function() {
169 this.$measure_list.append(
170 _.map(this.measure_list, function (measure) {
171 return $('<li>').append($('<a>').attr('data-choice', measure.field)
173 .text(measure.string));
175 this.$measure_list.find('li').click(this.measure_selection.bind(this));
178 // ----------------------------------------------------------------------
179 // Configuration methods
180 // ----------------------------------------------------------------------
181 set: function (domain, row_groupby, col_groupby, measures_groupby) {
183 this.pivot_options.domain = domain;
184 this.pivot_options.row_groupby = row_groupby;
185 this.pivot_options.col_groupby = col_groupby;
186 this.pivot_options.measures_groupby = measures_groupby;
189 var row_gbs = this.create_field_values(row_groupby),
190 col_gbs = this.create_field_values(col_groupby),
191 measures_gbs = this.create_field_values(measures_groupby),
192 dom_changed = !_.isEqual(this.pivot.domain, domain),
193 row_gb_changed = !_.isEqual(row_gbs, this.pivot.rows.groupby),
194 col_gb_changed = !_.isEqual(col_gbs, this.pivot.cols.groupby),
195 measures_gb_changed = !_.isEqual(measures_gbs, this.pivot.measures),
196 row_reduced = is_strict_beginning_of(row_gbs, this.pivot.rows.groupby),
197 col_reduced = is_strict_beginning_of(col_gbs, this.pivot.cols.groupby),
198 measures_reduced = is_strict_beginning_of(measures_gbs, this.pivot.measures);
200 if (!dom_changed && row_reduced && !col_gb_changed && !measures_gb_changed) {
201 this.pivot.fold_with_depth(this.pivot.rows, row_gbs.length);
205 if (!dom_changed && col_reduced && !row_gb_changed && !measures_gb_changed) {
206 this.pivot.fold_with_depth(this.pivot.cols, col_gbs.length);
211 if (!dom_changed && col_reduced && row_reduced && !measures_gb_changed) {
212 this.pivot.fold_with_depth(this.pivot.rows, row_gbs.length);
213 this.pivot.fold_with_depth(this.pivot.cols, col_gbs.length);
218 if (dom_changed || row_gb_changed || col_gb_changed || measures_gb_changed) {
219 this.pivot.set(domain, row_gbs, col_gbs, measures_gbs).then(this.proxy('display_data'));
222 if (measures_gb_changed) {
223 this.put_measure_checkmarks();
227 set_mode: function (mode) {
230 if (mode === 'pivot') {
231 this.$('.graph_heatmap label').removeClass('disabled');
232 this.$('.graph_main_content').removeClass('graph_chart_mode').addClass('graph_pivot_mode');
234 this.$('.graph_heatmap label').addClass('disabled');
235 this.$('.graph_main_content').removeClass('graph_pivot_mode').addClass('graph_chart_mode');
240 create_field_value: function (f) {
241 var field = (_.contains(f, ':')) ? f.split(':')[0] : f,
242 groupby_field = _.findWhere(this.groupby_fields, {field:field}),
243 string = groupby_field ? groupby_field.string : this.fields[field].string,
244 result = {field: f, string: string, type: this.fields[field].type };
247 result.filter = groupby_field.filter;
253 create_field_values: function (field_ids) {
254 return _.map(field_ids, this.proxy('create_field_value'));
258 get_col_groupbys: function () {
259 return _.pluck(this.pivot.cols.groupby, 'field');
262 get_current_measures: function () {
263 return _.pluck(this.pivot.measures, 'field');
266 // ----------------------------------------------------------------------
268 // ----------------------------------------------------------------------
270 'click .graph_mode_selection label' : 'mode_selection',
271 'click .graph_measure_selection li' : 'measure_selection',
272 'click .graph_options_selection label' : 'option_selection',
273 'click .graph_heatmap label' : 'heatmap_mode_selection',
274 'click .web_graph_click' : 'header_cell_clicked',
275 'click a.field-selection' : 'field_selection',
278 mode_selection: function (event) {
279 event.preventDefault();
280 var mode = event.currentTarget.getAttribute('data-mode');
284 measure_selection: function (event) {
285 event.preventDefault();
286 event.stopPropagation();
287 var measure_field = event.target.getAttribute('data-choice');
289 field: measure_field,
290 type: this.fields[measure_field].type,
291 string: this.fields[measure_field].string
294 this.pivot.toggle_measure(measure).then(this.proxy('display_data'));
295 this.put_measure_checkmarks();
298 put_measure_checkmarks: function () {
300 measures_li = this.$measure_list.find('li');
301 measures_li.removeClass('selected');
302 _.each(this.measure_list, function (measure, index) {
303 if (_.findWhere(self.pivot.measures, measure)) {
304 measures_li.eq(index).addClass('selected');
310 option_selection: function (event) {
311 event.preventDefault();
312 switch (event.currentTarget.getAttribute('data-choice')) {
317 this.pivot.expand_all().then(this.proxy('display_data'));
319 case 'update_values':
320 this.pivot.update_data().then(this.proxy('display_data'));
328 header_cell_clicked: function (event) {
329 event.preventDefault();
330 event.stopPropagation();
331 var id = event.target.getAttribute('data-id'),
332 header = this.pivot.get_header(id),
335 if (header.expanded) {
336 if (header.root === this.pivot.rows) {
337 this.fold_row(header, event);
339 this.fold_col(header);
343 if (header.path.length < header.root.groupby.length) {
344 this.$row_clicked = $(event.target).closest('tr');
348 if (!this.groupby_fields.length) {
352 var fields = _.map(this.groupby_fields, function (field) {
353 return {id: field.field, value: field.string, type:self.fields[field.field.split(':')[0]].type};
356 this.dropdown.remove();
358 this.dropdown = $(QWeb.render('field_selection', {fields:fields, header_id:id}));
359 $(event.target).after(this.dropdown);
362 left:event.originalEvent.layerX,
364 this.$('.field-selection').next('.dropdown-menu').first().toggle();
367 field_selection: function (event) {
368 var id = event.target.getAttribute('data-id'),
369 field_id = event.target.getAttribute('data-field-id'),
371 groupby = this.create_field_value(field_id);
372 event.preventDefault();
373 if (this.fields[field_id].type === 'date' || this.fields[field_id].type === 'datetime') {
374 interval = event.target.getAttribute('data-interval');
375 groupby.field = groupby.field + ':' + interval;
377 this.expand(id, groupby);
380 // ----------------------------------------------------------------------
381 // Pivot Table integration
382 // ----------------------------------------------------------------------
383 expand: function (header_id, groupby) {
385 header = this.pivot.get_header(header_id),
386 update_groupby = !!groupby;
388 groupby = groupby || header.root.groupby[header.path.length];
390 this.pivot.expand(header_id, groupby).then(function () {
391 if (header.root === self.pivot.rows) {
392 // expanding rows can be done by only inserting in the dom
393 // console.log(event.target);
394 var rows = self.build_rows(header.children);
395 var doc_fragment = $(document.createDocumentFragment());
396 rows.map(function (row) {
397 doc_fragment.append(self.draw_row(row, 0));
399 self.$row_clicked.after(doc_fragment);
401 // expanding cols will redraw the full table
404 if (update_groupby && self.graph_view) {
405 self.graph_view.register_groupby(self.pivot.rows.groupby, self.pivot.cols.groupby);
411 fold_row: function (header, event) {
412 var rows_before = this.pivot.rows.headers.length,
413 update_groupby = this.pivot.fold(header),
414 rows_after = this.pivot.rows.headers.length,
415 rows_removed = rows_before - rows_after;
417 if (rows_after === 1) {
418 // probably faster to redraw the unique row instead of removing everything
421 var $row = $(event.target).parent().parent();
422 $row.nextAll().slice(0,rows_removed).remove();
424 if (update_groupby && this.graph_view) {
425 this.graph_view.register_groupby(this.pivot.rows.groupby, this.pivot.cols.groupby);
429 fold_col: function (header) {
430 var update_groupby = this.pivot.fold(header);
433 if (update_groupby && this.graph_view) {
434 this.graph_view.register_groupby(this.pivot.rows.groupby, this.pivot.cols.groupby);
438 swap_axis: function () {
439 this.pivot.swap_axis();
441 this.graph_view.register_groupby(this.pivot.rows.groupby, this.pivot.cols.groupby);
444 // ----------------------------------------------------------------------
445 // Convert Pivot data structure into table structure :
446 // compute rows, cols, colors, cell width, cell height, ...
447 // ----------------------------------------------------------------------
448 build_table: function(raw) {
450 headers: this.build_headers(),
451 measure_row: this.build_measure_row(),
452 rows: this.build_rows(this.pivot.rows.headers,raw),
453 nbr_measures: this.pivot.measures.length,
458 build_headers: function () {
459 var pivot = this.pivot,
460 nbr_measures = pivot.measures.length,
461 height = _.max(_.map(pivot.cols.headers, function(g) {return g.path.length;})) + 1,
464 _.each(pivot.cols.headers, function (col) {
465 var cell_width = nbr_measures * (col.expanded ? pivot.get_ancestor_leaves(col).length : 1),
466 cell_height = col.expanded ? 1 : height - col.path.length,
467 cell = {width: cell_width, height: cell_height, title: col.title, id: col.id, expanded: col.expanded};
468 if (rows[col.path.length]) {
469 rows[col.path.length].push(cell);
471 rows[col.path.length] = [cell];
475 if (pivot.get_cols_leaves().length > 1) {
476 rows[0].push({width: nbr_measures, height: height, title: ' ', id: pivot.main_col().id });
478 if (pivot.cols.headers.length === 1) {
479 rows = [[{width: nbr_measures, height: 1, title: _t('Total'), id: pivot.main_col().id, expanded: false}]];
484 build_measure_row: function () {
485 var nbr_leaves = this.pivot.get_cols_leaves().length,
486 nbr_cols = nbr_leaves + ((nbr_leaves > 1) ? 1 : 0),
488 add_total = this.pivot.get_cols_leaves().length > 1,
490 for (i = 0; i < nbr_cols; i++) {
491 for (m = 0; m < this.pivot.measures.length; m++) {
493 text:this.pivot.measures[m].string,
494 is_bold: add_total && (i === nbr_cols - 1)
501 make_cell: function (row, col, value, index, raw) {
502 var formatted_value = raw && !_.isUndefined(value) ? value : openerp.web.format_value(value, {type:this.pivot.measures[index].type}),
503 cell = {value:formatted_value};
508 build_rows: function (headers, raw) {
511 m, i, j, k, cell, row;
514 var cells, pivot_cells, values;
516 var nbr_of_rows = headers.length;
517 var col_headers = pivot.get_cols_leaves();
519 for (i = 0; i < nbr_of_rows; i++) {
523 for (j = 0; j < pivot.cells.length; j++) {
524 if (pivot.cells[j].x == row.id || pivot.cells[j].y == row.id) {
525 pivot_cells.push(pivot.cells[j]);
529 for (j = 0; j < col_headers.length; j++) {
531 for (k = 0; k < pivot_cells.length; k++) {
532 if (pivot_cells[k].x == col_headers[j].id || pivot_cells[k].y == col_headers[j].id) {
533 values = pivot_cells[k].values;
537 if (!values) { values = new Array(pivot.measures.length);}
538 for (m = 0; m < pivot.measures.length; m++) {
539 cells.push(self.make_cell(row,col_headers[j],values[m], m, raw));
542 if (col_headers.length > 1) {
543 var totals = pivot.get_total(row);
544 for (m = 0; m < pivot.measures.length; m++) {
545 cell = self.make_cell(row, pivot.cols.headers[0], totals[m], m, raw);
546 cell.is_bold = 'true';
552 indent: row.path.length,
554 expanded: row.expanded,
562 // ----------------------------------------------------------------------
563 // Main display method
564 // ----------------------------------------------------------------------
565 display_data: function () {
566 var scroll = $(window).scrollTop();
567 this.$('.graph_main_content svg').remove();
568 this.$('.graph_main_content div').remove();
570 this.$('.graph_options_selection label').last().toggleClass('disabled', this.pivot.no_data);
571 this.width = this.$el.width();
572 this.height = Math.min(Math.max(document.documentElement.clientHeight - 116 - 60, 250), Math.round(0.8*this.$el.width()));
574 this.$('.graph_header').toggle(this.visible_ui);
575 if (this.pivot.no_data) {
576 this.$('.graph_main_content').append($(QWeb.render('graph_no_data')));
578 if (this.mode === 'pivot') {
580 $(window).scrollTop(scroll);
582 this.$('.graph_main_content').append($('<div><svg>'));
583 this.svg = this.$('.graph_main_content svg')[0];
589 // ----------------------------------------------------------------------
591 // ----------------------------------------------------------------------
592 draw_table: function () {
593 var custom_gbs = this.graph_view.get_custom_filter_groupbys(),
594 frozen_rows = custom_gbs.groupby.length,
595 frozen_cols = custom_gbs.col_groupby.length;
597 var table = this.build_table();
598 var doc_fragment = $(document.createDocumentFragment());
599 this.draw_headers(table.headers, doc_fragment, frozen_cols);
600 this.draw_measure_row(table.measure_row, doc_fragment);
601 this.draw_rows(table.rows, doc_fragment, frozen_rows);
602 this.table.append(doc_fragment);
605 make_header_cell: function (header, frozen) {
606 var cell = (_.has(header, 'cells') ? $('<td>') : $('<th>'))
607 .addClass('graph_border')
608 .attr('rowspan', header.height)
609 .attr('colspan', header.width);
610 var $content = $('<span>').attr('href','#')
611 .text(' ' + (header.title || _t('Undefined')))
612 .css('margin-left', header.indent*30 + 'px')
613 .attr('data-id', header.id);
614 if (_.has(header, 'expanded')) {
615 if (('indent' in header) && header.indent >= frozen) {
616 $content.addClass(header.expanded ? 'fa fa-minus-square' : 'fa fa-plus-square');
617 $content.addClass('web_graph_click');
619 if (!('indent' in header) && header.lvl >= frozen) {
620 $content.addClass(header.expanded ? 'fa fa-minus-square' : 'fa fa-plus-square');
621 $content.addClass('web_graph_click');
624 $content.css('font-weight', 'bold');
626 return cell.append($content);
629 draw_headers: function (headers, doc_fragment, frozen_cols) {
630 var make_cell = this.make_header_cell,
631 $empty_cell = $('<th>').attr('rowspan', headers.length),
632 $thead = $('<thead>');
634 _.each(headers, function (row, lvl) {
635 var $row = $('<tr>');
636 _.each(row, function (header) {
638 $row.append(make_cell(header, frozen_cols));
642 $thead.children(':first').prepend($empty_cell);
643 doc_fragment.append($thead);
644 this.$thead = $thead;
647 draw_measure_row: function (measure_row) {
648 var $row = $('<tr>').append('<th>');
649 _.each(measure_row, function (cell) {
650 var $cell = $('<th>').addClass('measure_row').text(cell.text);
651 if (cell.is_bold) {$cell.css('font-weight', 'bold');}
654 this.$thead.append($row);
657 draw_row: function (row, frozen_rows) {
659 .attr('data-indent', row.indent)
660 .append(this.make_header_cell(row, frozen_rows));
662 var cells_length = row.cells.length;
666 for (var j = 0; j < cells_length; j++) {
669 if (cell.is_bold || cell.color) {
671 if (cell.is_bold) hcell += 'font-weight: bold;';
672 if (cell.color) hcell += 'background-color:' + $.Color(255, cell.color, cell.color) + ';';
675 hcell += '>' + cell.value + '</td>';
676 cells_list[j] = hcell;
678 return $row.append(cells_list.join(''));
681 draw_rows: function (rows, doc_fragment, frozen_rows) {
682 var rows_length = rows.length,
683 $tbody = $('<tbody>');
685 doc_fragment.append($tbody);
686 for (var i = 0; i < rows_length; i++) {
687 $tbody.append(this.draw_row(rows[i], frozen_rows));
691 // ----------------------------------------------------------------------
692 // Drawing charts code
693 // ----------------------------------------------------------------------
696 dim_x = this.pivot.rows.groupby.length,
697 dim_y = this.pivot.cols.groupby.length,
698 show_controls = (this.width > 400 && this.height > 300 && dim_x + dim_y >=2),
702 if ((dim_x === 0) && (dim_y === 0)) {
703 data = [{key: _t('Total'), values:[{
705 y: this.pivot.get_total()[0],
707 // Only column groupbys
708 } else if ((dim_x === 0) && (dim_y >= 1)){
709 data = _.map(this.pivot.get_cols_with_depth(1), function (header) {
712 values: [{x:header.title, y: self.pivot.get_total(header)[0]}]
715 // Just 1 row groupby
716 } else if ((dim_x === 1) && (dim_y === 0)) {
717 data = _.map(this.pivot.main_row().children, function (pt) {
718 var value = self.pivot.get_total(pt)[0],
719 title = (pt.title !== undefined) ? pt.title : _t('Undefined');
720 return {x: title, y: value};
722 data = [{key: self.pivot.measures[0].string, values:data}];
723 // 1 row groupby and some col groupbys
724 } else if ((dim_x === 1) && (dim_y >= 1)) {
725 data = _.map(this.pivot.get_cols_with_depth(1), function (colhdr) {
726 var values = _.map(self.pivot.get_rows_with_depth(1), function (header) {
728 x: header.title || _t('Undefined'),
729 y: self.pivot.get_values(header.id, colhdr.id)[0] || 0
732 return {key: colhdr.title || _t('Undefined'), values: values};
734 // At least two row groupby
736 var keys = _.uniq(_.map(this.pivot.get_rows_with_depth(2), function (hdr) {
737 return hdr.title || _t('Undefined');
739 data = _.map(keys, function (key) {
740 var values = _.map(self.pivot.get_rows_with_depth(1), function (hdr) {
741 var subhdr = _.find(hdr.children, function (child) {
742 return ((child.title === key) || ((child.title === undefined) && (key === _t('Undefined'))));
745 x: hdr.title || _t('Undefined'),
746 y: (subhdr) ? self.pivot.get_total(subhdr)[0] : 0
749 return {key:key, values: values};
753 nv.addGraph(function () {
754 var chart = nv.models.multiBarChart()
756 .stacked(self.bar_ui === 'stack')
757 .showControls(show_controls);
759 if (self.width / data[0].values.length < 80) {
760 chart.rotateLabels(-15);
761 chart.reduceXTicks(true);
762 chart.margin({bottom:40});
767 .attr('width', self.width)
768 .attr('height', self.height)
771 nv.utils.windowResize(chart.update);
779 dim_x = this.pivot.rows.groupby.length,
780 dim_y = this.pivot.cols.groupby.length;
782 var rows = this.pivot.get_rows_with_depth(dim_x),
783 labels = _.pluck(rows, 'title');
785 var data = _.map(this.pivot.get_cols_leaves(), function (col) {
786 var values = _.map(rows, function (row, index) {
787 return {x: index, y: self.pivot.get_values(row.id,col.id)[0] || 0};
789 var title = _.map(col.path, function (p) {
790 return p || _t('Undefined');
793 title = self.pivot.measures[0].string;
795 return {values: values, key: title};
798 nv.addGraph(function () {
799 var chart = nv.models.lineChart()
800 .x(function (d,u) { return u; });
802 chart.xAxis.tickFormat(function (d,u) {return labels[d];});
805 .attr('width', self.width)
806 .attr('height', self.height)
816 dim_x = this.pivot.rows.groupby.length;
817 var data = _.map(this.pivot.get_rows_leaves(), function (row) {
818 var title = _.map(row.path, function (p) {
819 return p || _t('Undefined');
822 title = self.measure_label;
824 return {x: title, y: self.pivot.get_total(row)[0]};
827 nv.addGraph(function () {
828 var chart = nv.models.pieChart()
831 .color(d3.scale.category10().range());
835 .transition().duration(1200)
836 .attr('width', self.width)
837 .attr('height', self.height)
840 nv.utils.windowResize(chart.update);
845 // ----------------------------------------------------------------------
846 // Controller stuff...
847 // ----------------------------------------------------------------------
848 export_xls: function() {
849 var c = openerp.webclient.crashmanager;
850 openerp.web.blockUI();
851 this.session.get_file({
852 url: '/web_graph/export_xls',
853 data: {data: JSON.stringify(this.build_table(true))},
854 complete: openerp.web.unblockUI,
855 error: c.rpc_error.bind(c)
861 // Utility function: returns true if the beginning of array2 is array1 and
862 // if array1 is not array2
863 function is_strict_beginning_of (array1, array2) {
864 if (array1.length >= array2.length) { return false; }
866 for (var i = 0; i < array1.length; i++) {
867 if (!_.isEqual(array1[i], array2[i])) { return false;}