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('Quantity')};
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:'Quantity'}]);
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 () {
128 var groupbygroups = _(this.search_view.drawer.inputs).select(function (g) {
129 return g instanceof openerp.web.search.GroupbyGroup;
132 var filters = _.flatten(_.pluck(groupbygroups, 'filters'), true),
133 groupbys = _.flatten(_.map(filters, function (filter) {
134 var groupby = py.eval(filter.attrs.context).group_by;
135 if (!(groupby instanceof Array)) { groupby = [groupby]; }
136 return _.map(groupby, function(g) {
137 return {field: g, filter: filter};
141 return _.uniq(_.map(groupbys, function (groupby) {
142 var field = groupby.field,
143 filter = groupby.filter,
144 raw_field = field.split(':')[0],
145 string = (field === raw_field) ? filter.attrs.string : self.fields[raw_field].string;
147 filter = (field === raw_field) ? filter : undefined;
149 return { field: raw_field, string: string, filter: filter };
150 }), false, function (filter) {return filter.field;});
153 // Extracts the integer/float fields which are not 'id'
154 get_measures: function() {
155 return _.compact(_.map(this.fields, function (f, id) {
156 if (((f.type === 'integer') || (f.type === 'float')) &&
158 (f.store !== false)) {
159 return {field:id, type: f.type, string: f.string};
164 add_measures_to_options: function() {
165 this.$measure_list.append(
166 _.map(this.measure_list, function (measure) {
167 return $('<li>').append($('<a>').attr('data-choice', measure.field)
169 .text(measure.string));
171 this.$measure_list.find('li').click(this.measure_selection.bind(this));
174 // ----------------------------------------------------------------------
175 // Configuration methods
176 // ----------------------------------------------------------------------
177 set: function (domain, row_groupby, col_groupby, measures_groupby) {
179 this.pivot_options.domain = domain;
180 this.pivot_options.row_groupby = row_groupby;
181 this.pivot_options.col_groupby = col_groupby;
182 this.pivot_options.measures_groupby = measures_groupby;
185 var row_gbs = this.create_field_values(row_groupby),
186 col_gbs = this.create_field_values(col_groupby),
187 measures_gbs = this.create_field_values(measures_groupby),
188 dom_changed = !_.isEqual(this.pivot.domain, domain),
189 row_gb_changed = !_.isEqual(row_gbs, this.pivot.rows.groupby),
190 col_gb_changed = !_.isEqual(col_gbs, this.pivot.cols.groupby),
191 measures_gb_changed = !_.isEqual(measures_gbs, this.pivot.measures),
192 row_reduced = is_strict_beginning_of(row_gbs, this.pivot.rows.groupby),
193 col_reduced = is_strict_beginning_of(col_gbs, this.pivot.cols.groupby),
194 measures_reduced = is_strict_beginning_of(measures_gbs, this.pivot.measures);
196 if (!dom_changed && row_reduced && !col_gb_changed && !measures_gb_changed) {
197 this.pivot.fold_with_depth(this.pivot.rows, row_gbs.length);
201 if (!dom_changed && col_reduced && !row_gb_changed && !measures_gb_changed) {
202 this.pivot.fold_with_depth(this.pivot.cols, col_gbs.length);
207 if (!dom_changed && col_reduced && row_reduced && !measures_gb_changed) {
208 this.pivot.fold_with_depth(this.pivot.rows, row_gbs.length);
209 this.pivot.fold_with_depth(this.pivot.cols, col_gbs.length);
214 if (dom_changed || row_gb_changed || col_gb_changed || measures_gb_changed) {
215 this.pivot.set(domain, row_gbs, col_gbs, measures_gbs).then(this.proxy('display_data'));
218 if (measures_gb_changed) {
219 this.put_measure_checkmarks();
223 set_mode: function (mode) {
226 if (mode === 'pivot') {
227 this.$('.graph_heatmap label').removeClass('disabled');
228 this.$('.graph_main_content').removeClass('graph_chart_mode').addClass('graph_pivot_mode');
230 this.$('.graph_heatmap label').addClass('disabled');
231 this.$('.graph_main_content').removeClass('graph_pivot_mode').addClass('graph_chart_mode');
236 create_field_value: function (f) {
237 var field = (_.contains(f, ':')) ? f.split(':')[0] : f,
238 groupby_field = _.findWhere(this.groupby_fields, {field:field}),
239 string = groupby_field ? groupby_field.string : this.fields[field].string,
240 result = {field: f, string: string, type: this.fields[field].type };
243 result.filter = groupby_field.filter;
249 create_field_values: function (field_ids) {
250 return _.map(field_ids, this.proxy('create_field_value'));
254 get_col_groupbys: function () {
255 return _.pluck(this.pivot.cols.groupby, 'field');
258 get_current_measures: function () {
259 return _.pluck(this.pivot.measures, 'field');
262 // ----------------------------------------------------------------------
264 // ----------------------------------------------------------------------
266 'click .graph_mode_selection label' : 'mode_selection',
267 'click .graph_measure_selection li' : 'measure_selection',
268 'click .graph_options_selection label' : 'option_selection',
269 'click .graph_heatmap label' : 'heatmap_mode_selection',
270 'click .web_graph_click' : 'header_cell_clicked',
271 'click a.field-selection' : 'field_selection',
274 mode_selection: function (event) {
275 event.preventDefault();
276 var mode = event.currentTarget.getAttribute('data-mode');
280 measure_selection: function (event) {
281 event.preventDefault();
282 event.stopPropagation();
283 var measure_field = event.target.getAttribute('data-choice');
285 field: measure_field,
286 type: this.fields[measure_field].type,
287 string: this.fields[measure_field].string
290 this.pivot.toggle_measure(measure).then(this.proxy('display_data'));
291 this.put_measure_checkmarks();
294 put_measure_checkmarks: function () {
296 measures_li = this.$measure_list.find('li');
297 measures_li.removeClass('selected');
298 _.each(this.measure_list, function (measure, index) {
299 if (_.findWhere(self.pivot.measures, measure)) {
300 measures_li.eq(index).addClass('selected');
306 option_selection: function (event) {
307 event.preventDefault();
308 switch (event.currentTarget.getAttribute('data-choice')) {
313 this.pivot.expand_all().then(this.proxy('display_data'));
315 case 'update_values':
316 this.pivot.update_data().then(this.proxy('display_data'));
324 header_cell_clicked: function (event) {
325 event.preventDefault();
326 event.stopPropagation();
327 var id = event.target.getAttribute('data-id'),
328 header = this.pivot.get_header(id),
331 if (header.expanded) {
332 if (header.root === this.pivot.rows) {
333 this.fold_row(header, event);
335 this.fold_col(header);
339 if (header.path.length < header.root.groupby.length) {
340 this.$row_clicked = $(event.target).closest('tr');
344 if (!this.groupby_fields.length) {
348 var fields = _.map(this.groupby_fields, function (field) {
349 return {id: field.field, value: field.string, type:self.fields[field.field.split(':')[0]].type};
352 this.dropdown.remove();
354 this.dropdown = $(QWeb.render('field_selection', {fields:fields, header_id:id}));
355 $(event.target).after(this.dropdown);
358 left:event.originalEvent.layerX,
360 this.$('.field-selection').next('.dropdown-menu').first().toggle();
363 field_selection: function (event) {
364 var id = event.target.getAttribute('data-id'),
365 field_id = event.target.getAttribute('data-field-id'),
367 groupby = this.create_field_value(field_id);
368 event.preventDefault();
369 if (this.fields[field_id].type === 'date' || this.fields[field_id].type === 'datetime') {
370 interval = event.target.getAttribute('data-interval');
371 groupby.field = groupby.field + ':' + interval;
373 this.expand(id, groupby);
376 // ----------------------------------------------------------------------
377 // Pivot Table integration
378 // ----------------------------------------------------------------------
379 expand: function (header_id, groupby) {
381 header = this.pivot.get_header(header_id),
382 update_groupby = !!groupby;
384 groupby = groupby || header.root.groupby[header.path.length];
386 this.pivot.expand(header_id, groupby).then(function () {
387 if (header.root === self.pivot.rows) {
388 // expanding rows can be done by only inserting in the dom
389 // console.log(event.target);
390 var rows = self.build_rows(header.children);
391 var doc_fragment = $(document.createDocumentFragment());
392 rows.map(function (row) {
393 doc_fragment.append(self.draw_row(row, 0));
395 self.$row_clicked.after(doc_fragment);
397 // expanding cols will redraw the full table
400 if (update_groupby && self.graph_view) {
401 self.graph_view.register_groupby(self.pivot.rows.groupby, self.pivot.cols.groupby);
407 fold_row: function (header, event) {
408 var rows_before = this.pivot.rows.headers.length,
409 update_groupby = this.pivot.fold(header),
410 rows_after = this.pivot.rows.headers.length,
411 rows_removed = rows_before - rows_after;
413 if (rows_after === 1) {
414 // probably faster to redraw the unique row instead of removing everything
417 var $row = $(event.target).parent().parent();
418 $row.nextAll().slice(0,rows_removed).remove();
420 if (update_groupby && this.graph_view) {
421 this.graph_view.register_groupby(this.pivot.rows.groupby, this.pivot.cols.groupby);
425 fold_col: function (header) {
426 var update_groupby = this.pivot.fold(header);
429 if (update_groupby && this.graph_view) {
430 this.graph_view.register_groupby(this.pivot.rows.groupby, this.pivot.cols.groupby);
434 swap_axis: function () {
435 this.pivot.swap_axis();
437 this.graph_view.register_groupby(this.pivot.rows.groupby, this.pivot.cols.groupby);
440 // ----------------------------------------------------------------------
441 // Convert Pivot data structure into table structure :
442 // compute rows, cols, colors, cell width, cell height, ...
443 // ----------------------------------------------------------------------
444 build_table: function(raw) {
446 headers: this.build_headers(),
447 measure_row: this.build_measure_row(),
448 rows: this.build_rows(this.pivot.rows.headers,raw),
449 nbr_measures: this.pivot.measures.length,
454 build_headers: function () {
455 var pivot = this.pivot,
456 nbr_measures = pivot.measures.length,
457 height = _.max(_.map(pivot.cols.headers, function(g) {return g.path.length;})) + 1,
460 _.each(pivot.cols.headers, function (col) {
461 var cell_width = nbr_measures * (col.expanded ? pivot.get_ancestor_leaves(col).length : 1),
462 cell_height = col.expanded ? 1 : height - col.path.length,
463 cell = {width: cell_width, height: cell_height, title: col.title, id: col.id, expanded: col.expanded};
464 if (rows[col.path.length]) {
465 rows[col.path.length].push(cell);
467 rows[col.path.length] = [cell];
471 if (pivot.get_cols_leaves().length > 1) {
472 rows[0].push({width: nbr_measures, height: height, title: ' ', id: pivot.main_col().id });
474 if (pivot.cols.headers.length === 1) {
475 rows = [[{width: nbr_measures, height: 1, title: _t('Total'), id: pivot.main_col().id, expanded: false}]];
480 build_measure_row: function () {
481 var nbr_leaves = this.pivot.get_cols_leaves().length,
482 nbr_cols = nbr_leaves + ((nbr_leaves > 1) ? 1 : 0),
484 add_total = this.pivot.get_cols_leaves().length > 1,
486 for (i = 0; i < nbr_cols; i++) {
487 for (m = 0; m < this.pivot.measures.length; m++) {
489 text:this.pivot.measures[m].string,
490 is_bold: add_total && (i === nbr_cols - 1)
497 make_cell: function (row, col, value, index, raw) {
498 var formatted_value = raw && !_.isUndefined(value) ? value : openerp.web.format_value(value, {type:this.pivot.measures[index].type}),
499 cell = {value:formatted_value};
504 build_rows: function (headers, raw) {
507 m, i, j, k, cell, row;
510 var cells, pivot_cells, values;
512 var nbr_of_rows = headers.length;
513 var col_headers = pivot.get_cols_leaves();
515 for (i = 0; i < nbr_of_rows; i++) {
519 for (j = 0; j < pivot.cells.length; j++) {
520 if (pivot.cells[j].x == row.id || pivot.cells[j].y == row.id) {
521 pivot_cells.push(pivot.cells[j]);
525 for (j = 0; j < col_headers.length; j++) {
527 for (k = 0; k < pivot_cells.length; k++) {
528 if (pivot_cells[k].x == col_headers[j].id || pivot_cells[k].y == col_headers[j].id) {
529 values = pivot_cells[k].values;
533 if (!values) { values = new Array(pivot.measures.length);}
534 for (m = 0; m < pivot.measures.length; m++) {
535 cells.push(self.make_cell(row,col_headers[j],values[m], m, raw));
538 if (col_headers.length > 1) {
539 var totals = pivot.get_total(row);
540 for (m = 0; m < pivot.measures.length; m++) {
541 cell = self.make_cell(row, pivot.cols.headers[0], totals[m], m, raw);
542 cell.is_bold = 'true';
548 indent: row.path.length,
550 expanded: row.expanded,
558 // ----------------------------------------------------------------------
559 // Main display method
560 // ----------------------------------------------------------------------
561 display_data: function () {
562 var scroll = $(window).scrollTop();
563 this.$('.graph_main_content svg').remove();
564 this.$('.graph_main_content div').remove();
566 this.$('.graph_options_selection label').last().toggleClass('disabled', this.pivot.no_data);
567 this.width = this.$el.width();
568 this.height = Math.min(Math.max(document.documentElement.clientHeight - 116 - 60, 250), Math.round(0.8*this.$el.width()));
570 this.$('.graph_header').toggle(this.visible_ui);
571 if (this.pivot.no_data) {
572 this.$('.graph_main_content').append($(QWeb.render('graph_no_data')));
574 if (this.mode === 'pivot') {
576 $(window).scrollTop(scroll);
578 this.$('.graph_main_content').append($('<div><svg>'));
579 this.svg = this.$('.graph_main_content svg')[0];
585 // ----------------------------------------------------------------------
587 // ----------------------------------------------------------------------
588 draw_table: function () {
589 var custom_gbs = this.graph_view.get_custom_filter_groupbys(),
590 frozen_rows = custom_gbs.groupby.length,
591 frozen_cols = custom_gbs.col_groupby.length;
593 var table = this.build_table();
594 var doc_fragment = $(document.createDocumentFragment());
595 this.draw_headers(table.headers, doc_fragment, frozen_cols);
596 this.draw_measure_row(table.measure_row, doc_fragment);
597 this.draw_rows(table.rows, doc_fragment, frozen_rows);
598 this.table.append(doc_fragment);
601 make_header_cell: function (header, frozen) {
602 var cell = (_.has(header, 'cells') ? $('<td>') : $('<th>'))
603 .addClass('graph_border')
604 .attr('rowspan', header.height)
605 .attr('colspan', header.width);
606 var $content = $('<span>').attr('href','#')
607 .text(' ' + (header.title || _t('Undefined')))
608 .css('margin-left', header.indent*30 + 'px')
609 .attr('data-id', header.id);
610 if (_.has(header, 'expanded')) {
611 if (('indent' in header) && header.indent >= frozen) {
612 $content.addClass(header.expanded ? 'fa fa-minus-square' : 'fa fa-plus-square');
613 $content.addClass('web_graph_click');
615 if (!('indent' in header) && header.lvl >= frozen) {
616 $content.addClass(header.expanded ? 'fa fa-minus-square' : 'fa fa-plus-square');
617 $content.addClass('web_graph_click');
620 $content.css('font-weight', 'bold');
622 return cell.append($content);
625 draw_headers: function (headers, doc_fragment, frozen_cols) {
626 var make_cell = this.make_header_cell,
627 $empty_cell = $('<th>').attr('rowspan', headers.length),
628 $thead = $('<thead>');
630 _.each(headers, function (row, lvl) {
631 var $row = $('<tr>');
632 _.each(row, function (header) {
634 $row.append(make_cell(header, frozen_cols));
638 $thead.children(':first').prepend($empty_cell);
639 doc_fragment.append($thead);
640 this.$thead = $thead;
643 draw_measure_row: function (measure_row) {
644 var $row = $('<tr>').append('<th>');
645 _.each(measure_row, function (cell) {
646 var $cell = $('<th>').addClass('measure_row').text(cell.text);
647 if (cell.is_bold) {$cell.css('font-weight', 'bold');}
650 this.$thead.append($row);
653 draw_row: function (row, frozen_rows) {
655 .attr('data-indent', row.indent)
656 .append(this.make_header_cell(row, frozen_rows));
658 var cells_length = row.cells.length;
662 for (var j = 0; j < cells_length; j++) {
665 if (cell.is_bold || cell.color) {
667 if (cell.is_bold) hcell += 'font-weight: bold;';
668 if (cell.color) hcell += 'background-color:' + $.Color(255, cell.color, cell.color) + ';';
671 hcell += '>' + cell.value + '</td>';
672 cells_list[j] = hcell;
674 return $row.append(cells_list.join(''));
677 draw_rows: function (rows, doc_fragment, frozen_rows) {
678 var rows_length = rows.length,
679 $tbody = $('<tbody>');
681 doc_fragment.append($tbody);
682 for (var i = 0; i < rows_length; i++) {
683 $tbody.append(this.draw_row(rows[i], frozen_rows));
687 // ----------------------------------------------------------------------
688 // Drawing charts code
689 // ----------------------------------------------------------------------
692 dim_x = this.pivot.rows.groupby.length,
693 dim_y = this.pivot.cols.groupby.length,
694 show_controls = (this.width > 400 && this.height > 300 && dim_x + dim_y >=2),
698 if ((dim_x === 0) && (dim_y === 0)) {
699 data = [{key: _t('Total'), values:[{
701 y: this.pivot.get_total()[0],
703 // Only column groupbys
704 } else if ((dim_x === 0) && (dim_y >= 1)){
705 data = _.map(this.pivot.get_cols_with_depth(1), function (header) {
708 values: [{x:header.title, y: self.pivot.get_total(header)[0]}]
711 // Just 1 row groupby
712 } else if ((dim_x === 1) && (dim_y === 0)) {
713 data = _.map(this.pivot.main_row().children, function (pt) {
714 var value = self.pivot.get_total(pt)[0],
715 title = (pt.title !== undefined) ? pt.title : _t('Undefined');
716 return {x: title, y: value};
718 data = [{key: self.pivot.measures[0].string, values:data}];
719 // 1 row groupby and some col groupbys
720 } else if ((dim_x === 1) && (dim_y >= 1)) {
721 data = _.map(this.pivot.get_cols_with_depth(1), function (colhdr) {
722 var values = _.map(self.pivot.get_rows_with_depth(1), function (header) {
724 x: header.title || _t('Undefined'),
725 y: self.pivot.get_values(header.id, colhdr.id)[0] || 0
728 return {key: colhdr.title || _t('Undefined'), values: values};
730 // At least two row groupby
732 var keys = _.uniq(_.map(this.pivot.get_rows_with_depth(2), function (hdr) {
733 return hdr.title || _t('Undefined');
735 data = _.map(keys, function (key) {
736 var values = _.map(self.pivot.get_rows_with_depth(1), function (hdr) {
737 var subhdr = _.find(hdr.children, function (child) {
738 return ((child.title === key) || ((child.title === undefined) && (key === _t('Undefined'))));
741 x: hdr.title || _t('Undefined'),
742 y: (subhdr) ? self.pivot.get_total(subhdr)[0] : 0
745 return {key:key, values: values};
749 nv.addGraph(function () {
750 var chart = nv.models.multiBarChart()
752 .stacked(self.bar_ui === 'stack')
753 .showControls(show_controls);
755 if (self.width / data[0].values.length < 80) {
756 chart.rotateLabels(-15);
757 chart.reduceXTicks(true);
758 chart.margin({bottom:40});
763 .attr('width', self.width)
764 .attr('height', self.height)
767 nv.utils.windowResize(chart.update);
775 dim_x = this.pivot.rows.groupby.length,
776 dim_y = this.pivot.cols.groupby.length;
778 var rows = this.pivot.get_rows_with_depth(dim_x),
779 labels = _.pluck(rows, 'title');
781 var data = _.map(this.pivot.get_cols_leaves(), function (col) {
782 var values = _.map(rows, function (row, index) {
783 return {x: index, y: self.pivot.get_values(row.id,col.id)[0] || 0};
785 var title = _.map(col.path, function (p) {
786 return p || _t('Undefined');
789 title = self.pivot.measures[0].string;
791 return {values: values, key: title};
794 nv.addGraph(function () {
795 var chart = nv.models.lineChart()
796 .x(function (d,u) { return u; });
798 chart.xAxis.tickFormat(function (d,u) {return labels[d];});
801 .attr('width', self.width)
802 .attr('height', self.height)
812 dim_x = this.pivot.rows.groupby.length;
813 var data = _.map(this.pivot.get_rows_leaves(), function (row) {
814 var title = _.map(row.path, function (p) {
815 return p || _t('Undefined');
818 title = self.measure_label;
820 return {x: title, y: self.pivot.get_total(row)[0]};
823 nv.addGraph(function () {
824 var chart = nv.models.pieChart()
827 .color(d3.scale.category10().range());
831 .transition().duration(1200)
832 .attr('width', self.width)
833 .attr('height', self.height)
836 nv.utils.windowResize(chart.update);
841 // ----------------------------------------------------------------------
842 // Controller stuff...
843 // ----------------------------------------------------------------------
844 export_xls: function() {
845 var c = openerp.webclient.crashmanager;
846 openerp.web.blockUI();
847 this.session.get_file({
848 url: '/web_graph/export_xls',
849 data: {data: JSON.stringify(this.build_table(true))},
850 complete: openerp.web.unblockUI,
851 error: c.rpc_error.bind(c)
857 // Utility function: returns true if the beginning of array2 is array1 and
858 // if array1 is not array2
859 function is_strict_beginning_of (array1, array2) {
860 if (array1.length >= array2.length) { return false; }
862 for (var i = 0; i < array1.length; i++) {
863 if (!_.isEqual(array1[i], array2[i])) { return false;}