[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
This commit is contained in:
msh-openerp
2012-09-24 10:35:58 +05:30
parent a6fa3ac71b
commit b72d0b4b0c
+22 -3
View File
@@ -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