[IMP] OPW 579391: update code to move selection field ordering fix to final graph_dat...
authorXavier ALT <xal@openerp.com>
Thu, 29 Nov 2012 08:41:50 +0000 (09:41 +0100)
committerXavier ALT <xal@openerp.com>
Thu, 29 Nov 2012 08:41:50 +0000 (09:41 +0100)
bzr revid: xal@openerp.com-20121129084150-j4s2cfmod7ml6v62

addons/web_graph/static/src/js/graph.js

index f9c95a3..af7c5f4 100644 (file)
@@ -104,9 +104,6 @@ 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) {
@@ -173,11 +170,15 @@ openerp.web_graph.GraphView = openerp.web.View.extend({
 
             if (!r) { graph_data.push(datapoint); }
         });
-        if(self.fields[self.abscissa].type != 'selection'){
-           graph_data = _(graph_data).sortBy(function (point) {
-               return point[self.abscissa] + '[[--]]' + point[self.group_field];
-           });
-        }
+        graph_data = _(graph_data).sortBy(function (point) {
+            var point_abscissa = point[self.abscissa];
+            if (self.fields[self.abscissa].type == 'selection') {
+                var selection_index = _.chain(self.fields[self.abscissa].selection)
+                                        .pluck(1).indexOf(point_abscissa).value();
+                point_abscissa = _.str.sprintf('%08d', selection_index);
+            }
+            return point_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") {
@@ -396,20 +397,6 @@ 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