[REF] adds a 'get_total' method and simplify a few parts of the code using totals (addon web_graph)
bzr revid: ged@openerp.com-20131128094746-mthch89zqx66flq7
This commit is contained in:
parent
d790f8e96f
commit
4aa70638ef
|
@ -363,8 +363,7 @@ instance.web_graph.GraphView = instance.web.View.extend({
|
|||
});
|
||||
|
||||
if (pivot.cols.main.children.length > 0) {
|
||||
var row_total = pivot.get_value(row.id, pivot.cols.main.id),
|
||||
cell = make_cell(row_total, pivot.cols.main)
|
||||
var cell = make_cell(pivot.get_total(row), pivot.cols.main)
|
||||
.css('font-weight', 'bold');
|
||||
html_row.append(cell);
|
||||
}
|
||||
|
@ -384,16 +383,17 @@ instance.web_graph.GraphView = instance.web.View.extend({
|
|||
}
|
||||
cell.append(value);
|
||||
if (self.mode === 'heatmap') {
|
||||
color = Math.floor(50 + 205*(pivot.total - value)/pivot.total);
|
||||
total = pivot.get_total();
|
||||
color = Math.floor(50 + 205*(total - value)/total);
|
||||
cell.css('background-color', $.Color(255, color, color));
|
||||
}
|
||||
if (self.mode === 'row_heatmap') {
|
||||
total = pivot.get_value(row.id, pivot.cols.main.id);
|
||||
total = pivot.get_total(row);
|
||||
color = Math.floor(50 + 205*(total - value)/total);
|
||||
cell.css('background-color', $.Color(255, color, color));
|
||||
}
|
||||
if (self.mode === 'col_heatmap') {
|
||||
total = pivot.get_value(col.id, pivot.rows.main.id);
|
||||
total = pivot.get_total(col);
|
||||
color = Math.floor(50 + 205*(total - value)/total);
|
||||
cell.css('background-color', $.Color(255, color, color));
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
|
|||
this.model = options.model;
|
||||
this.domain = options.domain;
|
||||
this.measure = options.measure;
|
||||
this.total = 0;
|
||||
this.id_seed = 0;
|
||||
this.no_data = true;
|
||||
},
|
||||
|
@ -168,7 +167,6 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
|
|||
self.cells = result.cells;
|
||||
self.rows.main = self.rows.headers[0];
|
||||
self.cols.main = self.cols.headers[0];
|
||||
self.total = self.rows.main.total;
|
||||
self.rows.main.title = '';
|
||||
self.cols.main.title = '';
|
||||
_.each(self.rows.headers, function (row) {
|
||||
|
@ -186,6 +184,15 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
|
|||
});
|
||||
},
|
||||
|
||||
get_total: function (header) {
|
||||
if (header) {
|
||||
var main = (header.root === this.rows) ? this.cols.main : this.rows.main;
|
||||
return this.get_value(header.id, main.id);
|
||||
} else {
|
||||
return this.rows.main.total;
|
||||
}
|
||||
},
|
||||
|
||||
update_values: function () {
|
||||
var self = this;
|
||||
return this.query_all_values().then(function (result) {
|
||||
|
@ -226,8 +233,6 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
|
|||
return updated_headers;
|
||||
}
|
||||
|
||||
// now some more tweaks
|
||||
self.total = self.rows.main.total;
|
||||
_.each(self.rows.headers, function (row) {
|
||||
row.root = self.rows;
|
||||
});
|
||||
|
@ -341,7 +346,6 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
|
|||
function make_tree_headers (data_pt, parent, max_depth) {
|
||||
var node = {
|
||||
id: self.generate_id(),
|
||||
total: data_pt.attributes.aggregates[self.measure],
|
||||
path: parent.path.concat(data_pt.attributes.value[1]),
|
||||
title: data_pt.attributes.value[1],
|
||||
domain: data_pt.model._domain,
|
||||
|
|
Loading…
Reference in New Issue