diff options
| author | Gery Debongnie <ged@openerp.com> | 2013-11-24 15:52:40 +0100 |
|---|---|---|
| committer | Gery Debongnie <ged@openerp.com> | 2013-11-24 15:52:40 +0100 |
| commit | 5173a56db659f91eb71255bcecb0cfe072f54cdb (patch) | |
| tree | 7720fe8b43317f1ee91aec96307f68fbbb1235ca /addons/web_graph/static/src/js | |
| parent | aa5958eaf5bab2bc193eea7e1a1e76644967b9ce (diff) | |
[IMP] add heat map functionality to pivot table (addon web_graph)
bzr revid: ged@openerp.com-20131124145240-dn5vq5ecb598gf4e
Diffstat (limited to 'addons/web_graph/static/src/js')
| -rw-r--r-- | addons/web_graph/static/src/js/graph.js | 21 | ||||
| -rw-r--r-- | addons/web_graph/static/src/js/pivot.js | 4 |
2 files 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 c0ccb80285a..037a07c60ec 100644 --- a/addons/web_graph/static/src/js/graph.js +++ b/addons/web_graph/static/src/js/graph.js @@ -77,6 +77,11 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.pivot_table.fold_cols(); this.draw_table(); }, + + 'click label.graph_heat_map' : function (event) { + this.heat_map_mode = !this.heat_map_mode; + this.draw_table(); + }, }, view_loading: function (fields_view_get) { @@ -90,6 +95,7 @@ instance.web_graph.GraphView = instance.web.View.extend({ row_groupby = []; this.pivot_table = null; + this.heat_map_mode = false; // get the default groupbys and measure defined in the field view _.each(fields_view_get.arch.children, function (field) { @@ -300,7 +306,8 @@ instance.web_graph.GraphView = instance.web.View.extend({ }, draw_row: function (row) { - var pivot = this.pivot_table, + var self = this, + pivot = this.pivot_table, html_row = $('<tr></tr>'), row_header = this.make_border_cell(1,1) .append(this.make_header_title(row).attr('data-row-id', row.id)) @@ -314,7 +321,17 @@ instance.web_graph.GraphView = instance.web.View.extend({ _.each(pivot.cols.headers, function (col) { if (col.children.length === 0) { - var cell = $('<td></td>').append(pivot.get_value(row.id, col.id)); + var value = pivot.get_value(row.id, col.id), + cell = $('<td></td>'); + + cell.append((value === undefined) ? '' : value); + if ((self.heat_map_mode) && (value !== undefined)) { + // heat map + console.log("heat map", self.heat_map_mode, pivot.total); + var ratio = Math.floor(70 + 185*(pivot.total - value)/pivot.total); + console.log("ratio",ratio); + cell.css("background-color", "rgb(255," + ratio + "," + ratio + ")"); + } html_row.append(cell); } }); diff --git a/addons/web_graph/static/src/js/pivot.js b/addons/web_graph/static/src/js/pivot.js index 06b8a97a05d..99bc20b1015 100644 --- a/addons/web_graph/static/src/js/pivot.js +++ b/addons/web_graph/static/src/js/pivot.js @@ -38,6 +38,7 @@ var PivotTable = openerp.web.Class.extend({ this.domain = options.domain; this.measure = options.measure; this.measure_label = options.measure_label; + this.total = 0; }, // Load initial data into the rows, cols and cells array. @@ -50,6 +51,7 @@ var PivotTable = openerp.web.Class.extend({ .then(function (total) { var val = total[0].attributes.aggregates[self.measure]; self.set_value(self.rows.main.id, self.cols.main.id, val); + self.total = val; }); return $.when(total, initial_group); @@ -79,7 +81,7 @@ var PivotTable = openerp.web.Class.extend({ var cell = _.find(this.cells, function (c) { return ((c.row_id == row) && (c.col_id == col)); }); - return (cell) ? cell.value : ''; + return (cell === undefined) ? undefined : cell.value; }, get_col: function (id) { |
