From 00cb732ea03ed398a31ca0b8a6b8fe3a6749d245 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 22 Apr 2014 16:59:18 +0200 Subject: [PATCH 1/6] [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(-) 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) { From c3c56bb2b1a1f3a8000c9a974e403b11f83ed060 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 22 Apr 2014 16:59:55 +0200 Subject: [PATCH 2/6] [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(+) 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())); From 8c001acda0726042f52f30b37a5f7b266d069c5f Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 22 Apr 2014 17:02:09 +0200 Subject: [PATCH 3/6] [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(-) 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]; From f584b030bc869277f8ae2573e125b347d579364c Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 22 Apr 2014 17:03:16 +0200 Subject: [PATCH 4/6] [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/static/src/js/search.js | 27 ++++++++++++------- addons/web_graph/static/src/js/graph_view.js | 4 +-- .../web_graph/static/src/js/graph_widget.js | 6 ++--- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/addons/web/static/src/js/search.js b/addons/web/static/src/js/search.js index 04bb1a61d99..251f1977332 100644 --- a/addons/web/static/src/js/search.js +++ b/addons/web/static/src/js/search.js @@ -29,8 +29,8 @@ my.Facet = B.Model.extend({ B.Model.prototype.initialize.apply(this, arguments); this.values = new my.FacetValues(values || []); - this.values.on('add remove change reset', function () { - this.trigger('change', this); + this.values.on('add remove change reset', function (_, options) { + this.trigger('change', this, options); }, this); }, get: function (key) { @@ -399,7 +399,8 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea this.setup_global_completion(); this.query = new my.SearchQuery() .on('add change reset remove', this.proxy('do_search')) - .on('add change reset remove', this.proxy('renderFacets')); + .on('change', this.proxy('renderChangedFacets')) + .on('add reset remove', this.proxy('renderFacets')); if (this.options.hidden) { this.$el.hide(); @@ -578,14 +579,20 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea .trigger('blur'); }, /** - * - * @param {openerp.web.search.SearchQuery | openerp.web.search.Facet} _1 - * @param {openerp.web.search.Facet} [_2] + * Call the renderFacets method with the correct arguments. + * This is due to the fact that change events are called with two arguments + * (model, options) while add, reset and remove events are called with + * (collection, model, options) as arguments + */ + renderChangedFacets: function (model, options) { + this.renderFacets(undefined, model, options); + }, + /** + * @param {openerp.web.search.SearchQuery | undefined} Undefined if event is change + * @param {openerp.web.search.Facet} * @param {Object} [options] */ - renderFacets: function (_1, _2, options) { - // _1: model if event=change, otherwise collection - // _2: undefined if event=change, otherwise model + renderFacets: function (collection, model, options) { var self = this; var started = []; var $e = this.$('div.oe_searchview_facets'); @@ -610,6 +617,7 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea }); $.when.apply(null, started).then(function () { + if (options && options.focus_input === false) return; var input_to_focus; // options.at: facet inserted at given index, focus next input // otherwise just focus last input @@ -618,7 +626,6 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea } else { input_to_focus = self.input_subviews[(options.at + 1) * 2]; } - input_to_focus.$el.focus(); }); }, diff --git a/addons/web_graph/static/src/js/graph_view.js b/addons/web_graph/static/src/js/graph_view.js index 25a1f932cc4..e4e074b2e7f 100644 --- a/addons/web_graph/static/src/js/graph_view.js +++ b/addons/web_graph/static/src/js/graph_view.js @@ -167,7 +167,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ row_search_facet = query.findWhere({category:'GroupBy'}); if (row_search_facet) { - row_search_facet.values.reset(row_facet.values); + row_search_facet.values.reset(row_facet.values, {focus_input:false}); } else { if (row_groupby.length) { query.add(row_facet); @@ -181,7 +181,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ col_search_facet = query.findWhere({category:'ColGroupBy'}); if (col_search_facet) { - col_search_facet.values.reset(col_facet.values); + col_search_facet.values.reset(col_facet.values, {focus_input:false}); } else { if (col_groupby.length) { query.add(col_facet); 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]; From 394897383fb0d6f278a89d5a7dffb7e74857a59c Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 22 Apr 2014 17:04:01 +0200 Subject: [PATCH 5/6] [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(-) 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) From 0241b762b21ea66efc91cc78133463bc9e683ef2 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 22 Apr 2014 17:04:41 +0200 Subject: [PATCH 6/6] [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(-) 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)