From 00cb732ea03ed398a31ca0b8a6b8fe3a6749d245 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 22 Apr 2014 16:59:18 +0200 Subject: [FIX] only hide the export button (and not all the config buttons) in graph view when the module xlwt is not installed (addon web) bzr revid: ged@openerp.com-20140422145918-s20n3qla1nfte5dj --- addons/web_graph/static/src/js/graph_widget.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web_graph/static/src/js/graph_widget.js') diff --git a/addons/web_graph/static/src/js/graph_widget.js b/addons/web_graph/static/src/js/graph_widget.js index 317ea6cbfb9..7666b345700 100644 --- a/addons/web_graph/static/src/js/graph_widget.js +++ b/addons/web_graph/static/src/js/graph_widget.js @@ -44,7 +44,7 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ } openerp.session.rpc('/web_graph/check_xlwt').then(function (result) { - self.$('.graph_options_selection label').toggle(result); + self.$('.graph_options_selection label').last().toggle(result); }); return this.model.call('fields_get', []).then(function (f) { -- cgit v1.2.3 From c3c56bb2b1a1f3a8000c9a974e403b11f83ed060 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 22 Apr 2014 16:59:55 +0200 Subject: [FIX] disable export to xls button in graph view when there are no data to export, this prevent a crash (addon web) bzr revid: ged@openerp.com-20140422145955-vfls1hxktnq8m67b --- addons/web_graph/static/src/js/graph_widget.js | 1 + 1 file changed, 1 insertion(+) (limited to 'addons/web_graph/static/src/js/graph_widget.js') diff --git a/addons/web_graph/static/src/js/graph_widget.js b/addons/web_graph/static/src/js/graph_widget.js index 7666b345700..5222e505253 100644 --- a/addons/web_graph/static/src/js/graph_widget.js +++ b/addons/web_graph/static/src/js/graph_widget.js @@ -502,6 +502,7 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ this.$('.graph_main_content div').remove(); this.table.empty(); this.table.toggleClass('heatmap', this.heatmap_mode !== 'none'); + this.$('.graph_options_selection label').last().toggleClass('disabled', this.pivot.no_data); this.width = this.$el.width(); this.height = Math.min(Math.max(document.documentElement.clientHeight - 116 - 60, 250), Math.round(0.8*this.$el.width())); -- cgit v1.2.3 From 8c001acda0726042f52f30b37a5f7b266d069c5f Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 22 Apr 2014 17:02:09 +0200 Subject: [FIX] in graph view, save the scrolling position and use it when redrawing the table (addon web_graph) bzr revid: ged@openerp.com-20140422150209-f06ffxry1h46cpfh --- addons/web_graph/static/src/js/graph_widget.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'addons/web_graph/static/src/js/graph_widget.js') diff --git a/addons/web_graph/static/src/js/graph_widget.js b/addons/web_graph/static/src/js/graph_widget.js index 5222e505253..1cac1051ec7 100644 --- a/addons/web_graph/static/src/js/graph_widget.js +++ b/addons/web_graph/static/src/js/graph_widget.js @@ -26,6 +26,8 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ this.graph_view = options.graph_view || null; this.pivot_options = options; this.title = options.title || 'Data'; + + this.scroll = 0; }, start: function() { @@ -305,11 +307,11 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ if (header.expanded) { this.fold(header); return; - } + } if (header.path.length < header.root.groupby.length) { this.expand(id); return; - } + } if (!this.important_fields.length) { return; } @@ -354,6 +356,7 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ groupby = groupby || header.root.groupby[header.path.length]; this.pivot.expand(header_id, groupby).then(function () { + self.scroll = $(window).scrollTop(); if (update_groupby && self.graph_view) { self.graph_view.register_groupby(self.pivot.rows.groupby, self.pivot.cols.groupby); } @@ -512,6 +515,7 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ } else { if (this.mode === 'pivot') { this.draw_table(); + $(window).scrollTop(this.scroll); } else { this.$('.graph_main_content').append($('
')); this.svg = this.$('.graph_main_content svg')[0]; -- cgit v1.2.3 From f584b030bc869277f8ae2573e125b347d579364c Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 22 Apr 2014 17:03:16 +0200 Subject: [FIX] correct fix for the scrolling problem in graph view: the view now saves its scrolling position before redrawing itself (addon web_graph) bzr revid: ged@openerp.com-20140422150316-m51u750732re8qib --- addons/web_graph/static/src/js/graph_widget.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'addons/web_graph/static/src/js/graph_widget.js') diff --git a/addons/web_graph/static/src/js/graph_widget.js b/addons/web_graph/static/src/js/graph_widget.js index 1cac1051ec7..3d3c8b77513 100644 --- a/addons/web_graph/static/src/js/graph_widget.js +++ b/addons/web_graph/static/src/js/graph_widget.js @@ -26,8 +26,6 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ this.graph_view = options.graph_view || null; this.pivot_options = options; this.title = options.title || 'Data'; - - this.scroll = 0; }, start: function() { @@ -356,7 +354,6 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ groupby = groupby || header.root.groupby[header.path.length]; this.pivot.expand(header_id, groupby).then(function () { - self.scroll = $(window).scrollTop(); if (update_groupby && self.graph_view) { self.graph_view.register_groupby(self.pivot.rows.groupby, self.pivot.cols.groupby); } @@ -501,6 +498,7 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ // Main display method // ---------------------------------------------------------------------- display_data: function () { + var scroll = $(window).scrollTop(); this.$('.graph_main_content svg').remove(); this.$('.graph_main_content div').remove(); this.table.empty(); @@ -515,7 +513,7 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ } else { if (this.mode === 'pivot') { this.draw_table(); - $(window).scrollTop(this.scroll); + $(window).scrollTop(scroll); } else { this.$('.graph_main_content').append($('
')); this.svg = this.$('.graph_main_content svg')[0]; -- cgit v1.2.3 From 394897383fb0d6f278a89d5a7dffb7e74857a59c Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 22 Apr 2014 17:04:01 +0200 Subject: [FIX] correct the scaling problem of graph bar charts: nvd3 needs a numeric value and was given a [value]. Also, improves the margin of bar/line/pie charts (addon web_graph) bzr revid: ged@openerp.com-20140422150401-p0t9xmittp73j7hx --- addons/web_graph/static/src/js/graph_widget.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'addons/web_graph/static/src/js/graph_widget.js') diff --git a/addons/web_graph/static/src/js/graph_widget.js b/addons/web_graph/static/src/js/graph_widget.js index 3d3c8b77513..1941047c437 100644 --- a/addons/web_graph/static/src/js/graph_widget.js +++ b/addons/web_graph/static/src/js/graph_widget.js @@ -611,7 +611,7 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ if ((dim_x === 0) && (dim_y === 0)) { data = [{key: _t('Total'), values:[{ x: _t('Total'), - y: this.pivot.get_total(), + y: this.pivot.get_total()[0], }]}]; // Only column groupbys } else if ((dim_x === 0) && (dim_y >= 1)){ @@ -624,7 +624,7 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ // Just 1 row groupby } else if ((dim_x === 1) && (dim_y === 0)) { data = _.map(this.pivot.main_row().children, function (pt) { - var value = self.pivot.get_total(pt), + var value = self.pivot.get_total(pt)[0], title = (pt.title !== undefined) ? pt.title : _t('Undefined'); return {x: title, y: value}; }); @@ -661,8 +661,6 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ nv.addGraph(function () { var chart = nv.models.multiBarChart() - .width(self.width) - .height(self.height) .reduceXTicks(false) .stacked(self.bar_ui === 'stack') .showControls(show_controls); @@ -705,10 +703,7 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ nv.addGraph(function () { var chart = nv.models.lineChart() - .x(function (d,u) { return u; }) - .width(self.width) - .height(self.height) - .margin({top: 30, right: 20, bottom: 20, left: 60}); + .x(function (d,u) { return u; }); d3.select(self.svg) .attr('width', self.width) @@ -730,14 +725,14 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ if (dim_x === 0) { title = self.measure_label; } - return {x: title, y: self.pivot.get_total(row)}; + return {x: title, y: self.pivot.get_total(row)[0]}; }); nv.addGraph(function () { var chart = nv.models.pieChart() - .color(d3.scale.category10().range()) .width(self.width) - .height(self.height); + .height(self.height) + .color(d3.scale.category10().range()); d3.select(self.svg) .datum(data) -- cgit v1.2.3 From 0241b762b21ea66efc91cc78133463bc9e683ef2 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 22 Apr 2014 17:04:41 +0200 Subject: [FIX] fix line chart x-axis labels: it now correctly uses the name of the row, and not a number (addon web_graph) bzr revid: ged@openerp.com-20140422150441-3vll2jw69z319yza --- addons/web_graph/static/src/js/graph_widget.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'addons/web_graph/static/src/js/graph_widget.js') diff --git a/addons/web_graph/static/src/js/graph_widget.js b/addons/web_graph/static/src/js/graph_widget.js index 1941047c437..9091bf2b4da 100644 --- a/addons/web_graph/static/src/js/graph_widget.js +++ b/addons/web_graph/static/src/js/graph_widget.js @@ -688,9 +688,12 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ dim_x = this.pivot.rows.groupby.length, dim_y = this.pivot.cols.groupby.length; + var rows = this.pivot.get_rows_with_depth(dim_x), + labels = _.pluck(rows, 'title'); + var data = _.map(this.pivot.get_cols_leaves(), function (col) { - var values = _.map(self.pivot.get_rows_with_depth(dim_x), function (row) { - return {x: row.title, y: self.pivot.get_values(row.id,col.id)[0] || 0}; + var values = _.map(rows, function (row, index) { + return {x: index, y: self.pivot.get_values(row.id,col.id)[0] || 0}; }); var title = _.map(col.path, function (p) { return p || _t('Undefined'); @@ -705,6 +708,8 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ var chart = nv.models.lineChart() .x(function (d,u) { return u; }); + chart.xAxis.tickFormat(function (d,u) {return labels[d];}); + d3.select(self.svg) .attr('width', self.width) .attr('height', self.height) -- cgit v1.2.3 From 065b3c2176b8a7df31eeca2d2a6c87b27dd4a4fb Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Mon, 28 Apr 2014 11:02:21 +0200 Subject: [IMP] add the expand all button back to the graph view It was removed a long time ago, but it looks like the 'expand all' button is useful enough to make a comeback. Also, this commit removes a few useless lines in graph_widget about the grouped/stacked status of bar charts bzr revid: ged@openerp.com-20140428090221-po3ksrd73093w3qm --- addons/web_graph/static/src/js/graph_widget.js | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'addons/web_graph/static/src/js/graph_widget.js') diff --git a/addons/web_graph/static/src/js/graph_widget.js b/addons/web_graph/static/src/js/graph_widget.js index 317ea6cbfb9..923b488d17a 100644 --- a/addons/web_graph/static/src/js/graph_widget.js +++ b/addons/web_graph/static/src/js/graph_widget.js @@ -260,21 +260,12 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ option_selection: function (event) { event.preventDefault(); switch (event.currentTarget.getAttribute('data-choice')) { - case 'bar_grouped': - this.bar_ui = 'group'; - if (this.mode === 'bar') { - this.display_data(); - } - break; - case 'bar_stacked': - this.bar_ui = 'stack'; - if (this.mode === 'bar') { - this.display_data(); - } - break; case 'swap_axis': this.swap_axis(); break; + case 'expand_all': + this.pivot.expand_all().then(this.proxy('display_data')); + break; case 'update_values': this.pivot.update_data().then(this.proxy('display_data')); break; -- cgit v1.2.3 From 36e3aac85ef60e39371d848bebcac265981d87f2 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 30 Apr 2014 09:47:33 +0200 Subject: [IMP] large optimizations to the graph view rendering (pivot table) The pivot table rendering was slow with large tables : it appended to the table each line, so the browser had to rerender each time the page. This was solved by rendering the table to a document fragment, then only add the fragment to the main document. This speeds up considerably the process (from 2600ms to 420ms in one test) Also, uses basic loops instead of underscore maps in the build_rows method bzr revid: ged@openerp.com-20140430074733-quhfkzz33rlpahps --- addons/web_graph/static/src/js/graph_widget.js | 115 +++++++++++++++---------- 1 file changed, 71 insertions(+), 44 deletions(-) (limited to 'addons/web_graph/static/src/js/graph_widget.js') diff --git a/addons/web_graph/static/src/js/graph_widget.js b/addons/web_graph/static/src/js/graph_widget.js index 317ea6cbfb9..d6f9b929dea 100644 --- a/addons/web_graph/static/src/js/graph_widget.js +++ b/addons/web_graph/static/src/js/graph_widget.js @@ -453,45 +453,55 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ build_rows: function (raw) { var self = this, pivot = this.pivot, - m, i, cell; - - return _.map(pivot.rows.headers, function (row) { - var cells = []; - var pivot_cells = []; - for (i = 0; i < pivot.cells.length; i++) { - if (pivot.cells[i].x == row.id || pivot.cells[i].y == row.id) { - pivot_cells.push(pivot.cells[i]); - } + m, i, j, k, cell, row; + + var rows = []; + var cells, pivot_cells, values; + + var nbr_of_rows = pivot.rows.headers.length; + var col_headers = pivot.get_cols_leaves(); + + for (i = 0; i < nbr_of_rows; i++) { + row = pivot.rows.headers[i]; + cells = []; + pivot_cells = []; + for (j = 0; j < pivot.cells.length; j++) { + if (pivot.cells[j].x == row.id || pivot.cells[j].y == row.id) { + pivot_cells.push(pivot.cells[j]); + } } - _.each(pivot.get_cols_leaves(), function (col) { - var values; - for (i = 0; i < pivot_cells.length; i++) { - if (pivot_cells[i].x == col.id || pivot_cells[i].y == col.id) { - values = pivot_cells[i].values; + + for (j = 0; j < col_headers.length; j++) { + values = undefined; + for (k = 0; k < pivot_cells.length; k++) { + if (pivot_cells[k].x == col_headers[j].id || pivot_cells[k].y == col_headers[j].id) { + values = pivot_cells[k].values; break; - } + } } if (!values) { values = new Array(pivot.measures.length);} for (m = 0; m < pivot.measures.length; m++) { - cells.push(self.make_cell(row,col,values[m], m, raw)); + cells.push(self.make_cell(row,col_headers[j],values[m], m, raw)); } - }); - if (pivot.get_cols_leaves().length > 1) { + } + if (col_headers.length > 1) { var totals = pivot.get_total(row); for (m = 0; m < pivot.measures.length; m++) { - cell = self.make_cell(row, pivot.main_col(), totals[m], m, raw); + cell = self.make_cell(row, pivot.cols.headers[0], totals[m], m, raw); cell.is_bold = 'true'; cells.push(cell); } } - return { + rows.push({ id: row.id, indent: row.path.length, title: row.title, expanded: row.expanded, cells: cells, - }; - }); + }); + } + + return rows; }, // ---------------------------------------------------------------------- @@ -524,9 +534,11 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ // ---------------------------------------------------------------------- draw_table: function () { var table = this.build_table(); - this.draw_headers(table.headers); - this.draw_measure_row(table.measure_row); - this.draw_rows(table.rows); + var doc_fragment = $(document.createDocumentFragment()); + this.draw_headers(table.headers, doc_fragment); + this.draw_measure_row(table.measure_row, doc_fragment); + this.draw_rows(table.rows, doc_fragment); + this.table.append(doc_fragment); }, make_header_cell: function (header) { @@ -549,7 +561,7 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ return cell.append(content); }, - draw_headers: function (headers) { + draw_headers: function (headers, doc_fragment) { var make_cell = this.make_header_cell, empty_cell = $('').attr('rowspan', headers.length), thead = $(''); @@ -562,10 +574,11 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ thead.append(html_row); }); thead.children(':first').prepend(empty_cell); - this.table.append(thead); + doc_fragment.append(thead); + this.thead = thead; }, - draw_measure_row: function (measure_row) { + draw_measure_row: function (measure_row, doc_fragment) { if (this.pivot.measures.length === 1) { return; } var html_row = $('
').append(''); _.each(measure_row, function (cell) { @@ -573,25 +586,39 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ if (cell.is_bold) {measure_cell.css('font-weight', 'bold');} html_row.append(measure_cell); }); - this.$('thead').append(html_row); + this.thead.append(html_row); }, - draw_rows: function (rows) { - var table = this.table, - make_cell = this.make_header_cell; - - _.each(rows, function (row) { - var html_row = $('
').append(make_cell(row)); - _.each(row.cells, function (cell) { - var html_cell = $('').text(cell.value); - if (_.has(cell, 'color')) { - html_cell.css('background-color', $.Color(255, cell.color, cell.color)); + draw_rows: function (rows, doc_fragment) { + var make_cell = this.make_header_cell, + cell, + html_row, i, j; + + var cells_list, + hcell, + rows_length, cells_length; + + rows_length = rows.length; + for (i = 0; i < rows_length; i++) { + html_row = $('
').append(make_cell(rows[i])); + cells_length = rows[i].cells.length; + cells_list = []; + + for (j = 0; j < cells_length; j++) { + cell = rows[i].cells[j]; + hcell = ''; + cells_list[j] = hcell; + } + html_row.append(cells_list.join('')); + doc_fragment.append($('').append(html_row)); + } }, // ---------------------------------------------------------------------- -- cgit v1.2.3 From 1f693aaed6f6e28a384f20d357f8a3f558d33f6a Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 30 Apr 2014 10:49:27 +0200 Subject: [FIX] fix a crash in graphview when user clicked rapidly twice on menu item The issue was that the get_search_fields method tried to get the view's corresponding searchview after a rpc (fields_get). Sadly, if the user had meanwhile clicked again on the menu item, the first view would be detached from the view manager and would be unable to reach the search view. The solution is to move the lookup for the search view in the start method, where it is guaranteed to exist. bzr revid: ged@openerp.com-20140430084927-m11dxqg9ko0dnu08 --- addons/web_graph/static/src/js/graph_widget.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'addons/web_graph/static/src/js/graph_widget.js') diff --git a/addons/web_graph/static/src/js/graph_widget.js b/addons/web_graph/static/src/js/graph_widget.js index d6f9b929dea..84ca75ddda2 100644 --- a/addons/web_graph/static/src/js/graph_widget.js +++ b/addons/web_graph/static/src/js/graph_widget.js @@ -43,6 +43,13 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ this.$('.graph_main_content').addClass('graph_pivot_mode'); } + // get search view + var parent = this.getParent(); + while (!(parent instanceof openerp.web.ViewManager)) { + parent = parent.getParent(); + } + this.search_view = parent.searchview; + openerp.session.rpc('/web_graph/check_xlwt').then(function (result) { self.$('.graph_options_selection label').toggle(result); }); @@ -76,16 +83,9 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ // this method gets the fields that appear in the search view, under the // 'Groupby' heading get_search_fields: function () { - var self = this, - parent = this.getParent(); - - while (!(parent instanceof openerp.web.ViewManager)) { - parent = parent.getParent(); - } - - var search_view = parent.searchview; + var self = this; - var groupbygroups = _(search_view.inputs).select(function (g) { + var groupbygroups = _(this.search_view.inputs).select(function (g) { return g instanceof openerp.web.search.GroupbyGroup; }); -- cgit v1.2.3