From b72d0b4b0cce67dedcbafa6d2d957473dbb84ee7 Mon Sep 17 00:00:00 2001 From: msh-openerp Date: Mon, 24 Sep 2012 10:35:58 +0530 Subject: [PATCH] [FIX]Fixed the issue of graph sorted data on x-axis, when there is month or states on x-axis it should come in the order in which they are defined, the data like state or month generally stored in selection field and if there is grouping on selection field then data should come in order which they are defined in the code. bzr revid: msh@tinyerp.com-20120924050558-550kn31vmc5qcdqb --- addons/web_graph/static/src/js/graph.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js index 7396d46af10..f9c95a3c1b6 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -104,6 +104,9 @@ openerp.web_graph.GraphView = openerp.web.View.extend({ if (this.group_field) { fields.push(this.group_field); } // transform search result into usable records (convert from OpenERP // value shapes to usable atomic types + if(self.fields[self.abscissa].type == 'selection'){ + results = self.sortSelection(results); + } var records = _(results).map(function (result) { var point = {}; _(result).each(function (value, field) { @@ -170,9 +173,11 @@ openerp.web_graph.GraphView = openerp.web.View.extend({ if (!r) { graph_data.push(datapoint); } }); - graph_data = _(graph_data).sortBy(function (point) { - return point[self.abscissa] + '[[--]]' + point[self.group_field]; - }); + if(self.fields[self.abscissa].type != 'selection'){ + graph_data = _(graph_data).sortBy(function (point) { + return point[self.abscissa] + '[[--]]' + point[self.group_field]; + }); + } if (_.include(['bar','line','area'],this.chart)) { return this.schedule_bar_line_area(graph_data); } else if (this.chart == "pie") { @@ -391,6 +396,20 @@ openerp.web_graph.GraphView = openerp.web.View.extend({ } this.renderer = setTimeout(renderer, 0); }, + sortSelection: function(results){ + var self = this; + var grouped_data = _(results).groupBy(function(result){ + return result[self.abscissa]; + }); + var options = _(self.fields[self.abscissa].selection).map(function(option){ return option[0]; }) + var sorted_data = _(options).chain().map(function(option){ + return grouped_data[option]; + }).filter(function(data){ return data != undefined; }).value(); + if(sorted_data.length){ + sorted_data = _.reduceRight(sorted_data, function(a, b){ return b.concat(a);}) + } + return sorted_data; + }, open_list_view : function (id){ var self = this; // unconditionally nuke tooltips before switching view