diff --git a/pivot_heat_map/README.rst b/pivot_heat_map/README.rst new file mode 100644 index 000000000..7448fc6bd --- /dev/null +++ b/pivot_heat_map/README.rst @@ -0,0 +1,39 @@ +====================== +Heat Map in Pivot View +====================== + +Added option for heat map in pivot view. + +Installation +============ + +Select the module and install it, there are no other setups needed. + +Usage +===== + +Go to the pivot view, and there will be three new buttons, Heatmap Page, Heatmap Row and Heatmap Colomn. +After setting up the table, click on the button to activate heatmap. + +Known issues / Roadmap +====================== + +* ... + +Bug Tracker +=========== + +Contact odoo@cybrosys.com + +Contributors +------------ + +* Linto CT +* Faslu CA + +Maintainer +---------- + +This module is maintained by Cybrosys Technologies. + +For support and more information, please visit https://www.cybrosys.com. diff --git a/pivot_heat_map/__init__.py b/pivot_heat_map/__init__.py new file mode 100644 index 000000000..158a0001c --- /dev/null +++ b/pivot_heat_map/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- + +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2018-TODAY Cybrosys Technologies(). +# Author: LINTO C T() +# you can modify it under the terms of the GNU LESSER +# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. +# +# It is forbidden to publish, distribute, sublicense, or sell copies +# of the Software or modified copies of the Software. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. +# +# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE +# GENERAL PUBLIC LICENSE (LGPL v3) along with this program. +# If not, see . +# +############################################################################## diff --git a/pivot_heat_map/__manifest__.py b/pivot_heat_map/__manifest__.py new file mode 100644 index 000000000..46b5370e2 --- /dev/null +++ b/pivot_heat_map/__manifest__.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- + +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2018-TODAY Cybrosys Technologies(). +# Author: LINTO C T() +# you can modify it under the terms of the GNU LESSER +# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. +# +# It is forbidden to publish, distribute, sublicense, or sell copies +# of the Software or modified copies of the Software. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. +# +# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE +# GENERAL PUBLIC LICENSE (LGPL v3) along with this program. +# If not, see . +# +############################################################################## + +{ + 'name': 'Heat Map in Pivot View', + 'version': '11.0.1.0.0', + 'summary': 'Heat Map in Pivot View', + 'category': 'Reporting', + 'author': 'Cybrosys Techno Solutions', + 'company': 'Cybrosys Techno Solutions', + 'maintainer': 'Cybrosys Techno Solutions', + 'depends': ['web'], + 'website': 'https://www.cybrosys.com', + 'data': [ + 'views/templates.xml', + ], + 'qweb': ["static/src/xml/*.xml"], + 'images': ['static/description/banner.jpg'], + 'license': 'LGPL-3', + 'installable': True, + 'auto_install': False, + 'application': False, +} diff --git a/pivot_heat_map/static/description/banner.jpg b/pivot_heat_map/static/description/banner.jpg new file mode 100644 index 000000000..e65b090cc Binary files /dev/null and b/pivot_heat_map/static/description/banner.jpg differ diff --git a/pivot_heat_map/static/description/cybro_logo.png b/pivot_heat_map/static/description/cybro_logo.png new file mode 100644 index 000000000..bb309114c Binary files /dev/null and b/pivot_heat_map/static/description/cybro_logo.png differ diff --git a/pivot_heat_map/static/description/heat_map_col.png b/pivot_heat_map/static/description/heat_map_col.png new file mode 100644 index 000000000..4ba1acd38 Binary files /dev/null and b/pivot_heat_map/static/description/heat_map_col.png differ diff --git a/pivot_heat_map/static/description/heat_map_page.png b/pivot_heat_map/static/description/heat_map_page.png new file mode 100644 index 000000000..9bff9d15f Binary files /dev/null and b/pivot_heat_map/static/description/heat_map_page.png differ diff --git a/pivot_heat_map/static/description/heat_map_row.png b/pivot_heat_map/static/description/heat_map_row.png new file mode 100644 index 000000000..b6536ed55 Binary files /dev/null and b/pivot_heat_map/static/description/heat_map_row.png differ diff --git a/pivot_heat_map/static/description/icon.png b/pivot_heat_map/static/description/icon.png new file mode 100644 index 000000000..3a5b4bea3 Binary files /dev/null and b/pivot_heat_map/static/description/icon.png differ diff --git a/pivot_heat_map/static/description/index.html b/pivot_heat_map/static/description/index.html new file mode 100644 index 000000000..737913f25 --- /dev/null +++ b/pivot_heat_map/static/description/index.html @@ -0,0 +1,101 @@ +
+
+

Heat Map in Pivot View

+

+

Cybrosys Technologies

+
+
+

Features:

+
+ Heat Map for Pivot View
+
+
+
+ +
+
+
+

Overview

+

+ Heat map can be used to color the entries in the pivot view. The coloring will be + in a format where the maximum value will be shown in a dark color and next largest value + will be in a lighter color than the maximum one. + This applies for all the values in the table. +

+
+
+
+ +
+
+
New buttons in the pivot view.
+
+
+ +
+
+
+
+
Clicking on these buttons will enable the + corresponding heat map. +
+
+
+
+ +
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+ +
+

Need Any Help?

+ +
diff --git a/pivot_heat_map/static/description/pivot_buttons.png b/pivot_heat_map/static/description/pivot_buttons.png new file mode 100644 index 000000000..c170f1479 Binary files /dev/null and b/pivot_heat_map/static/description/pivot_buttons.png differ diff --git a/pivot_heat_map/static/src/img/icon.png b/pivot_heat_map/static/src/img/icon.png new file mode 100644 index 000000000..3a5b4bea3 Binary files /dev/null and b/pivot_heat_map/static/src/img/icon.png differ diff --git a/pivot_heat_map/static/src/js/pivot_controller_extended.js b/pivot_heat_map/static/src/js/pivot_controller_extended.js new file mode 100644 index 000000000..ca447ca56 --- /dev/null +++ b/pivot_heat_map/static/src/js/pivot_controller_extended.js @@ -0,0 +1,52 @@ +odoo.define('pivot_heat_map.controllers', function (require) { + "use strict"; + + var PivotController = require('web.PivotController'); + var PivotRenderer = require('web.PivotRenderer'); + + PivotController.include({ + init: function (parent, model, renderer, params) { + renderer.heat_map = null; + renderer.cells = {}; + this._super(parent, model, renderer, params); + }, + _onButtonClick: function (event) { + var $target = $(event.target); + this._super(event); + /* catching heat map button click and switching between modes*/ + if ($target.hasClass('o_heat_map_col')) { + if (this.renderer.heat_map == 'col' ){ + this.renderer.heat_map = null; + } + else{ + this.renderer.cells = {}; + this.renderer.heat_map = 'col'; + } + + this.renderer._render(); + } + else if ($target.hasClass('o_heat_map_row')) { + if (this.renderer.heat_map == 'row'){ + this.renderer.heat_map = null; + } + else{ + this.renderer.cells = {}; + this.renderer.heat_map = 'row'; + } + + this.renderer._render(); + } + else if ($target.hasClass('o_heat_map_both')) { + if (this.renderer.heat_map == 'both'){ + this.renderer.heat_map = null; + } + else{ + this.renderer.cells = {}; + this.renderer.heat_map = 'both'; + } + + this.renderer._render(); + } + } + }); +}); diff --git a/pivot_heat_map/static/src/js/pivot_renderer_extended.js b/pivot_heat_map/static/src/js/pivot_renderer_extended.js new file mode 100644 index 000000000..e8949b3f1 --- /dev/null +++ b/pivot_heat_map/static/src/js/pivot_renderer_extended.js @@ -0,0 +1,221 @@ +odoo.define('pivot_heat_map.renderer', function (require) { + "use strict"; + + var PivotRenderer = require('web.PivotRenderer'); + var field_utils = require('web.field_utils'); + var core = require('web.core'); + + var _t = core._t; + + PivotRenderer.include({ + get_total_col: function(rows, indent, col){ + var total = 0; + _.each(rows, function(rec){ + if(indent == rec.indent && rec.values[col]){ + total += rec.values[col]; + } + }); + return total; + }, + get_total_row: function(values, row, col){ + var total = 0; + var measures = this.state.measures.length; + + for (var i=col;i=0;i-=measures){ + total += values[i] ? values[i] : 0; + } + return total; + }, + + get_parent_index: function(indent, row, col){ + var rows = this.state.rows; + for (var i=row-1;i>=0;i--){ + if(rows[i].indent == indent-1){ + return (indent-1)+'-'+i+'-'+col; + } + } + }, + get_bg_color: function(value, row, col, indent){ + var index = indent+'-'+row+'-'+col; + if (value != 'undefined'){ + if(index in this.cells){ + return 'rgb(250,'+this.cells[index]+','+this.cells[index]+')'; + } + } + else{ + this.cells[index] = null; + return null; + } + }, + get_base_value: function(row, col, measures){ + for(var j=row.values.length-measures;j= cols-measures){ + cells[index] = 90; + continue; + } + /*other rows*/ + total = self.get_total_row(row.values, i, j); + + color_code = Math.floor(90 + 165*(total - Math.abs(value))/total); + cells[index] = color_code; + } + } + + } + } + break; + } + case 'both': { + /*setting first row and last columns as base*/ + for(i=0;i=0;j--){ + value = row.values[j]; + if(value != 'undefined'){ + index = row.indent+'-'+i+'-'+j; + if(!(index in cells)){ + if((j >= cols-measures) && i==0){ + cells[index] = 90; + continue; + } + else if(j >= cols-measures){ + total = self.get_total_col(rows, row.indent, j); + parent_index = self.get_parent_index(row.indent, i, j); + base = (parent_index && cells[parent_index]) ? cells[parent_index] : 90; + color_code = Math.floor(base + 165*(total - Math.abs(value))/total); + cells[index] = color_code; + } + else{ + total = self.get_total_row(row.values, i, j); + var parent_col = self.get_base_value(row, j, measures); + parent_index = parent_col ? (row.indent+'-'+i+'-'+parent_col):null; + base = parent_index ? cells[parent_index] : 90; + color_code = Math.floor(base + 165*(total - Math.abs(value))/total); + cells[index] = color_code; + } + } + } + } + } + } + } + this.cells = cells; + } + }, + _renderRowsHeat: function ($tbody, rows) { + var self = this; + /*setting cell colors*/ + this.update_cell_colors(rows); + var i, j, value, measure, name, $row, $cell, $header; + var nbrMeasures = this.state.measures.length; + var length = rows[0].values.length; + var shouldDisplayTotal = this.state.mainColWidth > 1; + var groupbyLabels = _.map(this.state.rowGroupBys, function (gb) { + return self.state.fields[gb.split(':')[0]].string; + }); + var measureTypes = this.state.measures.map(function (name) { + return self.state.fields[name].type; + }); + for (i = 0; i < rows.length; i++) { + $row = $(''); + $header = $('') + .text(rows[i].title) + .data('id', rows[i].id) + .css('padding-left', (5 + rows[i].indent * 30) + 'px') + .addClass(rows[i].expanded ? 'o_pivot_header_cell_opened' : 'o_pivot_header_cell_closed'); + if (rows[i].indent > 0) $header.attr('title', groupbyLabels[rows[i].indent - 1]); + $header.appendTo($row); + for (j = 0; j < length; j++) { + value = rows[i].values[j]; + if (value !== undefined) { + name = this.state.measures[j % nbrMeasures]; + measure = this.state.fields[name]; + value = field_utils.format[measureTypes[j % nbrMeasures]](value, measure); + } + /*fetching background color*/ + var bg_color = null; + if (value){ + bg_color = self.get_bg_color(value, i, j, rows[i].indent); + } + + $cell = $('') + .data('id', rows[i].id) + .data('col_id', rows[i].col_ids[Math.floor(j / nbrMeasures)]) + .toggleClass('o_empty', !value) + .text(value) + .addClass('o_pivot_cell_value text-right'); + if(bg_color != null){ + $cell.css({'background-color': bg_color}); + } + if (((j >= length - this.state.measures.length) && shouldDisplayTotal) || i === 0){ + $cell.css('font-weight', 'bold'); + } + $row.append($cell); + + $cell.toggleClass('hidden-xs', j < length - nbrMeasures); + } + $tbody.append($row); + } + }, + + _renderRows: function ($tbody, rows) { + var self = this; + if(this.heat_map != null){ + self._renderRowsHeat($tbody, rows); + } + else{ + this._super($tbody, rows); + } + } + }); +}); diff --git a/pivot_heat_map/static/src/xml/heat_map_buttons.xml b/pivot_heat_map/static/src/xml/heat_map_buttons.xml new file mode 100644 index 000000000..0ad7919fc --- /dev/null +++ b/pivot_heat_map/static/src/xml/heat_map_buttons.xml @@ -0,0 +1,10 @@ + + + + +